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