From 36d22d82aa202bb199967e9512281e9a53db42c9 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 21:33:14 +0200 Subject: Adding upstream version 115.7.0esr. Signed-off-by: Daniel Baumann --- .../dedicated-worker-import-blob-url.any.js | 26 ++ .../modules/dedicated-worker-import-csp.html | 120 ++++++++ ...icated-worker-import-data-url-cross-origin.html | 43 +++ .../dedicated-worker-import-data-url.any.js | 22 ++ .../modules/dedicated-worker-import-failure.html | 54 ++++ .../modules/dedicated-worker-import-meta.html | 59 ++++ .../modules/dedicated-worker-import-referrer.html | 244 ++++++++++++++++ .../workers/modules/dedicated-worker-import.any.js | 22 ++ .../dedicated-worker-options-credentials.html | 304 ++++++++++++++++++++ ...dicated-worker-options-credentials.html.headers | 2 + .../modules/dedicated-worker-options-type.html | 46 +++ .../dedicated-worker-parse-error-failure.html | 51 ++++ ...dynamic-import-and-then-static-import-worker.js | 32 +++ .../dynamic-import-data-url-block-cross-origin.js | 24 ++ .../resources/dynamic-import-given-url-worker.js | 21 ++ ...remote-origin-credentials-checker-worker.sub.js | 15 + ...rt-remote-origin-referrer-checker-worker.sub.js | 16 ++ ...namic-import-remote-origin-script-worker.sub.js | 17 ++ ...mport-same-origin-credentials-checker-worker.js | 13 + ...c-import-same-origin-referrer-checker-worker.js | 15 + .../dynamic-import-script-block-cross-origin.js | 24 ++ .../modules/resources/dynamic-import-worker.js | 32 +++ .../workers/modules/resources/empty-worker.js | 1 + .../resources/eval-dynamic-import-worker.js | 29 ++ .../modules/resources/export-block-cross-origin.js | 1 + .../modules/resources/export-credentials.py | 15 + .../resources/export-on-dynamic-import-script.js | 8 + .../export-on-dynamic-import-script.js.headers | 1 + .../modules/resources/export-on-load-script.js | 1 + .../resources/export-on-load-script.js.headers | 1 + .../modules/resources/export-on-load-script.py | 15 + .../resources/export-on-static-import-script.js | 3 + .../export-on-static-import-script.js.headers | 1 + .../modules/resources/export-referrer-checker.py | 9 + .../modules/resources/import-meta-url-export.js | 1 + .../modules/resources/import-meta-url-worker.js | 10 + .../modules/resources/import-scripts-worker.js | 33 +++ .../workers/modules/resources/import-test-cases.js | 59 ++++ .../resources/nested-dynamic-import-worker.js | 34 +++ .../resources/nested-static-import-worker.js | 21 ++ .../resources/new-shared-worker-window.html | 19 ++ .../modules/resources/new-worker-window.html | 19 ++ .../resources/post-message-on-load-worker.js | 10 + .../modules/resources/postmessage-credentials.py | 22 ++ .../resources/postmessage-referrer-checker.py | 16 ++ .../tests/workers/modules/resources/redirect.py | 8 + ...static-import-and-then-dynamic-import-worker.js | 34 +++ .../static-import-data-url-block-cross-origin.js | 14 + .../static-import-non-existent-script-worker.js | 1 + .../resources/static-import-redirect-worker.js | 21 ++ ...remote-origin-credentials-checker-worker.sub.js | 12 + ...rt-remote-origin-referrer-checker-worker.sub.js | 12 + ...tatic-import-remote-origin-script-worker.sub.js | 20 ++ ...mport-same-origin-credentials-checker-worker.js | 11 + ...c-import-same-origin-referrer-checker-worker.js | 11 + .../static-import-script-block-cross-origin.js | 14 + .../resources/static-import-syntax-error.js | 1 + .../modules/resources/static-import-worker.js | 21 ++ .../workers/modules/resources/syntax-error.js | 1 + .../tests/workers/modules/resources/throw.js | 1 + .../shared-worker-import-blob-url.window.js | 26 ++ .../workers/modules/shared-worker-import-csp.html | 128 +++++++++ ...shared-worker-import-data-url-cross-origin.html | 43 +++ .../shared-worker-import-data-url.window.js | 23 ++ .../modules/shared-worker-import-failure.html | 67 +++++ .../workers/modules/shared-worker-import-meta.html | 49 ++++ .../modules/shared-worker-import-referrer.html | 259 +++++++++++++++++ .../workers/modules/shared-worker-import.window.js | 22 ++ .../modules/shared-worker-options-credentials.html | 309 +++++++++++++++++++++ .../shared-worker-options-credentials.html.headers | 2 + .../modules/shared-worker-options-type.html | 48 ++++ .../modules/shared-worker-parse-error-failure.html | 49 ++++ 72 files changed, 2738 insertions(+) create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-blob-url.any.js create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-csp.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url-cross-origin.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url.any.js create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-failure.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-meta.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-import.any.js create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html.headers create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-options-type.html create mode 100644 testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-and-then-static-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-data-url-block-cross-origin.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-given-url-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-referrer-checker-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-script-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-referrer-checker-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-script-block-cross-origin.js create mode 100644 testing/web-platform/tests/workers/modules/resources/dynamic-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/empty-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/eval-dynamic-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/export-block-cross-origin.js create mode 100644 testing/web-platform/tests/workers/modules/resources/export-credentials.py create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js.headers create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-load-script.js create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-load-script.js.headers create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-load-script.py create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js create mode 100644 testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js.headers create mode 100644 testing/web-platform/tests/workers/modules/resources/export-referrer-checker.py create mode 100644 testing/web-platform/tests/workers/modules/resources/import-meta-url-export.js create mode 100644 testing/web-platform/tests/workers/modules/resources/import-meta-url-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/import-scripts-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/import-test-cases.js create mode 100644 testing/web-platform/tests/workers/modules/resources/nested-dynamic-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/nested-static-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/new-shared-worker-window.html create mode 100644 testing/web-platform/tests/workers/modules/resources/new-worker-window.html create mode 100644 testing/web-platform/tests/workers/modules/resources/post-message-on-load-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/postmessage-credentials.py create mode 100644 testing/web-platform/tests/workers/modules/resources/postmessage-referrer-checker.py create mode 100644 testing/web-platform/tests/workers/modules/resources/redirect.py create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-and-then-dynamic-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-data-url-block-cross-origin.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-non-existent-script-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-redirect-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-referrer-checker-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-script-worker.sub.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-same-origin-referrer-checker-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-script-block-cross-origin.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-syntax-error.js create mode 100644 testing/web-platform/tests/workers/modules/resources/static-import-worker.js create mode 100644 testing/web-platform/tests/workers/modules/resources/syntax-error.js create mode 100644 testing/web-platform/tests/workers/modules/resources/throw.js create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-blob-url.window.js create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-csp.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-data-url-cross-origin.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-data-url.window.js create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-failure.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-meta.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import-referrer.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-import.window.js create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html.headers create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-options-type.html create mode 100644 testing/web-platform/tests/workers/modules/shared-worker-parse-error-failure.html (limited to 'testing/web-platform/tests/workers/modules') diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-blob-url.any.js b/testing/web-platform/tests/workers/modules/dedicated-worker-import-blob-url.any.js new file mode 100644 index 0000000000..e5d79add73 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-blob-url.any.js @@ -0,0 +1,26 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Imports |testCase.scriptURL| on a dedicated worker loaded from a blob URL, +// and waits until the list of imported modules is sent from the worker. Passes +// if the list is equal to |testCase.expectation|. +function import_blob_url_test(testCase) { + promise_test(async () => { + const importURL = new URL(testCase.scriptURL, location.href); + const blob = new Blob([`import "${importURL}";`], + { type: 'text/javascript' }); + const blobURL = URL.createObjectURL(blob); + const worker = new Worker(blobURL, { type: 'module'}); + worker.postMessage('Send message for tests from main script.'); + const msgEvent = await new Promise((resolve, reject) => { + worker.onmessage = resolve; + worker.onerror = error => { + const msg = error instanceof ErrorEvent ? error.message + : 'unknown error'; + reject(msg); + }; + }); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_blob_url_test); diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-csp.html b/testing/web-platform/tests/workers/modules/dedicated-worker-import-csp.html new file mode 100644 index 0000000000..20b03a7276 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-csp.html @@ -0,0 +1,120 @@ + +DedicatedWorker: CSP for ES Modules + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url-cross-origin.html b/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url-cross-origin.html new file mode 100644 index 0000000000..37390947b6 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url-cross-origin.html @@ -0,0 +1,43 @@ + +DedicatedWorker: ES modules for data URL workers + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url.any.js b/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url.any.js new file mode 100644 index 0000000000..0d8510da0c --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-data-url.any.js @@ -0,0 +1,22 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Imports |testCase.scriptURL| on a dedicated worker loaded from a data URL, +// and waits until the list of imported modules is sent from the worker. Passes +// if the list is equal to |testCase.expectation|. +function import_data_url_test(testCase) { + promise_test(async () => { + // The Access-Control-Allow-Origin header is necessary because a worker + // loaded from a data URL has a null origin and import() on the worker + // without the header is blocked. + const importURL = new URL(testCase.scriptURL, location.href) + + '?pipe=header(Access-Control-Allow-Origin, *)'; + const dataURL = `data:text/javascript,import "${importURL}";`; + + const worker = new Worker(dataURL, { type: 'module'}); + worker.postMessage('Send message for tests from main script.'); + const msgEvent = await new Promise(resolve => worker.onmessage = resolve); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_data_url_test); diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-failure.html b/testing/web-platform/tests/workers/modules/dedicated-worker-import-failure.html new file mode 100644 index 0000000000..4c705e7325 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-failure.html @@ -0,0 +1,54 @@ + +DedicatedWorker: import failure + + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-meta.html b/testing/web-platform/tests/workers/modules/dedicated-worker-import-meta.html new file mode 100644 index 0000000000..97a5da870f --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-meta.html @@ -0,0 +1,59 @@ + +DedicatedWorker: import.meta + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html b/testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html new file mode 100644 index 0000000000..855df62194 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import-referrer.html @@ -0,0 +1,244 @@ + +DedicatedWorker: Referrer + + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-import.any.js b/testing/web-platform/tests/workers/modules/dedicated-worker-import.any.js new file mode 100644 index 0000000000..d5bb6cccbe --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-import.any.js @@ -0,0 +1,22 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Starts a dedicated worker for |testCase.scriptURL| and waits until the list +// of imported modules is sent from the worker. Passes if the list is equal to +// |testCase.expectation|. +function import_test(testCase) { + promise_test(async () => { + const worker = new Worker(testCase.scriptURL, { type: 'module' }); + worker.postMessage('Send message for tests from main script.'); + const msgEvent = await new Promise((resolve, reject) => { + worker.onmessage = resolve; + worker.onerror = error => { + const msg = error instanceof ErrorEvent ? error.message + : 'unknown error'; + reject(msg); + }; + }); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_test); diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html new file mode 100644 index 0000000000..94916d7ff5 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html @@ -0,0 +1,304 @@ + +DedicatedWorker: WorkerOptions 'credentials' + + + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html.headers b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html.headers new file mode 100644 index 0000000000..8da851ab73 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-options-credentials.html.headers @@ -0,0 +1,2 @@ +Set-Cookie: COOKIE_NAME=1 +Access-Control-Allow-Credentials: true diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-options-type.html b/testing/web-platform/tests/workers/modules/dedicated-worker-options-type.html new file mode 100644 index 0000000000..bb37a18f2c --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-options-type.html @@ -0,0 +1,46 @@ + +DedicatedWorker: WorkerOptions 'type' + + + diff --git a/testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html b/testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html new file mode 100644 index 0000000000..343bfe289f --- /dev/null +++ b/testing/web-platform/tests/workers/modules/dedicated-worker-parse-error-failure.html @@ -0,0 +1,51 @@ + +DedicatedWorker: parse error failure + + + + + diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-and-then-static-import-worker.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-and-then-static-import-worker.js new file mode 100644 index 0000000000..527702f551 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-and-then-static-import-worker.js @@ -0,0 +1,32 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.source); + }; + } +}); + +const importedModulesPromise = + import('./export-on-static-import-script.js') + .then(module => module.importedModules) + .catch(error => `Failed to do dynamic import: ${error}`); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-data-url-block-cross-origin.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-data-url-block-cross-origin.js new file mode 100644 index 0000000000..caa15319c5 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-data-url-block-cross-origin.js @@ -0,0 +1,24 @@ +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } +}); + +const importedModulesPromise = + import("data:text/javascript, export const importedModules = ['export-block-cross-origin.js'];") + .then(module => module.importedModules) + .catch(() => ['ERROR']); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-given-url-worker.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-given-url-worker.js new file mode 100644 index 0000000000..5510275935 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-given-url-worker.js @@ -0,0 +1,21 @@ +// This worker dynamically imports the script URL sent by postMessage(), and +// sends back an error name if the dynamic import fails. +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = msg_event => { + import(msg_event.data) + .then(module => postMessage(module.meta_url)) + .catch(e => postMessage(e.name)); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = connect_event => { + const port = connect_event.ports[0]; + port.onmessage = msg_event => { + import(msg_event.data) + .then(module => port.postMessage(module.meta_url)) + .catch(e => port.postMessage(e.name)); + }; + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js new file mode 100644 index 0000000000..3cfbe7c6e4 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-credentials-checker-worker.sub.js @@ -0,0 +1,15 @@ +// Import a remote origin script. +const import_url = + 'http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/export-credentials.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + import(import_url) + .then(module => postMessage(module.cookie)); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + import(import_url) + .then(module => e.ports[0].postMessage(module.cookie)); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-referrer-checker-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-referrer-checker-worker.sub.js new file mode 100644 index 0000000000..3f281faa7c --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-referrer-checker-worker.sub.js @@ -0,0 +1,16 @@ +// Import a remote origin script. +const import_url = 'https://{{domains[www1]}}:{{ports[https][0]}}/workers/modules/resources/export-referrer-checker.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + import(import_url) + .then(module => postMessage(module.referrer)) + .catch(error => postMessage(`Import failed: ${error}`)); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + import(import_url) + .then(module => e.ports[0].postMessage(module.referrer)) + .catch(error => e.ports[0].postMessage(`Import failed: ${error}`)); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-script-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-script-worker.sub.js new file mode 100644 index 0000000000..7ed6543890 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-remote-origin-script-worker.sub.js @@ -0,0 +1,17 @@ +// Import a remote origin script. +const importUrl = + 'https://{{domains[www1]}}:{{ports[https][0]}}/workers/modules/resources/export-on-load-script.js'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + import(importUrl) + .then(module => postMessage(module.importedModules)) + .catch(e => postMessage(['ERROR'])); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + import(importUrl) + .then(module => e.ports[0].postMessage(module.importedModules)) + .catch(error => e.ports[0].postMessage(['ERROR'])); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js new file mode 100644 index 0000000000..24dbd55128 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-credentials-checker-worker.js @@ -0,0 +1,13 @@ +const import_url = './export-credentials.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + import(import_url) + .then(module => postMessage(module.cookie)); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + import(import_url) + .then(module => e.ports[0].postMessage(module.cookie)); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-referrer-checker-worker.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-referrer-checker-worker.js new file mode 100644 index 0000000000..56f8a6ffe8 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-same-origin-referrer-checker-worker.js @@ -0,0 +1,15 @@ +const import_url = './export-referrer-checker.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + import(import_url) + .then(module => postMessage(module.referrer)) + .catch(error => postMessage(`Import failed: ${error}`)); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + import(import_url) + .then(module => e.ports[0].postMessage(module.referrer)) + .catch(error => e.ports[0].postMessage(`Import failed: ${error}`)); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-script-block-cross-origin.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-script-block-cross-origin.js new file mode 100644 index 0000000000..52ec530663 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-script-block-cross-origin.js @@ -0,0 +1,24 @@ +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } +}); + +const importedModulesPromise = + import('./export-block-cross-origin.js') + .then(module => module.importedModules) + .catch(() => ['ERROR']); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/dynamic-import-worker.js b/testing/web-platform/tests/workers/modules/resources/dynamic-import-worker.js new file mode 100644 index 0000000000..2e756fe055 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/dynamic-import-worker.js @@ -0,0 +1,32 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.source); + }; + } +}); + +const importedModulesPromise = + import('./export-on-load-script.js') + .then(module => module.importedModules) + .catch(error => `Failed to do dynamic import: ${error}`); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/empty-worker.js b/testing/web-platform/tests/workers/modules/resources/empty-worker.js new file mode 100644 index 0000000000..49ceb2648a --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/empty-worker.js @@ -0,0 +1 @@ +// Do nothing. diff --git a/testing/web-platform/tests/workers/modules/resources/eval-dynamic-import-worker.js b/testing/web-platform/tests/workers/modules/resources/eval-dynamic-import-worker.js new file mode 100644 index 0000000000..60080d4292 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/eval-dynamic-import-worker.js @@ -0,0 +1,29 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +const code = 'const sourcePromise = new Promise(resolve => {' + + ' if (\'DedicatedWorkerGlobalScope\' in self &&' + + ' self instanceof DedicatedWorkerGlobalScope) {' + + ' self.onmessage = e => {' + + ' resolve(e.target);' + + ' };' + + ' } else if (\'SharedWorkerGlobalScope\' in self &&' + + ' self instanceof SharedWorkerGlobalScope) {' + + ' self.onconnect = e => {' + + ' resolve(e.ports[0]);' + + ' };' + + ' } else if (\'ServiceWorkerGlobalScope\' in self &&' + + ' self instanceof ServiceWorkerGlobalScope) {' + + ' self.onmessage = e => {' + + ' resolve(e.source);' + + ' };' + + ' }' + + '});' + + 'const importedModulesPromise =' + + ' import(\'./export-on-load-script.js\')' + + ' .then(module => module.importedModules)' + + ' .catch(error => `Failed to do dynamic import: ${error}`);' + + 'Promise.all([sourcePromise, importedModulesPromise]).then(results => {' + + ' const [source, importedModules] = results;' + + ' source.postMessage(importedModules);' + + '});'; +eval(code); diff --git a/testing/web-platform/tests/workers/modules/resources/export-block-cross-origin.js b/testing/web-platform/tests/workers/modules/resources/export-block-cross-origin.js new file mode 100644 index 0000000000..a4b513d280 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-block-cross-origin.js @@ -0,0 +1 @@ +export const importedModules = ['export-block-cross-origin.js']; diff --git a/testing/web-platform/tests/workers/modules/resources/export-credentials.py b/testing/web-platform/tests/workers/modules/resources/export-credentials.py new file mode 100644 index 0000000000..3d0ba778d1 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-credentials.py @@ -0,0 +1,15 @@ +def main(request, response): + cookie = request.cookies.first(b"COOKIE_NAME", None) + + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Credentials", b"true")] + + origin = request.headers.get(b"Origin", None) + if origin: + response_headers.append((b"Access-Control-Allow-Origin", origin)) + + cookie_value = b''; + if cookie: + cookie_value = cookie.value; + return (200, response_headers, + b"export const cookie = '"+cookie_value+b"';") diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js b/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js new file mode 100644 index 0000000000..bab7cb48d2 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js @@ -0,0 +1,8 @@ +// Export the list of imported modules. It's available after the |ready| promise +// is resolved. +export let importedModules = ['export-on-dynamic-import-script.js']; +export let ready = import('./export-on-load-script.js') + .then(module => { + Array.prototype.push.apply(importedModules, module.importedModules); + return importedModules; + }); diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js.headers b/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js.headers new file mode 100644 index 0000000000..cb762eff80 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-dynamic-import-script.js.headers @@ -0,0 +1 @@ +Access-Control-Allow-Origin: * diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js new file mode 100644 index 0000000000..7d1b122c32 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js @@ -0,0 +1 @@ +export const importedModules = ['export-on-load-script.js']; diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js.headers b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js.headers new file mode 100644 index 0000000000..cb762eff80 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.js.headers @@ -0,0 +1 @@ +Access-Control-Allow-Origin: * diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-load-script.py b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.py new file mode 100644 index 0000000000..9014341915 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-load-script.py @@ -0,0 +1,15 @@ +import datetime + +def main(request, response): + # This script serves both preflight and main GET request for cross-origin + # static imports from module service workers. + # According to https://w3c.github.io/ServiceWorker/#update-algorithm, + # `Service-Worker: script` request header is added, which triggers CORS + # preflight. + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Origin", b"*"), + (b"Access-Control-Allow-Headers", b"Service-Worker")] + + body = b"export const importedModules = ['export-on-load-script.js'];" + body += b"// %d" % datetime.datetime.now().timestamp() + return (200, response_headers, body) diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js b/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js new file mode 100644 index 0000000000..3f7174eef0 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js @@ -0,0 +1,3 @@ +import * as module from './export-on-load-script.js'; +const filename = 'export-on-static-import-script.js'; +export const importedModules = [filename].concat(module.importedModules); diff --git a/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js.headers b/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js.headers new file mode 100644 index 0000000000..cb762eff80 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-on-static-import-script.js.headers @@ -0,0 +1 @@ +Access-Control-Allow-Origin: * diff --git a/testing/web-platform/tests/workers/modules/resources/export-referrer-checker.py b/testing/web-platform/tests/workers/modules/resources/export-referrer-checker.py new file mode 100644 index 0000000000..3b0fda1aa6 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/export-referrer-checker.py @@ -0,0 +1,9 @@ +# Returns a worker script that posts the request's referrer header. +def main(request, response): + referrer = request.headers.get(b"referer", b"") + + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Origin", b"*")] + + return (200, response_headers, + b"export const referrer = '"+referrer+b"';") diff --git a/testing/web-platform/tests/workers/modules/resources/import-meta-url-export.js b/testing/web-platform/tests/workers/modules/resources/import-meta-url-export.js new file mode 100644 index 0000000000..5287b2e9e8 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/import-meta-url-export.js @@ -0,0 +1 @@ +export const meta_url = import.meta.url; diff --git a/testing/web-platform/tests/workers/modules/resources/import-meta-url-worker.js b/testing/web-platform/tests/workers/modules/resources/import-meta-url-worker.js new file mode 100644 index 0000000000..7887836a6c --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/import-meta-url-worker.js @@ -0,0 +1,10 @@ +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(import.meta.url); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(import.meta.url); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/import-scripts-worker.js b/testing/web-platform/tests/workers/modules/resources/import-scripts-worker.js new file mode 100644 index 0000000000..d85f573ffe --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/import-scripts-worker.js @@ -0,0 +1,33 @@ +try { + importScripts('empty-worker.js'); + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage('LOADED'); + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + e.ports[0].postMessage('LOADED'); + }; + } +} catch (e) { + // Post a message instead of propagating an ErrorEvent to the page because + // propagated event loses an error name. + // + // Step 1. "Let notHandled be the result of firing an event named error at the + // Worker object associated with the worker, using ErrorEvent, with the + // cancelable attribute initialized to true, the message, filename, lineno, + // and colno attributes initialized appropriately, and the error attribute + // initialized to null." + // https://html.spec.whatwg.org/multipage/workers.html#runtime-script-errors-2 + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(e.name); + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = connectEvent => { + connectEvent.ports[0].postMessage(e.name); + }; + } +} diff --git a/testing/web-platform/tests/workers/modules/resources/import-test-cases.js b/testing/web-platform/tests/workers/modules/resources/import-test-cases.js new file mode 100644 index 0000000000..8ad89e8fda --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/import-test-cases.js @@ -0,0 +1,59 @@ +const testCases = [ + { + scriptURL: '/workers/modules/resources/static-import-worker.js', + expectation: ['export-on-load-script.js'], + description: 'Static import.' + }, + { + scriptURL: '/workers/modules/resources/static-import-remote-origin-script-worker.sub.js', + expectation: ['export-on-load-script.js'], + description: 'Static import (cross-origin).' + }, + { + scriptURL: '/workers/modules/resources/static-import-redirect-worker.js', + expectation: ['export-on-load-script.js'], + description: 'Static import (redirect).' + }, + { + scriptURL: '/workers/modules/resources/nested-static-import-worker.js', + expectation: [ + 'export-on-static-import-script.js', + 'export-on-load-script.js' + ], + description: 'Nested static import.' + }, + { + scriptURL: '/workers/modules/resources/static-import-and-then-dynamic-import-worker.js', + expectation: [ + 'export-on-dynamic-import-script.js', + 'export-on-load-script.js' + ], + description: 'Static import and then dynamic import.' + }, + { + scriptURL: '/workers/modules/resources/dynamic-import-worker.js', + expectation: ['export-on-load-script.js'], + description: 'Dynamic import.' + }, + { + scriptURL: '/workers/modules/resources/nested-dynamic-import-worker.js', + expectation: [ + 'export-on-dynamic-import-script.js', + 'export-on-load-script.js' + ], + description: 'Nested dynamic import.' + }, + { + scriptURL: '/workers/modules/resources/dynamic-import-and-then-static-import-worker.js', + expectation: [ + 'export-on-static-import-script.js', + 'export-on-load-script.js' + ], + description: 'Dynamic import and then static import.' + }, + { + scriptURL: '/workers/modules/resources/eval-dynamic-import-worker.js', + expectation: ['export-on-load-script.js'], + description: 'eval(import()).' + } +]; diff --git a/testing/web-platform/tests/workers/modules/resources/nested-dynamic-import-worker.js b/testing/web-platform/tests/workers/modules/resources/nested-dynamic-import-worker.js new file mode 100644 index 0000000000..00da43c5f0 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/nested-dynamic-import-worker.js @@ -0,0 +1,34 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. + +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.source); + }; + } +}); + +const importedModulesPromise = + import('./export-on-dynamic-import-script.js') + .then(module => module.ready) + .then(importedModules => importedModules) + .catch(error => `Failed to do dynamic import: ${error}`); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/nested-static-import-worker.js b/testing/web-platform/tests/workers/modules/resources/nested-static-import-worker.js new file mode 100644 index 0000000000..c3a9ff0b79 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/nested-static-import-worker.js @@ -0,0 +1,21 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +import * as module from './export-on-static-import-script.js'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + e.source.postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/new-shared-worker-window.html b/testing/web-platform/tests/workers/modules/resources/new-shared-worker-window.html new file mode 100644 index 0000000000..84564fd7b6 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/new-shared-worker-window.html @@ -0,0 +1,19 @@ + +SharedWorker: new SharedWorker() + + + diff --git a/testing/web-platform/tests/workers/modules/resources/new-worker-window.html b/testing/web-platform/tests/workers/modules/resources/new-worker-window.html new file mode 100644 index 0000000000..32a89fae0e --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/new-worker-window.html @@ -0,0 +1,19 @@ + +DedicatedWorker: new Worker() + + + diff --git a/testing/web-platform/tests/workers/modules/resources/post-message-on-load-worker.js b/testing/web-platform/tests/workers/modules/resources/post-message-on-load-worker.js new file mode 100644 index 0000000000..e1c547ab6a --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/post-message-on-load-worker.js @@ -0,0 +1,10 @@ +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage('LOADED'); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage('LOADED'); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/postmessage-credentials.py b/testing/web-platform/tests/workers/modules/resources/postmessage-credentials.py new file mode 100644 index 0000000000..a054a1a923 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/postmessage-credentials.py @@ -0,0 +1,22 @@ +def main(request, response): + cookie = request.cookies.first(b"COOKIE_NAME", None) + + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Credentials", b"true")] + + origin = request.headers.get(b"Origin", None) + if origin: + response_headers.append((b"Access-Control-Allow-Origin", origin)) + + cookie_value = b''; + if cookie: + cookie_value = cookie.value; + return (200, response_headers, + b"if ('DedicatedWorkerGlobalScope' in self &&" + + b" self instanceof DedicatedWorkerGlobalScope) {" + + b" postMessage('"+cookie_value+b"');" + + b"} else if (" + + b" 'SharedWorkerGlobalScope' in self &&" + + b" self instanceof SharedWorkerGlobalScope) {" + + b" onconnect = e => e.ports[0].postMessage('"+cookie_value+b"');" + + b"}") diff --git a/testing/web-platform/tests/workers/modules/resources/postmessage-referrer-checker.py b/testing/web-platform/tests/workers/modules/resources/postmessage-referrer-checker.py new file mode 100644 index 0000000000..699af684a2 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/postmessage-referrer-checker.py @@ -0,0 +1,16 @@ +# Returns a worker script that posts the request's referrer header. +def main(request, response): + referrer = request.headers.get(b"referer", b"") + + response_headers = [(b"Content-Type", b"text/javascript"), + (b"Access-Control-Allow-Origin", b"*")] + + return (200, response_headers, + b"if ('DedicatedWorkerGlobalScope' in self &&" + + b" self instanceof DedicatedWorkerGlobalScope) {" + + b" postMessage('"+referrer+b"');" + + b"} else if (" + + b" 'SharedWorkerGlobalScope' in self &&" + + b" self instanceof SharedWorkerGlobalScope) {" + + b" onconnect = e => e.ports[0].postMessage('"+referrer+b"');" + + b"}") diff --git a/testing/web-platform/tests/workers/modules/resources/redirect.py b/testing/web-platform/tests/workers/modules/resources/redirect.py new file mode 100644 index 0000000000..396bd4c4b2 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/redirect.py @@ -0,0 +1,8 @@ +def main(request, response): + """Simple handler that causes redirection. + This is placed here to stay within the same directory during redirects, + to avoid issues like https://crbug.com/1136775. + """ + response.status = 302 + location = request.GET.first(b"location") + response.headers.set(b"Location", location) diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-and-then-dynamic-import-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-and-then-dynamic-import-worker.js new file mode 100644 index 0000000000..2d857a2e90 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-and-then-dynamic-import-worker.js @@ -0,0 +1,34 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +import * as module from './export-on-dynamic-import-script.js'; + +const sourcePromise = new Promise(resolve => { + if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.target); + }; + } else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + resolve(e.ports[0]); + }; + } else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + resolve(e.source); + }; + } +}); + +export let importedModules = ['export-on-dynamic-import-script.js']; +const importedModulesPromise = module.ready + .then(importedModules => importedModules) + .catch(error => `Failed to do dynamic import: ${error}`); + +Promise.all([sourcePromise, importedModulesPromise]).then(results => { + const [source, importedModules] = results; + source.postMessage(importedModules); +}); diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-data-url-block-cross-origin.js b/testing/web-platform/tests/workers/modules/resources/static-import-data-url-block-cross-origin.js new file mode 100644 index 0000000000..833348d66c --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-data-url-block-cross-origin.js @@ -0,0 +1,14 @@ +import * as module from "data:text/javascript, export const importedModules = ['export-block-cross-origin.js'];"; + +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-non-existent-script-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-non-existent-script-worker.js new file mode 100644 index 0000000000..16f70e9daf --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-non-existent-script-worker.js @@ -0,0 +1 @@ +import './non-existent-script.js'; diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-redirect-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-redirect-worker.js new file mode 100644 index 0000000000..8434c1a34e --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-redirect-worker.js @@ -0,0 +1,21 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +import * as module from './redirect.py?location=/workers/modules/resources/export-on-load-script.js'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + e.source.postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js new file mode 100644 index 0000000000..c543cb4961 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-credentials-checker-worker.sub.js @@ -0,0 +1,12 @@ +// Import a remote origin script. +import * as module from 'http://{{domains[www1]}}:{{ports[http][0]}}/workers/modules/resources/export-credentials.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(module.cookie); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + e.ports[0].postMessage(module.cookie); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-referrer-checker-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-referrer-checker-worker.sub.js new file mode 100644 index 0000000000..45fc5493c9 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-referrer-checker-worker.sub.js @@ -0,0 +1,12 @@ +// Import a remote origin script. +import * as module from 'https://{{domains[www1]}}:{{ports[https][0]}}/workers/modules/resources/export-referrer-checker.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(module.referrer); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + e.ports[0].postMessage(module.referrer); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-script-worker.sub.js b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-script-worker.sub.js new file mode 100644 index 0000000000..6432dd5d80 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-remote-origin-script-worker.sub.js @@ -0,0 +1,20 @@ +// Import a remote origin script. +import * as module from 'https://{{domains[www1]}}:{{ports[https][0]}}/workers/modules/resources/export-on-load-script.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + e.source.postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js new file mode 100644 index 0000000000..e83dc92070 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-credentials-checker-worker.js @@ -0,0 +1,11 @@ +import * as module from './export-credentials.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(module.cookie); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + e.ports[0].postMessage(module.cookie); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-referrer-checker-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-referrer-checker-worker.js new file mode 100644 index 0000000000..ffcab9e45f --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-same-origin-referrer-checker-worker.js @@ -0,0 +1,11 @@ +import * as module from './export-referrer-checker.py'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + postMessage(module.referrer); +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + onconnect = e => { + e.ports[0].postMessage(module.referrer); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-script-block-cross-origin.js b/testing/web-platform/tests/workers/modules/resources/static-import-script-block-cross-origin.js new file mode 100644 index 0000000000..82be8e7ce7 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-script-block-cross-origin.js @@ -0,0 +1,14 @@ +import * as module from './export-block-cross-origin.js'; + +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-syntax-error.js b/testing/web-platform/tests/workers/modules/resources/static-import-syntax-error.js new file mode 100644 index 0000000000..3a20e792c4 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-syntax-error.js @@ -0,0 +1 @@ +import * as module from './syntax-error.js'; diff --git a/testing/web-platform/tests/workers/modules/resources/static-import-worker.js b/testing/web-platform/tests/workers/modules/resources/static-import-worker.js new file mode 100644 index 0000000000..19a347999d --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/static-import-worker.js @@ -0,0 +1,21 @@ +// This script is meant to be imported by a module worker. It receives a +// message from the worker and responds with the list of imported modules. +import * as module from './export-on-load-script.js'; +if ('DedicatedWorkerGlobalScope' in self && + self instanceof DedicatedWorkerGlobalScope) { + self.onmessage = e => { + e.target.postMessage(module.importedModules); + }; +} else if ( + 'SharedWorkerGlobalScope' in self && + self instanceof SharedWorkerGlobalScope) { + self.onconnect = e => { + e.ports[0].postMessage(module.importedModules); + }; +} else if ( + 'ServiceWorkerGlobalScope' in self && + self instanceof ServiceWorkerGlobalScope) { + self.onmessage = e => { + e.source.postMessage(module.importedModules); + }; +} diff --git a/testing/web-platform/tests/workers/modules/resources/syntax-error.js b/testing/web-platform/tests/workers/modules/resources/syntax-error.js new file mode 100644 index 0000000000..8c5c4df671 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/syntax-error.js @@ -0,0 +1 @@ +1 + ; diff --git a/testing/web-platform/tests/workers/modules/resources/throw.js b/testing/web-platform/tests/workers/modules/resources/throw.js new file mode 100644 index 0000000000..3d876d43d9 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/resources/throw.js @@ -0,0 +1 @@ +throw new Error('custom message'); diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-blob-url.window.js b/testing/web-platform/tests/workers/modules/shared-worker-import-blob-url.window.js new file mode 100644 index 0000000000..a79d5725ad --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-blob-url.window.js @@ -0,0 +1,26 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Imports |testCase.scriptURL| on a shared worker loaded from a blob URL, +// and waits until the list of imported modules is sent from the worker. Passes +// if the list is equal to |testCase.expectation|. +function import_blob_url_test(testCase) { + promise_test(async () => { + const importURL = new URL(testCase.scriptURL, location.href); + const blob = + new Blob([`import "${importURL}";`], {type: 'text/javascript'}); + const blobURL = URL.createObjectURL(blob); + const worker = new SharedWorker(blobURL, {type: 'module'}); + worker.port.postMessage('Send message for tests from main script.'); + const msgEvent = await new Promise((resolve, reject) => { + worker.port.onmessage = resolve; + worker.onerror = error => { + const msg = error instanceof ErrorEvent ? error.message + : 'unknown error'; + reject(msg); + }; + }); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_blob_url_test); diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-csp.html b/testing/web-platform/tests/workers/modules/shared-worker-import-csp.html new file mode 100644 index 0000000000..c7ca37557a --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-csp.html @@ -0,0 +1,128 @@ + +SharedWorker: CSP for ES Modules + + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-data-url-cross-origin.html b/testing/web-platform/tests/workers/modules/shared-worker-import-data-url-cross-origin.html new file mode 100644 index 0000000000..3f22c5094d --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-data-url-cross-origin.html @@ -0,0 +1,43 @@ + +SharedWorker: ES modules for data URL workers + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-data-url.window.js b/testing/web-platform/tests/workers/modules/shared-worker-import-data-url.window.js new file mode 100644 index 0000000000..6d54c0e232 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-data-url.window.js @@ -0,0 +1,23 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Imports |testCase.scriptURL| on a shared worker loaded from a data URL, +// and waits until the list of imported modules is sent from the worker. Passes +// if the list is equal to |testCase.expectation|. +function import_data_url_test(testCase) { + promise_test(async () => { + // The Access-Control-Allow-Origin header is necessary because a worker + // loaded from a data URL has a null origin and import() on the worker + // without the header is blocked. + const importURL = new URL(testCase.scriptURL, location.href) + + '?pipe=header(Access-Control-Allow-Origin, *)'; + const dataURL = `data:text/javascript,import "${importURL}";`; + + const worker = new SharedWorker(dataURL, { type: 'module'}); + worker.port.postMessage('Send message for tests from main script.'); + const msgEvent = + await new Promise(resolve => worker.port.onmessage = resolve); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_data_url_test); diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html b/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html new file mode 100644 index 0000000000..14579ba762 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-failure.html @@ -0,0 +1,67 @@ + +SharedWorker: import failure + + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-meta.html b/testing/web-platform/tests/workers/modules/shared-worker-import-meta.html new file mode 100644 index 0000000000..e8e9b51f6a --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-meta.html @@ -0,0 +1,49 @@ + +SharedWorker: import.meta + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import-referrer.html b/testing/web-platform/tests/workers/modules/shared-worker-import-referrer.html new file mode 100644 index 0000000000..1096fd2ad8 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import-referrer.html @@ -0,0 +1,259 @@ + +SharedWorker: Referrer + + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-import.window.js b/testing/web-platform/tests/workers/modules/shared-worker-import.window.js new file mode 100644 index 0000000000..5be49ec125 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-import.window.js @@ -0,0 +1,22 @@ +// META: script=/workers/modules/resources/import-test-cases.js + +// Starts a shared worker for |testCase.scriptURL| and waits until the list +// of imported modules is sent from the worker. Passes if the list is equal to +// |testCase.expectation|. +function import_test(testCase) { + promise_test(async () => { + const worker = new SharedWorker(testCase.scriptURL, {type: 'module'}); + worker.port.postMessage('Send message for tests from main script.'); + const msgEvent = await new Promise((resolve, reject) => { + worker.port.onmessage = resolve; + worker.onerror = error => { + const msg = error instanceof ErrorEvent ? error.message + : 'unknown error'; + reject(msg); + }; + }); + assert_array_equals(msgEvent.data, testCase.expectation); + }, testCase.description); +} + +testCases.forEach(import_test); diff --git a/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html b/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html new file mode 100644 index 0000000000..221dd01a37 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html @@ -0,0 +1,309 @@ + +SharedWorker: WorkerOptions 'credentials' + + + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html.headers b/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html.headers new file mode 100644 index 0000000000..8da851ab73 --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-options-credentials.html.headers @@ -0,0 +1,2 @@ +Set-Cookie: COOKIE_NAME=1 +Access-Control-Allow-Credentials: true diff --git a/testing/web-platform/tests/workers/modules/shared-worker-options-type.html b/testing/web-platform/tests/workers/modules/shared-worker-options-type.html new file mode 100644 index 0000000000..f62eeeb76b --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-options-type.html @@ -0,0 +1,48 @@ + +SharedWorker: WorkerOptions 'type' + + + diff --git a/testing/web-platform/tests/workers/modules/shared-worker-parse-error-failure.html b/testing/web-platform/tests/workers/modules/shared-worker-parse-error-failure.html new file mode 100644 index 0000000000..8f63d5f37a --- /dev/null +++ b/testing/web-platform/tests/workers/modules/shared-worker-parse-error-failure.html @@ -0,0 +1,49 @@ + +SharedWorker: parse error failure + + + + -- cgit v1.2.3