Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 <!DOCTYPE html> | |
| 2 <script src="../../resources/testharness.js"></script> | |
| 3 <script src="../../resources/testharnessreport.js"></script> | |
| 4 <script src="../../resources/get-host-info.js"></script> | |
| 5 <script src="test-helpers.js"></script> | |
| 6 <script> | |
| 7 var host_info = get_host_info(); | |
| 8 var SCOPE = 'blank.html?clients-get'; | |
| 9 var SCRIPT = 'clients-get-worker.js'; | |
| 10 | |
| 11 var registration; | |
| 12 var worker; | |
| 13 var wait_for_worker_promise = navigator.serviceWorker.getRegistration(SCOPE) | |
| 14 .then(function(reg) { | |
| 15 if (reg) | |
| 16 return reg.unregister(); | |
| 17 }) | |
| 18 .then(function() { | |
| 19 return navigator.serviceWorker.register(SCRIPT, {scope: SCOPE}); | |
| 20 }) | |
| 21 .then(function(reg) { | |
| 22 registration = reg; | |
| 23 worker = reg.installing; | |
| 24 return new Promise(function(resolve) { | |
| 25 worker.addEventListener('statechange', function() { | |
| 26 if (worker.state == 'activated') | |
| 27 resolve(); | |
| 28 }); | |
| 29 }); | |
| 30 }); | |
| 31 | |
| 32 function send_result(result) { | |
| 33 window.parent.postMessage( | |
| 34 {result: result}, | |
| 35 host_info['HTTP_ORIGIN']); | |
| 36 } | |
| 37 | |
| 38 window.addEventListener('message', function on_message(e) { | |
|
nhiroki
2016/02/08 06:27:03
"function on_message(e)" -> "function(e)"
jungkees
2016/02/12 15:03:22
Done.
| |
| 39 assert_equals(e.origin, host_info['HTTP_ORIGIN']); | |
| 40 if (e.data.message == 'get_client_id') { | |
| 41 var otherOriginClientId = e.data.clientId; | |
| 42 wait_for_worker_promise | |
| 43 .then(function() { | |
| 44 return with_iframe(SCOPE); | |
| 45 }) | |
| 46 .then(function(iframe) { | |
| 47 var channel = new MessageChannel(); | |
| 48 channel.port1.onmessage = function(e) { | |
| 49 navigator.serviceWorker.getRegistration(SCOPE) | |
| 50 .then(function(reg) { | |
| 51 reg.unregister(); | |
| 52 send_result(e.data); | |
| 53 }); | |
| 54 }; | |
| 55 iframe.contentWindow.navigator.serviceWorker.controller.postMessage( | |
| 56 {port:channel.port2, clientId: otherOriginClientId, | |
| 57 message: 'get_other_client_id'}, [channel.port2]); | |
| 58 }); | |
| 59 } | |
| 60 }); | |
| 61 </script> | |
| OLD | NEW |