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