Bug 1463050 [wpt PR 11019] - Worker: Add service worker interception tests for module...
[gecko.git] / testing / web-platform / tests / service-workers / service-worker / dedicated-worker-service-worker-interception.https.html
blob2144f4827121b4902d8c56a61df823f04ee8801d
1 <!DOCTYPE html>
2 <title>DedicatedWorker: ServiceWorker interception</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>
8 // Note that Chrome cannot pass these tests because of https://crbug.com/731599.
10 function service_worker_interception_test(url, description) {
11 promise_test(async t => {
12 // Register a service worker whose scope includes |url|.
13 const kServiceWorkerScriptURL =
14 'resources/service-worker-interception-service-worker.js';
15 const registration = await service_worker_unregister_and_register(
16 t, kServiceWorkerScriptURL, url);
17 add_result_callback(() => registration.unregister());
18 await wait_for_state(t, registration.installing, 'activated');
20 // Start a dedicated worker for |url|. The top-level script request and any
21 // module imports should be intercepted by the service worker.
22 const worker = new Worker(url, { type: 'module' });
23 const msg_event = await new Promise(resolve => worker.onmessage = resolve);
24 assert_equals(msg_event.data, 'LOADED_FROM_SERVICE_WORKER');
25 }, description);
28 service_worker_interception_test(
29 'resources/service-worker-interception-network-worker.js',
30 'Top-level module loading should be intercepted by a service worker.');
32 service_worker_interception_test(
33 'resources/service-worker-interception-static-import-worker.js',
34 'Static import should be intercepted by a service worker.');
36 service_worker_interception_test(
37 'resources/service-worker-interception-dynamic-import-worker.js',
38 'Dynamic import should be intercepted by a service worker.');
40 </script>