diff --git a/testing/web-platform/tests/docs/writing-tests/testharness.md b/testing/web-platform/tests/docs/writing-tests/testharness.md index db672cce99851..d952ecf705921 100644 --- a/testing/web-platform/tests/docs/writing-tests/testharness.md +++ b/testing/web-platform/tests/docs/writing-tests/testharness.md @@ -1184,6 +1184,30 @@ META : global = +dedicatedworker +- +module +/ +/ += += +> +would +run +in +the +dedicated +worker +scope +as +a +module +/ +/ +META +: +global += worker / / @@ -1290,6 +1314,37 @@ html code > * +dedicatedworker +- +module +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +worker +- +module +. +html +< +/ +code +> +* serviceworker : to @@ -1324,7 +1379,75 @@ is implied ) * +serviceworker +- +module +: +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +serviceworker +- +module +. +html +< +/ +code +> +( +. +https +is +implied +) +* +sharedworker +: +to +be +run +at +< +code +> +< +var +> +x +< +/ +var +> +. +any +. +sharedworker +. +html +< +/ +code +> +* sharedworker +- +module : to be @@ -1345,6 +1468,8 @@ var any . sharedworker +- +module . html < @@ -1605,6 +1730,50 @@ in a test . +In +window +environments +the +script +will +be +included +using +a +classic +< +script +> +tag +. +In +classic +worker +environments +the +script +will +be +imported +using +importScripts +( +) +. +In +module +worker +environments +the +script +will +be +imported +using +a +static +import +. # # # diff --git a/testing/web-platform/tests/service-workers/service-worker/import-module-scripts.https.html b/testing/web-platform/tests/service-workers/service-worker/import-module-scripts.https.html deleted file mode 100644 index a24c3392d13f4..0000000000000 --- a/testing/web-platform/tests/service-workers/service-worker/import-module-scripts.https.html +++ /dev/null @@ -1,342 +0,0 @@ -< -! -DOCTYPE -html -> -< -meta -charset -= -" -utf -- -8 -" -> -< -title -> -Tests -for -module -import -: -ServiceWorker -< -/ -title -> -< -script -src -= -" -/ -resources -/ -testharness -. -js -" -> -< -/ -script -> -< -script -src -= -" -/ -resources -/ -testharnessreport -. -js -" -> -< -/ -script -> -< -script -src -= -" -resources -/ -test -- -helpers -. -sub -. -js -" -> -< -/ -script -> -< -script -src -= -" -/ -workers -/ -modules -/ -resources -/ -import -- -test -- -cases -. -js -" -> -< -/ -script -> -< -body -> -< -script -> -function -import_test -( -testCase -) -{ -promise_test -( -async -t -= -> -{ -const -msgPromise1 -= -new -Promise -( -resolve -= -> -{ -navigator -. -serviceWorker -. -onmessage -= -resolve -; -} -) -; -await -service_worker_unregister -( -t -testCase -. -scriptURL -) -; -t -. -add_cleanup -( -( -) -= -> -service_worker_unregister -( -t -testCase -. -scriptURL -) -) -; -const -registration -= -await -navigator -. -serviceWorker -. -register -( -testCase -. -scriptURL -{ -scope -: -testCase -. -scriptURL -type -: -' -module -' -} -) -; -registration -. -installing -. -postMessage -( -' -Send -message -for -tests -from -main -script -. -' -) -; -const -msgEvent1 -= -await -msgPromise1 -; -assert_array_equals -( -msgEvent1 -. -data -testCase -. -expectation -) -; -/ -/ -Tests -importing -module -scripts -for -updated -service -workers -. -const -msgPromise2 -= -new -Promise -( -resolve -= -> -{ -navigator -. -serviceWorker -. -onmessage -= -resolve -; -} -) -; -await -registration -. -update -( -) -; -const -worker -= -registration -. -installing -? -registration -. -installing -: -registration -. -active -; -worker -. -postMessage -( -' -Send -message -for -tests -from -main -script -. -' -) -; -const -msgEvent2 -= -await -msgPromise2 -; -assert_array_equals -( -msgEvent2 -. -data -testCase -. -expectation -) -; -} -testCase -. -description -) -; -} -testCases -. -forEach -( -import_test -) -; -< -/ -script -> -< -/ -body -> diff --git a/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import-in-module.any.js b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import-in-module.any.js new file mode 100644 index 0000000000000..b49a4afa27e35 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import-in-module.any.js @@ -0,0 +1,28 @@ +import +' +. +/ +basic +- +module +- +2 +. +js +' +; +import +' +. +/ +resources +/ +no +- +dynamic +- +import +. +js +' +; diff --git a/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import.any.js b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import.any.js new file mode 100644 index 0000000000000..2e5304ab99abb --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import.any.js @@ -0,0 +1,15 @@ +importScripts +( +' +resources +/ +no +- +dynamic +- +import +. +js +' +) +; diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/basic-module-2.js b/testing/web-platform/tests/service-workers/service-worker/resources/basic-module-2.js new file mode 100644 index 0000000000000..05688e9d6c6ca --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/basic-module-2.js @@ -0,0 +1,8 @@ +export +default +' +hello +again +! +' +; diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/basic-module.js b/testing/web-platform/tests/service-workers/service-worker/resources/basic-module.js new file mode 100644 index 0000000000000..0623c7f2c26b4 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/basic-module.js @@ -0,0 +1,7 @@ +export +default +' +hello +! +' +; diff --git a/testing/web-platform/tests/service-workers/service-worker/resources/no-dynamic-import.js b/testing/web-platform/tests/service-workers/service-worker/resources/no-dynamic-import.js new file mode 100644 index 0000000000000..ffe0b187741f2 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/no-dynamic-import.js @@ -0,0 +1,107 @@ +const +importUrlTests += +[ +[ +" +Module +URL +" +" +. +/ +basic +- +module +. +js +" +] +[ +" +Another +module +URL +" +" +. +/ +basic +- +module +- +2 +. +js +" +] +[ +" +Module +data +: +URL +" +" +data +: +text +/ +javascript +; +charset += +utf +- +8 +" ++ +encodeURIComponent +( +export +default +' +hello +! +' +; +) +] +] +; +for +( +const +[ +name +url +] +of +importUrlTests +) +{ +promise_test +( +( +t +) += +> +promise_rejects_js +( +t +TypeError +import +( +url +) +" +Import +must +reject +" +) +name +) +; +} diff --git a/testing/web-platform/tests/tools/manifest/sourcefile.py b/testing/web-platform/tests/tools/manifest/sourcefile.py index d2bc8b3daf246..d1f43d0942720 100644 --- a/testing/web-platform/tests/tools/manifest/sourcefile.py +++ b/testing/web-platform/tests/tools/manifest/sourcefile.py @@ -482,6 +482,20 @@ True } +" +serviceworker +- +module +" +: +{ +" +force_https +" +: +True +} + " sharedworker " @@ -489,8 +503,38 @@ { } +" +sharedworker +- +module +" +: +{ +} + +" +dedicatedworker +" +: +{ +" +suffix +" +: +" +. +any +. +worker +. +html +" +} + " dedicatedworker +- +module " : { @@ -503,6 +547,8 @@ any . worker +- +module . html " @@ -530,6 +576,15 @@ } } +" +worker +- +module +" +: +{ +} + " jsshell " diff --git a/testing/web-platform/tests/tools/serve/serve.py b/testing/web-platform/tests/tools/serve/serve.py index 77a0d6fe00f20..4c48254e9b630 100644 --- a/testing/web-platform/tests/tools/serve/serve.py +++ b/testing/web-platform/tests/tools/serve/serve.py @@ -1575,6 +1575,173 @@ " " class +WorkerModulesHandler +( +HtmlWrapperHandler +) +: + +global_type += +" +dedicatedworker +- +module +" + +path_replace += +[ +( +" +. +any +. +worker +- +module +. +html +" +" +. +any +. +js +" +" +. +any +. +worker +- +module +. +js +" +) + +( +" +. +worker +. +html +" +" +. +worker +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +fetch_tests_from_worker +( +new +Worker +( +" +% +( +path +) +s +% +( +query +) +s +" +{ +type +: +" +module +" +} +) +) +; +< +/ +script +> +" +" +" +class WindowHandler ( HtmlWrapperHandler @@ -1990,7 +2157,7 @@ " " class -ServiceWorkersHandler +SharedWorkerModulesHandler ( HtmlWrapperHandler ) @@ -1999,7 +2166,9 @@ global_type = " -serviceworker +sharedworker +- +module " path_replace @@ -2010,7 +2179,9 @@ . any . -serviceworker +sharedworker +- +module . html " @@ -2025,6 +2196,8 @@ any . worker +- +module . js " @@ -2101,59 +2274,10 @@ < script > +fetch_tests_from_worker ( -async -function -( -) -{ - -const -scope -= -' -does -/ -not -/ -exist -' -; - -let -reg -= -await -navigator -. -serviceWorker -. -getRegistration -( -scope -) -; - -if -( -reg -) -await -reg -. -unregister -( -) -; - -reg -= -await -navigator -. -serviceWorker -. -register +new +SharedWorker ( " % @@ -2168,21 +2292,13 @@ s " { -scope -} -) -; - -fetch_tests_from_worker -( -reg -. -installing -) -; +type +: +" +module +" } ) -( ) ; < @@ -2193,29 +2309,595 @@ " " class -AnyWorkerHandler +ServiceWorkersHandler +( +HtmlWrapperHandler +) +: + +global_type += +" +serviceworker +" + +path_replace += +[ +( +" +. +any +. +serviceworker +. +html +" +" +. +any +. +js +" +" +. +any +. +worker +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +( +async +function +( +) +{ + +const +scope += +' +does +/ +not +/ +exist +' +; + +let +reg += +await +navigator +. +serviceWorker +. +getRegistration +( +scope +) +; + +if +( +reg +) +await +reg +. +unregister +( +) +; + +reg += +await +navigator +. +serviceWorker +. +register +( +" +% +( +path +) +s +% +( +query +) +s +" +{ +scope +} +) +; + +fetch_tests_from_worker +( +reg +. +installing +) +; +} +) +( +) +; +< +/ +script +> +" +" +" +class +ServiceWorkerModulesHandler +( +HtmlWrapperHandler +) +: + +global_type += +" +serviceworker +- +module +" + +path_replace += +[ +( +" +. +any +. +serviceworker +- +module +. +html +" + +" +. +any +. +js +" +" +. +any +. +worker +- +module +. +js +" +) +] + +wrapper += +" +" +" +< +! +doctype +html +> +< +meta +charset += +utf +- +8 +> +% +( +meta +) +s +< +script +src += +" +/ +resources +/ +testharness +. +js +" +> +< +/ +script +> +< +script +src += +" +/ +resources +/ +testharnessreport +. +js +" +> +< +/ +script +> +< +div +id += +log +> +< +/ +div +> +< +script +> +( +async +function +( +) +{ + +const +scope += +' +does +/ +not +/ +exist +' +; + +let +reg += +await +navigator +. +serviceWorker +. +getRegistration +( +scope +) +; + +if +( +reg +) +await +reg +. +unregister +( +) +; + +reg += +await +navigator +. +serviceWorker +. +register +( + +" +% +( +path +) +s +% +( +query +) +s +" + +{ +scope +type +: +' +module +' +} + +) +; + +fetch_tests_from_worker +( +reg +. +installing +) +; +} +) +( +) +; +< +/ +script +> +" +" +" +class +BaseWorkerHandler +( +WrapperHandler +) +: + +headers += +[ +( +' +Content +- +Type +' +' +text +/ +javascript +' +) +] + +def +_meta_replacement +( +self +key +value +) +: + +return +None + +abc +. +abstractmethod + +def +_create_script_import +( +self +attribute +) +: + +pass + +def +_script_replacement +( +self +key +value +) +: + +if +key += += +" +script +" +: + +attribute += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( +' +" +' +' +\ +\ +" +' +) + +return +self +. +_create_script_import +( +attribute +) + +if +key += += +" +title +" +: + +value += +value +. +replace +( +" +\ +\ +" +" +\ +\ +\ +\ +" +) +. +replace +( +' +" +' +' +\ +\ +" +' +) + +return +' +self +. +META_TITLE += +" +% +s +" +; +' +% +value + +return +None +class +ClassicWorkerHandler ( -WrapperHandler +BaseWorkerHandler ) : -headers -= -[ -( -' -Content -- -Type -' -' -text -/ -javascript -' -) -] - path_replace = [ @@ -2313,123 +2995,137 @@ " def -_meta_replacement +_create_script_import ( self -key -value +attribute ) : return -None - -def -_script_replacement +' +importScripts ( -self -key -value +" +% +s +" +) +' +% +attribute +class +ModuleWorkerHandler +( +BaseWorkerHandler ) : - -if -key -= + +path_replace = +[ +( +" +. +any +. +worker +- +module +. +js " -script " -: - -attribute -= -value . -replace -( +any +. +js " -\ -\ +) +] + +wrapper += " " -\ -\ -\ -\ " +% +( +meta ) +s +self . -replace +GLOBAL += +{ + +isWindow +: +function ( -' -" -' -' -\ -\ -" -' ) - +{ return -' -importScripts +false +; +} + +isWorker +: +function ( +) +{ +return +true +; +} +} +; +import +" +/ +resources +/ +testharness +. +js " +; % +( +script +) s +import " -) -' % -attribute - -if -key -= -= -" -title -" -: - -value -= -value -. -replace ( +path +) +s " -\ -\ +; +done +( +) +; " " -\ -\ -\ -\ " -) -. -replace + +def +_create_script_import ( -' -" -' -' -\ -\ -" -' +self +attribute ) - +: + return ' -self -. -META_TITLE -= +import " % s @@ -2437,10 +3133,7 @@ ; ' % -value - -return -None +attribute rewrites = [ @@ -2826,6 +3519,22 @@ WorkersHandler ) +( +" +GET +" +" +* +. +worker +- +module +. +html +" +WorkerModulesHandler +) + ( " GET @@ -2870,6 +3579,24 @@ SharedWorkersHandler ) +( +" +GET +" +" +* +. +any +. +sharedworker +- +module +. +html +" +SharedWorkerModulesHandler +) + ( " GET @@ -2886,6 +3613,24 @@ ServiceWorkersHandler ) +( +" +GET +" +" +* +. +any +. +serviceworker +- +module +. +html +" +ServiceWorkerModulesHandler +) + ( " GET @@ -2899,7 +3644,25 @@ . js " -AnyWorkerHandler +ClassicWorkerHandler +) + +( +" +GET +" +" +* +. +any +. +worker +- +module +. +js +" +ModuleWorkerHandler ) ( diff --git a/testing/web-platform/tests/tools/wptserve/tests/functional/test_handlers.py b/testing/web-platform/tests/tools/wptserve/tests/functional/test_handlers.py index 50fc403453477..c6014392fe88e 100644 --- a/testing/web-platform/tests/tools/wptserve/tests/functional/test_handlers.py +++ b/testing/web-platform/tests/tools/wptserve/tests/functional/test_handlers.py @@ -4547,7 +4547,7 @@ ServiceWorkersHandler ) class -TestAnyWorkerHandler +TestClassicWorkerHandler ( TestWrapperHandlerUsingServer ) @@ -4597,7 +4597,7 @@ serve . -AnyWorkerHandler +ClassicWorkerHandler ) if __name__