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