From 079ee9a36a2ae120b6f1e2a83d66576f44d964d8 Mon Sep 17 00:00:00 2001 From: Marco Castelluccio Date: Wed, 1 Jan 2025 01:13:16 +0000 Subject: [PATCH] Bug 1907849: part 7) Add Worker tests to . r=smaug Fixes https://github.com/w3c/trusted-types/issues/568. Differential Revision: https://phabricator.services.mozilla.com/D232323 UltraBlame original commit: 64153e8a66668197c1a1a6398a1b7151eea286d3 --- ...ndowTimers-setTimeout-setInterval.html.ini | 73 +++ testing/web-platform/tests/lint.ignore | 4 +- ...OMWindowTimers-setTimeout-setInterval.html | 562 ++++++------------ ...dowTimers-setTimeout-setInterval-worker.js | 75 +++ ...s-setTimeout-setInterval-worker.js.headers | 17 + .../DOMWindowTimers-setTimeout-setInterval.js | 515 ++++++++++++++++ 6 files changed, 879 insertions(+), 367 deletions(-) create mode 100644 testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js create mode 100644 testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers create mode 100644 testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js diff --git a/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini b/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini index 958a5355e855e..ee51476824a19 100644 --- a/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini +++ b/testing/web-platform/meta/trusted-types/DOMWindowTimers-setTimeout-setInterval.html.ini @@ -26,6 +26,7 @@ debug OK TIMEOUT ] +TIMEOUT [ window . @@ -94,3 +95,75 @@ debug PASS TIMEOUT ] +[ +DedicatedWorkerGlobalScope +. +setTimeout +assigned +via +default +policy +( +successful +Script +transformation +) +. +] +expected +: +TIMEOUT +[ +DedicatedWorkerGlobalScope +. +setInterval +assigned +via +default +policy +( +successful +Script +transformation +) +. +] +expected +: +TIMEOUT +[ +SharedWorkerGlobalScope +. +setTimeout +assigned +via +default +policy +( +successful +Script +transformation +) +. +] +expected +: +TIMEOUT +[ +SharedWorkerGlobalScope +. +setInterval +assigned +via +default +policy +( +successful +Script +transformation +) +. +] +expected +: +TIMEOUT diff --git a/testing/web-platform/tests/lint.ignore b/testing/web-platform/tests/lint.ignore index a8889cec55daf..64917646b1904 100644 --- a/testing/web-platform/tests/lint.ignore +++ b/testing/web-platform/tests/lint.ignore @@ -4020,13 +4020,15 @@ trusted - types / +support +/ DOMWindowTimers - setTimeout - setInterval . -html +js SET TIMEOUT : diff --git a/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html b/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html index 9014e14a394b8..c95a2c54ed144 100644 --- a/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html +++ b/testing/web-platform/tests/trusted-types/DOMWindowTimers-setTimeout-setInterval.html @@ -4,6 +4,50 @@ html > < +html +> +< +head +> +< +meta +charset += +" +utf +- +8 +" +> +< +meta +http +- +equiv += +" +Content +- +Security +- +Policy +" +content += +" +require +- +trusted +- +types +- +for +' +script +' +" +> +< script src = @@ -56,438 +100,224 @@ script > < -meta -http -- -equiv +link +rel = " -Content -- -Security -- -Policy +help " -content +href = " -require +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +multipage +/ +timers - -trusted +and - -types +user - -for -' -script -' +prompts +. +html +# +timer +- +initialisation +- +steps " > < -body +/ +head > < -script -> -async_test -( -t -= +body > -{ -window -. -timeoutTrustedTest -= -t -; -let -policy -= -createScript_policy -( -window -' -timeout -' -) -; -let -script -= -policy -. -createScript -( +< +! +- +- " -window -. -timeoutTrustedTest -. -done -( -) -; +META +: +global += +worker " -) -; -setTimeout ( -script -) -; -} -" -window +https +: +/ +/ +web +- +platform +- +tests . -setTimeout -assigned -via -policy -( -successful -Script -transformation -) +org +/ +writing +- +tests +/ +testharness . -" +html +# +tests +- +for +- +other +- +or +- +multiple +- +globals +- +any +- +js ) -; -async_test -( +can +' t -= -> -{ -window +be +used +here +because +constructing +the +worker +would +require +a +trusted +type . -intervalTrustedTest -= -t -; -let -policy -= -createScript_policy -( -window -' -script -' -) -; -let +- +- +> +< script +src = -policy -. -createScript -( " -window -. -intervalTrustedTest -. -done -( -) -; -" -) -; -setInterval -( -script -) -; -} -" -window -. +support +/ +DOMWindowTimers +- +setTimeout +- setInterval -assigned -via -policy -( -successful -Script -transformation -) . +js " -) -; +> +< +/ +script +> +< +script +> +let +test_setup_policy += trustedTypes . createPolicy ( " -default +p " { -createScript +createScriptURL : -( -s -_ -sink -) +x = > -{ -if -( -s -= -= -= -" -timeoutStringTest -" -) -{ -assert_equals -( -sink -' -Window -setTimeout -' -) -; +x } -else -if -( -s -= -= -= -" -intervalStringTest -" -) -{ -assert_equals -( -sink -' -Window -setInterval -' ) ; -} -return -" -window -. -" -+ -s -+ -" -. -done +fetch_tests_from_worker ( -) -" -; -} -} -) -; -async_test +new +Worker ( -t -= -> -{ -window +test_setup_policy . -timeoutStringTest -= -t -; -let -script -= -" -timeoutStringTest -" -; -setTimeout +createScriptURL ( -script -) -; -} " -window -. +support +/ +DOMWindowTimers +- setTimeout -assigned -via -default -policy -( -successful -Script -transformation -) -. -" -) -; -async_test -( -t -= -> -{ -window +- +setInterval +- +worker . -intervalStringTest -= -t -; -let -script -= -" -intervalStringTest +js " -; -setInterval -( -script ) -; -} -" -window -. -setInterval -assigned -via -default -policy -( -successful -Script -transformation ) -. -" ) ; -async_test +fetch_tests_from_worker ( -t -= -> -{ -window -. -timeoutFunctionTest -= -t -; -let -script -= +new +SharedWorker ( -) -= -> -window -. -timeoutFunctionTest +test_setup_policy . -done -( -) -; -setTimeout +createScriptURL ( -script -) -; -} " -window -. +support +/ +DOMWindowTimers +- setTimeout -assigned -with -a -function -handler -shouldn -' -t -go -through -default -policy +- +setInterval +- +worker . +js " ) -; -async_test -( -t -= -> -{ -window -. -intervalFunctionTest -= -t -; -let -script -= -( ) -= -> -window -. -intervalFunctionTest -. -done -( -) -; -setInterval -( -script -) -; -} -" -window -. -setInterval -assigned -with -a -function -handler -shouldn -' -t -go -through -default -policy -. -" ) ; < / script > +< +/ +body +> +< +/ +html +> diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js new file mode 100644 index 0000000000000..e591362f9744d --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js @@ -0,0 +1,75 @@ +let +test_setup_policy += +trustedTypes +. +createPolicy +( +" +p +" +{ +createScriptURL +: +x += +> +x +} +) +; +importScripts +( +test_setup_policy +. +createScriptURL +( +" +/ +resources +/ +testharness +. +js +" +) +) +; +importScripts +( +test_setup_policy +. +createScriptURL +( +" +helper +. +sub +. +js +" +) +) +; +importScripts +( +test_setup_policy +. +createScriptURL +( +" +DOMWindowTimers +- +setTimeout +- +setInterval +. +js +" +) +) +; +done +( +) +; diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers new file mode 100644 index 0000000000000..f00be599736f1 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval-worker.js.headers @@ -0,0 +1,17 @@ +Content +- +Security +- +Policy +: +require +- +trusted +- +types +- +for +' +script +' +; diff --git a/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js new file mode 100644 index 0000000000000..c9f8b90f491b0 --- /dev/null +++ b/testing/web-platform/tests/trusted-types/support/DOMWindowTimers-setTimeout-setInterval.js @@ -0,0 +1,515 @@ +/ +/ +globalThis +. +toString +( +) +is +of +the +form +" +[ +Object +< +someName +> +] +" +. +const +globalThisStr += +globalThis +. +toString +( +) +. +split +( +" +" +) +[ +1 +] +. +slice +( +0 +- +1 +) +; +async_test +( +t += +> +{ +globalThis +. +timeoutTrustedTest += +t +; +let +policy += +createScript_policy +( +globalThis +' +timeout +' +) +; +let +script += +policy +. +createScript +( +" +globalThis +. +timeoutTrustedTest +. +done +( +) +; +" +) +; +globalThis +. +setTimeout +( +script +) +; +} +{ +globalThisStr +} +. +setTimeout +assigned +via +policy +( +successful +Script +transformation +) +. +) +; +async_test +( +t += +> +{ +globalThis +. +intervalTrustedTest += +t +; +let +policy += +createScript_policy +( +globalThis +' +script +' +) +; +let +script += +policy +. +createScript +( +" +globalThis +. +intervalTrustedTest +. +done +( +) +; +" +) +; +globalThis +. +setInterval +( +script +) +; +} +{ +globalThisStr +} +. +setInterval +assigned +via +policy +( +successful +Script +transformation +) +. +) +; +globalThis +. +trustedTypes +. +createPolicy +( +" +default +" +{ +createScript +: +( +s +_ +sink +) += +> +{ +/ +/ +https +: +/ +/ +html +. +spec +. +whatwg +. +org +/ +multipage +/ +timers +- +and +- +user +- +prompts +. +html +# +timer +- +initialisation +- +steps +/ +/ +step +9 +. +6 +. +1 +. +1 +. +const +expectedSink += +globalThisStr +. +includes +( +" +Window +" +) +? +" +Window +" +: +" +Worker +" +; +if +( +s += += += +" +timeoutStringTest +" +) +{ +assert_equals +( +sink +{ +expectedSink +} +setTimeout +) +; +} +else +if +( +s += += += +" +intervalStringTest +" +) +{ +assert_equals +( +sink +{ +expectedSink +} +setInterval +) +; +} +return +" +globalThis +. +" ++ +s ++ +" +. +done +( +) +" +; +} +} +) +; +async_test +( +t += +> +{ +globalThis +. +timeoutStringTest += +t +; +let +script += +" +timeoutStringTest +" +; +globalThis +. +setTimeout +( +script +) +; +} +{ +globalThisStr +} +. +setTimeout +assigned +via +default +policy +( +successful +Script +transformation +) +. +) +; +async_test +( +t += +> +{ +globalThis +. +intervalStringTest += +t +; +let +script += +" +intervalStringTest +" +; +globalThis +. +setInterval +( +script +) +; +} +{ +globalThisStr +} +. +setInterval +assigned +via +default +policy +( +successful +Script +transformation +) +. +) +; +async_test +( +t += +> +{ +globalThis +. +timeoutFunctionTest += +t +; +let +script += +( +) += +> +globalThis +. +timeoutFunctionTest +. +done +( +) +; +setTimeout +( +script +) +; +} +{ +globalThisStr +} +. +setTimeout +assigned +with +a +function +handler +shouldn +' +t +go +through +default +policy +. +) +; +async_test +( +t += +> +{ +globalThis +. +intervalFunctionTest += +t +; +let +script += +( +) += +> +globalThis +. +intervalFunctionTest +. +done +( +) +; +setInterval +( +script +) +; +} +{ +globalThisStr +} +. +setInterval +assigned +with +a +function +handler +shouldn +' +t +go +through +default +policy +. +) +;