skip-waiting.https.html (2351B)
1 <!DOCTYPE html> 2 <title>Service Worker: Skip waiting</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'; 11 var url1 = 'resources/empty.js'; 12 var url2 = 'resources/empty-worker.js'; 13 var url3 = 'resources/skip-waiting-worker.js'; 14 var sw_registration, activated_worker, waiting_worker; 15 return service_worker_unregister_and_register(t, url1, scope) 16 .then(function(registration) { 17 t.add_cleanup(function() { 18 return service_worker_unregister(t, scope); 19 }); 20 21 sw_registration = registration; 22 return wait_for_state(t, registration.installing, 'activated'); 23 }) 24 .then(function() { 25 return with_iframe(scope); 26 }) 27 .then(function(f) { 28 t.add_cleanup(function() { 29 f.remove(); 30 }); 31 return navigator.serviceWorker.register(url2, {scope: scope}); 32 }) 33 .then(function(registration) { 34 return wait_for_state(t, registration.installing, 'installed'); 35 }) 36 .then(function() { 37 activated_worker = sw_registration.active; 38 waiting_worker = sw_registration.waiting; 39 assert_equals(activated_worker.scriptURL, normalizeURL(url1), 40 'Worker with url1 should be activated'); 41 assert_equals(waiting_worker.scriptURL, normalizeURL(url2), 42 'Worker with url2 should be waiting'); 43 return navigator.serviceWorker.register(url3, {scope: scope}); 44 }) 45 .then(function(registration) { 46 return wait_for_state(t, registration.installing, 'activated'); 47 }) 48 .then(function() { 49 assert_equals(activated_worker.state, 'redundant', 50 'Worker with url1 should be redundant'); 51 assert_equals(waiting_worker.state, 'redundant', 52 'Worker with url2 should be redundant'); 53 assert_equals(sw_registration.active.scriptURL, normalizeURL(url3), 54 'Worker with url3 should be activated'); 55 }); 56 }, 'Test skipWaiting with both active and waiting workers'); 57 58 </script>