diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /testing/web-platform/tests/trusted-types/worker-constructor.https.html | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rw-r--r-- | testing/web-platform/tests/trusted-types/worker-constructor.https.html | 86 |
1 files changed, 86 insertions, 0 deletions
diff --git a/testing/web-platform/tests/trusted-types/worker-constructor.https.html b/testing/web-platform/tests/trusted-types/worker-constructor.https.html new file mode 100644 index 0000000000..6e127b11a5 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/worker-constructor.https.html @@ -0,0 +1,86 @@ +<!doctype html> +<html> +<head> + <meta http-equiv="Content-Security-Policy" content="require-trusted-types-for 'script';"> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> +<script> + +const test_url = "support/WorkerGlobalScope-importScripts.https.js" +const trusted_url = trustedTypes.createPolicy("anythinggoes", { + createScriptURL: x => x}).createScriptURL(test_url); +const default_url = "support/WorkerGlobalScope-importScripts.potato.js" + +async function service_worker(url) { + if (!('serviceWorker' in navigator)) return Promise.resolve(); + + const scope = 'support/some/scope/for/this/test'; + const reg = await navigator.serviceWorker.getRegistration(scope); + if (reg) await reg.unregister(); + return await navigator.serviceWorker.register(url, {scope}); +} + +// Most tests below don't need promises, but the ones related to +// ServiceWorkers do. Since we can't mix promise and non-promise tests, +// we'll just run the non-promise tests in the main function and return +// an empty-resolved promise for those. +// Since an active default policy will affect all subsequent DOM operations, +// we're wrapping policy creation in a promise_test. Together, this will +// force proper serialization of all tests. +// +// Generally, we don't actually care what the workers here do, we'll merely +// check whether creation succeeds. + +promise_test(t => { + new Worker(trusted_url); + return Promise.resolve(); +}, "Create Worker via ScriptTestUrl"); + +promise_test(t => { + new SharedWorker(trusted_url); + return Promise.resolve(); +}, "Create SharedWorker via ScriptTestUrl"); + +promise_test(t => { + return service_worker(trusted_url); +}, "Create ServiceWorker via ScriptTestUrl"); + +promise_test(t => { + assert_throws_js(TypeError, () => new Worker(test_url)); + return Promise.resolve(); +}, "Block Worker creation via string"); + +promise_test(t => { + assert_throws_js(TypeError, () => new SharedWorker(test_url)); + return Promise.resolve(); +}, "Block SharedWorker creation via string"); + +promise_test(t => { + return promise_rejects_js(t, TypeError, service_worker(test_url)); +}, "Block ServiceWorker creation via String"); + +// Tests with default policy. +promise_test(t => { + trustedTypes.createPolicy("default", { + createScriptURL: s => s.replace("potato", "https") }); + return Promise.resolve(); +}, "Setup default policy."); + +promise_test(t => { + new Worker(default_url); + return Promise.resolve(); +}, "Create Worker via string with default policy."); + +promise_test(t => { + new SharedWorker(default_url); + return Promise.resolve(); +}, "Create SharedWorker via string with default policy."); + +promise_test(t => { + return service_worker(default_url); +}, "Create ServiceWorker via string with default policy."); + +</script> +</body> |