2 <title>Service Worker: registration events
</title>
3 <script src=
"../resources/testharness.js"></script>
4 <script src=
"../resources/testharnessreport.js"></script>
5 <script src=
"resources/test-helpers.js"></script>
7 var t
= async_test('Registration: events');
9 var scope
= 'resources/in-scope/';
10 service_worker_unregister_and_register(
11 t
, 'resources/events-worker.js', scope
)
12 .then(t
.step_func(function(registration
) {
13 onRegister(registration
.installing
);
15 .catch(unreached_rejection(t
));
17 function sendMessagePort(worker
, from) {
18 var messageChannel
= new MessageChannel();
19 worker
.postMessage({from:from, port
:messageChannel
.port2
}, [messageChannel
.port2
]);
20 return messageChannel
.port1
;
23 function onRegister(sw
) {
24 sw
.onstatechange
= t
.step_func(function() {
25 if (sw
.state
!== 'activated')
28 sendMessagePort(sw
, 'registering doc').onmessage
= t
.step_func(function (e
) {
29 assert_array_equals(e
.data
.events
,
30 ['install', 'activate'],
31 'Worker should see install then activate events');
32 service_worker_unregister_and_done(t
, scope
);