OLD | NEW |
1 <!DOCTYPE html> | 1 <!DOCTYPE html> |
2 <title>Service Worker: registration events</title> | 2 <title>Service Worker: registration events</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: events'); | 7 var t = async_test('Registration: events'); |
8 t.step(function() { | 8 t.step(function() { |
9 var scope = '/in-scope/'; | 9 var scope = '/in-scope/'; |
10 service_worker_unregister_and_register( | 10 service_worker_unregister_and_register( |
11 t, 'resources/events-worker.js', scope).then(t.step_func(onRegister)); | 11 t, 'resources/events-worker.js', scope) |
| 12 .then(t.step_func(function(registration) { |
| 13 return wait_for_update(t, registration); |
| 14 })) |
| 15 .then(t.step_func(onRegister)) |
| 16 .catch(unreached_rejection(t)); |
12 | 17 |
13 function sendMessagePort(worker, from) { | 18 function sendMessagePort(worker, from) { |
14 var messageChannel = new MessageChannel(); | 19 var messageChannel = new MessageChannel(); |
15 worker.postMessage({from:from, port:messageChannel.port2}, [messageChann
el.port2]); | 20 worker.postMessage({from:from, port:messageChannel.port2}, [messageChann
el.port2]); |
16 return messageChannel.port1; | 21 return messageChannel.port1; |
17 } | 22 } |
18 | 23 |
19 function onRegister(sw) { | 24 function onRegister(sw) { |
20 sw.onstatechange = t.step_func(function() { | 25 sw.onstatechange = t.step_func(function() { |
21 if (sw.state !== 'activated') | 26 if (sw.state !== 'activated') |
22 return; | 27 return; |
23 | 28 |
24 sendMessagePort(sw, 'registering doc').onmessage = t.step_func(funct
ion (e) { | 29 sendMessagePort(sw, 'registering doc').onmessage = t.step_func(funct
ion (e) { |
25 assert_array_equals(e.data.events, | 30 assert_array_equals(e.data.events, |
26 ['install', 'activate'], | 31 ['install', 'activate'], |
27 'Worker should see install then activate even
ts'); | 32 'Worker should see install then activate even
ts'); |
28 service_worker_unregister_and_done(t, scope); | 33 service_worker_unregister_and_done(t, scope); |
29 }); | 34 }); |
30 }); | 35 }); |
31 } | 36 } |
32 }); | 37 }); |
33 </script> | 38 </script> |
OLD | NEW |