Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | <!DOCTYPE html> |
michael@0 | 2 | <html> |
michael@0 | 3 | <head> |
michael@0 | 4 | <title>postMessage's interaction with closed windows</title> |
michael@0 | 5 | <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
michael@0 | 6 | <script type="text/javascript" src="browserFu.js"></script> |
michael@0 | 7 | <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> |
michael@0 | 8 | </head> |
michael@0 | 9 | <body> |
michael@0 | 10 | <p><a href="https://bugzilla.mozilla.org/show_bug.cgi?id=417075">Bug 417075</a></p> |
michael@0 | 11 | <p id="display"></p> |
michael@0 | 12 | <div id="content" style="display: none"></div> |
michael@0 | 13 | |
michael@0 | 14 | <div id="holder"></div> |
michael@0 | 15 | |
michael@0 | 16 | <pre id="test"> |
michael@0 | 17 | <script class="testbody" type="application/javascript"> |
michael@0 | 18 | |
michael@0 | 19 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 20 | |
michael@0 | 21 | function receiveMessage(evt) |
michael@0 | 22 | { |
michael@0 | 23 | is(evt.origin, "http://mochi.test:8888", "wrong origin"); |
michael@0 | 24 | ok(evt.source === openedWindow, "wrong source"); |
michael@0 | 25 | is(evt.lastEventId, "", "postMessage creates events with empty lastEventId"); |
michael@0 | 26 | |
michael@0 | 27 | is(evt.data, "message", "wrong data"); |
michael@0 | 28 | if (evt.data !== "message") |
michael@0 | 29 | return; // prevent recursion if bugs |
michael@0 | 30 | |
michael@0 | 31 | evt.source.close(); |
michael@0 | 32 | |
michael@0 | 33 | function afterClose() |
michael@0 | 34 | { |
michael@0 | 35 | document.removeEventListener("message", receiveMessage, false); |
michael@0 | 36 | evt.source.postMessage("NOT-RECEIVED", "*"); |
michael@0 | 37 | |
michael@0 | 38 | var iframe = document.createElement("iframe"); |
michael@0 | 39 | iframe.id = "insertedIframe"; |
michael@0 | 40 | $("holder").appendChild(iframe); |
michael@0 | 41 | iframe.addEventListener("load", iframeLoaded, false); |
michael@0 | 42 | iframe.src = "postMessage_closed_helper.html?parent"; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | setTimeout(afterClose, 0); |
michael@0 | 46 | } |
michael@0 | 47 | |
michael@0 | 48 | window.addEventListener("message", receiveMessage, false); |
michael@0 | 49 | |
michael@0 | 50 | function iframeLoaded(evt) |
michael@0 | 51 | { |
michael@0 | 52 | var iframe = $("insertedIframe"); |
michael@0 | 53 | iframe.removeEventListener("load", iframeLoaded, false); |
michael@0 | 54 | |
michael@0 | 55 | var iframeWindow = iframe.contentWindow; |
michael@0 | 56 | $("holder").removeChild($("insertedIframe")); |
michael@0 | 57 | iframeWindow.postMessage("NOT-RECEIVED", "*"); |
michael@0 | 58 | |
michael@0 | 59 | SimpleTest.finish(); |
michael@0 | 60 | } |
michael@0 | 61 | |
michael@0 | 62 | var openedWindow; |
michael@0 | 63 | |
michael@0 | 64 | function run() |
michael@0 | 65 | { |
michael@0 | 66 | openedWindow = window.open("postMessage_closed_helper.html?opener", "foobar"); |
michael@0 | 67 | if (!openedWindow) |
michael@0 | 68 | { |
michael@0 | 69 | ok(false, "this test must be run with popup blocking disabled"); |
michael@0 | 70 | SimpleTest.finish(); |
michael@0 | 71 | } |
michael@0 | 72 | } |
michael@0 | 73 | |
michael@0 | 74 | window.addEventListener("load", run, false); |
michael@0 | 75 | </script> |
michael@0 | 76 | </pre> |
michael@0 | 77 | </body> |
michael@0 | 78 | </html> |