skip-waiting-using-registration.https.html (2647B)
1 <!DOCTYPE html> 2 <title>Service Worker: Skip waiting using registration</title> 3 <meta name="timeout" content="long"> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 'use strict'; 9 10 promise_test(function(t) { 11 var scope = 'resources/blank.html?skip-waiting-using-registration'; 12 var url1 = 'resources/empty.js'; 13 var url2 = 'resources/skip-waiting-worker.js'; 14 var frame, frame_sw, sw_registration, oncontrollerchanged; 15 var saw_controllerchanged = new Promise(function(resolve) { 16 oncontrollerchanged = function(e) { 17 resolve(e); 18 }; 19 }) 20 .then(function(e) { 21 assert_equals(e.type, 'controllerchange', 22 'Event name should be "controllerchange"'); 23 assert_true( 24 e.target instanceof frame.contentWindow.ServiceWorkerContainer, 25 'Event target should be a ServiceWorkerContainer'); 26 assert_equals(e.target.controller.state, 'activating', 27 'Controller state should be activating'); 28 assert_equals( 29 frame_sw.controller.scriptURL, normalizeURL(url2), 30 'Controller scriptURL should change to the second one'); 31 }); 32 33 return service_worker_unregister_and_register(t, url1, scope) 34 .then(function(registration) { 35 return wait_for_state(t, registration.installing, 'activated'); 36 }) 37 .then(function() { 38 return with_iframe(scope); 39 }) 40 .then(function(f) { 41 t.add_cleanup(function() { 42 f.remove(); 43 }); 44 frame = f; 45 frame_sw = f.contentWindow.navigator.serviceWorker; 46 assert_equals( 47 frame_sw.controller.scriptURL, normalizeURL(url1), 48 'Document controller scriptURL should equal to the first one'); 49 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); 50 return navigator.serviceWorker.register(url2, {scope: scope}); 51 }) 52 .then(function(registration) { 53 sw_registration = registration; 54 t.add_cleanup(function() { 55 return registration.unregister(); 56 }); 57 return saw_controllerchanged; 58 }) 59 .then(function() { 60 assert_not_equals(sw_registration.active, null, 61 'Registration active worker should not be null'); 62 return fetch_tests_from_worker(sw_registration.active); 63 }); 64 }, 'Test skipWaiting while a client is using the registration'); 65 66 </script>