diff --git a/testing/web-platform/tests/clear-site-data/storage.https.html b/testing/web-platform/tests/clear-site-data/storage.https.html index aee22dd079e2f..c4683385e5c63 100644 --- a/testing/web-platform/tests/clear-site-data/storage.https.html +++ b/testing/web-platform/tests/clear-site-data/storage.https.html @@ -48,6 +48,37 @@ src = " +. +. +/ +service +- +workers +/ +service +- +worker +/ +resources +/ +test +- +helpers +. +sub +. +js +" +> +< +/ +script +> +< +script +src += +" support / test_utils @@ -114,6 +145,51 @@ 0 ] ; +var +serviceWorkerTestPageIFrame +; +function +fetchFromIFrame +( +) +{ +return +serviceWorkerTestPageIFrame +. +contentWindow +. +fetch +( +' +support +/ +controlled +- +endpoint +. +py +' +) +. +then +( +( +result +) += +> +{ +return +result +. +text +( +) +; +} +) +; +} / / The @@ -190,10 +266,290 @@ . then ( +( +) += +> +{ +return +new +Promise +( +function +( +resolve +reject +) +{ +promise_test +( +function +( +t +) +{ +return +navigator +. +serviceWorker +. +getRegistration +( +" +support +/ +" +) +. +then +( +function +( +reg +) +{ +return +wait_for_state +( +t +reg +. +installing +| +| +reg +. +waiting +| +| +reg +. +active +' +activated +' +) +; +} +) +. +then +( +resolve +reject +) +; +} +) +; +} +) +; +} +) +. +then +( +( +) += +> +{ +return +new +Promise +( +function +( +resolve +) +{ +/ +/ +Create +iFrame +in +the +service +worker +' +s +scope +. +This +page +will +make +a +request +/ +/ +for +another +page +that +is +only +served +by +the +service +worker +serviceWorkerTestPageIFrame += +document +. +createElement +( +" +iframe +" +) +; +serviceWorkerTestPageIFrame +. +src += +" +support +/ +page_using_service_worker +. +html +" +; +serviceWorkerTestPageIFrame +. +onload += +function +( +) +{ +resolve +( +) +; +} +; +document +. +body +. +appendChild +( +serviceWorkerTestPageIFrame +) +; +} +) +; +} +) +. +then +( +( +) += +> +{ +const +serviceWorkerResponseBody += +fetchFromIFrame +( +) +; +promise_test +( function ( ) { +return +serviceWorkerResponseBody +. +then +( +function +( +body +) +{ +assert_equals +( +body +" +FROM_SERVICE_WORKER +" +" +Response +should +be +from +service +worker +" +) +; +} +) +; +} +" +Baseline +: +Service +worker +responds +to +request +" +) +; +return +serviceWorkerResponseBody +; +} +) +. +then +( +function +( +) +{ +const +waitForControllerChange += +new +Promise +( +function +( +resolve +) +{ +serviceWorkerTestPageIFrame +. +contentWindow +. +navigator +. +serviceWorker +. +addEventListener +( +" +controllerchange +" +resolve +) +; +} +) +; / / Navigate @@ -369,6 +725,115 @@ } ) ; +promise_test +( +function +( +) +{ +return +fetchFromIFrame +( +) +. +then +( +function +( +body +) +{ +assert_equals +( +body +" +FROM_NETWORK +" +" +Response +should +be +from +network +and +not +from +the +service +worker +" +) +; +} +) +; +} +" +Service +worker +no +longer +responds +to +requests +" +) +; +promise_test +( +function +( +) +{ +return +waitForControllerChange +. +then +( +function +( +) +{ +assert_false +( +! +! +serviceWorkerTestPageIFrame +. +contentWindow +. +navigator +. +serviceWorker +. +controller +" +Client +should +not +have +a +controller +" +) +; +} +) +; +} +" +controllerchange +event +fires +and +client +no +longer +has +controller +" +) +; done ( ) diff --git a/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py b/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py new file mode 100644 index 0000000000000..1ac9535c0b868 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/controlled-endpoint.py @@ -0,0 +1,29 @@ +def +main +( +request +response +) +: + +return +( +[ +( +" +Content +- +Type +" +" +text +/ +html +" +) +] + +" +FROM_NETWORK +" +) diff --git a/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html b/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html new file mode 100644 index 0000000000000..70364402abec2 --- /dev/null +++ b/testing/web-platform/tests/clear-site-data/support/page_using_service_worker.html @@ -0,0 +1,36 @@ +< +! +DOCTYPE +html +> +< +html +> +< +head +> +< +title +> +Clear +- +Site +- +Data ++ +Service +Workers +Test +Page +< +/ +title +> +< +/ +head +> +< +/ +html +> diff --git a/testing/web-platform/tests/clear-site-data/support/service_worker.js b/testing/web-platform/tests/clear-site-data/support/service_worker.js index 4835dfee4b6d6..d0e8d6d5ad8b4 100644 --- a/testing/web-platform/tests/clear-site-data/support/service_worker.js +++ b/testing/web-platform/tests/clear-site-data/support/service_worker.js @@ -1,11 +1,61 @@ -/ -* -This -file -is -intentionally -left -blank -. -* -/ +self +. +addEventListener +( +' +fetch +' +( +e +) += +> +{ +const +url += +new +URL +( +e +. +request +. +url +) +; +if +( +url +. +pathname +. +match +( +' +controlled +- +endpoint +. +py +' +) +) +{ +e +. +respondWith +( +new +Response +( +' +FROM_SERVICE_WORKER +' +) +) +; +} +} +) +; diff --git a/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js b/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js index 019d834d8e280..25333a87345b7 100644 --- a/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js +++ b/testing/web-platform/tests/clear-site-data/support/test_utils.sub.js @@ -858,20 +858,6 @@ scope " support / -scope -- -that -- -does -- -not -- -contain -- -this -- -test -/ " } )