postmessage-from-waiting-serviceworker.https.html (1843B)
1 <!DOCTYPE html> 2 <title>Service Worker: postMessage from waiting serviceworker</title> 3 <script src="/resources/testharness.js"></script> 4 <script src="/resources/testharnessreport.js"></script> 5 <script src="/common/get-host-info.sub.js"></script> 6 <script src="resources/test-helpers.sub.js"></script> 7 <script> 8 9 function echo(worker, data) { 10 return new Promise(resolve => { 11 navigator.serviceWorker.addEventListener('message', function onMsg(evt) { 12 navigator.serviceWorker.removeEventListener('message', onMsg); 13 resolve(evt); 14 }); 15 worker.postMessage(data); 16 }); 17 } 18 19 promise_test(t => { 20 let script = 'resources/echo-message-to-source-worker.js'; 21 let scope = 'resources/client-postmessage-from-wait-serviceworker'; 22 let registration; 23 let frame; 24 return service_worker_unregister_and_register(t, script, scope) 25 .then(swr => { 26 t.add_cleanup(() => service_worker_unregister(t, scope)); 27 28 registration = swr; 29 return wait_for_state(t, registration.installing, 'activated'); 30 }).then(_ => { 31 return with_iframe(scope); 32 }).then(f => { 33 frame = f; 34 return navigator.serviceWorker.register(script + '?update', { scope: scope }) 35 }).then(swr => { 36 assert_equals(swr, registration, 'should be same registration'); 37 return wait_for_state(t, registration.installing, 'installed'); 38 }).then(_ => { 39 return echo(registration.waiting, 'waiting'); 40 }).then(evt => { 41 assert_equals(evt.source, registration.waiting, 42 'message event source should be correct'); 43 return echo(registration.active, 'active'); 44 }).then(evt => { 45 assert_equals(evt.source, registration.active, 46 'message event source should be correct'); 47 frame.remove(); 48 }); 49 }, 'Client.postMessage() from waiting serviceworker.'); 50 </script>