| OLD | NEW |
| 1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
| 2 <title>Service Worker: Skip waiting using registration</title> | 2 <title>Service Worker: Skip waiting using registration</title> |
| 3 <script src="/resources/testharness.js"></script> | 3 <script src="/resources/testharness.js"></script> |
| 4 <script src="resources/testharness-helpers.js"></script> | |
| 5 <script src="/resources/testharnessreport.js"></script> | 4 <script src="/resources/testharnessreport.js"></script> |
| 6 <script src="resources/test-helpers.sub.js"></script> | 5 <script src="resources/test-helpers.sub.js"></script> |
| 7 <script> | 6 <script> |
| 7 'use strict'; |
| 8 | 8 |
| 9 promise_test(function(t) { | 9 promise_test(function(t) { |
| 10 var scope = 'resources/blank.html?skip-waiting-using-registration'; | 10 var scope = 'resources/blank.html?skip-waiting-using-registration'; |
| 11 var url1 = 'resources/empty.js'; | 11 var url1 = 'resources/empty.js'; |
| 12 var url2 = 'resources/skip-waiting-worker.js'; | 12 var url2 = 'resources/skip-waiting-worker.js'; |
| 13 var frame, frame_sw, sw_registration, oncontrollerchanged; | 13 var frame, frame_sw, sw_registration, oncontrollerchanged; |
| 14 var saw_controllerchanged = new Promise(function(resolve) { | 14 var saw_controllerchanged = new Promise(function(resolve) { |
| 15 oncontrollerchanged = function(e) { | 15 oncontrollerchanged = function(e) { |
| 16 assert_equals(e.type, 'controllerchange', | 16 resolve(e); |
| 17 'Event name should be "controllerchange"'); | 17 }; |
| 18 assert_true( | 18 }) |
| 19 e.target instanceof frame.contentWindow.ServiceWorkerContainer, | 19 .then(function(e) { |
| 20 'Event target should be a ServiceWorkerContainer'); | 20 assert_equals(e.type, 'controllerchange', |
| 21 assert_equals(e.target.controller.state, 'activating', | 21 'Event name should be "controllerchange"'); |
| 22 'Controller state should be activating'); | 22 assert_true( |
| 23 assert_equals( | 23 e.target instanceof frame.contentWindow.ServiceWorkerContainer, |
| 24 frame_sw.controller.scriptURL, normalizeURL(url2), | 24 'Event target should be a ServiceWorkerContainer'); |
| 25 'Controller scriptURL should change to the second one'); | 25 assert_equals(e.target.controller.state, 'activating', |
| 26 resolve(); | 26 'Controller state should be activating'); |
| 27 }; | 27 assert_equals( |
| 28 }); | 28 frame_sw.controller.scriptURL, normalizeURL(url2), |
| 29 'Controller scriptURL should change to the second one'); |
| 30 }); |
| 31 |
| 29 return service_worker_unregister_and_register(t, url1, scope) | 32 return service_worker_unregister_and_register(t, url1, scope) |
| 30 .then(function(registration) { | 33 .then(function(registration) { |
| 31 return wait_for_state(t, registration.installing, 'activated'); | 34 return wait_for_state(t, registration.installing, 'activated'); |
| 32 }) | 35 }) |
| 33 .then(function() { | 36 .then(function() { |
| 34 return with_iframe(scope); | 37 return with_iframe(scope); |
| 35 }) | 38 }) |
| 36 .then(function(f) { | 39 .then(function(f) { |
| 40 t.add_cleanup(function() { |
| 41 f.remove(); |
| 42 }); |
| 37 frame = f; | 43 frame = f; |
| 38 frame_sw = f.contentWindow.navigator.serviceWorker; | 44 frame_sw = f.contentWindow.navigator.serviceWorker; |
| 39 assert_equals( | 45 assert_equals( |
| 40 frame_sw.controller.scriptURL, normalizeURL(url1), | 46 frame_sw.controller.scriptURL, normalizeURL(url1), |
| 41 'Document controller scriptURL should equal to the first one'); | 47 'Document controller scriptURL should equal to the first one'); |
| 42 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); | 48 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); |
| 43 return navigator.serviceWorker.register(url2, {scope: scope}); | 49 return navigator.serviceWorker.register(url2, {scope: scope}); |
| 44 }) | 50 }) |
| 45 .then(function(registration) { | 51 .then(function(registration) { |
| 46 sw_registration = registration; | 52 sw_registration = registration; |
| 47 add_completion_callback(function() { | 53 t.add_cleanup(function() { |
| 48 frame.remove(); | |
| 49 registration.unregister(); | 54 registration.unregister(); |
| 50 }); | 55 }); |
| 51 return saw_controllerchanged; | 56 return saw_controllerchanged; |
| 52 }) | 57 }) |
| 53 .then(function() { | 58 .then(function() { |
| 54 assert_not_equals(sw_registration.active, null, | 59 assert_not_equals(sw_registration.active, null, |
| 55 'Registration active worker should not be null'); | 60 'Registration active worker should not be null'); |
| 56 fetch_tests_from_worker(sw_registration.active); | 61 fetch_tests_from_worker(sw_registration.active); |
| 57 }); | 62 }); |
| 58 }, 'Test skipWaiting while a client is using the registration'); | 63 }, 'Test skipWaiting while a client is using the registration'); |
| 59 | 64 |
| 60 </script> | 65 </script> |
| OLD | NEW |