dom/tests/mochitest/chrome/test_docshell_swap.xul

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

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

mercurial