waiting.https.html (1854B)
1 <!DOCTYPE html> 2 <title>ServiceWorker: navigator.serviceWorker.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 <body> 7 <script> 8 9 const SCRIPT = 'resources/empty-worker.js'; 10 const SCOPE = 'resources/blank.html'; 11 12 promise_test(async t => { 13 14 t.add_cleanup(async() => { 15 if (frame) 16 frame.remove(); 17 if (registration) 18 await registration.unregister(); 19 }); 20 21 await service_worker_unregister(t, SCOPE); 22 const frame = await with_iframe(SCOPE); 23 const registration = 24 await navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); 25 await wait_for_state(t, registration.installing, 'installed'); 26 const controller = frame.contentWindow.navigator.serviceWorker.controller; 27 assert_equals(controller, null, 'controller'); 28 assert_equals(registration.active, null, 'registration.active'); 29 assert_equals(registration.waiting.state, 'installed', 30 'registration.waiting'); 31 assert_equals(registration.installing, null, 'registration.installing'); 32 }, 'waiting is set after installation'); 33 34 // Tests that the ServiceWorker objects returned from waiting attribute getter 35 // that represent the same service worker are the same objects. 36 promise_test(async t => { 37 const registration1 = 38 await service_worker_unregister_and_register(t, SCRIPT, SCOPE); 39 const registration2 = await navigator.serviceWorker.getRegistration(SCOPE); 40 assert_equals(registration1.waiting, registration2.waiting, 41 'ServiceWorkerRegistration.waiting should return the same ' + 42 'object'); 43 await registration1.unregister(); 44 }, 'The ServiceWorker objects returned from waiting attribute getter that ' + 45 'represent the same service worker are the same objects'); 46 </script> 47 </body>