Bug 1252723 - [e10s] Make toolkit/components/prompts/test work under e10s. r=dolske
authorDrew Willcoxon <adw@mozilla.com>
Fri, 01 Apr 2016 17:36:28 -0700
changeset 291466 7e4c0bee56f35104a4809121e8672f1e659258f5
parent 291465 6f4210b98c4b8f892fafddc1ca0b1c7638427f5c
child 291467 82a40128b81b1ec85c55933a0baa9e7f0b8e148b
push id19656
push usergwagner@mozilla.com
push dateMon, 04 Apr 2016 13:43:23 +0000
treeherderb2g-inbound@e99061fde28a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1252723
milestone48.0a1
Bug 1252723 - [e10s] Make toolkit/components/prompts/test work under e10s. r=dolske
toolkit/components/prompts/test/chromeScript.js
toolkit/components/prompts/test/mochitest.ini
toolkit/components/prompts/test/test_bug619644.html
toolkit/components/prompts/test/test_bug620145.html
toolkit/components/prompts/test/test_bug625187.html
toolkit/components/prompts/test/test_bug861605.html
new file mode 100644
--- /dev/null
+++ b/toolkit/components/prompts/test/chromeScript.js
@@ -0,0 +1,44 @@
+Components.utils.import("resource://gre/modules/Services.jsm");
+Components.utils.import("resource://gre/modules/Timer.jsm");
+
+// Define these to make EventUtils happy.
+let window = this;
+let parent = {};
+
+let EventUtils = {};
+Services.scriptloader.loadSubScript(
+  "chrome://mochikit/content/tests/SimpleTest/EventUtils.js",
+  EventUtils
+);
+
+addMessageListener("cancelPrompt", message => {
+  cancelPromptWhenItAppears();
+});
+
+function cancelPromptWhenItAppears() {
+  let interval = setInterval(() => {
+    if (cancelPrompt()) {
+      clearInterval(interval);
+    }
+  }, 100);
+}
+
+function cancelPrompt() {
+  let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
+  let gBrowser = browserWin.gBrowser;
+  let promptManager = gBrowser.getTabModalPromptBox(gBrowser.selectedBrowser);
+  let prompts = promptManager.listPrompts();
+  if (!prompts.length) {
+    return false;
+  }
+  sendAsyncMessage("promptCanceled", {
+    ui: {
+      infoTitle: {
+        hidden: prompts[0].ui.infoTitle.getAttribute("hidden") == "true",
+      },
+    },
+  });
+  EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }, browserWin);
+  return true;
+}
+
--- a/toolkit/components/prompts/test/mochitest.ini
+++ b/toolkit/components/prompts/test/mochitest.ini
@@ -1,16 +1,17 @@
 [DEFAULT]
-skip-if = buildapp == 'mulet' || buildapp == 'b2g' || e10s
+skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 support-files =
   bug619644_inner.html
   bug625187_iframe.html
   prompt_common.js
+  chromeScript.js
 
 [test_bug619644.html]
 [test_bug620145.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_bug625187.html]
 [test_bug861605.html]
 [test_modal_prompts.html]
-skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) #TIMED_OUT (For Linux : 950636)
+skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) || e10s #android: TIMED_OUT (For Linux : 950636)
 [test_modal_select.html]
