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

     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"/>
     8   <!-- test results are displayed in the html:body -->
     9   <body xmlns="http://www.w3.org/1999/xhtml">
    11   </body>
    13   <!-- test code goes here -->
    14   <script type="application/javascript">
    15   <![CDATA[
    17   SimpleTest.waitForExplicitFinish();
    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");
    23   let loadCount = 0;
    24   function loadHandler() {
    25     loadCount++;
    26     if (loadCount < 2)
    27       return;
    29     let browser1 = win1.document.getElementById("browser");
    30     let browser2 = win2.document.getElementById("browser");
    32     let flo1 = browser1.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
    33     let flo2 = browser2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
    35     let pongCount = 0;
    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     }
    47     let mm1 = flo1.frameLoader.messageManager;
    48     let mm2 = flo2.frameLoader.messageManager;
    49     mm1.addMessageListener("pong", () => { gotPong(true); });
    50     mm2.addMessageListener("pong", () => { gotPong(false); });
    52     // Swap docshells. Everything should be identical to before, since there was nothing to
    53     // distinguish these docshells.
    54     flo1.swapFrameLoaders(flo2);
    56     // mm1 shouldn't change here, but we update it in case it does due to a bug.
    57     mm1 = flo1.frameLoader.messageManager;
    59     // Load ping-pong code into first window.
    60     mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false);
    62     // A pong message received in win1 means success.
    63     win1.messageManager.addMessageListener("pong", () => { gotPong(true); });
    65     // A pong message received in win2 means failure!
    66     win2.messageManager.addMessageListener("pong", () => { gotPong(false); });
    68     // Send the ping to win1.
    69     mm1.sendAsyncMessage("ping");
    70   }
    72   win1.addEventListener("load", loadHandler, false);
    73   win2.addEventListener("load", loadHandler, false);
    74   ]]>
    75   </script>
    76 </window>

mercurial