registration-events.https.html (1516B)
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.sub.js"></script> 6 <script> 7 promise_test(function(t) { 8 var scope = 'resources/in-scope/'; 9 return service_worker_unregister_and_register( 10 t, 'resources/events-worker.js', scope) 11 .then(function(registration) { 12 t.add_cleanup(function() { 13 return service_worker_unregister(t, scope); 14 }); 15 16 return onRegister(registration.installing); 17 }); 18 19 function sendMessagePort(worker, from) { 20 var messageChannel = new MessageChannel(); 21 worker.postMessage({from:from, port:messageChannel.port2}, [messageChannel.port2]); 22 return messageChannel.port1; 23 } 24 25 function onRegister(sw) { 26 return new Promise(function(resolve) { 27 sw.onstatechange = function() { 28 if (sw.state === 'activated') 29 resolve(); 30 }; 31 }).then(function() { 32 return new Promise(function(resolve) { 33 sendMessagePort(sw, 'registering doc').onmessage = resolve; 34 }); 35 }).then(function(e) { 36 assert_array_equals(e.data.events, 37 ['install', 'activate'], 38 'Worker should see install then activate events'); 39 }); 40 } 41 }, 'Registration: events'); 42 </script>