Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / serviceworker / registration-events.html
blob1a3377627e6d5980ddde1ef4826007c2a4997695
1 <!DOCTYPE html>
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>
6 <script>
7 var t = async_test('Registration: events');
8 t.step(function() {
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);
14 }))
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')
26 return;
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);
33 });
34 });
36 });
37 </script>