Bug 1265194 - Refactor prompt tests to use state/action objects and new common helpers. r=adw
authorJustin Dolske <dolske@mozilla.com>
Sun, 24 Apr 2016 11:01:01 -0700
changeset 332392 7f54642144c27146b981a6d4c632396c7cd1d6c8
parent 332391 80b01ead9803b251a97eed873fbb096b469a77c2
child 332393 13cbfc180fe6ea8ba7ad99eb5da126e1b5b7fdf2
push id6048
push userkmoir@mozilla.com
push dateMon, 06 Jun 2016 19:02:08 +0000
treeherdermozilla-beta@46d72a56c57d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersadw
bugs1265194
milestone48.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 1265194 - Refactor prompt tests to use state/action objects and new common helpers. r=adw
toolkit/components/prompts/test/chromeScript.js
toolkit/components/prompts/test/prompt_common.js
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_dom_prompts.html
toolkit/components/prompts/test/test_modal_prompts.html
toolkit/components/prompts/test/test_modal_select.html
--- a/toolkit/components/prompts/test/chromeScript.js
+++ b/toolkit/components/prompts/test/chromeScript.js
@@ -76,16 +76,17 @@ function getSelectState(ui) {
   }
 
   return state;
 }
 
 function getPromptState(ui) {
   let state = {};
   state.msg         = ui.infoBody.textContent;
+  state.titleHidden = ui.infoTitle.getAttribute("hidden") == "true";
   state.textHidden  = ui.loginContainer.hidden;
   state.passHidden  = ui.password1Container.hidden;
   state.checkHidden = ui.checkboxContainer.hidden;
   state.checkMsg    = ui.checkbox.label;
   state.checked     = ui.checkbox.checked;
   // tab-modal prompts don't have an infoIcon
   state.iconClass   = ui.infoIcon ? ui.infoIcon.className : null;
   state.textValue   = ui.loginTextbox.getAttribute("value");
@@ -169,16 +170,21 @@ function dismissPrompt(ui, action) {
       break;
     case "cancel":
     case 1:
       ui.button1.click();
       break;
     case 2:
       ui.button2.click();
       break;
+    case "ESC":
+      // XXX This is assuming tab-modal.
+      let browserWin = Services.wm.getMostRecentWindow("navigator:browser");
+      EventUtils.synthesizeKey("KEY_Escape", { code: "Escape" }, browserWin);
+      break;
     case "pollOK":
       // Buttons are disabled at the moment, poll until they're reenabled.
       // Can't use setInterval here, because the window's in a modal state
       // and thus DOM events are suppressed.
       let interval = setInterval(() => {
         if (ui.button0.disabled)
           return;
         ui.button0.click();
@@ -186,49 +192,16 @@ function dismissPrompt(ui, action) {
       }, 100);
       break;
 
     default:
       throw "dismissPrompt action listed unknown button.";
   }
 }
 
-
-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;
-}
-
-
 function getDialogDoc() {
   // Trudge through all the open windows, until we find the one
   // that has either commonDialog.xul or selectDialog.xul loaded.
   var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
            getService(Ci.nsIWindowMediator);
   //var enumerator = wm.getEnumerator("navigator:browser");
   var enumerator = wm.getXULWindowEnumerator(null);
 
--- a/toolkit/components/prompts/test/prompt_common.js
+++ b/toolkit/components/prompts/test/prompt_common.js
@@ -1,153 +1,46 @@
 const Ci = SpecialPowers.Ci;
 const Cc = SpecialPowers.Cc;
 ok(Ci != null, "Access Ci");
 ok(Cc != null, "Access Cc");
 
-var didDialog;
-
 var isSelectDialog = false;
 var isTabModal = false;
 if (SpecialPowers.getBoolPref("prompts.tab_modal.enabled")) {
     isTabModal = true;
 }
-var usePromptService = true;
-
-var timer; // keep in outer scope so it's not GC'd before firing
-function startCallbackTimer() {
-    didDialog = false;
-
-    // Delay before the callback twiddles the prompt.
-    const dialogDelay = 10;
-
-    // Use a timer to invoke a callback to twiddle the authentication dialog
-    timer = Cc["@mozilla.org/timer;1"].createInstance(Ci.nsITimer);
-    timer.init(observer, dialogDelay, Ci.nsITimer.TYPE_ONE_SHOT);
-}
-
-
-var observer = {
-    QueryInterface : SpecialPowers.wrapCallback(function (iid) {
-        const interfaces = [Ci.nsIObserver,
-                            Ci.nsISupports, Ci.nsISupportsWeakReference];
-
-        if (!interfaces.some( function(v) { return iid.equals(v) } ))
-            throw SpecialPowers.Cr.NS_ERROR_NO_INTERFACE;
-        return this;
-    }),
-
-    observe : SpecialPowers.wrapCallback(function (subject, topic, data) {
-      try {
-        if (isTabModal) {
-          var promptBox = getTabModalPromptBox(window);
-          ok(promptBox, "got tabmodal promptbox");
-          var prompts = SpecialPowers.wrap(promptBox).listPrompts();
-          if (prompts.length)
-              handleDialog(prompts[0].Dialog.ui, testNum);
-          else
-              startCallbackTimer(); // try again in a bit
-        } else {
-          var doc = getDialogDoc();
-          if (isSelectDialog && doc)
-              handleDialog(doc, testNum);
-          else if (doc)
-              handleDialog(doc.defaultView.Dialog.ui, testNum);
-          else
-              startCallbackTimer(); // try again in a bit
-        }
-      } catch (e) {
-        ok(false, "Exception thrown in the timer callback: " + e + " at " + (e.fileName || e.filename) + ":" + (e.lineNumber || e.linenumber));
-      }
-    })
-};
-
-function getTabModalPromptBox(domWin) {
-    var promptBox = null;
-
-    // Given a content DOM window, returns the chrome window it's in.
-    function getChromeWindow(aWindow) {
-        var chromeWin = SpecialPowers.wrap(aWindow).QueryInterface(Ci.nsIInterfaceRequestor)
-                               .getInterface(Ci.nsIWebNavigation)
-                               .QueryInterface(Ci.nsIDocShell)
-                               .chromeEventHandler.ownerDocument.defaultView;
-        return chromeWin;
-    }
-
-    try {
-        // Get the topmost window, in case we're in a frame.
-        var promptWin = domWin.top;
-
-        // Get the chrome window for the content window we're using.
-        var chromeWin = getChromeWindow(promptWin);
-
-        if (chromeWin.getTabModalPromptBox)
-            promptBox = chromeWin.getTabModalPromptBox(promptWin);
-    } catch (e) {
-        // If any errors happen, just assume no tabmodal prompter.
-    }
-
-    // Callers get confused by a wrapped promptBox here.
-    return SpecialPowers.unwrap(promptBox);
-}
-
-function getDialogDoc() {
-  // Trudge through all the open windows, until we find the one
-  // that has either commonDialog.xul or selectDialog.xul loaded.
-  var wm = Cc["@mozilla.org/appshell/window-mediator;1"].
-           getService(Ci.nsIWindowMediator);
-  //var enumerator = wm.getEnumerator("navigator:browser");
-  var enumerator = wm.getXULWindowEnumerator(null);
-
-  while (enumerator.hasMoreElements()) {
-    var win = enumerator.getNext();
-    var windowDocShell = win.QueryInterface(Ci.nsIXULWindow).docShell;
-
-    var containedDocShells = windowDocShell.getDocShellEnumerator(
-                                      Ci.nsIDocShellTreeItem.typeChrome,
-                                      Ci.nsIDocShell.ENUMERATE_FORWARDS);
-    while (containedDocShells.hasMoreElements()) {
-        // Get the corresponding document for this docshell
-        var childDocShell = containedDocShells.getNext();
-        // We don't want it if it's not done loading.
-        if (childDocShell.busyFlags != Ci.nsIDocShell.BUSY_FLAGS_NONE)
-          continue;
-        var childDoc = childDocShell.QueryInterface(Ci.nsIDocShell)
-                                    .contentViewer
-                                    .DOMDocument;
-
-        //ok(true, "Got window: " + childDoc.location.href);
-        if (childDoc.location.href == "chrome://global/content/commonDialog.xul")
-          return childDoc;
-        if (childDoc.location.href == "chrome://global/content/selectDialog.xul")
-          return childDoc;
-    }
-  }
-
-  return null;
-}
 
 var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci);
 var isLinux = ("@mozilla.org/gnome-gconf-service;1" in SpecialPowers.Cc);
 var isE10S = SpecialPowers.Services.appinfo.processType == 2;
 
