broadcastchannel-current.sub.html (1851B)
1 <!DOCTYPE html> 2 <meta charset="utf-8"> 3 <title>The current page being cross-origin must prevent the BroadcastChannel message from being seen</title> 4 <script src="/resources/testharness.js"></script> 5 <script src="/resources/testharnessreport.js"></script> 6 7 <!-- This is the entry global --> 8 9 <iframe src="support/incumbent-document-domain.sub.html" id="incumbent"></iframe> 10 <iframe src="http://{{hosts[][www]}}:{{ports[http][0]}}/webmessaging/multi-globals/support/current-document-domain.sub.html" id="current"></iframe> 11 12 <script> 13 "use strict"; 14 document.domain = "{{hosts[][]}}"; 15 16 setup({ explicit_done: true }); 17 18 const incumbentIframe = document.querySelector("#incumbent"); 19 const currentIframe = document.querySelector("#current"); 20 21 window.onload = () => { 22 promise_test(async t => { 23 const createdCrossOrigin = frames[0].createBroadcastChannel("current"); 24 const createdSameOrigin = new BroadcastChannel("current"); 25 26 createdSameOrigin.onmessage = t.unreached_func("message event fired"); 27 createdSameOrigin.onmessageerror = t.unreached_func("messageerror event fired"); 28 29 createdCrossOrigin.postMessage("the message"); 30 31 // BroadcastChannel messages are guaranteed to be ordered within an event loop, as they all use 32 // the DOM manipulation task source. So, any messages from the "current" channel, if they are 33 // going to be erroneously delivered, would have to be delivered before those from this 34 // channel. I.e., if we recieve a message from this channel without first recieving one from 35 // the "current" channel, then the test passes. 36 const testEnder = new BroadcastChannel("current / test-ender"); 37 const testEnder2 = new BroadcastChannel("current / test-ender"); 38 39 testEnder.postMessage("end test"); 40 await new Promise(resolve => testEnder2.onmessage = resolve); 41 }); 42 43 done(); 44 }; 45 </script>