registration-scope-module-static-import.https.html (1658B)
1 <!DOCTYPE html> 2 <title>Service Worker: Static imports from module top-level scripts shouldn't be affected by the service worker script path restriction</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="resources/test-helpers.sub.js"></script> 6 <script> 7 // https://w3c.github.io/ServiceWorker/#path-restriction 8 // is applied to top-level scripts in 9 // https://w3c.github.io/ServiceWorker/#update-algorithm 10 // but not to submodules imported from top-level scripts. 11 async function runTest(t, script, scope) { 12 const script_url = new URL(script, location.href); 13 await service_worker_unregister(t, scope); 14 const registration = await 15 navigator.serviceWorker.register(script, {type: 'module'}); 16 t.add_cleanup(_ => registration.unregister()); 17 const msg = await new Promise(resolve => { 18 registration.installing.postMessage('ping'); 19 navigator.serviceWorker.onmessage = resolve; 20 }); 21 assert_equals(msg.data, 'pong'); 22 } 23 24 promise_test(async t => { 25 await runTest(t, 26 'resources/scope2/imported-module-script.js', 27 'resources/scope2/'); 28 }, 'imported-module-script.js works when used as top-level'); 29 30 promise_test(async t => { 31 await runTest(t, 32 'resources/scope1/module-worker-importing-scope2.js', 33 'resources/scope1/'); 34 }, 'static imports to outside path restriction should be allowed'); 35 36 promise_test(async t => { 37 await runTest(t, 38 'resources/scope1/module-worker-importing-redirect-to-scope2.js', 39 'resources/scope1/'); 40 }, 'static imports redirecting to outside path restriction should be allowed'); 41 </script>