OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <title>Service Worker: Skip waiting installed worker</title> |
| 3 <script src="../resources/testharness.js"></script> |
| 4 <script src="../resources/testharness-helpers.js"></script> |
| 5 <script src="../resources/testharnessreport.js"></script> |
| 6 <script src="resources/test-helpers.js"></script> |
| 7 <script> |
| 8 |
| 9 promise_test(function(t) { |
| 10 var scope = 'resources/blank.html'; |
| 11 var url1 = 'resources/empty.js'; |
| 12 var url2 = 'resources/skip-waiting-installed-worker.js'; |
| 13 var frame, frame_sw, service_worker, onmessage, oncontrollerchanged; |
| 14 var saw_message = new Promise(function(resolve) { |
| 15 onmessage = function(e) { |
| 16 var message = e.data; |
| 17 assert_equals( |
| 18 message, 'PASS', |
| 19 'skipWaiting promise should be resolved after activated'); |
| 20 resolve(); |
| 21 }; |
| 22 }); |
| 23 var saw_controllerchanged = new Promise(function(resolve) { |
| 24 oncontrollerchanged = function() { |
| 25 assert_equals( |
| 26 frame_sw.controller.scriptURL, normalizeURL(url2), |
| 27 'Controller scriptURL should change to the second one'); |
| 28 resolve(); |
| 29 }; |
| 30 }); |
| 31 return service_worker_unregister_and_register(t, url1, scope) |
| 32 .then(function(registration) { |
| 33 return wait_for_state(t, registration.installing, 'activated'); |
| 34 }) |
| 35 .then(function() { |
| 36 return with_iframe(scope); |
| 37 }) |
| 38 .then(function(f) { |
| 39 frame = f; |
| 40 frame_sw = f.contentWindow.navigator.serviceWorker; |
| 41 assert_equals( |
| 42 frame_sw.controller.scriptURL, normalizeURL(url1), |
| 43 'Document controller scriptURL should equal to the first one'); |
| 44 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); |
| 45 return navigator.serviceWorker.register(url2, {scope: scope}); |
| 46 }) |
| 47 .then(function(registration) { |
| 48 service_worker = registration.installing; |
| 49 return wait_for_state(t, service_worker, 'installed'); |
| 50 }) |
| 51 .then(function() { |
| 52 var channel = new MessageChannel(); |
| 53 channel.port1.onmessage = t.step_func(onmessage); |
| 54 service_worker.postMessage({port: channel.port2}, [channel.port2]); |
| 55 return Promise.all([saw_message, saw_controllerchanged]); |
| 56 }) |
| 57 .then(function() { |
| 58 frame.remove(); |
| 59 return service_worker_unregister_and_done(t, scope); |
| 60 }); |
| 61 }, 'Test skipWaiting when a installed worker is waiting'); |
| 62 |
| 63 </script> |
OLD | NEW |