-skip-if = toolkit == 'android' #TIMED_OUT
+skip-if = toolkit == 'android' || e10s #android: TIMED_OUT
--- a/toolkit/components/prompts/test/test_bug619644.html
+++ b/toolkit/components/prompts/test/test_bug619644.html
@@ -26,26 +26,32 @@ if (!hasTabModalPrompts()) {
 } else {
 SimpleTest.waitForExplicitFinish();
 
 // This is a little yucky, but it works
 // The contents of bug619644_inner.html
 const expectedFinalDoc =
 "<head><\/head><body><p>Original content<\/p>\n<script>\n    window.opener.postMessage(\"\", \"*\");\n    confirm (\"Message\");\n    document.write (\"Extra content\");\n    window.opener.postMessage(document.documentElement.innerHTML, \"*\");\n<\/script>Extra content<\/body>";
 
+let gChromeMessageManager;
+
 function runtest(e)
 {
   window.removeEventListener("message", runtest, false);
   window.addEventListener("message", checktest, false);
-  synthesizeKey("VK_ESCAPE", {}, e.source);
+
+  let url = SimpleTest.getTestFileURL("chromeScript.js");
+  gChromeMessageManager = SpecialPowers.loadChromeScript(url);
+  gChromeMessageManager.sendAsyncMessage("cancelPrompt");
 }
 
 function checktest(e) {
   is(e.data, expectedFinalDoc, "ESC press should not abort document load");
   e.source.close();
+  gChromeMessageManager.destroy();
   SimpleTest.finish();
 }
 
 window.addEventListener("message", runtest, false);
 window.open("bug619644_inner.html", "619644");
 }
 </script>
 </pre>
--- a/toolkit/components/prompts/test/test_bug620145.html
+++ b/toolkit/components/prompts/test/test_bug620145.html
@@ -1,15 +1,14 @@
 <html>
 <head>
   <title>Test for Bug 620145</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
-  <script type="text/javascript" src="prompt_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="runtest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=620145">Mozilla Bug 620145</a>
 <pre id="test">
 </pre>
 
 <div id="text" style="max-width: 100px" onmouseup="openAlert()">
@@ -48,52 +47,61 @@ function runtest()
   // The <button> in this test's HTML opens a prompt when clicked.
   // Here we send the events to simulate clicking it.
   ok(true, "starting test");
   isTabModal = hasTabModalPrompts();
   if (!isTabModal)
     todo(false, "Test is run with tab modal prompts disabled.");
   else
     ok(true, "Test is run with tab modal prompts enabled.");
-  startCallbackTimer();
+
+  selectionTest = isTabModal;
+
+  let url = SimpleTest.getTestFileURL("chromeScript.js");
+  let chrome = SpecialPowers.loadChromeScript(url);
+  chrome.sendAsyncMessage("cancelPrompt");
 
   var button = $("button");
   dispatchMouseEvent(button, "mousedown");
   dispatchMouseEvent(button, "mouseup");
 
-  selectionTest = isTabModal;
+  // alert appears at this point, to be closed by the chrome script.
 
-  startCallbackTimer();
+  checkSelection();
+
+  chrome.sendAsyncMessage("cancelPrompt");
 
   var text = $("text");
   dispatchMouseEvent(text, "mousedown");
   dispatchMouseEvent(text, "mouseup");
 
+  // alert appears at this point, to be closed by the chrome script.
+
+  checkSelection();
+
+  chrome.destroy();
   SimpleTest.finish();
 }
 
 function dispatchMouseEvent(target, type)
 {
   var win = target.ownerDocument.defaultView;
   e = document.createEvent("MouseEvent");
   e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
               false, false, false, false, 0, null);
   var utils = SpecialPowers.getDOMWindowUtils(win);
   utils.dispatchDOMEventViaPresShell(target, e, true);
   ok(true, type + " sent to " + target.id);
 }
 
