test_postMessage_override.html (1275B)
1 <!DOCTYPE html> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage 5 --> 6 <head> 7 <title>postMessage override test</title> 8 <script src="/tests/SimpleTest/SimpleTest.js"></script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 10 </head> 11 <body> 12 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=postMessage">Mozilla Bug 387706</a> 13 <p id="display"></p> 14 <div id="content" style="display: none"></div> 15 16 <iframe src="http://example.org:8000/tests/dom/tests/mochitest/whatwg/postMessage_override_helper.html"></iframe> 17 18 19 <pre id="test"> 20 <script class="testbody" type="application/javascript"> 21 /** Test for Bug 387706 */ 22 23 SimpleTest.waitForExplicitFinish(); 24 25 async function run() { 26 function ping(win, msg) { 27 return new Promise(resolve => { 28 window.addEventListener("message", evt => { 29 is(evt.source, win, "Response should come from the correct window"); 30 is(evt.data, msg, "Should get the correct response"); 31 resolve(); 32 }, { once: true }); 33 34 win.postMessage(msg, "http://example.org:8000"); 35 }); 36 } 37 38 await ping(frames[0], "PASS 1"); 39 await ping(frames[0], "PASS 2"); 40 SimpleTest.finish(); 41 } 42 43 window.addEventListener("load", run); 44 </script> 45 </pre> 46 </body> 47 </html>