From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../shared-worker-in-data-url-context.window.js | 65 ++++++++++++++++++++++ 1 file changed, 65 insertions(+) create mode 100644 testing/web-platform/tests/workers/shared-worker-in-data-url-context.window.js (limited to 'testing/web-platform/tests/workers/shared-worker-in-data-url-context.window.js') diff --git a/testing/web-platform/tests/workers/shared-worker-in-data-url-context.window.js b/testing/web-platform/tests/workers/shared-worker-in-data-url-context.window.js new file mode 100644 index 0000000000..b768c815d0 --- /dev/null +++ b/testing/web-platform/tests/workers/shared-worker-in-data-url-context.window.js @@ -0,0 +1,65 @@ +// META: title=data URL shared worker in data URL context +// META: script=/service-workers/service-worker/resources/test-helpers.sub.js +const mimeType = 'application/javascript'; + +// Tests creating a data URL shared worker in a data URL iframe. +promise_test(async t => { + const nestedWorkerScriptURL = + new URL('/workers/support/post-message-on-load-worker.js', location.href); + + // This code will be executed in a data URL iframe. The iframe tries to create + // a shared worker from |nestedWorkerScriptURL|, but that should result in a + // failure. This is because the data URL iframe has an opaque origin, and + // script fetch is handled as a cross-origin request. + const frameCode = ` + + `; + + const p = new Promise(r => window.onmessage = e => r(e.data)); + const frame = await with_iframe(`data:text/html;base64,${btoa(frameCode)}`); + const result = await p; + assert_equals(result, 'PASS'); +}, 'Create a shared worker in a data url frame'); + +// Tests creating a data URL shared worker in a data URL iframe. +promise_test(async t => { + const workerCode = `onconnect = e => e.ports[0].postMessage("PASS");`; + + // This code will be executed in a data URL iframe. The iframe tries to create + // a data URL shared worker. Fetching a data URL from the data URL shared + // worker is allowed, so the worker construction should succeed. The worker + // posts the result to the parent frame. + const frameCode = ` + + `; + + const p = new Promise(r => window.onmessage = e => r(e.data)); + const frame = await with_iframe(`data:text/html;base64,${btoa(frameCode)}`); + const result = await p; + assert_equals(result, 'PASS'); +}, 'Create a data url shared worker in a data url frame'); -- cgit v1.2.3