activate-event-after-install-state-change.https.html (1121B)
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 script = 'resources/empty-worker.js'; 9 var scope = 'resources/blank.html'; 10 var registration; 11 12 return service_worker_unregister_and_register(t, script, scope) 13 .then(function(registration) { 14 t.add_cleanup(function() { 15 return service_worker_unregister(t, scope); 16 }); 17 18 var sw = registration.installing; 19 20 return new Promise(t.step_func(function(resolve) { 21 sw.onstatechange = t.step_func(function() { 22 if (sw.state === 'installed') { 23 assert_equals(registration.active, null, 24 'installed event should be fired before activating service worker'); 25 resolve(); 26 } 27 }); 28 })); 29 }) 30 .catch(unreached_rejection(t)); 31 }, 'installed event should be fired before activating service worker'); 32 33 </script>