summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html
diff options
context:
space:
mode:
Diffstat (limited to 'testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html')
-rw-r--r--testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html29
1 files changed, 29 insertions, 0 deletions
diff --git a/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html
new file mode 100644
index 0000000000..cc47da1499
--- /dev/null
+++ b/testing/web-platform/tests/html/semantics/scripting-1/the-script-element/json-module-assertions/json-module-service-worker-test.https.html
@@ -0,0 +1,29 @@
+<!doctype html>
+
+<script src="/resources/testharness.js"></script>
+<script src="/resources/testharnessreport.js"></script>
+
+<script>
+ promise_test(async (test) => {
+ const reg = await navigator.serviceWorker.register('./serviceworker.js', { type: 'module' });
+ test.add_cleanup(() => reg.unregister());
+ assert_not_equals(reg.installing, undefined);
+ }, "Javascript importing JSON Module should load within the context of a service worker");
+
+ promise_test(test => {
+ return promise_rejects_dom(test, "SecurityError",
+ navigator.serviceWorker.register('./module.json', { type: 'module' }),
+ "Attempting to load JSON as a service worker should fail");
+ }, "Trying to register a service worker with a top-level JSON Module should fail");
+
+ promise_test(async (test) => {
+ const reg = await navigator.serviceWorker.register('./serviceworker-dynamic-import.js', { type: 'module' });
+ test.add_cleanup(() => reg.unregister());
+ assert_not_equals(reg.installing, undefined);
+ reg.installing.postMessage("PING");
+ const msgEvent = await new Promise(resolve => {
+ navigator.serviceWorker.onmessage = resolve;
+ });
+ assert_equals(msgEvent.data, "FAILED");
+ }, "JSON Module dynamic import should not load within the context of a service worker");
+</script> \ No newline at end of file