Bug 962767 - Testcase for docshell swapping with message manager (r=smaug)
authorBill McCloskey <wmccloskey@mozilla.com>
Fri, 31 Jan 2014 10:46:16 -0800
changeset 182404 df918fe43131a2d404309c5171a1b9c09d4310cc
parent 182403 f55a6150f6ee0df055ecf676b2cb4dc452a77a7f
child 182405 78bbd153072a539d534a2c2c71e34a2afb49eb9c
push id3343
push userffxbld
push dateMon, 17 Mar 2014 21:55:32 +0000
treeherdermozilla-beta@2f7d3415f79f [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssmaug
bugs962767
milestone29.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 962767 - Testcase for docshell swapping with message manager (r=smaug)
dom/tests/mochitest/chrome/chrome.ini
dom/tests/mochitest/chrome/test_docshell_swap.xul
dom/tests/mochitest/chrome/window_docshell_swap.xul
--- a/dom/tests/mochitest/chrome/chrome.ini
+++ b/dom/tests/mochitest/chrome/chrome.ini
@@ -14,29 +14,31 @@ support-files =
   focus_window2.xul
   fullscreen.xul
   fullscreen_preventdefault.xul
   queryCaretRectUnix.html
   queryCaretRectWin.html
   selectAtPoint.html
   window_activation.xul
   window_callback_wrapping.xul
+  window_docshell_swap.xul
   window_focus.xul
   window_focus_docnav.xul
 
 [test_DOMWindowCreated.xul]
 [test_DOM_element_instanceof.xul]
 [test_activation.xul]
 [test_bug799299.xul]
 [test_bug800817.xul]
 [test_bug830396.xul]
 [test_bug830858.xul]
 [test_callback_wrapping.xul]
 [test_clonewrapper.xul]
 [test_cyclecollector.xul]
+[test_docshell_swap.xul]
 [test_focus.xul]
 [test_focus_docnav.xul]
 [test_focus_switchbinding.xul]
 [test_focused_link_scroll.xul]
 [test_fullscreen_preventdefault.xul]
 [test_geolocation.xul]
 [test_indexedSetter.html]
 [test_moving_nodeList.xul]
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/chrome/test_docshell_swap.xul
@@ -0,0 +1,76 @@
+<?xml version="1.0"?>
+<?xml-stylesheet type="text/css" href="chrome://global/skin"?>
+<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
+<window title="Docshell swap test"
+        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
+
+  <!-- test results are displayed in the html:body -->
+  <body xmlns="http://www.w3.org/1999/xhtml">
+
+  </body>
+
+  <!-- test code goes here -->
+  <script type="application/javascript">
+  <![CDATA[
+
+  SimpleTest.waitForExplicitFinish();
+
+  // Create two identical windows, each with a <browser> element.
+  let win1 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200");
+  let win2 = window.openDialog("window_docshell_swap.xul", "_blank","chrome,width=300,height=200");
+
+  let loadCount = 0;
+  function loadHandler() {
+    loadCount++;
+    if (loadCount < 2)
+      return;
+
+    let browser1 = win1.document.getElementById("browser");
+    let browser2 = win2.document.getElementById("browser");
+
+    let flo1 = browser1.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
+    let flo2 = browser2.QueryInterface(Components.interfaces.nsIFrameLoaderOwner);
+
+    let pongCount = 0;
+
+    function gotPong(target_ok) {
+      pongCount++;
+      ok(target_ok, "message went to correct target");
+      if (pongCount == 1) {
+        win1.close();
+        win2.close();
+        SimpleTest.finish();
+      }
+    }
+
+    let mm1 = flo1.frameLoader.messageManager;
+    let mm2 = flo2.frameLoader.messageManager;
+    mm1.addMessageListener("pong", () => { gotPong(true); });
+    mm2.addMessageListener("pong", () => { gotPong(false); });
+
+    // Swap docshells. Everything should be identical to before, since there was nothing to
+    // distinguish these docshells.
+    flo1.swapFrameLoaders(flo2);
+
+    // mm1 shouldn't change here, but we update it in case it does due to a bug.
+    mm1 = flo1.frameLoader.messageManager;
+
+    // Load ping-pong code into first window.
+    mm1.loadFrameScript("data:,addMessageListener('ping', () => sendAsyncMessage('pong'));", false);
+
+    // A pong message received in win1 means success.
+    win1.messageManager.addMessageListener("pong", () => { gotPong(true); });
+
+    // A pong message received in win2 means failure!
+    win2.messageManager.addMessageListener("pong", () => { gotPong(false); });
+
+    // Send the ping to win1.
+    mm1.sendAsyncMessage("ping");
+  }
+
+  win1.addEventListener("load", loadHandler, false);
+  win2.addEventListener("load", loadHandler, false);
+  ]]>
+  </script>
+</window>
new file mode 100644
--- /dev/null
+++ b/dom/tests/mochitest/chrome/window_docshell_swap.xul
@@ -0,0 +1,8 @@
+<?xml version="1.0"?>
+<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
+
+<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
+
+<browser type="content" src="about:blank" id="browser"/>
+
+</window>