Truly independent web browser
LibWeb: Import origin-keyed agent cluster coverage
Andreas Klingecd8629730c2
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 70fc16a2777..8608af32676 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -1,4 +1,5 @@[LoadFromHttpServer]+Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/Text/input/HTML/xml-document-encoding.htmlText/input/HTML/createImageBitmap-video.htmlText/input/HTML/HTMLVideoElement-capture-before-seek-keeps-frame.html@@ -1145,6 +1146,7 @@ Text/input/visual-viewport-horizontal-scroll-hit-test.htmlText/input/visual-viewport-scrollend-after-pan.html[LoadFromInsecureOrigin]+Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.htmlText/input/HTML/page-from-an-insecure-origin-is-not-a-secure-context.html; A frame nested in its localhost iframe prohibits mixed security contexts while this page does not.Text/input/SiteIsolation/iframe/mixed-content-of-an-isolated-iframes-navigation-is-decided-by-the-iframe.htmldiff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.txtnew file mode 100644index 00000000000..863bbd7f843--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.txt@@ -0,0 +1,27 @@+Harness status: OK++Found 21 tests++7 Pass+14 Fail+Pass "": frame insertion+Fail "": setting document.domain must give sync access+Fail "": originAgentCluster must equal false+Pass "?0": frame insertion+Fail "?0": setting document.domain must give sync access+Fail "?0": originAgentCluster must equal false+Pass "true": frame insertion+Fail "true": setting document.domain must give sync access+Fail "true": originAgentCluster must equal false+Pass ""?1"": frame insertion+Fail ""?1"": setting document.domain must give sync access+Fail ""?1"": originAgentCluster must equal false+Pass "1": frame insertion+Fail "1": setting document.domain must give sync access+Fail "1": originAgentCluster must equal false+Pass "?2": frame insertion+Fail "?2": setting document.domain must give sync access+Fail "?2": originAgentCluster must equal false+Pass "(?1)": frame insertion+Fail "(?1)": setting document.domain must give sync access+Fail "(?1)": originAgentCluster must equal false\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.txtnew file mode 100644index 00000000000..9c5db26b287--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++1 Pass+3 Fail+Fail messageerror event must occur+Pass setting document.domain must not give sync access+Fail parent: originAgentCluster must equal false+Fail child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.txtnew file mode 100644index 00000000000..60eef0aaf63--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 3 tests++1 Pass+2 Fail+Pass setting document.domain must give sync access+Fail parent: originAgentCluster must equal true+Fail child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.txtnew file mode 100644index 00000000000..4255b9c98ff--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.txt@@ -0,0 +1,10 @@+Harness status: OK++Found 4 tests++1 Pass+3 Fail+Fail messageerror event must occur+Pass setting document.domain must not give sync access+Fail parent: originAgentCluster must equal true+Fail child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.txtnew file mode 100644index 00000000000..f8dabc89fef--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++3 Pass+5 Fail+Pass parent to about:blank: setting document.domain must give sync access+Fail about:blank to child2: messageerror event must occur+Pass about:blank to child2: setting document.domain must not give sync access+Fail child2 to about:blank: messageerror event must occur+Pass child2 to about:blank: setting document.domain must not give sync access+Fail parent: originAgentCluster must equal true+Fail about:blank: originAgentCluster must equal true+Fail child2: originAgentCluster must equal false\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.txtnew file mode 100644index 00000000000..1bcb94a5e73--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.txt@@ -0,0 +1,7 @@+Harness status: OK++Found 2 tests++2 Fail+Fail self: originAgentCluster must equal true+Fail child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.txtnew file mode 100644index 00000000000..eb932500534--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail data: URL child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.txtnew file mode 100644index 00000000000..dc7cd722920--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Fail+Fail originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.txtnew file mode 100644index 00000000000..1a3a9c647fb--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.txt@@ -0,0 +1,6 @@+Harness status: OK++Found 1 tests++1 Pass+Pass Sending a WebAssembly.Module between two sandboxed iframes must fire messageerror\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.txtnew file mode 100644index 00000000000..5f8cb08c9c0--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.txt@@ -0,0 +1,14 @@+Harness status: OK++Found 8 tests++3 Pass+5 Fail+Pass Before: parent to child: setting document.domain must give sync access+Fail before parent: originAgentCluster must equal false+Fail before child: originAgentCluster must equal false+Pass Navigation+Fail After: parent to child: messageerror event must occur+Pass After: parent to child: setting document.domain must not give sync access+Fail after parent: originAgentCluster must equal false+Fail after child: originAgentCluster must equal true\ No newline at end of filediff --git a/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.txt b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.txtnew file mode 100644index 00000000000..4ad2fbf8fdc--- /dev/null+++ b/Tests/LibWeb/Text/expected/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.txt@@ -0,0 +1,9 @@+Harness status: OK++Found 3 tests++1 Pass+2 Fail+Pass setting document.domain must give sync access+Fail parent: originAgentCluster must equal false+Fail child: originAgentCluster must equal false\ No newline at end of filediff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.htmlnew file mode 100644index 00000000000..dc12f37073d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-bad-subdomain.sub.https.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent is site-keyed, child attempts to origin-key but uses a bad header value, child is a subdomain of the parent</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ testSameAgentCluster,+ testGetter+} from "../resources/helpers.mjs";++let frameIndex = 0;+for (const badValue of ["", "?0", "true", "\"?1\"", "1", "?2", "(?1)"]) {+ promise_test(async () => {+ await insertIframe("{{hosts[][www]}}", badValue);+ }, `"${badValue}": frame insertion`);++ // Since the header values are bad they should be site-keyed.+ testSameAgentCluster([self, frameIndex], `"${badValue}"`);+ testGetter(frameIndex, false, `"${badValue}"`);+ ++frameIndex;+}+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.htmlnew file mode 100644index 00000000000..9fb7faa4755--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-no-child-yeswithparams-subdomain.sub.https.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent is site-keyed, child is origin-keyed using parameters on its structured header, child is a subdomain of the parent</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ testDifferentAgentClusters,+ testGetter+} from "../resources/helpers.mjs";++promise_setup(async () => {+ await insertIframe("{{hosts[][www]}}", "?1;param1;param2=value2");+});++// Since they're different-origin, the child's request is respected, so the+// parent ends up in the site-keyed agent cluster and the child in the+// origin-keyed one.+testDifferentAgentClusters([self, 0]);++testGetter(self, false, "parent");+testGetter(0, true, "child");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.htmlnew file mode 100644index 00000000000..72e6f2f711e--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.html@@ -0,0 +1,26 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent is origin-keyed, child is site-keyed, child is same-origin to the parent</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ testSameAgentCluster,+ testGetter+} from "../resources/helpers.mjs";++promise_setup(async () => {+ await insertIframe("{{hosts[][]}}");+});++// Since they're same-origin, and the parent loaded with origin-keying, the+// child's non-request gets ignored, and both end up origin-keyed.+testSameAgentCluster([self, 0]);++testGetter(self, true, "parent");+testGetter(0, true, "child");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-no-same.sub.https.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.htmlnew file mode 100644index 00000000000..292c9ecbc41--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent is origin-keyed, child is site-keyed, child is a subdomain of the parent</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ testDifferentAgentClusters,+ testGetter+} from "../resources/helpers.mjs";++promise_setup(async () => {+ await insertIframe("{{hosts[][www]}}", "?1");+});++// Both request origin-keying, so the parent ends up in one origin-keyed agent+// cluster (the base domain's origin), and the child ends up in a different+// origin-keyed agent cluster (the www subdomain's origin).+testDifferentAgentClusters([self, 0]);++testGetter(self, true, "parent");+testGetter(0, true, "child");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/1-iframe/parent-yes-child-yes-subdomain.sub.https.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.htmlnew file mode 100644index 00000000000..975fe3b6cc4--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.html@@ -0,0 +1,64 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>The initial about:blank respects origin isolation</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ setBothDocumentDomains,+ testSameAgentCluster,+ testDifferentAgentClusters,+ testGetter+} from "./resources/helpers.mjs";++promise_setup(async () => {+ await insertAboutBlankIframe();+ await insertIframe("{{hosts[][www]}}");+});++// Since the initial about:blank inherits its origin from its parent, it is+// same-origin with the parent, and thus cross-origin with child2.+testSameAgentCluster([self, 0], "parent to about:blank");+testDifferentAgentClusters([0, 1], "about:blank to child2");+testDifferentAgentClusters([1, 0], "child2 to about:blank");++testGetter(self, true, "parent");+testGetter(0, true, "about:blank");+testGetter(1, false, "child2");++async function insertAboutBlankIframe() {+ const iframe = await createBlankIframe();++ // Now create and add the script, but don't navigate anywhere (since we want+ // to stay on the initial about:blank).+ // We need to absolutize the URL to since about:blank doesn't have a base URL.+ const scriptURL = (new URL("./resources/send-header-page-script.mjs", import.meta.url)).href;+ const script = iframe.contentDocument.createElement("script");+ script.type = "module";+ script.src = scriptURL;++ await new Promise((resolve, reject) => {+ script.onload = resolve;+ script.onerror = () => reject(+ new Error("Could not load the child frame script into the about:blank page")+ );+ iframe.contentDocument.body.append(script);+ });++ await setBothDocumentDomains(iframe.contentWindow);+}++async function createBlankIframe() {+ const iframe = document.createElement("iframe");+ const promise = new Promise(resolve => {+ iframe.addEventListener("load", resolve);+ });+ document.body.append(iframe);+ await promise;+ return iframe;+}+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/about-blank.https.sub.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.htmlnew file mode 100644index 00000000000..6fffe2454f3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.html@@ -0,0 +1,28 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>window.originAgentCluster must be implied by cross-origin isolation</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<iframe src="//{{domains[www1]}}:{{location[port]}}/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html"></iframe>++<div id="log"></div>++<script type="module">+import { testGetter } from "../resources/helpers.mjs";++setup({ explicit_done: true });++window.onload = () => {+ // Cross-origin isolated pages are always origin-keyed.+ testGetter(self, true, "self");++ // Child frames of cross-origin isolated pages must also be cross-origin+ // isolated, and thus also origin-keyed. Make sure the implementation doesn't+ // treat them specially in some weird way, for the purposes of this+ // implication.+ testGetter(0, true, "child");++ done();+};+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.html.headersnew file mode 100644index 00000000000..5f8621ef836--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/cross-origin-isolated.sub.https.html.headers@@ -0,0 +1,2 @@+Cross-Origin-Embedder-Policy: require-corp+Cross-Origin-Opener-Policy: same-origindiff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.htmlnew file mode 100644index 00000000000..becbe5827ff--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/data-url-no.https.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>window.originAgentCluster for a data: URL on a site-keyed page</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import runTest from "./resources/data-url-test.mjs";+runTest();+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.htmlnew file mode 100644index 00000000000..fdfdbf70d61--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>window.originAgentCluster for a javascript: URL on an origin-keyed page</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import runTest from "./resources/javascript-url-test.mjs";+runTest({ expected: true });+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/javascript-url-yes.https.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/data-url-test.mjs b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/data-url-test.mjsnew file mode 100644index 00000000000..1a9b3be47f6--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/data-url-test.mjs@@ -0,0 +1,13 @@+import { insertCustomIframe, testSupportScript } from "./helpers.mjs";+import { testGetter } from "../../resources/helpers.mjs";++export default () => {+ promise_setup(() => {+ return insertCustomIframe(`data:text/html,${testSupportScript}`);+ });++ // The data: URL iframe has an opaque origin, so it should return true, since+ // for them site === origin so they are always origin-keyed.++ testGetter(0, true, "data: URL child");+};diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/helpers.mjs b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/helpers.mjsnew file mode 100644index 00000000000..4610ffcad0a--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/helpers.mjs@@ -0,0 +1,28 @@+import { waitForIframe } from "../../resources/helpers.mjs";++/**+ * Inserts an iframe, not specialized for origin-keyed agent cluster testing,+ * pointing to a custom URL. This is just a wrapper to remove some boilerplate.+ * @param {string} src - The src="" value for the iframe+ */+export async function insertCustomIframe(src) {+ const iframe = document.createElement("iframe");+ iframe.src = src;++ const waitPromise = waitForIframe(iframe);+ document.body.append(iframe);+ await waitPromise;++ return iframe;+}++/**+ * This is the part of send-oac-header.py that allows us to reuse testGetter.+ */+export const testSupportScript = `+ <script>+ window.onmessage = () => {+ parent.postMessage(self.originAgentCluster, "*");+ };+ </script>+`;diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/javascript-url-test.mjs b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/javascript-url-test.mjsnew file mode 100644index 00000000000..de474d8cafc--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/resources/javascript-url-test.mjs@@ -0,0 +1,14 @@+import { insertCustomIframe, testSupportScript } from "./helpers.mjs";+import { testGetter } from "../../resources/helpers.mjs";++export default ({ expected }) => {+ promise_setup(() => {+ return insertCustomIframe(`javascript:'${testSupportScript}'`);+ });++ // The javascript: URL iframe inherits its origin from the previous occupant+ // of the iframe, which is about:blank, which in turn inherits from the+ // parent. So, the caller needs to tell us what to expect.++ testGetter(0, expected);+};diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.htmlnew file mode 100644index 00000000000..27ab38ef15c--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/getter-special-cases/two-sandboxed-iframes.https.html@@ -0,0 +1,59 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Two sandboxed iframes are in different agent clusters</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+// Each sandboxed iframe (without allow-same-origin) gets a unique opaque+// origin and so should be in its own agent cluster. Sending a+// WebAssembly.Module from one sandboxed iframe to another should therefore+// fire messageerror, not a successful message event.++const helperSrcdoc = `+ <script>+ addEventListener("message", e => {+ if (e.data && e.data.cmd === "send-wasm") {+ const wasm = new WebAssembly.Module(new Uint8Array([0,97,115,109,1,0,0,0]));+ parent.frames[e.data.targetIndex].postMessage(wasm, "*");+ return;+ }+ if (e.data instanceof WebAssembly.Module) {+ parent.postMessage({ result: "message" }, "*");+ }+ });+ addEventListener("messageerror", () => {+ parent.postMessage({ result: "messageerror" }, "*");+ });+ <\/script>+`;++function insertSandboxedIframe() {+ const iframe = document.createElement("iframe");+ iframe.sandbox = "allow-scripts";+ iframe.srcdoc = helperSrcdoc;+ const loaded = new Promise(resolve => iframe.addEventListener("load", resolve));+ document.body.append(iframe);+ return loaded.then(() => iframe);+}++function nextResult() {+ return new Promise(resolve => {+ addEventListener("message", e => {+ if (e.data && e.data.result)+ resolve(e.data.result);+ }, { once: true });+ });+}++promise_test(async () => {+ const iframe1 = await insertSandboxedIframe();+ await insertSandboxedIframe();++ const result = nextResult();+ iframe1.contentWindow.postMessage({ cmd: "send-wasm", targetIndex: 1 }, "*");+ assert_equals(await result, "messageerror");+}, "Sending a WebAssembly.Module between two sandboxed iframes must fire messageerror");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.htmlnew file mode 100644index 00000000000..7d8a579dea3--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/iframe-navigation/parent-no-1-no-same-2-yes-subdomain.sub.https.html@@ -0,0 +1,41 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent is site-keyed, navigate a frame from same-origin site-keyed to different-origin (subdomain) origin-keyed</title>+<script src="../../../../../resources/testharness.js"></script>+<script src="../../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ navigateIframe,+ setBothDocumentDomains,+ testSameAgentCluster,+ testDifferentAgentClusters,+ testGetter+} from "../resources/helpers.mjs";++let frame1;+promise_setup(async () => {+ frame1 = await insertIframe("{{hosts[][]}}");+});++// Nobody requested origin-keying yet.++testSameAgentCluster([self, 0], "Before: parent to child");+testGetter(self, false, "before parent");+testGetter(0, false, "before child");++promise_test(async () => {+ await navigateIframe(frame1, "{{hosts[][www]}}", "?1");+ await setBothDocumentDomains(frames[0]);+}, "Navigation");++// Since the new page is different-origin, its origin-keying request should be+// respected.++testDifferentAgentClusters([self, 0], "After: parent to child");+testGetter(self, false, "after parent");+testGetter(0, true, "after child");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.htmlnew file mode 100644index 00000000000..67f63716713--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.html@@ -0,0 +1,27 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>Parent requests origin-keying, child requests origin-keying, child is same-origin with the parent, but all over insecure HTTP</title>+<script src="../../../../resources/testharness.js"></script>+<script src="../../../../resources/testharnessreport.js"></script>++<div id="log"></div>++<script type="module">+import {+ insertIframe,+ testSameAgentCluster,+ testGetter+} from "./resources/helpers.mjs";++promise_setup(async () => {+ // NB: The text runner assigns this fixture an isolated insecure host. Keep its child on that host.+ await insertIframe(location.host, "?1");+});++// All origin-keying requests are ignored, since this is over insecure HTTP.+// So both end up in the site-keyed agent cluster.+testSameAgentCluster([self, 0]);++testGetter(self, false, "parent");+testGetter(0, false, "child");+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/insecure-http.sub.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.htmlnew file mode 100644index 00000000000..7cbd89b943f--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html@@ -0,0 +1,5 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>A page with COEP set that will respond when asked</title>++<script type="module" src="send-header-page-script.mjs"></script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html.headersnew file mode 100644index 00000000000..4e798cd9f5d--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/coep-frame.html.headers@@ -0,0 +1,2 @@+Cross-Origin-Embedder-Policy: require-corp+Cross-Origin-Resource-Policy: cross-origindiff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.html b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.htmlnew file mode 100644index 00000000000..537de07b140--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.html@@ -0,0 +1,12 @@+<!DOCTYPE html>+<meta charset="utf-8">+<title>A frame included by a test page</title>++<script>+window.onmessage = e => {+ if (e.data.type === "set document.domain") {+ document.domain = e.data.newValue;+ e.source.postMessage({ type: "new document.domain", result: document.domain }, "*");+ }+};+</script>diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.html.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.html.headersnew file mode 100644index 00000000000..79a20f30fc0--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/frame.html.headers@@ -0,0 +1 @@+Origin-Agent-Cluster: ?1diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjs b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjsnew file mode 100644index 00000000000..6bad76e3d91--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjs@@ -0,0 +1,390 @@+/**+ * Inserts an iframe usable for origin-keyed agent cluster testing, and returns+ * a promise fulfilled when the iframe is loaded and its document.domain is set.+ * The iframe will point to the send-oac-header.py file, on the designated+ * host.+ * @param {string} host - The host used to calculate the iframe's src=""+ * @param {string=} header - The value of the Origin-Agent-Cluster header that+ * the iframe will set. Omit this to set no header.+ * @param {object=} options - Rarely-used options.+ * @param {boolean=} options.redirectFirst - Whether to do a 302 redirect first+ * before arriving at the page that sets the header. The redirecting page will+ * not set the Origin-Agent-Cluster header.+ * @returns {HTMLIFrameElement} The created iframe element+ */+export async function insertIframe(host, header, { redirectFirst = false } = {}) {+ const iframe = document.createElement("iframe");+ const navigatePromise = navigateIframe(iframe, host, header, { redirectFirst });+ document.body.append(iframe);+ await navigatePromise;+ await setBothDocumentDomains(iframe.contentWindow);+ return iframe;+}++/**+ * Navigates an iframe to a page for origin-keyed agent cluster testing, similar+ * to insertIframe but operating on an existing iframe.+ * @param {HTMLIFrameElement} iframeEl - The <iframe> element to navigate+ * @param {string} host - The host to calculate the iframe's new src=""+ * @param {string=} header - The value of the Origin-Agent-Cluster header that+ * the newly-navigated-to page will set. Omit this to set no header.+ * @param {object=} options - Rarely-used options.+ * @param {boolean=} options.redirectFirst - Whether to do a 302 redirect first+ * before arriving at the page that sets the header. The redirecting page will+ * not set the Origin-Agent-Cluster header.+ * @returns {Promise} a promise fulfilled when the load event fires, or rejected+ * if the error event fires+ */+export function navigateIframe(iframeEl, host, header, { redirectFirst = false } = {}) {+ const url = getSendHeaderURL(host, header, { redirectFirst });++ const waitPromise = waitForIframe(iframeEl, url);+ iframeEl.src = url;+ return waitPromise;+}++/**+ * Returns a promise that is fulfilled when an iframe's load event fires, or+ * rejected when its error event fires.+ * @param {HTMLIFrameElement} iframeEl - The <iframe> element to wait on+ * @param {string} destinationForErrorMessage - A string used in the promise+ * rejection error message, if the error event fires+ * @returns {Promise} a promise fulfilled when the load event fires, or rejected+ * if the error event fires+ */+export function waitForIframe(iframeEl, destinationForErrorMessage) {+ return new Promise((resolve, reject) => {+ iframeEl.addEventListener("load", () => resolve());+ iframeEl.addEventListener(+ "error",+ () => reject(new Error(`Could not navigate to ${destinationForErrorMessage}`))+ );+ });+}++/**+ * Opens a new window usable for origin-keyed agent cluster testing, and returns+ * a promise fulfilled when the window is loaded and its document.domain is set.+ * The window will point to the send-oac-header.py file, on the designated host.+ *+ * The opened window will be automatically closed when all the tests complete.+ * @param {string} host - The host used to calculate the window's URL+ * @param {string=} header - The value of the Origin-Agent-Cluster header that+ * the opened window's page will set. Omit this to set no header.+ * @returns {WindowProxy} The created window+ */+export async function openWindow(host, header) {+ const url = getSendHeaderURL(host, header, { sendLoadedMessage: true });+ const openedWindow = window.open(url);++ add_completion_callback(() => openedWindow.close());++ const whatHappened = await waitForMessage(openedWindow);+ assert_equals(whatHappened, "loaded");++ await setBothDocumentDomains(openedWindow);++ return openedWindow;+}++/**+ * Expands into a pair of promise_test() calls to ensure that two Windows are in+ * the same agent cluster, by checking both that we can send a+ * WebAssembly.Module, and that we can synchronously access the DOM.+ * @param {Array} testFrames - An array of either the form [self, frameIndex] or+ * [frameIndex1, frameIndex2], indicating the two Windows under test. E.g.+ * [self, 0] or [0, 1].+ * @param {string=} testLabelPrefix - A prefix used in the test names. This can+ * be omitted if testSameAgentCluster is only used once in a test file.+ */+export function testSameAgentCluster(testFrames, testLabelPrefix) {+ const prefix = testLabelPrefix === undefined ? "" : `${testLabelPrefix}: `;++ if (testFrames[0] === self) {+ // Between parent and a child at the index given by testFrames[1]++ promise_test(async () => {+ const frameWindow = frames[testFrames[1]];+ const frameElement = document.querySelectorAll("iframe")[testFrames[1]];++ // Must not throw+ frameWindow.document;++ // Must not throw+ frameWindow.location.href;++ assert_not_equals(frameElement.contentDocument, null, "contentDocument");++ const whatHappened = await accessFrameElement(frameWindow);+ assert_equals(whatHappened, "frameElement accessed successfully");+ }, `${prefix}setting document.domain must give sync access`);+ } else {+ // Between the two children at the index given by testFrames[0] and+ // testFrames[1]++ promise_test(async () => {+ const whatHappened1 = await accessDocumentBetween(testFrames);+ assert_equals(whatHappened1, "accessed document successfully");++ const whatHappened2 = await accessLocationHrefBetween(testFrames);+ assert_equals(whatHappened2, "accessed location.href successfully");++ // We don't test contentDocument/frameElement for these because accessing+ // those via siblings has to go through the parent anyway.+ }, `${prefix}setting document.domain must give sync access`);+ }+}++/**+ * Expands into a pair of promise_test() calls to ensure that two Windows are in+ * different agent clusters, by checking both that we cannot send a+ * WebAssembly.Module, and that we cannot synchronously access the DOM.+ * @param {Array} testFrames - An array of either the form [self, frameIndex] or+ * [frameIndex1, frameIndex2], indicating the two Windows under test. E.g.+ * [self, 0] or [0, 1].+ * @param {string=} testLabelPrefix - A prefix used in the test names. This can+ * be omitted if testDifferentAgentClusters is only used once in a test file.+ */+export function testDifferentAgentClusters(testFrames, testLabelPrefix) {+ const prefix = testLabelPrefix === undefined ? "" : `${testLabelPrefix}: `;++ if (testFrames[0] === self) {+ // Between parent and a child at the index given by testFrames[1]++ promise_test(async () => {+ // In general, cross-origin sharing of WebAssembly.Module is prohibited,+ // so if we're in different agent clusters, it's definitely prohibited.+ // Basic tests for this cross-origin prohibition are elsewhere; we include+ // these here as an extra check to make sure there's no weird interactions+ // with Origin-Agent-Cluster.+ const frameWindow = frames[testFrames[1]];+ const whatHappened = await sendWasmModule(frameWindow);++ assert_equals(whatHappened, "messageerror");+ }, `${prefix}messageerror event must occur`);++ promise_test(async () => {+ const frameWindow = frames[testFrames[1]];+ const frameElement = document.querySelectorAll("iframe")[testFrames[1]];++ assert_throws_dom("SecurityError", DOMException, () => {+ frameWindow.document;+ });++ assert_throws_dom("SecurityError", DOMException, () => {+ frameWindow.location.href;+ });++ assert_equals(frameElement.contentDocument, null, "contentDocument");++ const whatHappened = await accessFrameElement(frameWindow);+ assert_equals(whatHappened, "null");+ }, `${prefix}setting document.domain must not give sync access`);+ } else {+ // Between the two children at the index given by testFrames[0] and+ // testFrames[1]++ promise_test(async () => {+ const whatHappened = await sendWasmModuleBetween(testFrames);+ assert_equals(whatHappened, "messageerror");+ }, `${prefix}messageerror event must occur`);++ promise_test(async () => {+ const whatHappened1 = await accessDocumentBetween(testFrames);+ assert_equals(whatHappened1, "SecurityError");++ const whatHappened2 = await accessLocationHrefBetween(testFrames);+ assert_equals(whatHappened2, "SecurityError");++ // We don't test contentDocument/frameElement for these because accessing+ // those via siblings has to go through the parent anyway.+ }, `${prefix}setting document.domain must not give sync access`);+ }+}++/**+ * Expands into a pair of promise_test() calls to ensure that the given window,+ * opened by window.open(), is in a different agent cluster from the current+ * (opener) window.+ * @param {function} openedWindowGetter - A function that returns the opened+ * window+ */+export function testOpenedWindowIsInADifferentAgentCluster(openedWindowGetter) {+ promise_test(async () => {+ const whatHappened = await sendWasmModule(openedWindowGetter());++ assert_equals(whatHappened, "messageerror");+ }, `messageerror event must occur`);++ promise_test(async () => {+ assert_throws_dom("SecurityError", DOMException, () => {+ openedWindowGetter().document;+ });++ assert_throws_dom("SecurityError", DOMException, () => {+ openedWindowGetter().location.href;+ });+ }, `setting document.domain must not give sync access`);+}++/**+ * Expands into a pair of promise_test() calls to ensure that the given window,+ * opened by window.open(), is in the same agent cluster as the current+ * (opener) window.+ * @param {function} openedWindowGetter - A function that returns the opened+ * window+ */+export function testOpenedWindowIsInSameAgentCluster(openedWindowGetter) {+ promise_test(async () => {+ const whatHappened = await sendWasmModule(openedWindowGetter());++ assert_equals(whatHappened, "WebAssembly.Module message received");+ }, `message event must occur`);++ promise_test(async () => {+ // Must not throw+ openedWindowGetter().document;++ // Must not throw+ openedWindowGetter().location.href;+ }, `setting document.domain must give sync access`);+}++/**+ * Creates a promise_test() to check the value of the originAgentCluster getter+ * in the given testFrame.+ * @param {Window|number|function} testFrame - Either self, or a frame index to+ test, or a function that returns a Window to test.+ * @param {boolean} expected - The expected value for originAgentCluster.+ * @param {string=} testLabelPrefix - A prefix used in the test names. This can+ * be omitted if the function is only used once in a test file.+ */+export function testGetter(testFrame, expected, testLabelPrefix) {+ const prefix = testLabelPrefix === undefined ? "" : `${testLabelPrefix}: `;++ promise_test(async () => {+ if (testFrame === self) {+ assert_equals(self.originAgentCluster, expected);+ } else if (typeof testFrame === "number") {+ const frameWindow = frames[testFrame];+ const result = await accessOriginAgentCluster(frameWindow);+ assert_equals(result, expected);+ } else {+ assert_equals(typeof testFrame, "function",+ "testFrame argument must be self, a number, or a function");+ const result = await accessOriginAgentCluster(testFrame());+ assert_equals(result, expected);+ }+ }, `${prefix}originAgentCluster must equal ${expected}`);+}++/**+ * Sends a WebAssembly.Module instance to the given Window, and waits for it to+ * send back a message indicating whether it got the module or got a+ * messageerror event. (This relies on the given Window being derived from+ * insertIframe or navigateIframe.)+ * @param {Window} frameWindow - The destination Window+ * @returns {Promise} A promise which will be fulfilled with either+ * "WebAssembly.Module message received" or "messageerror"+ */+export async function sendWasmModule(frameWindow) {+ // This function is coupled to ./send-oac-header.py, which ensures that+ // sending such a message will result in a message back.+ frameWindow.postMessage(await createWasmModule(), "*");+ return waitForMessage(frameWindow);+}++/**+ * Sets document.domain (to itself) for both the current Window and the given+ * Window. The latter relies on the given Window being derived from insertIframe+ * or navigateIframe.+ * @param frameWindow - The other Window whose document.domain is to be set+ * @returns {Promise} A promise which will be fulfilled after both+ * document.domains are set+ */+export async function setBothDocumentDomains(frameWindow) {+ // By setting both this page's document.domain and the iframe's+ // document.domain to the same value, we ensure that they can synchronously+ // access each other, unless they are origin-keyed.+ // NOTE: document.domain being unset is different than it being set to its+ // current value. It is a terrible API.+ document.domain = document.domain;++ // This function is coupled to ./send-oac-header.py, which ensures that+ // sending such a message will result in a message back.+ frameWindow.postMessage({ command: "set document.domain", newDocumentDomain: document.domain }, "*");+ const whatHappened = await waitForMessage(frameWindow);+ assert_equals(whatHappened, "document.domain is set");+}++async function accessOriginAgentCluster(frameWindow) {+ // This function is coupled to ./send-oac-header.py, which ensures that+ // sending such a message will result in a message back.+ frameWindow.postMessage({ command: "get originAgentCluster" }, "*");+ return waitForMessage(frameWindow);+}++function getSendHeaderURL(host, header, { sendLoadedMessage = false, redirectFirst = false } = {}) {+ const url = new URL("send-oac-header.py", import.meta.url);+ url.host = host;+ if (header !== undefined) {+ url.searchParams.set("header", header);+ }+ if (sendLoadedMessage) {+ url.searchParams.set("send-loaded-message", "");+ }+ if (redirectFirst) {+ url.searchParams.set("redirect-first", "");+ }++ return url.href;+}++async function sendWasmModuleBetween(testFrames) {+ const sourceFrame = frames[testFrames[0]];+ const indexIntoParentFrameOfDestination = testFrames[1];++ sourceFrame.postMessage({ command: "send WASM module", indexIntoParentFrameOfDestination }, "*");+ return waitForMessage(sourceFrame);+}++async function accessDocumentBetween(testFrames) {+ const sourceFrame = frames[testFrames[0]];+ const indexIntoParentFrameOfDestination = testFrames[1];++ sourceFrame.postMessage({ command: "access document", indexIntoParentFrameOfDestination }, "*");+ return waitForMessage(sourceFrame);+}++async function accessLocationHrefBetween(testFrames) {+ const sourceFrame = frames[testFrames[0]];+ const indexIntoParentFrameOfDestination = testFrames[1];++ sourceFrame.postMessage({ command: "access location.href", indexIntoParentFrameOfDestination }, "*");+ return waitForMessage(sourceFrame);+}++async function accessFrameElement(frameWindow) {+ frameWindow.postMessage({ command: "access frameElement" }, "*");+ return waitForMessage(frameWindow);+}++function waitForMessage(expectedSource) {+ return new Promise(resolve => {+ const handler = e => {+ if (e.source === expectedSource) {+ resolve(e.data);+ window.removeEventListener("message", handler);+ }+ };+ window.addEventListener("message", handler);+ });+}++// Any WebAssembly.Module will work fine for our tests; we just want to find out+// if it gives message or messageerror. So, we reuse one from the /wasm/ tests.+async function createWasmModule() {+ const response = await fetch("/wasm/serialization/module/resources/incrementer.wasm");+ const ab = await response.arrayBuffer();+ return WebAssembly.compile(ab);+}diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjs.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjs.headersnew file mode 100644index 00000000000..cb762eff806--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/helpers.mjs.headers@@ -0,0 +1 @@+Access-Control-Allow-Origin: *diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjs b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjsnew file mode 100644index 00000000000..17b00684d64--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjs@@ -0,0 +1,63 @@+import { sendWasmModule } from "./helpers.mjs";++// This is done for the window.open() case. For <iframe>s we use the+// <iframe> element's load event instead.+const usp = new URLSearchParams(location.search);+if (usp.has("send-loaded-message")) {+ opener.postMessage("loaded", "*");+}++window.onmessage = async (e) => {+ // These could come from the parent, opener, or siblings.+ if (e.data.constructor === WebAssembly.Module) {+ e.source.postMessage("WebAssembly.Module message received", "*");+ }++ // These could come from the parent or opener.+ if (e.data.command === "set document.domain") {+ document.domain = e.data.newDocumentDomain;+ e.source.postMessage("document.domain is set", "*");+ } else if (e.data.command === "get originAgentCluster") {+ e.source.postMessage(self.originAgentCluster, "*");+ }++ // These only come from the parent.+ if (e.data.command === "send WASM module") {+ const destinationFrameWindow = parent.frames[e.data.indexIntoParentFrameOfDestination];+ const whatHappened = await sendWasmModule(destinationFrameWindow);+ parent.postMessage(whatHappened, "*");+ } else if (e.data.command === "access document") {+ const destinationFrameWindow = parent.frames[e.data.indexIntoParentFrameOfDestination];+ try {+ destinationFrameWindow.document;+ parent.postMessage("accessed document successfully", "*");+ } catch (e) {+ parent.postMessage(e.name, "*");+ }+ } else if (e.data.command === "access location.href") {+ const destinationFrameWindow = parent.frames[e.data.indexIntoParentFrameOfDestination];+ try {+ destinationFrameWindow.location.href;+ parent.postMessage("accessed location.href successfully", "*");+ } catch (e) {+ parent.postMessage(e.name, "*");+ }+ } else if (e.data.command === "access frameElement") {+ if (frameElement === null) {+ parent.postMessage("null", "*");+ } else if (frameElement?.constructor?.name === "HTMLIFrameElement") {+ parent.postMessage("frameElement accessed successfully", "*");+ } else {+ parent.postMessage("something wierd happened", "*");+ }+ }++ // We could also receive e.data === "WebAssembly.Module message received",+ // but that's handled by await sendWasmModule() above.+};++window.onmessageerror = e => {+ e.source.postMessage("messageerror", "*");+};++document.body.textContent = location.href;diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjs.headers b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjs.headersnew file mode 100644index 00000000000..cb762eff806--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-header-page-script.mjs.headers@@ -0,0 +1 @@+Access-Control-Allow-Origin: *diff --git a/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-oac-header.py b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-oac-header.pynew file mode 100644index 00000000000..cc8860fe75b--- /dev/null+++ b/Tests/LibWeb/Text/input/wpt-import/html/browsers/origin/origin-keyed-agent-clusters/resources/send-oac-header.py@@ -0,0 +1,43 @@+def main(request, response):+ """Send a response with the Origin-Agent-Cluster header given in the+ "header" query parameter, or no header if that is not provided. Other query+ parameters (only their presence/absence matters) are "send-loaded-message"+ and "redirect-first", which modify the behavior a bit.++ In either case, the response will listen for various messages posted and+ coordinate with the sender. See ./helpers.mjs for how these handlers are+ used.+ """++ if b"redirect-first" in request.GET:+ # Create a new query string, which is the same as the one we're given but+ # with the redirect-first component stripped out. This allows tests to use+ # any value (or no value) for the other query params, in combination with+ # redirect-first.+ query_string_pieces = []+ if b"header" in request.GET:+ query_string_pieces.append(b"header=" + request.GET.first(b"header"))+ if b"send-loaded-message" in request.GET:+ query_string_pieces.append(b"send-loaded-message")+ query_string = b"?" + b"&".join(query_string_pieces)++ return (+ 302,+ [(b"Location", b"/html/browsers/origin/origin-keyed-agent-clusters/resources/send-oac-header.py" + query_string)],+ u""+ )++ if b"header" in request.GET:+ header = request.GET.first(b"header")+ response.headers.set(b"Origin-Agent-Cluster", header)++ response.headers.set(b"Content-Type", b"text/html")++ return u"""+ <!DOCTYPE html>+ <meta charset="utf-8">+ <title>Helper page for origin-keyed agent cluster tests</title>++ <body>+ <script type="module" src="send-header-page-script.mjs"></script>+ """