OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: registration end-to-end</title> | 2 <title>Service Worker: registration end-to-end</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/testharnessreport.js"></script> |
5 <script src="resources/test-helpers.js"></script> | 5 <script src="resources/test-helpers.js"></script> |
6 <script> | 6 <script> |
7 var t = async_test('Registration: end-to-end'); | 7 var t = async_test('Registration: end-to-end'); |
8 t.step(function() { | 8 t.step(function() { |
9 | 9 |
10 var scope = '/in-scope/'; | 10 var scope = '/in-scope/'; |
11 var serviceWorkerStates = []; | 11 var serviceWorkerStates = []; |
12 var lastServiceWorkerState = ''; | 12 var lastServiceWorkerState = ''; |
13 var receivedMessageFromPort = ''; | 13 var receivedMessageFromPort = ''; |
14 var currentChangeCount = 0; | 14 var currentChangeCount = 0; |
15 | 15 |
16 assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer); | 16 assert_true(navigator.serviceWorker instanceof ServiceWorkerContainer); |
17 assert_equals(typeof navigator.serviceWorker.register, 'function'); | 17 assert_equals(typeof navigator.serviceWorker.register, 'function'); |
18 assert_equals(typeof navigator.serviceWorker.unregister, 'function'); | 18 assert_equals(typeof navigator.serviceWorker.unregister, 'function'); |
19 | 19 |
20 navigator.serviceWorker.oncurrentchange = function() { | 20 navigator.serviceWorker.oncurrentchange = function() { |
21 ++currentChangeCount; | 21 ++currentChangeCount; |
22 }; | 22 }; |
23 | 23 |
24 service_worker_unregister_and_register( | 24 service_worker_unregister_and_register( |
25 t, 'resources/end-to-end-worker.js', scope) | 25 t, 'resources/end-to-end-worker.js', scope) |
26 .then(function(registration) { | |
27 return wait_for_update(t, registration); | |
28 }) | |
29 .then(onRegister) | 26 .then(onRegister) |
30 .catch(unreached_rejection(t)); | 27 .catch(unreached_rejection(t)); |
31 | 28 |
32 function sendMessagePort(worker, from) { | 29 function sendMessagePort(worker, from) { |
33 var messageChannel = new MessageChannel(); | 30 var messageChannel = new MessageChannel(); |
34 worker.postMessage({from:from, port:messageChannel.port2}, [messageChann
el.port2]); | 31 worker.postMessage({from:from, port:messageChannel.port2}, [messageChann
el.port2]); |
35 return messageChannel.port1; | 32 return messageChannel.port1; |
36 } | 33 } |
37 | 34 |
38 function onRegister(sw) { | 35 function onRegister(registration) { |
| 36 var sw = registration.installing; |
39 serviceWorkerStates.push(sw.state); | 37 serviceWorkerStates.push(sw.state); |
40 lastServiceWorkerState = sw.state; | 38 lastServiceWorkerState = sw.state; |
41 | 39 |
42 var sawMessage = new Promise(t.step_func(function(resolve) { | 40 var sawMessage = new Promise(t.step_func(function(resolve) { |
43 sendMessagePort(sw, 'registering doc').onmessage = t.step_func(funct
ion (e) { | 41 sendMessagePort(sw, 'registering doc').onmessage = t.step_func(funct
ion (e) { |
44 receivedMessageFromPort = e.data; | 42 receivedMessageFromPort = e.data; |
45 resolve(); | 43 resolve(); |
46 }); | 44 }); |
47 })); | 45 })); |
48 | 46 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 }); | 90 }); |
93 })); | 91 })); |
94 navigator.serviceWorker.unregister(scope); | 92 navigator.serviceWorker.unregister(scope); |
95 sawRedundant.then(t.step_func(function() { | 93 sawRedundant.then(t.step_func(function() { |
96 t.done(); | 94 t.done(); |
97 })); | 95 })); |
98 })); | 96 })); |
99 } | 97 } |
100 }); | 98 }); |
101 </script> | 99 </script> |
OLD | NEW |