active.https.html (1962B)
1 <!DOCTYPE html> 2 <title>ServiceWorker: navigator.serviceWorker.active</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 // "active" is set 13 promise_test(async t => { 14 15 t.add_cleanup(async() => { 16 if (frame) 17 frame.remove(); 18 if (registration) 19 await registration.unregister(); 20 }); 21 22 await service_worker_unregister(t, SCOPE); 23 const frame = await with_iframe(SCOPE); 24 const registration = 25 await navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); 26 await wait_for_state(t, registration.installing, 'activating'); 27 const container = frame.contentWindow.navigator.serviceWorker; 28 assert_equals(container.controller, null, 'controller'); 29 assert_equals(registration.active.state, 'activating', 30 'registration.active'); 31 assert_equals(registration.waiting, null, 'registration.waiting'); 32 assert_equals(registration.installing, null, 'registration.installing'); 33 34 // FIXME: Add a test for a frame created after installation. 35 // Should the existing frame ("frame") block activation? 36 }, 'active is set'); 37 38 // Tests that the ServiceWorker objects returned from active attribute getter 39 // that represent the same service worker are the same objects. 40 promise_test(async t => { 41 const registration1 = 42 await service_worker_unregister_and_register(t, SCRIPT, SCOPE); 43 const registration2 = await navigator.serviceWorker.getRegistration(SCOPE); 44 assert_equals(registration1.active, registration2.active, 45 'ServiceWorkerRegistration.active should return the same ' + 46 'object'); 47 await registration1.unregister(); 48 }, 'The ServiceWorker objects returned from active attribute getter that ' + 49 'represent the same service worker are the same objects'); 50 </script>