From 4e9b210636bb69a3974d28b472f1899360ff24f3 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 1 Jan 2025 01:03:15 +0000 Subject: [PATCH] Bug 1907849: part 8) Add WPTs for trusted types when constructing Workers from WorkerGlobalScope. r=smaug Fixes https://github.com/w3c/trusted-types/issues/567. Differential Revision: https://phabricator.services.mozilla.com/D232359 UltraBlame original commit: 1615038844f1294ee4033d766e9080f0c7dbda3b --- ...kerGlobalScope-worker-constructor.html.ini | 22 +++ .../WorkerGlobalScope-worker-constructor.html | 96 ++++++++++ .../WorkerGlobalScope-worker-constructor.js | 172 ++++++++++++++++++ ...rGlobalScope-worker-constructor.js.headers | 16 ++ 4 files changed, 306 insertions(+) create mode 100644 testing/web-platform/meta/trusted-types/WorkerGlobalScope-worker-constructor.html.ini create mode 100644 testing/web-platform/tests/trusted-types/WorkerGlobalScope-worker-constructor.html create mode 100644 testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js create mode 100644 testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js.headers diff --git a/testing/web-platform/meta/trusted-types/WorkerGlobalScope-worker-constructor.html.ini b/testing/web-platform/meta/trusted-types/WorkerGlobalScope-worker-constructor.html.ini new file mode 100644 index 0000000000000..288b7abd650ca --- /dev/null +++ b/testing/web-platform/meta/trusted-types/WorkerGlobalScope-worker-constructor.html.ini @@ -0,0 +1,22 @@ +[ +WorkerGlobalScope +- +worker +- +constructor +. +html +] +[ +Creating +a +Worker +from +a +string +should +throw +] +expected +: +FAIL diff --git a/testing/web-platform/tests/trusted-types/WorkerGlobalScope-worker-constructor.html b/testing/web-platform/tests/trusted-types/WorkerGlobalScope-worker-constructor.html new file mode 100644 index 0000000000000..f012763b4b292 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/WorkerGlobalScope-worker-constructor.html @@ -0,0 +1,96 @@ +< +! +DOCTYPE +html +> +< +html +> +< +head +> +< +meta +charset += +" +utf +- +8 +" +> +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +/ +head +> +< +body +> +< +script +> +fetch_tests_from_worker +( +new +Worker +( +" +support +/ +WorkerGlobalScope +- +worker +- +constructor +. +js +" +) +) +; +< +/ +script +> +< +/ +body +> +< +/ +html +> diff --git a/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js b/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js new file mode 100644 index 0000000000000..bd03b83fdcd2e --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js @@ -0,0 +1,172 @@ +const +test_setup_policy += +trustedTypes +. +createPolicy +( +" +p +" +{ +createScriptURL +: +s += +> +s +} +) +; +importScripts +( +test_setup_policy +. +createScriptURL +( +" +/ +resources +/ +testharness +. +js +" +) +) +; +test +( +( +) += +> +{ +assert_throws_js +( +TypeError +( +) += +> +{ +new +Worker +( +" +w +" +) +; +} +" +Creating +a +Worker +threw +" +) +; +} +" +Creating +a +Worker +from +a +string +should +throw +" +) +; +test +( +( +) += +> +{ +new +Worker +( +test_setup_policy +. +createScriptURL +( +" +u +" +) +) +; +} +" +Creating +a +Worker +from +a +TrustedScriptURL +should +not +throw +" +) +; +test +( +( +) += +> +{ +trustedTypes +. +createPolicy +( +" +default +" +{ +createScriptURL +: +s += +> +" +defaultValue +" +} +) +; +new +Worker +( +" +s +" +) +; +} +" +Creating +a +Worker +from +a +string +with +a +default +policy +should +not +throw +" +) +; +done +( +) +; diff --git a/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js.headers b/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js.headers new file mode 100644 index 0000000000000..6b6f2522ef7ab --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/WorkerGlobalScope-worker-constructor.js.headers @@ -0,0 +1,16 @@ +Content +- +Security +- +Policy +: +require +- +trusted +- +types +- +for +' +script +'