fetch-destination-iframe.https.html (1698B)
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 const kScope = 'resources/dummy.html?dest=iframe'; 10 11 // Set up the service worker and the frame. 12 promise_test(t => { 13 const kScript = 'resources/fetch-destination-worker-iframe.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 }, 'Initialize global state'); 23 24 var waitOnMessageFromSW = async t => { 25 await new Promise((resolve, reject) => { 26 navigator.serviceWorker.onmessage = t.step_func(event => { 27 if (event.data == "PASS") { 28 resolve(); 29 } else { 30 reject(); 31 } 32 }); 33 }).catch(() => {; 34 assert_unreached("Wrong destination."); 35 }); 36 t.add_cleanup(() => { frame.contentWindow.navigator.serviceWorker.onmessage = null; }); 37 } 38 39 // Document destination 40 /////////////////////// 41 promise_test(async t => { 42 var f = document.createElement('iframe'); 43 frame = f; 44 f.className = 'test-iframe'; 45 f.src = kScope; 46 document.body.appendChild(f); 47 await waitOnMessageFromSW(t); 48 add_completion_callback(() => { f.remove(); }); 49 }, 'iframe fetches with a "iframe" Request.destination'); 50 51 </script>