+
+var gChromeScript = SpecialPowers.loadChromeScript(SimpleTest.getTestFileURL("chromeScript.js"));
+SimpleTest.registerCleanupFunction(() => gChromeScript.destroy());
+
+
 function handlePrompt() {
   return new Promise(resolve => {
     gChromeScript.addMessageListener("promptHandled", function handled(msg) {
       gChromeScript.removeMessageListener("promptHandled", handled);
       checkPromptState(msg.promptState, state);
       resolve(true);
     });
     gChromeScript.sendAsyncMessage("handlePrompt", { action: action, isTabModal: isTabModal});
   });
 }
 
 function checkPromptState(promptState, expectedState) {
     // XXX check title? OS X has title in content
     is(promptState.msg,         expectedState.msg,         "Checking expected message");
+    if (isOSX && !isTabModal)
+      ok(!promptState.titleHidden, "Checking title always visible on OS X");
+    else
+      is(promptState.titleHidden, expectedState.titleHidden, "Checking title visibility");
     is(promptState.textHidden,  expectedState.textHidden,  "Checking textbox visibility");
     is(promptState.passHidden,  expectedState.passHidden,  "Checking passbox visibility");
     is(promptState.checkHidden, expectedState.checkHidden, "Checking checkbox visibility");
     is(promptState.checkMsg,    expectedState.checkMsg,    "Checking checkbox label");
     is(promptState.checked,     expectedState.checked,     "Checking checkbox checked");
     if (!isTabModal)
       is(promptState.iconClass, "spaced " + expectedState.iconClass, "Checking expected icon CSS class");
     is(promptState.textValue, expectedState.textValue, "Checking textbox value");
--- a/toolkit/components/prompts/test/test_bug619644.html
+++ b/toolkit/components/prompts/test/test_bug619644.html
@@ -3,57 +3,74 @@
 <!--
 https://bugzilla.mozilla.org/show_bug.cgi?id=619644
 -->
 <head>
   <title>Test for Bug 619644</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>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=619644">Mozilla Bug 619644</a>
 <pre id="test">
 <script class="testbody" type="text/javascript">
-function hasTabModalPrompts() {
-  var prefName = "prompts.tab_modal.enabled";
-  Services = SpecialPowers.Services;
-  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
-         Services.prefs.getBoolPref(prefName);
-}
-
-if (!hasTabModalPrompts()) {
-  todo(false, "Test disabled when tab modal prompts are not enabled.");
-} 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;
+if (!isTabModal) {
+  todo(false, "Test disabled when tab modal prompts are not enabled.");
+} else {
+  inittest();
+}
+
+var promptDone;
 
-function runtest(e)
-{
+function inittest() {
+  window.addEventListener("message", runtest, false);
+  window.open("bug619644_inner.html", "619644");
+
+  SimpleTest.waitForExplicitFinish();
+}
+
+function runtest(e) {
   window.removeEventListener("message", runtest, false);
   window.addEventListener("message", checktest, false);
 
-  let url = SimpleTest.getTestFileURL("chromeScript.js");
-  gChromeMessageManager = SpecialPowers.loadChromeScript(url);
-  gChromeMessageManager.sendAsyncMessage("cancelPrompt");
+  state = {
+      msg         : "Message",
+      iconClass   : "question-icon",
+      titleHidden : true,
+      textHidden  : true,
+      passHidden  : true,
+      checkHidden : true,
+      textValue   : "",
+      passValue   : "",
+      checkMsg    : "",
+      checked     : false,
+      focused     : "button0",
+      defButton   : "button0",
+  };
+  action = {
+      buttonClick: "ESC",
+  };
+
+  promptDone = handlePrompt(action);
 }
 
 function checktest(e) {
   is(e.data, expectedFinalDoc, "ESC press should not abort document load");
   e.source.close();
-  gChromeMessageManager.destroy();
-  SimpleTest.finish();
+  promptDone.then(endtest);
 }
 
-window.addEventListener("message", runtest, false);
-window.open("bug619644_inner.html", "619644");
+function endtest() {
+  info("Ending test");
+  SimpleTest.finish();
 }
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_bug620145.html
+++ b/toolkit/components/prompts/test/test_bug620145.html
@@ -1,90 +1,88 @@
 <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/SpawnTask.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()">
+<body>
 <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()">
   This is a short piece of text used for testing that mouse selecting is
   stopped when an alert appears.
 </div>
 <div id="text2" style="max-width: 100px">
   This is another short piece of text used for testing that mouse selecting is
   stopped when an alert appears.
 </div>
 <button id="button" onmouseup="openAlert()">Button</button>
 
 <script class="testbody" type="text/javascript">
-SimpleTest.waitForExplicitFinish();
-
 var selectionTest = false;
-var testNum = 0;
-
-function hasTabModalPrompts() {
-  var prefName = "prompts.tab_modal.enabled";
-  var Services = SpecialPowers.Cu
-                              .import("resource://gre/modules/Services.jsm")
-                              .Services;
-  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
-         Services.prefs.getBoolPref(prefName);
-}
+var state, action;
 
 function openAlert() {
-  ok(true, "opening alert...");
+  info("opening alert...");
   alert("hello!");
-  ok(true, "...alert done.");
+  info("...alert done.");
 }
 
-function runtest()
-{
+add_task(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.");
-
+  info("isTabModal? " + isTabModal);
   selectionTest = isTabModal;
 
-  let url = SimpleTest.getTestFileURL("chromeScript.js");
-  let chrome = SpecialPowers.loadChromeScript(url);
-  chrome.sendAsyncMessage("cancelPrompt");
+  state = {
+    msg         : "hello!",
+    iconClass   : "alert-icon",
+    titleHidden : true,
+    textHidden  : true,
+    passHidden  : true,
+    checkHidden : true,
+    textValue   : "",
+    passValue   : "",
+    checkMsg    : "",
+    checked     : false,
+    focused     : "button0",
+    defButton   : "button0",
+  };
+  action = {
+    buttonClick: "ok",
+  };
+
+  promptDone = handlePrompt(action);
 
   var button = $("button");
   dispatchMouseEvent(button, "mousedown");
   dispatchMouseEvent(button, "mouseup");
-
   // alert appears at this point, to be closed by the chrome script.
 
+  yield promptDone;
   checkSelection();
 
-  chrome.sendAsyncMessage("cancelPrompt");
+  // using same state and action.
+  promptDone = handlePrompt(action);
 
   var text = $("text");
   dispatchMouseEvent(text, "mousedown");
   dispatchMouseEvent(text, "mouseup");
-
   // alert appears at this point, to be closed by the chrome script.
 
+  yield promptDone;
   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);
--- a/toolkit/components/prompts/test/test_bug625187.html
+++ b/toolkit/components/prompts/test/test_bug625187.html
@@ -1,101 +1,104 @@
 <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/SpawnTask.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>
    -->
 </head>
-<body onload="runtest()">
+<body>
 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=625187">Mozilla Bug 625187</a>
 
 <p><button onclick="alert('hello world')">Button</button></p>
 
 <iframe id="iframe_diff_origin" src="http://example.com/tests/toolkit/components/prompts/test/bug625187_iframe.html"></iframe>
 
 <iframe id="iframe_same_origin" src="bug625187_iframe.html"></iframe>
 
 <pre id="test"></pre>
 
 <script class="testbody" type="text/javascript">
-SimpleTest.waitForExplicitFinish();
-
-var testNum = 0;
-var dialogNum = 0;
-
-function hasTabModalPrompts() {
-  var prefName = "prompts.tab_modal.enabled";
-  var Services = SpecialPowers.Cu.import("resource://gre/modules/Services.jsm").Services;
-  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
-         Services.prefs.getBoolPref(prefName);
-}
-
-function runtest()
+add_task(function* runTest()
 {
-  isTabModal = hasTabModalPrompts();
-
   // 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;
   }
 
-  let url = SimpleTest.getTestFileURL("chromeScript.js");
-  let chrome = SpecialPowers.loadChromeScript(url);
+  state = {
+    msg         : "hello world",
+    iconClass   : "alert-icon",
+    titleHidden : true,
+    textHidden  : true,
+    passHidden  : true,
+    checkHidden : true,
+    textValue   : "",
+    passValue   : "",
+    checkMsg    : "",
+    checked     : false,
+    focused     : "button0",
+    defButton   : "button0",
+  };
+  action = {
+    buttonClick: "ok",
+  };
 
-  chrome.addMessageListener("promptCanceled", msg => {
-    checkSelection(msg.ui);
-  });
-
-  chrome.sendAsyncMessage("cancelPrompt");
+  promptDone = handlePrompt(action);
 
   var button = document.querySelector("button");
   dispatchMouseEvent(button, "click");
 
-  chrome.sendAsyncMessage("cancelPrompt");
+  yield promptDone;
+
+
+  // mostly reusing same state/action
+  state.titleHidden = false;
+  state.msg = "hello world 2";
+  promptDone = handlePrompt(action);
 
   var iframe = document.getElementById("iframe_diff_origin");
   button = SpecialPowers.wrap(iframe.contentWindow).document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
-  chrome.sendAsyncMessage("cancelPrompt");
+  yield promptDone;
+
+
+  // mostly reusing same state/action
+  state.titleHidden = true;
+  state.msg = "hello world 2";
+  promptDone = handlePrompt(action);
 
   iframe = document.getElementById("iframe_same_origin");
   button = iframe.contentWindow.document.getElementById("btn1");
   dispatchMouseEvent(button, "click");
 
-  chrome.sendAsyncMessage("cancelPrompt");
+  yield promptDone;
+
+
+  // mostly reusing same state/action
+  state.msg = "hello world 3";
+  promptDone = handlePrompt(action);
 
   button = iframe.contentWindow.document.getElementById("btn2");
   dispatchMouseEvent(button, "click");
 
-  chrome.destroy();
-  SimpleTest.finish();
-}
-
-function checkSelection(ui)
-{
-  dialogNum++;
-  if (dialogNum == 1 || dialogNum == 3 || dialogNum == 4)
-    ok(ui.infoTitle.hidden,
-       "dialog #" + dialogNum + ": the tabprompt infoTitle element is hidden");
-  else if (dialogNum == 2)
-    ok(!ui.infoTitle.hidden,
-       "dialog #" + dialogNum + ": the tabprompt infoTitle element is not hidden");
-}
+  yield promptDone;
+});
 
 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);
   var utils = SpecialPowers.getDOMWindowUtils(win);
