fetch-event-after-navigation-within-page.https.html (2504B)
1 <!DOCTYPE html> 2 <title>ServiceWorker: navigator.serviceWorker.waiting</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 <body> 7 <script> 8 9 promise_test(function(t) { 10 var scope = 11 'resources/fetch-event-after-navigation-within-page-iframe.html' + 12 '?hashchange'; 13 var worker = 'resources/simple-intercept-worker.js'; 14 var frame; 15 16 return service_worker_unregister_and_register(t, worker, scope) 17 .then(function(reg) { 18 t.add_cleanup(function() { 19 return service_worker_unregister(t, scope); 20 }); 21 22 return wait_for_state(t, reg.installing, 'activated'); 23 }) 24 .then(function() { return with_iframe(scope); }) 25 .then(function(f) { 26 frame = f; 27 return frame.contentWindow.fetch_url('simple.txt'); 28 }) 29 .then(function(response) { 30 assert_equals(response, 'intercepted by service worker'); 31 frame.contentWindow.location.hash = 'foo'; 32 return frame.contentWindow.fetch_url('simple.txt'); 33 }) 34 .then(function(response) { 35 assert_equals(response, 'intercepted by service worker'); 36 frame.remove(); 37 }) 38 }, 'Service Worker should respond to fetch event after the hash changes'); 39 40 promise_test(function(t) { 41 var scope = 42 'resources/fetch-event-after-navigation-within-page-iframe.html' + 43 '?pushState'; 44 var worker = 'resources/simple-intercept-worker.js'; 45 var frame; 46 47 return service_worker_unregister_and_register(t, worker, scope) 48 .then(function(reg) { 49 t.add_cleanup(function() { 50 return service_worker_unregister(t, scope); 51 }); 52 53 return wait_for_state(t, reg.installing, 'activated'); 54 }) 55 .then(function() { return with_iframe(scope); }) 56 .then(function(f) { 57 frame = f; 58 return frame.contentWindow.fetch_url('simple.txt'); 59 }) 60 .then(function(response) { 61 assert_equals(response, 'intercepted by service worker'); 62 frame.contentWindow.history.pushState('', '', 'bar'); 63 return frame.contentWindow.fetch_url('simple.txt'); 64 }) 65 .then(function(response) { 66 assert_equals(response, 'intercepted by service worker'); 67 frame.remove(); 68 }) 69 }, 'Service Worker should respond to fetch event after the pushState'); 70 71 </script>