diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /testing/web-platform/tests/html/anonymous-iframe/resources | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/html/anonymous-iframe/resources')
4 files changed, 164 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/anonymous-iframe/resources/common.js b/testing/web-platform/tests/html/anonymous-iframe/resources/common.js new file mode 100644 index 0000000000..2fa51aa9c6 --- /dev/null +++ b/testing/web-platform/tests/html/anonymous-iframe/resources/common.js @@ -0,0 +1,55 @@ +// Create a credentialless iframe. The new document will execute any scripts +// sent toward the token it returns. +const newIframeCredentialless = (child_origin, opt_headers) => { + opt_headers ||= ""; + const sub_document_token = token(); + let iframe = document.createElement('iframe'); + iframe.src = child_origin + executor_path + opt_headers + + `&uuid=${sub_document_token}`; + iframe.credentialless = true; + document.body.appendChild(iframe); + return sub_document_token; +}; + +// Create a normal iframe. The new document will execute any scripts sent +// toward the token it returns. +const newIframe = (child_origin) => { + const sub_document_token = token(); + let iframe = document.createElement('iframe'); + iframe.src = child_origin + executor_path + `&uuid=${sub_document_token}`; + iframe.credentialless = false + document.body.appendChild(iframe); + return sub_document_token; +}; + +// Create a popup. The new document will execute any scripts sent toward the +// token it returns. +const newPopup = (test, origin) => { + const popup_token = token(); + const popup = window.open(origin + executor_path + `&uuid=${popup_token}`); + test.add_cleanup(() => popup.close()); + return popup_token; +} + +// Create a fenced frame. The new document will execute any scripts sent +// toward the token it returns. +const newFencedFrame = async (child_origin) => { + const support_loading_mode_fenced_frame = + "|header(Supports-Loading-Mode,fenced-frame)"; + const sub_document_token = token(); + const url = child_origin + executor_path + + support_loading_mode_fenced_frame + + `&uuid=${sub_document_token}`; + const urn = await generateURNFromFledge(url, []); + attachFencedFrame(urn); + return sub_document_token; +}; + +const importScript = (url) => { + const script = document.createElement("script"); + script.type = "text/javascript"; + script.src = url; + const loaded = new Promise(resolve => script.onload = resolve); + document.body.appendChild(script); + return loaded; +} diff --git a/testing/web-platform/tests/html/anonymous-iframe/resources/embedding-test.js b/testing/web-platform/tests/html/anonymous-iframe/resources/embedding-test.js new file mode 100644 index 0000000000..fb5d11efa0 --- /dev/null +++ b/testing/web-platform/tests/html/anonymous-iframe/resources/embedding-test.js @@ -0,0 +1,72 @@ +// One document embeds another in an iframe. Both are loaded from the network. +// Check whether or not the child can load. + +// There are no interoperable ways to check an iframe failed to load. So a +// timeout is being used. See https://github.com/whatwg/html/issues/125 +// Moreover, we want to track progress, managing timeout explicitly allows to +// get a per-test results, even in case of failure of one. +setup({ explicit_timeout: true }); + +const EXPECT_LOAD = "load"; +const EXPECT_BLOCK = "block"; + +// Load a credentialless iframe. Control both the parent and the child headers. +// Check whether it loaded or not. +const embeddingTest = (description, { + parent_headers, + child_headers, + child_origin, + expectation, +}) => { + // Default values: + child_origin ||= globalThis.origin; + parent_headers ||= ""; + child_headers||= ""; + + const parent_origin = window.origin; + + promise_test_parallel(async test => { + const parent_token = token(); + const parent_url = parent_origin + executor_path + parent_headers + + `&uuid=${parent_token}`; + + const child_token = token(); + const child_url = child_origin + executor_path + child_headers + + `&uuid=${child_token}`; + + // Create the parent: + window.open(parent_url); + add_completion_callback(() => send(parent_token, "close()")); + + // The parent creates its child: + await send(parent_token, ` + const iframe = document.createElement("iframe"); + iframe.credentialless = true; + iframe.src = "${child_url}"; + document.body.appendChild(iframe); + `); + + // Ping the child to know whether it was allowed to load or not: + const reply_token = token(); + await send(child_token, ` + send("${reply_token}", "load"); + `); + + // There are no interoperable ways to check an iframe failed to load. So a + // timeout is being used. + // See https://github.com/whatwg/html/issues/125 + // Use a shorter timeout when it is expected to be reached. + // - The long delay reduces the false-positive rate. False-positive causes + // stability problems on bot, so a big delay is used to vanish them. + // https://crbug.com/1215956. + // - The short delay avoids delaying too much the test(s) for nothing and + // timing out. False-negative are not a problem, they just need not to + // overwhelm the true-negative, which is trivial to get. + step_timeout(() => send(reply_token, "block"), expectation == EXPECT_BLOCK + ? 1500 + : 3500 + ); + + assert_equals(await receive(reply_token), expectation); + }, description); +}; diff --git a/testing/web-platform/tests/html/anonymous-iframe/resources/serviceworker-partitioning-helper.js b/testing/web-platform/tests/html/anonymous-iframe/resources/serviceworker-partitioning-helper.js new file mode 100644 index 0000000000..288ad5954e --- /dev/null +++ b/testing/web-platform/tests/html/anonymous-iframe/resources/serviceworker-partitioning-helper.js @@ -0,0 +1,16 @@ +let messages = {}; +let ports = {}; + +self.addEventListener("message", e => { + const from = e.data.from; + const check = e.data.check; + + if (from) { + messages[from] = true; + ports[from] = e.ports[0]; + } + + if (check) { + ports[check].postMessage(messages); + } +}); diff --git a/testing/web-platform/tests/html/anonymous-iframe/resources/sharedworker-partitioning-helper.js b/testing/web-platform/tests/html/anonymous-iframe/resources/sharedworker-partitioning-helper.js new file mode 100644 index 0000000000..8b416c33d7 --- /dev/null +++ b/testing/web-platform/tests/html/anonymous-iframe/resources/sharedworker-partitioning-helper.js @@ -0,0 +1,21 @@ +let messages = {}; + +onconnect = function(e) { + let port = e.ports[0]; + + port.addEventListener('message', function(e) { + const action = e.data.action; + const from = e.data.from; + + if (action === 'record') { + messages[from] = true; + port.postMessage({ack: from}); + } + + if (action === 'retrieve') { + port.postMessage({ack: from, messages: messages}); + } + }); + + port.start(); +}; |