1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/whatwg/test_postMessage_closed.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,78 @@ 1.4 +<!DOCTYPE html> 1.5 +<html> 1.6 +<head> 1.7 + <title>postMessage's interaction with closed windows</title> 1.8 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.9 + <script type="text/javascript" src="browserFu.js"></script> 1.10 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> 1.11 +</head> 1.12 +<body> 1.13 +<p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=417075">Bug 417075</a></p> 1.14 +<p id="display"></p> 1.15 +<div id="content" style="display: none"></div> 1.16 + 1.17 +<div id="holder"></div> 1.18 + 1.19 +<pre id="test"> 1.20 +<script class="testbody" type="application/javascript"> 1.21 + 1.22 +SimpleTest.waitForExplicitFinish(); 1.23 + 1.24 +function receiveMessage(evt) 1.25 +{ 1.26 + is(evt.origin, "http://mochi.test:8888", "wrong origin"); 1.27 + ok(evt.source === openedWindow, "wrong source"); 1.28 + is(evt.lastEventId, "", "postMessage creates events with empty lastEventId"); 1.29 + 1.30 + is(evt.data, "message", "wrong data"); 1.31 + if (evt.data !== "message") 1.32 + return; // prevent recursion if bugs 1.33 + 1.34 + evt.source.close(); 1.35 + 1.36 + function afterClose() 1.37 + { 1.38 + document.removeEventListener("message", receiveMessage, false); 1.39 + evt.source.postMessage("NOT-RECEIVED", "*"); 1.40 + 1.41 + var iframe = document.createElement("iframe"); 1.42 + iframe.id = "insertedIframe"; 1.43 + $("holder").appendChild(iframe); 1.44 + iframe.addEventListener("load", iframeLoaded, false); 1.45 + iframe.src = "postMessage_closed_helper.html?parent"; 1.46 + } 1.47 + 1.48 + setTimeout(afterClose, 0); 1.49 +} 1.50 + 1.51 +window.addEventListener("message", receiveMessage, false); 1.52 + 1.53 +function iframeLoaded(evt) 1.54 +{ 1.55 + var iframe = $("insertedIframe"); 1.56 + iframe.removeEventListener("load", iframeLoaded, false); 1.57 + 1.58 + var iframeWindow = iframe.contentWindow; 1.59 + $("holder").removeChild($("insertedIframe")); 1.60 + iframeWindow.postMessage("NOT-RECEIVED", "*"); 1.61 + 1.62 + SimpleTest.finish(); 1.63 +} 1.64 + 1.65 +var openedWindow; 1.66 + 1.67 +function run() 1.68 +{ 1.69 + openedWindow = window.open("postMessage_closed_helper.html?opener", "foobar"); 1.70 + if (!openedWindow) 1.71 + { 1.72 + ok(false, "this test must be run with popup blocking disabled"); 1.73 + SimpleTest.finish(); 1.74 + } 1.75 +} 1.76 + 1.77 +window.addEventListener("load", run, false); 1.78 +</script> 1.79 +</pre> 1.80 +</body> 1.81 +</html>