OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: recovery by navigation update</title> |
| 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="/resources/testharnessreport.js"></script> |
| 5 <script src="resources/testharness-helpers.js"></script> |
| 6 <script src="resources/test-helpers.sub.js"></script> |
| 7 <script> |
| 8 async_test(function(t) { |
| 9 var scope = 'resources/simple.txt'; |
| 10 var worker_url = 'resources/update-recovery-worker.py'; |
| 11 var expected_url = normalizeURL(worker_url); |
| 12 var registration; |
| 13 |
| 14 function with_bad_iframe(url) { |
| 15 return new Promise(function(resolve, reject) { |
| 16 var frame = document.createElement('iframe'); |
| 17 |
| 18 // There is no cross-browser event to listen for to detect an |
| 19 // iframe that fails to load due to a bad interception. Unfortunately |
| 20 // we have to use a timeout. |
| 21 var timeout = setTimeout(function() { |
| 22 frame.remove(); |
| 23 resolve(); |
| 24 }, 5000); |
| 25 |
| 26 // If we do get a load event, though, we know something went wrong. |
| 27 frame.addEventListener('load', function() { |
| 28 clearTimeout(timeout); |
| 29 frame.remove(); |
| 30 reject('expected bad iframe should not fire a load event!'); |
| 31 }); |
| 32 |
| 33 frame.src = url; |
| 34 document.body.appendChild(frame); |
| 35 }); |
| 36 } |
| 37 |
| 38 function with_update(t) { |
| 39 return new Promise(function(resolve, reject) { |
| 40 registration.addEventListener('updatefound', function onUpdate() { |
| 41 registration.removeEventListener('updatefound', onUpdate); |
| 42 wait_for_state(t, registration.installing, 'activated').then(function(
) { |
| 43 resolve(); |
| 44 }); |
| 45 }); |
| 46 }); |
| 47 } |
| 48 |
| 49 service_worker_unregister_and_register(t, worker_url, scope) |
| 50 .then(function(r) { |
| 51 registration = r; |
| 52 return wait_for_state(t, registration.installing, 'activated'); |
| 53 }) |
| 54 .then(function() { |
| 55 return Promise.all([ |
| 56 with_update(t), |
| 57 with_bad_iframe(scope) |
| 58 ]); |
| 59 }) |
| 60 .then(function() { |
| 61 return with_iframe(scope); |
| 62 }) |
| 63 .then(function(frame) { |
| 64 assert_equals(frame.contentWindow.navigator.serviceWorker.controller.s
criptURL, |
| 65 expected_url); |
| 66 frame.remove(); |
| 67 return service_worker_unregister_and_done(t, scope); |
| 68 }) |
| 69 .catch(unreached_rejection(t)); |
| 70 }, 'Recover from a bad service worker by updating after a failed navigation.')
; |
| 71 </script> |
OLD | NEW |