Bug 1265194 - Move handlePrompt() and checkPromptState() to prompt_common.js, and rename a test. r=adw
☠☠ backed out by de2a25e89256 ☠ ☠
authorJustin Dolske <dolske@mozilla.com>
Sat, 16 Apr 2016 16:06:40 -0700
changeset 332486 755257b3f436d949d912aedf305af82634ccfed3
parent 332485 fb0d7b82c072b81ec2d2551dd832f48c287527f9
child 332487 b9346277145b90f9b3eaacde3ef2ba85a4b7ab3b
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 - Move handlePrompt() and checkPromptState() to prompt_common.js, and rename a test. r=adw MozReview-Commit-ID: InDUkxPQoYd
toolkit/components/prompts/test/mochitest.ini
toolkit/components/prompts/test/prompt_common.js
toolkit/components/prompts/test/test_bug861605.html
toolkit/components/prompts/test/test_dom_prompts.html
toolkit/components/prompts/test/test_modal_prompts.html
--- a/toolkit/components/prompts/test/mochitest.ini
+++ b/toolkit/components/prompts/test/mochitest.ini
@@ -5,13 +5,13 @@ support-files =
   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_dom_prompts.html]
 [test_modal_prompts.html]
 skip-if = toolkit == 'android' || (os == 'linux' && (debug || asan)) #android: TIMED_OUT (For Linux : 950636)
 [test_modal_select.html]
 skip-if = toolkit == 'android' #android: TIMED_OUT
--- a/toolkit/components/prompts/test/prompt_common.js
+++ b/toolkit/components/prompts/test/prompt_common.js
@@ -2,16 +2,19 @@ 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;
@@ -116,8 +119,65 @@ function getDialogDoc() {
           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;
+
+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");
+    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");
+    is(promptState.passValue, expectedState.passValue, "Checking passbox value");
+
+    if (expectedState.butt0Label) {
+        is(promptState.butt0Label, expectedState.butt0Label, "Checking accept-button label");
+    }
+    if (expectedState.butt1Label) {
+        is(promptState.butt1Label, expectedState.butt1Label, "Checking cancel-button label");
+    }
+    if (expectedState.butt2Label) {
+        is(promptState.butt2Label, expectedState.butt2Label, "Checking extra1-button label");
+    }
+
+    // For prompts with a time-delay button.
+    if (expectedState.butt0Disabled) {
+        is(promptState.butt0Disabled, true,  "Checking accept-button is disabled");
+        is(promptState.butt1Disabled, false, "Checking cancel-button isn't disabled");
+    }
+
+    is(promptState.defButton0, expectedState.defButton == "button0", "checking button0 default");
+    is(promptState.defButton1, expectedState.defButton == "button1", "checking button1 default");
+    is(promptState.defButton2, expectedState.defButton == "button2", "checking button2 default");
+
+    if (isLinux && (!promptState.focused || isE10S)) {
+        todo(false, "Focus seems missing or wrong on Linux"); // bug 1265077
+    } else if (isOSX && expectedState.focused && expectedState.focused.startsWith("button")) {
+        is(promptState.focused, "infoBody", "buttons don't focus on OS X, but infoBody does instead");
+    } else {
+        is(promptState.focused, expectedState.focused, "Checking focused element");
+    }
+}
rename from toolkit/components/prompts/test/test_bug861605.html
rename to toolkit/components/prompts/test/test_dom_prompts.html
--- a/toolkit/components/prompts/test/test_bug861605.html
+++ b/toolkit/components/prompts/test/test_dom_prompts.html
@@ -1,18 +1,17 @@
 <html>
 <head>
-  <title>Test for Bug 861605</title>
+  <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/EventUtils.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">
 SimpleTest.waitForExplicitFinish();
 
 var selectionTest = false;
 var testNum = 0;
--- a/toolkit/components/prompts/test/test_modal_prompts.html
+++ b/toolkit/components/prompts/test/test_modal_prompts.html
@@ -13,76 +13,17 @@ Prompter tests: modal prompts
 
 <div id="content" style="display: none">
   <iframe id="iframe"></iframe>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript;version=1.8">
 
-var isOSX = ("nsILocalFileMac" in SpecialPowers.Ci);
-var isLinux = ("@mozilla.org/gnome-gconf-service;1" in SpecialPowers.Cc);
-var isE10S = SpecialPowers.Services.appinfo.processType == 2;
-
-function checkPromptState(promptState, expectedState) {
-    // XXX check title? OS X has title in content
-    is(promptState.msg,         expectedState.msg,         "Checking expected message");
-    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");
-    is(promptState.passValue, expectedState.passValue, "Checking passbox value");
-
-    if (expectedState.butt0Label) {
-        is(promptState.butt0Label, expectedState.butt0Label, "Checking accept-button label");
-    }
-    if (expectedState.butt1Label) {
-        is(promptState.butt1Label, expectedState.butt1Label, "Checking cancel-button label");
-    }
-    if (expectedState.butt2Label) {
-        is(promptState.butt2Label, expectedState.butt2Label, "Checking extra1-button label");
-    }
-
-    // For prompts with a time-delay button.
-    if (expectedState.butt0Disabled) {
-        is(promptState.butt0Disabled, true,  "Checking accept-button is disabled");
-        is(promptState.butt1Disabled, false, "Checking cancel-button isn't disabled");
-    }
-
-    is(promptState.defButton0, expectedState.defButton == "button0", "checking button0 default");
-    is(promptState.defButton1, expectedState.defButton == "button1", "checking button1 default");
-    is(promptState.defButton2, expectedState.defButton == "button2", "checking button2 default");
-
-    if (isLinux && (!promptState.focused || isE10S)) {
-        todo(false, "Focus seems missing or wrong on Linux"); // bug 1265077
-    } else if (isOSX && expectedState.focused && expectedState.focused.startsWith("button")) {
-        is(promptState.focused, "infoBody", "buttons don't focus on OS X, but infoBody does instead");
-    } else {
-        is(promptState.focused, expectedState.focused, "Checking focused element");
-    }
-}
-
-
 function* runTests() {
-
-    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});
-      });
-    }
-
     let ioService = Cc["@mozilla.org/network/io-service;1"].
                     getService(Ci.nsIIOService);
     ok(true, "Running tests (isTabModal=" + isTabModal + ", usePromptService=" + usePromptService + ")");
 
     let prompter, promptArgs;
     if (usePromptService) {
         prompter = Cc["@mozilla.org/embedcomp/prompt-service;1"].
                    getService(Ci.nsIPromptService2);