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/testharnessreport.js"></script> | |
5 <script src="resources/test-helpers.js"></script> | |
6 <script> | |
7 | |
8 promise_test(function(t) { | |
9 var scope = 'resources/blank.html'; | |
10 var url1 = 'resources/empty.js'; | |
11 var url2 = 'resources/skip-waiting-installed-worker.js'; | |
12 var frame, frame_sw, service_worker, onmessage, oncontrollerchanged; | |
13 var promise1 = new Promise(function(resolve) { | |
falken
2014/12/01 07:48:28
can you give a more descriptive name like "saw_mes
xiang
2014/12/03 00:07:25
Done.
| |
14 onmessage = function(e) { | |
15 var message = e.data; | |
16 assert_equals( | |
17 message, 'PASS', | |
18 'skipWaiting promise should be resolved after activated'); | |
19 resolve(); | |
20 }; | |
21 }); | |
22 var promise2 = new Promise(function(resolve) { | |
falken
2014/12/01 07:48:28
"saw_controlledchanged"?
xiang
2014/12/03 00:07:25
Done.
| |
23 oncontrollerchanged = function() { | |
24 assert_equals( | |
25 iframeContainer.controller.scriptURL, normalizeURL(url2), | |
26 'Controller scriptURL should change to the second one'); | |
27 resolve(); | |
28 }; | |
29 }); | |
30 return service_worker_unregister_and_register(t, url1, scope) | |
31 .then(function(registration) { | |
32 return wait_for_update(t, registration); | |
33 }) | |
34 .then(function(sw) { | |
35 return wait_for_state(t, sw, 'activated'); | |
36 }) | |
37 .then(function() { | |
38 return with_iframe(scope); | |
39 }) | |
40 .then(function(f) { | |
41 frame = f; | |
42 frame_sw = f.contentWindow.navigator.serviceWorker; | |
43 assert_equals( | |
44 frame_sw.controller.scriptURL, normalizeURL(url1), | |
45 'Document controller scriptURL should equal to the first one'); | |
46 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); | |
47 return navigator.serviceWorker.register(url2, {scope: scope}); | |
48 }) | |
49 .then(function(registration) { | |
50 return wait_for_update(t, registration); | |
51 }) | |
52 .then(function(sw) { | |
53 service_worker = sw; | |
54 return wait_for_state(t, sw, 'installed'); | |
55 }) | |
56 .then(function() { | |
57 var channel = new MessageChannel(); | |
58 channel.port1.onmessage = t.step_func(onmessage); | |
59 service_worker.postMessage({port: channel.port2}, [channel.port2]); | |
60 return Promise.all([promise1, promise2]); | |
61 }) | |
62 .then(function() { | |
falken
2014/12/01 07:48:28
remove frame
xiang
2014/12/03 00:07:25
Done.
| |
63 return service_worker_unregister_and_done(t, scope); | |
64 }) | |
65 }, 'Test skipWaiting when a installed worker is waiting'); | |
66 | |
67 </script> | |
OLD | NEW |