update-after-navigation-fetch-event.https.html (2701B)
1 <!DOCTYPE html> 2 <meta name=timeout content=long> 3 <title>Service Worker: Update should be triggered after a navigation</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 9 async function cleanup(frame, registration) { 10 if (frame) 11 frame.remove(); 12 if (registration) 13 await registration.unregister(); 14 } 15 16 promise_test(async t => { 17 const script = 'resources/update_shell.py?filename=empty.js'; 18 const scope = 'resources/scope/update'; 19 let registration; 20 let frame; 21 22 async function run() { 23 registration = await service_worker_unregister_and_register( 24 t, script, scope); 25 await wait_for_state(t, registration.installing, 'activated'); 26 27 // Navigation should trigger update. 28 frame = await with_iframe(scope); 29 await wait_for_update(t, registration); 30 } 31 32 try { 33 await run(); 34 } finally { 35 await cleanup(frame, registration); 36 } 37 }, 'Update should be triggered after a navigation (no fetch event worker).'); 38 39 promise_test(async t => { 40 const script = 'resources/update_shell.py?filename=simple-intercept-worker.js'; 41 const scope = 'resources/scope/update'; 42 let registration; 43 let frame; 44 45 async function run() { 46 registration = await service_worker_unregister_and_register( 47 t, script, scope); 48 await wait_for_state(t, registration.installing, 'activated'); 49 50 // Navigation should trigger update (network fallback). 51 frame = await with_iframe(scope + '?ignore'); 52 await wait_for_update(t, registration); 53 54 // Navigation should trigger update (respondWith called). 55 frame.src = scope + '?string'; 56 await wait_for_update(t, registration); 57 } 58 59 try { 60 await run(); 61 } finally { 62 await cleanup(frame, registration); 63 } 64 }, 'Update should be triggered after a navigation (fetch event worker).'); 65 66 promise_test(async t => { 67 const script = 'resources/update_shell.py?filename=empty.js'; 68 const scope = 'resources/'; 69 let registration; 70 let frame; 71 72 async function run() { 73 registration = await service_worker_unregister_and_register( 74 t, script, scope); 75 await wait_for_state(t, registration.installing, 'activated'); 76 77 // Navigation should trigger update. Don't use with_iframe as it waits for 78 // the onload event. 79 frame = document.createElement('iframe'); 80 frame.src = 'resources/malformed-http-response.asis'; 81 document.body.appendChild(frame); 82 await wait_for_update(t, registration); 83 } 84 85 try { 86 await run(); 87 } finally { 88 await cleanup(frame, registration); 89 } 90 }, 'Update should be triggered after a navigation (network error).'); 91 </script>