fetch-destination-worker.https.html (2222B)
1 <!DOCTYPE html> 2 <title>Fetch destination tests for resources with no load event</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="/service-workers/service-worker/resources/test-helpers.sub.js"></script> 7 <script> 8 let frame; 9 10 // Set up the service worker and the frame. 11 promise_test(t => { 12 const kScope = 'resources/dummy.html'; 13 const kScript = 'resources/fetch-destination-worker-no-load-event.js'; 14 return service_worker_unregister_and_register(t, kScript, kScope) 15 .then(registration => { 16 add_completion_callback(() => { 17 registration.unregister(); 18 }); 19 20 return wait_for_state(t, registration.installing, 'activated'); 21 }) 22 .then(() => { 23 return with_iframe(kScope); 24 }) 25 .then(f => { 26 frame = f; 27 add_completion_callback(() => { f.remove(); }); 28 }); 29 }, 'Initialize global state'); 30 31 var waitOnMessageFromSW = async t => { 32 await new Promise((resolve, reject) => { 33 frame.contentWindow.navigator.serviceWorker.onmessage = t.step_func(event => { 34 if (event.data == "PASS") { 35 resolve(); 36 } else { 37 reject(); 38 } 39 }); 40 }).catch(() => {; 41 assert_unreached("Wrong destination."); 42 }); 43 t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; }); 44 } 45 46 // worker destination 47 ///////////////////// 48 promise_test(async t => { 49 // We can use an html file as we don't really care about the dedicated worker successfully loading. 50 let worker = new frame.contentWindow.Worker("dummy.html?t=worker&dest=worker"); 51 await waitOnMessageFromSW(t); 52 }, 'DedicatedWorker fetches with a "worker" Request.destination'); 53 54 promise_test(async t => { 55 // We can use an html file as we don't really care about the shared worker successfully loading. 56 let worker = new frame.contentWindow.SharedWorker("dummy.html?t=sharedworker&dest=sharedworker"); 57 await waitOnMessageFromSW(t); 58 }, 'SharedWorker fetches with a "sharedworker" Request.destination'); 59 60 </script>