Best headless browser for AI agents. Lite, Fast, High-Compatibility. Built in Rust
Rust ai-agentsai-toolsbrowserbrowser-automationcloud-browserheadlessheadless-browserkitesurfplaywrightpuppeteerrustservoweb-crawlerweb-crawlingweb-scraperweb-scraping
test(wpt): support HTTPS and load-driven Window fixtures
ldm0163b67f36b3e
diff --git a/moli-core/tests/wpt_compat.rs b/moli-core/tests/wpt_compat.rsindex 72829289e..69ee0c783 100644--- a/moli-core/tests/wpt_compat.rs+++ b/moli-core/tests/wpt_compat.rs@@ -76,6 +76,8 @@ wpt_compat_cases! {wpt_compat_case_eventtarget_idlharness => "eventtarget-idlharness",wpt_compat_case_idlharness_shim_basic => "idlharness-shim-basic",wpt_compat_case_testharness_dom_exception_assertions => "testharness-dom-exception-assertions",+ wpt_compat_case_testharness_load_driven_crashtest => "testharness-load-driven-crashtest",+ wpt_compat_case_testharness_no_handler_crashtest => "testharness-no-handler-crashtest",wpt_compat_case_cssstyledeclaration_idlharness => "cssstyledeclaration-idlharness",wpt_compat_case_cssstylesheet_idlharness => "cssstylesheet-idlharness",wpt_compat_case_upstream_css_css_properties_values_api_property_cascade => "upstream-css-css-properties-values-api-property-cascade",diff --git a/moli-wpt-compat/fixtures/wpt/expected.toml b/moli-wpt-compat/fixtures/wpt/expected.tomlindex a469e4e8f..a689a8ffa 100644--- a/moli-wpt-compat/fixtures/wpt/expected.toml+++ b/moli-wpt-compat/fixtures/wpt/expected.toml@@ -1740,3 +1740,9 @@ status = "pass"[expectations.idlharness-shim-basic]status = "pass"++[expectations.testharness-load-driven-crashtest]+status = "pass"++[expectations.testharness-no-handler-crashtest]+status = "pass"diff --git a/moli-wpt-compat/fixtures/wpt/manifest.toml b/moli-wpt-compat/fixtures/wpt/manifest.tomlindex 88936a602..73448177b 100644--- a/moli-wpt-compat/fixtures/wpt/manifest.toml+++ b/moli-wpt-compat/fixtures/wpt/manifest.toml@@ -20647,3 +20647,31 @@ timeout_ms = 5000suite = "broad"tags = ["testharness", "domexception", "cross-realm"]notes = "Local harness canary for implicit and explicit DOMException constructors, cross-realm exceptions, and rejection of incorrect constructors or missing exceptions."++[[test]]+id = "testharness-load-driven-crashtest"+upstream = "local load-driven Window crashtest harness regression"+upstream_commit = "local-regression-2026-10-04"+local_path = "ported/harness/load-driven-crash.https.html"+type = "crashtest"+global = "window"+status = "pass"+wait_until = "load"+timeout_ms = 5000+suite = "broad"+tags = ["testharness", "crashtest"]+notes = "Exercise HTTPS fixture selection and load-driven crash reporting independently of browser features."++[[test]]+id = "testharness-no-handler-crashtest"+upstream = "local load-driven Window crashtest harness regression"+upstream_commit = "local-regression-2026-10-04"+local_path = "ported/harness/no-handler-crash.https.html"+type = "crashtest"+global = "window"+status = "pass"+wait_until = "load"+timeout_ms = 5000+suite = "broad"+tags = ["testharness", "crashtest"]+notes = "Exercise HTTPS fixture selection and load-driven crash reporting independently of browser features."diff --git a/moli-wpt-compat/fixtures/wpt/ported/harness/dom-exception-assertions.html b/moli-wpt-compat/fixtures/wpt/ported/harness/dom-exception-assertions.htmlindex ac9629970..cfa655b12 100644--- a/moli-wpt-compat/fixtures/wpt/ported/harness/dom-exception-assertions.html+++ b/moli-wpt-compat/fixtures/wpt/ported/harness/dom-exception-assertions.html@@ -45,4 +45,33 @@ test(() => {const error = new AssertionError("nested assertion");assert_throws_exactly(error, () => assert_throws_dom("AbortError", () => { throw error; }));}, "DOM exception assertions reject mismatches and preserve nested assertions");++promise_test(async t => {+ const error = new DOMException("canceled", "AbortError");+ await promise_rejects_dom(t, "AbortError", Promise.reject(error));+ await promise_rejects_dom(t, "AbortError", Promise.reject(error), "implicit constructor");+ await promise_rejects_dom(t, "AbortError", DOMException, Promise.reject(error));+}, "DOM promise assertions accept implicit and explicit constructors");++promise_test(async t => {+ const frame = document.createElement("iframe");+ document.body.appendChild(frame);+ t.add_cleanup(() => frame.remove());+ const ForeignDOMException = frame.contentWindow.DOMException;+ const error = new ForeignDOMException("canceled", "AbortError");+ await promise_rejects_dom(t, "AbortError", ForeignDOMException, Promise.reject(error));+ await promise_rejects_js(t, AssertionError,+ promise_rejects_dom(t, "AbortError", DOMException, Promise.reject(error)));+ await promise_rejects_js(t, AssertionError,+ promise_rejects_dom(t, "AbortError", ForeignDOMException,+ Promise.reject(new DOMException("canceled", "AbortError"))));+}, "DOM promise assertions enforce the explicit constructor's realm");++promise_test(async t => {+ let ready = false;+ t.step_timeout(() => { ready = true; }, 0);+ await t.step_wait(() => ready, "a browser task updates the condition", 3000, 0);+ assert_true(ready);+}, "step_wait resolves after its condition becomes true");+</script>diff --git a/moli-wpt-compat/fixtures/wpt/ported/harness/load-driven-crash.https.html b/moli-wpt-compat/fixtures/wpt/ported/harness/load-driven-crash.https.htmlnew file mode 100644index 000000000..801ef869b--- /dev/null+++ b/moli-wpt-compat/fixtures/wpt/ported/harness/load-driven-crash.https.html@@ -0,0 +1,15 @@+<!doctype html><body>+<script>+window.onload = async function() {+ if (this !== window || location.protocol !== 'https:') throw new Error('load context or HTTPS origin was lost');+ const frame = document.body.appendChild(document.createElement('iframe'));+ frame.remove();+ await Promise.resolve();+ const checkpoint = new MessageChannel();+ await new Promise(resolve => {+ checkpoint.port1.onmessage = resolve;+ checkpoint.port2.postMessage('author task');+ });+ checkpoint.port1.close();checkpoint.port2.close();+};+</script>diff --git a/moli-wpt-compat/fixtures/wpt/ported/harness/no-handler-crash.https.html b/moli-wpt-compat/fixtures/wpt/ported/harness/no-handler-crash.https.htmlnew file mode 100644index 000000000..e3ad542b0--- /dev/null+++ b/moli-wpt-compat/fixtures/wpt/ported/harness/no-handler-crash.https.html@@ -0,0 +1 @@+<!doctype html><body><div>Load-driven crash fixture without an onload handler</div>diff --git a/moli-wpt-compat/fixtures/wpt/resources/testharness.js b/moli-wpt-compat/fixtures/wpt/resources/testharness.jsindex 3caab9a4f..9381e8c89 100644--- a/moli-wpt-compat/fixtures/wpt/resources/testharness.js+++ b/moli-wpt-compat/fixtures/wpt/resources/testharness.js@@ -115,6 +115,16 @@}function installWaitHelpers(context) {+ context.step_wait = function (+ condition,+ description,+ timeout = 3000,+ interval = 100,+ ) {+ return new Promise(resolve => {+ context.step_wait_func(condition, resolve, description, timeout, interval);+ });+ };context.step_wait_func = function (condition,callback,@@ -723,7 +733,11 @@INDEX_SIZE_ERR: "IndexSizeError",};- global.promise_rejects_dom = function (test, name, promise, description) {+ global.promise_rejects_dom = function (test, name, constructorOrPromise, promiseOrDescription, description) {+ const hasConstructor = typeof constructorOrPromise === 'function';+ const constructor = hasConstructor ? constructorOrPromise : global.DOMException;+ const promise = hasConstructor ? promiseOrDescription : constructorOrPromise;+ description = hasConstructor ? description : promiseOrDescription;const expectedName = domExceptionLegacyNames[name] || name;return Promise.resolve(promise).then(function () {@@ -731,6 +745,10 @@},function (error) {if (error && error.name === expectedName) {+ if (hasConstructor) {+ global.assert_true(error instanceof constructor,+ (description || 'promise_rejects_dom') + ': exception belongs to the supplied realm');+ }return;}throw assertionError(diff --git a/moli-wpt-compat/src/runner.rs b/moli-wpt-compat/src/runner.rsindex ff1be444e..9fbd01d40 100644--- a/moli-wpt-compat/src/runner.rs+++ b/moli-wpt-compat/src/runner.rs@@ -69,13 +69,22 @@ pub fn collect_wpt_report_snapshot_expression() -> &'static str {}fn validate_supported_manifest_entry(test: &WptManifestTest) -> Result<()> {- if !matches!(test.test_type.as_str(), "testharness" | "idlharness") {+ if !matches!(+ test.test_type.as_str(),+ "testharness" | "idlharness" | "crashtest"+ ) {return Err(anyhow!("unsupported WPT test type '{}' for {}",test.test_type,test.id));}+ if test.test_type == "crashtest" && test.global != "window" {+ return Err(anyhow!(+ "load-driven crashtests require the Window global for {}",+ test.id+ ));+ }if !matches!(test.global.as_str(), "window" | "worker" | "sharedworker") {return Err(anyhow!("unsupported WPT global '{}' for {}",diff --git a/moli-wpt-compat/src/server.rs b/moli-wpt-compat/src/server.rsindex ed7462283..0c3a61dd1 100644--- a/moli-wpt-compat/src/server.rs+++ b/moli-wpt-compat/src/server.rs@@ -233,6 +233,7 @@ fn wpt_tls_acceptor() -> Result<TlsAcceptor> {pub struct WptFixtureServer {addr: std::net::SocketAddr,+ https_addr: std::net::SocketAddr,shutdown_txs: Vec<oneshot::Sender<()>>,tasks: Vec<JoinHandle<()>>,}@@ -329,6 +330,7 @@ impl WptFixtureServer {Ok(Self {addr,+ https_addr: primary_https_addr,shutdown_txs: vec![primary_shutdown_tx,secondary_shutdown_tx,@@ -349,13 +351,23 @@ impl WptFixtureServer {}pub fn case_url(&self, test: &WptManifestTest) -> String {- wpt_case_url(- self.addr,+ let secure =+ test.origin == WptManifestOrigin::Trusted && test.local_path.contains(".https.");+ let mut url = wpt_case_url(+ if secure { self.https_addr } else { self.addr },&test.local_path,&test.global,&test.query,test.origin,- )+ );+ if test.test_type == "crashtest" {+ append_raw_query(&mut url, "moli-wpt-crashtest=1");+ }+ if secure {+ url.replacen("http:", "https:", 1)+ } else {+ url+ }}pub fn fixture_url(&self, local_path: &str) -> String {@@ -366,6 +378,7 @@ impl WptFixtureServer {pub(crate) fn for_test_addr(addr: std::net::SocketAddr) -> Self {Self {addr,+ https_addr: addr,shutdown_txs: Vec::new(),tasks: Vec::new(),}@@ -1179,6 +1192,11 @@ async fn read_static_wpt_fixture_body(if wpt_fixture_needs_text_processing(fixture_path, content_type) {let source = tokio::fs::read_to_string(fs_path).await?;let source = apply_wpt_substitutions(fixture_path, source, runtime_state, query);+ let source = if query.contains_key("moli-wpt-crashtest") {+ wpt_crashtest_wrapper_html(source)+ } else {+ source+ };let mut response = static_text_response(adapt_upstream_html_fixture(fixture_path, source),content_type,@@ -1482,6 +1500,31 @@ fn wpt_fixture_host_port(runtime_state: &WptFixtureRuntimeState) -> String {format!("{}:{}", WPT_BROWSER_HOST, runtime_state.primary_addr.port())}+// Chromium's load-driven crashtests have no testharness report. Keep their+// source intact and observe completion of the load handler and a subsequent+// browser task, so queued cancellation/navigation work runs before teardown.+fn wpt_crashtest_wrapper_html(mut source: String) -> String {+ let scripts = r#"<script src="/resources/testharness.js"></script><script src="/resources/testharnessreport.js"></script><script src="/wpt/resources/moli-wpt-adapter.js"></script>"#;+ let insertion = source.find("<script").unwrap_or(source.len());+ source.insert_str(insertion, scripts);+ source.push_str(+ r#"<script>+const crashTest = async_test('Load handler and renderer remain live');+const crashLoad = window.onload;+window.onload = event => {+ Promise.resolve().then(() => typeof crashLoad === 'function' ? crashLoad.call(window, event) : undefined).then(() => {+ const checkpoint = new MessageChannel();+ checkpoint.port1.onmessage = crashTest.step_func_done(() => {+ checkpoint.port1.close(); checkpoint.port2.close();+ });+ checkpoint.port2.postMessage(null);+ }, crashTest.step_func(error => { throw error; }));+};+</script>"#,+ );+ source+}+fn adapt_upstream_html_fixture(path: &str, source: String) -> String {if !path.starts_with("upstream/") || !(path.ends_with(".html") || path.ends_with(".htm")) {return source;@@ -3219,6 +3262,39 @@ fn binary_response(bytes: &'static [u8]) -> Response {mod tests {use super::*;+ #[test]+ fn fixture_case_urls_use_https_port_only_for_trusted_https_cases() {+ let mut server = WptFixtureServer::for_test_addr("127.0.0.1:12345".parse().unwrap());+ server.https_addr = "127.0.0.1:23456".parse().unwrap();+ let mut case = crate::load_manifest_case("testharness-dom-exception-assertions")+ .unwrap()+ .unwrap();+ case.local_path = "upstream/example/sample.https.any.js".into();+ case.query = "1-10".into();+ assert_eq!(+ server.case_url(&case),+ "https://localhost:23456/wpt/upstream/example/sample.https.any.js?1-10&moli-wpt-window-wrapper=1"+ );+ case.origin = WptManifestOrigin::Insecure;+ assert_eq!(+ server.case_url(&case),+ "http://0.0.0.0:12345/wpt/upstream/example/sample.https.any.js?1-10&moli-wpt-window-wrapper=1"+ );+ case.origin = WptManifestOrigin::Trusted;+ case.local_path = "ported/harness/sample.html".into();+ case.query.clear();+ assert_eq!(+ server.case_url(&case),+ "http://localhost:12345/wpt/ported/harness/sample.html"+ );+ case.local_path = "ported/harness/sample.https.html".into();+ case.test_type = "crashtest".into();+ assert_eq!(+ server.case_url(&case),+ "https://localhost:23456/wpt/ported/harness/sample.https.html?moli-wpt-crashtest=1"+ );+ }+#[test]fn sanitize_wpt_fixture_path_rejects_escape_components() {assert!(sanitize_wpt_fixture_path("../manifest.toml").is_none());