skip-waiting-installed.https.html (2718B)
1 <!DOCTYPE html> 2 <title>Service Worker: Skip waiting installed worker</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 'use strict'; 8 9 promise_test(function(t) { 10 var scope = 'resources/blank.html?skip-waiting-installed'; 11 var url1 = 'resources/empty.js'; 12 var url2 = 'resources/skip-waiting-installed-worker.js'; 13 var frame, frame_sw, service_worker, registration, onmessage, oncontrollerchanged; 14 var saw_message = new Promise(function(resolve) { 15 onmessage = function(e) { 16 resolve(e.data); 17 }; 18 }) 19 .then(function(message) { 20 assert_equals( 21 message, 'PASS', 22 'skipWaiting promise should be resolved with undefined'); 23 }); 24 var saw_controllerchanged = new Promise(function(resolve) { 25 oncontrollerchanged = function() { 26 assert_equals( 27 frame_sw.controller.scriptURL, normalizeURL(url2), 28 'Controller scriptURL should change to the second one'); 29 assert_equals(registration.active.scriptURL, normalizeURL(url2), 30 'Worker which calls skipWaiting should be active by controllerchange'); 31 resolve(); 32 }; 33 }); 34 return service_worker_unregister_and_register(t, url1, scope) 35 .then(function(r) { 36 t.add_cleanup(function() { 37 return service_worker_unregister(t, scope); 38 }); 39 40 return wait_for_state(t, r.installing, 'activated'); 41 }) 42 .then(function() { 43 return with_iframe(scope); 44 }) 45 .then(function(f) { 46 frame = f; 47 frame_sw = f.contentWindow.navigator.serviceWorker; 48 assert_equals( 49 frame_sw.controller.scriptURL, normalizeURL(url1), 50 'Document controller scriptURL should equal to the first one'); 51 frame_sw.oncontrollerchange = t.step_func(oncontrollerchanged); 52 return navigator.serviceWorker.register(url2, {scope: scope}); 53 }) 54 .then(function(r) { 55 registration = r; 56 service_worker = r.installing; 57 return wait_for_state(t, service_worker, 'installed'); 58 }) 59 .then(function() { 60 var channel = new MessageChannel(); 61 channel.port1.onmessage = t.step_func(onmessage); 62 service_worker.postMessage({port: channel.port2}, [channel.port2]); 63 return Promise.all([saw_message, saw_controllerchanged]); 64 }) 65 .then(function() { 66 frame.remove(); 67 }); 68 }, 'Test skipWaiting when a installed worker is waiting'); 69 70 </script>