-function handleDialog(ui, testNum)
+function checkSelection()
 {
   if (!selectionTest) {
     todo(false, "Selection test is disabled when tab modal prompts are not enabled.");
   } else {
     synthesizeMouse($("text"), 25, 55, { type: "mousemove" });
     is(window.getSelection().toString(), "", "selection not made");
   }
-
-  ok(true, "handleDialog sending mouseclick to dialog...");
-  synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 </script>
 
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_bug625187.html
+++ b/toolkit/components/prompts/test/test_bug625187.html
@@ -1,15 +1,14 @@
 <html>
 <head>
   <title>Test for Bug 625187</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
-  <script type="text/javascript" src="prompt_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
 <!--
    - Any copyright is dedicated to the Public Domain.
    - http://creativecommons.org/publicdomain/zero/1.0/
    -
    - Contributor(s):
    -   Mihai Sucan <mihai.sucan@gmail.com>
    -->
@@ -44,52 +43,58 @@ function runtest()
 
   // This test depends on tab modal prompts being enabled.
   if (!isTabModal) {
     todo(false, "Test disabled when tab modal prompts are not enabled.");
     SimpleTest.finish();
     return;
   }
 
-  startCallbackTimer();
+  let url = SimpleTest.getTestFileURL("chromeScript.js");
+  let chrome = SpecialPowers.loadChromeScript(url);
+
+  chrome.addMessageListener("promptCanceled", msg => {
+    checkSelection(msg.ui);
+  });
+
+  chrome.sendAsyncMessage("cancelPrompt");
 
   var button = document.querySelector("button");
   dispatchMouseEvent(button, "click");
 
-  startCallbackTimer();
+  chrome.sendAsyncMessage("cancelPrompt");
 
   var iframe = document.getElementById("iframe_diff_origin");
   button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
-  startCallbackTimer();
+  chrome.sendAsyncMessage("cancelPrompt");
 
   iframe = document.getElementById("iframe_same_origin");
   button = iframe.contentWindow.document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
-  startCallbackTimer();
+  chrome.sendAsyncMessage("cancelPrompt");
 
   button = iframe.contentWindow.document.getElementById("btn2");
   dispatchMouseEvent(button, "click");
 
+  chrome.destroy();
   SimpleTest.finish();
 }
 
-function handleDialog(ui)
+function checkSelection(ui)
 {
   dialogNum++;
   if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
-    is(ui.infoTitle.getAttribute("hidden"), "true",
+    ok(ui.infoTitle.hidden,
        "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
   else if (dialogNum == 2)
-    ok(!ui.infoTitle.hasAttribute("hidden"),
+    ok(!ui.infoTitle.hidden,
        "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
-
-  synthesizeMouse(ui.button0, 2, 2, {}, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 
 function dispatchMouseEvent(target, type)
 {
   var win = SpecialPowers.unwrap(target.ownerDocument.defaultView);
   var e = document.createEvent("MouseEvent");
   e.initEvent(type, false, false, win, 0, 1, 1, 1, 1,
               false, false, false, false, 0, null);
--- a/toolkit/components/prompts/test/test_bug861605.html
+++ b/toolkit/components/prompts/test/test_bug861605.html
@@ -1,15 +1,14 @@
 <html>
 <head>
   <title>Test for Bug 861605</title>
   <script type="text/javascript" src="/MochiKit/MochiKit.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
   <script type="text/javascript" src="/tests/SimpleTest/EventUtils.js"></script>
-  <script type="text/javascript" src="prompt_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body onload="runtest()">
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=861605">Mozilla Bug 861605</a>
 <pre id="test">
 </pre>
 
 <script class="testbody" type="text/javascript">
@@ -33,34 +32,37 @@ function runtest()
   if (!isTabModal) {
     todo(false, "Test is run with tab modal prompts disabled.");
     SimpleTest.finish();
     return;
   }
 
   ok(true, "Test is run with tab modal prompts enabled.");
 
-  startCallbackTimer();
+  let url = SimpleTest.getTestFileURL("chromeScript.js");
+  let chrome = SpecialPowers.loadChromeScript(url);
+  chrome.sendAsyncMessage("cancelPrompt");
 
   try {
     alert();
     ok(true, "alert() without arguments should not throw!");
   } catch(e) {
     ok(false, "alert() without arguments should not throw!");
   }
 
-  startCallbackTimer();
+  chrome.sendAsyncMessage("cancelPrompt");
 
   try {
     confirm();
     ok(true, "confirm() without arguments should not throw!");
   } catch(e) {
     ok(false, "confirm() without arguments should not throw!");
   }
 
+  chrome.destroy();
   SimpleTest.finish();
 }
 
 function handleDialog(ui, testNum)
 {
   synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
 }
 </script>