tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_docshell_swap.xhtml (2419B)


      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 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.browsingContext.topChromeWindow.openDialog("window_docshell_swap.xhtml", "_blank","chrome,width=300,height=200");
     21  let win2 = window.browsingContext.topChromeWindow.openDialog("window_docshell_swap.xhtml", "_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 pongCount = 0;
     33 
     34    function gotPong(target_ok) {
     35      pongCount++;
     36      ok(target_ok, "message went to correct target");
     37      if (pongCount == 1) {
     38        win1.close();
     39        win2.close();
     40        SimpleTest.finish();
     41      }
     42    }
     43 
     44    let mm1 = browser1.frameLoader.messageManager;
     45    let mm2 = browser2.frameLoader.messageManager;
     46 
     47    // Swap docshells. Everything should be identical to before, since there was nothing to
     48    // distinguish these docshells.
     49    browser1.swapFrameLoaders(browser2);
     50 
     51    // mm1 shouldn't change here, but we update it in case it does due to a bug.
     52    mm1 = browser1.frameLoader.messageManager;
     53 
     54    // Load ping-pong code into first window.
     55    mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false);
     56 
     57    // A pong message received in win1 means success.
     58    win1.messageManager.addMessageListener("pong", () => { gotPong(true); });
     59 
     60    // A pong message received in win2 means failure!
     61    win2.messageManager.addMessageListener("pong", () => { gotPong(false); });
     62 
     63    // Send the ping to win1.
     64    mm1.sendAsyncMessage("ping");
     65  }
     66 
     67  win1.addEventListener("load", loadHandler);
     68  win2.addEventListener("load", loadHandler);
     69  ]]>
     70  </script>
     71 </window>