json-module-service-worker-test.https.html (1374B)
1 <!doctype html> 2 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 6 <script> 7 promise_test(async (test) => { 8 const reg = await navigator.serviceWorker.register('./serviceworker.js', { type: 'module' }); 9 test.add_cleanup(() => reg.unregister()); 10 assert_not_equals(reg.installing, undefined); 11 }, "Javascript importing JSON Module should load within the context of a service worker"); 12 13 promise_test(test => { 14 return promise_rejects_dom(test, "SecurityError", 15 navigator.serviceWorker.register('./module.json', { type: 'module' }), 16 "Attempting to load JSON as a service worker should fail"); 17 }, "Trying to register a service worker with a top-level JSON Module should fail"); 18 19 promise_test(async (test) => { 20 const reg = await navigator.serviceWorker.register('./serviceworker-dynamic-import.js', { type: 'module' }); 21 test.add_cleanup(() => reg.unregister()); 22 assert_not_equals(reg.installing, undefined); 23 reg.installing.postMessage("PING"); 24 const msgEvent = await new Promise(resolve => { 25 navigator.serviceWorker.onmessage = resolve; 26 }); 27 assert_equals(msgEvent.data, "FAILED"); 28 }, "JSON Module dynamic import should not load within the context of a service worker"); 29 </script>