|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?> |
|
3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> |
|
4 <window title="Docshell swap test" |
|
5 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
6 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> |
|
7 |
|
8 <!-- test results are displayed in the html:body --> |
|
9 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
10 |
|
11 </body> |
|
12 |
|
13 <!-- test code goes here --> |
|
14 <script type="application/javascript"> |
|
15 <![CDATA[ |
|
16 |
|
17 SimpleTest.waitForExplicitFinish(); |
|
18 |
|
19 // Create two identical windows, each with a <browser> element. |
|
20 let win1 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); |
|
21 let win2 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200"); |
|
22 |
|
23 let loadCount = 0; |
|
24 function loadHandler() { |
|
25 loadCount++; |
|
26 if (loadCount < 2) |
|
27 return; |
|
28 |
|
29 let browser1 = win1.document.getElementById("browser"); |
|
30 let browser2 = win2.document.getElementById("browser"); |
|
31 |
|
32 let flo1 = browser1.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); |
|
33 let flo2 = browser2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner); |
|
34 |
|
35 let pongCount = 0; |
|
36 |
|
37 function gotPong(target_ok) { |
|
38 pongCount++; |
|
39 ok(target_ok, "message went to correct target"); |
|
40 if (pongCount == 1) { |
|
41 win1.close(); |
|
42 win2.close(); |
|
43 SimpleTest.finish(); |
|
44 } |
|
45 } |
|
46 |
|
47 let mm1 = flo1.frameLoader.messageManager; |
|
48 let mm2 = flo2.frameLoader.messageManager; |
|
49 mm1.addMessageListener("pong", () => { gotPong(true); }); |
|
50 mm2.addMessageListener("pong", () => { gotPong(false); }); |
|
51 |
|
52 // Swap docshells. Everything should be identical to before, since there was nothing to |
|
53 // distinguish these docshells. |
|
54 flo1.swapFrameLoaders(flo2); |
|
55 |
|
56 // mm1 shouldn't change here, but we update it in case it does due to a bug. |
|
57 mm1 = flo1.frameLoader.messageManager; |
|
58 |
|
59 // Load ping-pong code into first window. |
|
60 mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false); |
|
61 |
|
62 // A pong message received in win1 means success. |
|
63 win1.messageManager.addMessageListener("pong", () => { gotPong(true); }); |
|
64 |
|
65 // A pong message received in win2 means failure! |
|
66 win2.messageManager.addMessageListener("pong", () => { gotPong(false); }); |
|
67 |
|
68 // Send the ping to win1. |
|
69 mm1.sendAsyncMessage("ping"); |
|
70 } |
|
71 |
|
72 win1.addEventListener("load", loadHandler, false); |
|
73 win2.addEventListener("load", loadHandler, false); |
|
74 ]]> |
|
75 </script> |
|
76 </window> |