--- a/toolkit/components/prompts/test/test_dom_prompts.html
+++ b/toolkit/components/prompts/test/test_dom_prompts.html
@@ -1,70 +1,208 @@
 <html>
 <head>
   <title>Test for DOM prompts</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/SpawnTask.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()">
+<body>
 <pre id="test">
 </pre>
 
 <script class="testbody" type="text/javascript">
-SimpleTest.waitForExplicitFinish();
+var rv;
+var state, action;
 
-var selectionTest = false;
-var testNum = 0;
+add_task(function* test_alert_ok() {
+    info("Starting test: Alert");
+    state = {
+        msg         : "This is the alert text.",
+        iconClass   : "alert-icon",
+        titleHidden : true,
+        textHidden  : true,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "button0",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
+
+    promptDone = handlePrompt(action);
+
+    alert("This is the alert text.");
+
+    yield promptDone;
+});
 
-function hasTabModalPrompts() {
-  var prefName = "prompts.tab_modal.enabled";
-  var Services = SpecialPowers.Cu
-                              .import("resource://gre/modules/Services.jsm")
-                              .Services;
-  return Services.prefs.getPrefType(prefName) == Services.prefs.PREF_BOOL &&
-         Services.prefs.getBoolPref(prefName);
-}
+// bug 861605 made the arguments to alert/confirm optional (prompt already was).
+add_task(function* test_alert_noargs() {
+    info("Starting test: Alert with no args");
+    state = {
+        msg         : "",
+        iconClass   : "alert-icon",
+        titleHidden : true,
+        textHidden  : true,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "button0",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
+
+    promptDone = handlePrompt(action);
+
+    try {
+        alert();
+        ok(true, "alert() without arguments should not throw!");
+    } catch(e) {
+        ok(false, "alert() without arguments should not throw!");
+    }
 
-function runtest()
-{
-  isTabModal = hasTabModalPrompts();
-  if (!isTabModal) {
-    todo(false, "Test is run with tab modal prompts disabled.");
-    SimpleTest.finish();
-    return;
-  }
+    yield promptDone;
+});
+
 
-  ok(true, "Test is run with tab modal prompts enabled.");
+add_task(function* test_confirm_ok() {
+    info("Starting test: Confirm");
+    state = {
+        msg         : "This is the confirm text.",
+        iconClass   : "question-icon",
+        titleHidden : true,
+        textHidden  : true,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "button0",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
+
+    promptDone = handlePrompt(action);
+
+    rv = confirm("This is the confirm text.");
+    is(rv, true, "check prompt return value");
+
+    yield promptDone;
+});
 
-  let url = SimpleTest.getTestFileURL("chromeScript.js");
-  let chrome = SpecialPowers.loadChromeScript(url);
-  chrome.sendAsyncMessage("cancelPrompt");
+// bug 861605 made the arguments to alert/confirm optional (prompt already was).
+add_task(function* test_confirm_noargs() {
+    info("Starting test: Confirm with no args");
+    state = {
+        msg         : "",
+        iconClass   : "question-icon",
+        titleHidden : true,
+        textHidden  : true,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "button0",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
 
-  try {
-    alert();
-    ok(true, "alert() without arguments should not throw!");
-  } catch(e) {
-    ok(false, "alert() without arguments should not throw!");
-  }
+    promptDone = handlePrompt(action);
 
-  chrome.sendAsyncMessage("cancelPrompt");
+    try {
+        rv = confirm();
+        ok(true, "confirm() without arguments should not throw!");
+    } catch(e) {
+        ok(false, "confirm() without arguments should not throw!");
+    }
+    is(rv, true, "check prompt return value");
+
+    yield promptDone;
+});
+
 
-  try {
-    confirm();
-    ok(true, "confirm() without arguments should not throw!");
-  } catch(e) {
-    ok(false, "confirm() without arguments should not throw!");
-  }
+add_task(function* test_prompt_ok() {
+    info("Starting test: Prompt");
+    state = {
+        msg         : "This is the Prompt text.",
+        iconClass   : "question-icon",
+        titleHidden : true,
+        textHidden  : false,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "textField",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
+
+    promptDone = handlePrompt(action);
+
+    rv = prompt("This is the Prompt text.");
+    is(rv, "", "check prompt return value");
+
+    yield promptDone;
+});
 
-  chrome.destroy();
-  SimpleTest.finish();
-}
+// bug 861605 made the arguments to alert/confirm optional (prompt already was).
+add_task(function* test_prompt_noargs() {
+    info("Starting test: Prompt with no args");
+    state = {
+        msg         : "",
+        iconClass   : "question-icon",
+        titleHidden : true,
+        textHidden  : false,
+        passHidden  : true,
+        checkHidden : true,
+        textValue   : "",
+        passValue   : "",
+        checkMsg    : "",
+        checked     : false,
+        focused     : "textField",
+        defButton   : "button0",
+    };
+    action = {
+        buttonClick: "ok",
+    };
 
-function handleDialog(ui, testNum)
-{
-  synthesizeMouse(ui.button0, 5, 5, { }, SpecialPowers.unwrap(ui.button0.ownerDocument.defaultView));
-}
+    promptDone = handlePrompt(action);
+
+    try {
+        rv = prompt();
+        ok(true, "prompt() without arguments should not throw!");
+    } catch(e) {
+        ok(false, "prompt() without arguments should not throw!");
+    }
+    is(rv, "", "check prompt return value");
+
+    yield promptDone;
+});
+
 </script>
 
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_modal_prompts.html
+++ b/toolkit/components/prompts/test/test_modal_prompts.html
@@ -44,16 +44,17 @@ function* runTests() {
     let isOK, clickedButton;
 
     // =====
     info("Starting test: Alert");
     state = {
         msg   : "This is the alert text.",
         title : "TestTitle",
         iconClass   : "alert-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -73,16 +74,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: AlertCheck (null checkbox label, so it's hidden)");
     state = {
         msg   : "This is the alertCheck text.",
         title : "TestTitle",
         iconClass   : "alert-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -102,16 +104,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: AlertCheck");
     state = {
         msg   : "This is the alertCheck text.",
         title : "TestTitle",
         iconClass   : "alert-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button0",
@@ -134,16 +137,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Confirm (ok)");
     state = {
         msg   : "This is the confirm text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -164,16 +168,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Confirm (cancel)");
     state = {
         msg   : "This is the confirm text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -194,16 +199,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmCheck (ok, null checkbox label)");
     state = {
         msg   : "This is the confirmCheck text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -224,16 +230,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmCheck (cancel, null checkbox label)");
     state = {
         msg   : "This is the confirmCheck text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -254,16 +261,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmCheck (ok)");
     state = {
         msg   : "This is the confirmCheck text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button0",
@@ -287,16 +295,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmCheck (cancel)");
     state = {
         msg   : "This is the confirmCheck text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button0",
@@ -320,16 +329,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (ok, no default text)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "textField",
@@ -353,16 +363,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (ok, default text)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : true,
         textValue   : "kittens",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "textField",
@@ -385,16 +396,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (cancel, default text)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : true,
         textValue   : "puppies",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "textField",
@@ -417,16 +429,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (cancel, default text modified)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : true,
         textValue   : "puppies",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "textField",
@@ -450,16 +463,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (ok, with checkbox)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : false,
         textValue   : "tribbles",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -485,16 +499,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: Prompt (cancel, with checkbox)");
     state = {
         msg   : "This is the prompt text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : true,
         checkHidden : false,
         textValue   : "tribbles",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -521,16 +536,17 @@ function* runTests() {
 
     // =====
     // Just two tests for this, since password manager already tests this extensively.
     info("Starting test: PromptUsernameAndPassword (ok)");
     state = {
         msg   : "This is the pUAP text.",
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : false,
         checkHidden : false,
         textValue   : "usr",
         passValue   : "ssh",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -560,16 +576,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: PromptUsernameAndPassword (cancel)");
     state = {
         msg   : "This is the pUAP text.",
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : false,
         checkHidden : false,
         textValue   : "usr",
         passValue   : "ssh",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -599,16 +616,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: PromptPassword (ok)");
     state = {
         msg   : "This is the promptPassword text.",
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : false,
         checkHidden : false,
         textValue   : "",
         passValue   : "ssh",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "passField",
@@ -635,16 +653,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: PromptPassword (cancel)");
     state = {
         msg   : "This is the promptPassword text.",
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : false,
         checkHidden : false,
         textValue   : "",
         passValue   : "ssh",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "passField",
@@ -671,16 +690,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmEx (ok/cancel, ok)");
     state = {
         msg   : "This is the confirmEx text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -704,16 +724,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmEx (yes/no, cancel)");
     state = {
         msg   : "This is the confirmEx text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -737,16 +758,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmEx (buttons from args, checkbox, ok)");
     state = {
         msg   : "This is the confirmEx text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button0",
@@ -778,16 +800,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmEx (buttons from args, checkbox, cancel)");
     state = {
         msg   : "This is the confirmEx text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button1", // Default changed!
@@ -820,16 +843,17 @@ function* runTests() {
     yield promptDone;
 
     // =====
     info("Starting test: ConfirmEx (buttons from args, checkbox, button3)");
     state = {
         msg   : "This is the confirmEx text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "button2", // Default changed!
@@ -863,16 +887,17 @@ function* runTests() {
 
     // =====
     // (skipped for E10S and tabmodal tests: window is required)
     info("Starting test: Alert, no window");
     state = {
         msg   : "This is the alert text.",
         title : "TestTitle",
         iconClass   : "alert-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : "button0",
@@ -895,16 +920,17 @@ function* runTests() {
 
     // =====
     // (skipped for tabmodal tests: delay not supported)
     info("Starting test: ConfirmEx (delay, ok)");
     state = {
         msg   : "This is the confirmEx delay text.",
         title : "TestTitle",
         iconClass   : "question-icon",
+        titleHidden : true,
         textHidden  : true,
         passHidden  : true,
         checkHidden : true,
         textValue   : "",
         passValue   : "",
         checkMsg    : "",
         checked     : false,
         focused     : null, // nothing focused until after delay fires
@@ -959,16 +985,17 @@ function* runTests() {
 
     // =====
     // (promptAuth is only accessible from the prompt service)
     info("Starting test: promptAuth with empty realm");
     state = {
         msg : 'Enter username and password for http://example.com',
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : false,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -999,16 +1026,17 @@ function* runTests() {
     info("Starting test: promptAuth with long realm");
     state = {
         msg : 'A username and password are being requested by http://example.com. The site '  +
               'says: "abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi ' +
               'abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi abcdefghi '        +
               'abcdefghi \u2026"',
         title : "TestTitle",
         iconClass   : "authentication-icon question-icon",
+        titleHidden : true,
         textHidden  : false,
         passHidden  : false,
         checkHidden : false,
         textValue   : "",
         passValue   : "",
         checkMsg    : "Check me out!",
         checked     : false,
         focused     : "textField",
@@ -1035,45 +1063,40 @@ function* runTests() {
         is(authinfo.username, "username", "checking filled username");
         is(authinfo.password, "password", "checking filled password");
         is(checkVal.value, true, "expected checkbox setting");
 
         yield promptDone;
     }
 }
 
-let gChromeScript;
 let state, action;
+let usePromptService;
 
 /*
  * Run the body of the 3 times:
  * - 1st pass: with window-modal prompts, using nsIPromptService
  * - 2nd pass: still window-modal, using nsIPrompt directly (via nsIPromptFactory)
  * - 3rd pass: with tab-modal prompts. Can't opt into these via * nsIPromptService.
  */
 
 add_task(function* runPromptTests() {
   info("Process type: " + SpecialPowers.Services.appinfo.processType);
 
-  let url = SimpleTest.getTestFileURL("chromeScript.js");
-  gChromeScript = SpecialPowers.loadChromeScript(url);
-
   isTabModal = false; usePromptService = true;
   info("Running tests with: isTabModal=" + isTabModal + ", usePromptService=" + usePromptService);
   yield* runTests();
 
   isTabModal = false; usePromptService = false;
   info("Running tests with: isTabModal=" + isTabModal + ", usePromptService=" + usePromptService);
   yield* runTests();
 
   if (SpecialPowers.getBoolPref("prompts.tab_modal.enabled")) {
       isTabModal = true; usePromptService = false;
       info("Running tests with: isTabModal=" + isTabModal + ", usePromptService=" + usePromptService);
       yield* runTests();
   }
-
-  gChromeScript.destroy();
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/components/prompts/test/test_modal_select.html
+++ b/toolkit/components/prompts/test/test_modal_select.html
@@ -36,31 +36,29 @@ function checkPromptState(promptState, e
 
     for (let i = 0; i < promptState.items; i++) {
         is(promptState.items[i], expectedState.items[i], "Checking list item #" + i);
     }
 }
 
 let selectVal = {};
 let isOK;
-let gChromeScript, state, action;
+let state, action;
 
 function handlePrompt() {
   return new Promise(resolve => {
     gChromeScript.addMessageListener("promptHandled", function handled(msg) {
       gChromeScript.removeMessageListener("promptHandled", handled);
       checkPromptState(msg.promptState, state);
       resolve(true);
     });
     gChromeScript.sendAsyncMessage("handlePrompt", { action: action, isSelect: true});
   });
 }
 
-let url = SimpleTest.getTestFileURL("chromeScript.js");
-gChromeScript = SpecialPowers.loadChromeScript(url);
 
 // =====
 add_task(function* test_select_empty_list() {
     info("Starting test: Select (0 items, ok)");
     state = {
         msg   : "This is the select text.",
         title : "TestTitle",
         items : [],
@@ -137,17 +135,12 @@ add_task(function* test_cancel_prompt() 
     selectVal.value = null; // outparam, just making sure.
     isOK = prompter.select(window, "TestTitle", "This is the select text.", items.length, items, selectVal);
     is(isOK, false, "checked expected retval");
     is(selectVal.value, 0, "checking selected index");
 
     yield promptDone;
 });
 
-// =====
-add_task(function* cleanup() {
-    gChromeScript.destroy();
-});
-
 </script>
 </pre>
 </body>
 </html>