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..8de4e859aa41d --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import-in-module.any.js @@ -0,0 +1,70 @@ +/ +/ +META +: +global += +serviceworker +- +module +/ +/ +This +is +imported +to +ensure +import +( +' +. +/ +basic +- +module +- +2 +. +js +' +) +fails +even +if +/ +/ +it +has +been +previously +statically +imported +. +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..fdf3c5347311c --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/no-dynamic-import.any.js @@ -0,0 +1,22 @@ +/ +/ +META +: +global += +serviceworker +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..452e2b52a67f6 --- /dev/null +++ b/testing/web-platform/tests/service-workers/service-worker/resources/no-dynamic-import.js @@ -0,0 +1,147 @@ +/ +* +* +type +{ +[ +name +: +string +url +: +string +] +[ +] +} +* +/ +const +importUrlTests += +[ +[ +" +Module +URL +" +" +. +/ +basic +- +module +. +js +" +] +/ +/ +In +no +- +dynamic +- +import +- +in +- +module +. +any +. +js +this +module +is +also +statically +imported +[ +" +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 17fe8b8a18b00..77a9d04b9d54b 100644 --- a/testing/web-platform/tests/tools/manifest/sourcefile.py +++ b/testing/web-platform/tests/tools/manifest/sourcefile.py @@ -535,6 +535,20 @@ True } +" +serviceworker +- +module +" +: +{ +" +force_https +" +: +True +} + " sharedworker " @@ -542,8 +556,38 @@ { } +" +sharedworker +- +module +" +: +{ +} + +" +dedicatedworker +" +: +{ +" +suffix +" +: +" +. +any +. +worker +. +html +" +} + " dedicatedworker +- +module " : { @@ -556,6 +600,8 @@ any . worker +- +module . html " @@ -583,6 +629,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 c537fb664d3af..989fe0be80390 100644 --- a/testing/web-platform/tests/tools/serve/serve.py +++ b/testing/web-platform/tests/tools/serve/serve.py @@ -1702,6 +1702,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 @@ -2117,7 +2284,7 @@ " " class -ServiceWorkersHandler +SharedWorkerModulesHandler ( HtmlWrapperHandler ) @@ -2126,7 +2293,9 @@ global_type = " -serviceworker +sharedworker +- +module " path_replace @@ -2137,7 +2306,9 @@ . any . -serviceworker +sharedworker +- +module . html " @@ -2152,6 +2323,8 @@ any . worker +- +module . js " @@ -2228,59 +2401,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 ( " % @@ -2295,21 +2419,13 @@ s " { -scope -} -) -; - -fetch_tests_from_worker -( -reg -. -installing -) -; +type +: +" +module +" } ) -( ) ; < @@ -2320,15 +2436,436 @@ " " class -AnyWorkerHandler +ServiceWorkersHandler ( -WrapperHandler +HtmlWrapperHandler ) : -headers +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 @@ -2341,7 +2878,179 @@ javascript ' ) -] +] + +def +_meta_replacement +( +self +key +value +) +: + +return +None + +abc +. +abstractmethod + +def +_create_script_import +( +self +attribute +) +: + +# +Take +attribute +( +a +string +URL +to +a +JS +script +) +and +return +JS +source +to +import +the +script + +# +into +the +worker +. + +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 +( +BaseWorkerHandler +) +: path_replace = @@ -2440,123 +3149,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 @@ -2564,10 +3287,7 @@ ; ' % -value - -return -None +attribute rewrites = [ @@ -2984,6 +3704,22 @@ WorkersHandler ) +( +" +GET +" +" +* +. +worker +- +module +. +html +" +WorkerModulesHandler +) + ( " GET @@ -3028,6 +3764,24 @@ SharedWorkersHandler ) +( +" +GET +" +" +* +. +any +. +sharedworker +- +module +. +html +" +SharedWorkerModulesHandler +) + ( " GET @@ -3044,6 +3798,40 @@ ServiceWorkersHandler ) +( +" +GET +" +" +* +. +any +. +serviceworker +- +module +. +html +" +ServiceWorkerModulesHandler +) + +( +" +GET +" +" +* +. +any +. +worker +. +js +" +ClassicWorkerHandler +) + ( " GET @@ -3054,10 +3842,12 @@ any . worker +- +module . js " -AnyWorkerHandler +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 49fc9614e19de..df28627cf75b3 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 @@ -4613,7 +4613,7 @@ ServiceWorkersHandler ) class -TestAnyWorkerHandler +TestClassicWorkerHandler ( TestWrapperHandlerUsingServer ) @@ -4663,7 +4663,7 @@ serve . -AnyWorkerHandler +ClassicWorkerHandler ) if __name__ diff --git a/testing/web-platform/tests/workers/examples/general.any.js b/testing/web-platform/tests/workers/examples/general.any.js index 8e2714fb0d104..e9239e69b9b35 100644 --- a/testing/web-platform/tests/workers/examples/general.any.js +++ b/testing/web-platform/tests/workers/examples/general.any.js @@ -85,7 +85,7 @@ server / / See -AnyWorkerHandler +ClassicWorkerHandler in / / @@ -357,7 +357,7 @@ server / / See -AnyWorkerHandler +ClassicWorkerHandler in / /