Bug 1258607 - Make test_case_differences.html work in e10s. r=dolske
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Tue, 22 Mar 2016 18:06:51 -0400
changeset 290278 96bfe329ad1ebbf3a07395fb410083838ed1aed6
parent 290277 e769ae36cbc7175207bb865222afe4db82b316e6
child 290279 d823452bea13282527bce173c1133f2f12990d7f
push id18365
push usermozilla@noorenberghe.ca
push dateFri, 25 Mar 2016 13:23:49 +0000
treeherderfx-team@d823452bea13 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdolske
bugs1258607
milestone48.0a1
Bug 1258607 - Make test_case_differences.html work in e10s. r=dolske Switch to add_task and use satchel helpers for autocomplete. MozReview-Commit-ID: 4X864ORiYXw
toolkit/components/passwordmgr/test/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
toolkit/components/passwordmgr/test/test_case_differences.html
--- a/toolkit/components/passwordmgr/test/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest.ini
@@ -15,18 +15,16 @@ support-files =
   subtst_privbrowsing_2.html
   subtst_privbrowsing_3.html
   subtst_privbrowsing_4.html
   subtst_prompt_async.html
 
 [test_basic_form_2pw_2.html]
 [test_basic_form_autocomplete.html]
 skip-if = toolkit == 'android'
-[test_case_differences.html]
-skip-if = toolkit == 'android'
 [test_bug_627616.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_master_password.html]
 skip-if = toolkit == 'android' #TIMED_OUT
 [test_master_password_cleanup.html]
 skip-if = toolkit == 'android'
 [test_notifications_popup.html]
 skip-if = os == "linux" || toolkit == 'android' # bug 934057
--- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
@@ -1,26 +1,30 @@
 [DEFAULT]
 skip-if = buildapp == 'mulet' || buildapp == 'b2g'
 support-files =
+  ../../../satchel/test/parent_utils.js
+  ../../../satchel/test/satchel_common.js
   ../authenticate.sjs
   ../pwmgr_common.js
   auth2/authenticate.sjs
 
 [test_autofill_password-only.html]
 [test_basic_form.html]
 [test_basic_form_0pw.html]
 [test_basic_form_1pw.html]
 [test_basic_form_1pw_2.html]
 [test_basic_form_2pw_1.html]
 [test_basic_form_3pw_1.html]
 [test_basic_form_html5.html]
 [test_basic_form_pwevent.html]
 [test_basic_form_pwonly.html]
 [test_bug_776171.html]
+[test_case_differences.html]
+skip-if = toolkit == 'android' # autocomplete
 [test_form_action_1.html]
 [test_form_action_2.html]
 [test_form_action_javascript.html]
 [test_input_events.html]
 [test_input_events_for_identical_values.html]
 [test_maxlength.html]
 [test_passwords_in_type_password.html]
 [test_recipe_login_fields.html]
rename from toolkit/components/passwordmgr/test/test_case_differences.html
rename to toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
--- a/toolkit/components/passwordmgr/test/test_case_differences.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_case_differences.html
@@ -1,57 +1,51 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test autocomplete due to multiple matching logins</title>
   <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="/tests/SimpleTest/SpawnTask.js"></script>
+  <script type="text/javascript" src="satchel_common.js"></script>
   <script type="text/javascript" src="pwmgr_common.js"></script>
   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 Login Manager test: autocomplete due to multiple matching logins
 
 <script>
-commonInit();
-SimpleTest.waitForExplicitFinish();
+runChecksAfterCommonInit(false);
+
+SpecialPowers.loadChromeScript(function addLogins() {
+  const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+  Cu.import("resource://gre/modules/Services.jsm");
 
-// Get the pwmgr service
-var pwmgr = SpecialPowers.Cc["@mozilla.org/login-manager;1"]
-                         .getService(SpecialPowers.Ci.nsILoginManager);
-ok(pwmgr != null, "nsLoginManager service");
+  // Create some logins just for this form, since we'll be deleting them.
+  var nsLoginInfo = Components.Constructor("@mozilla.org/login-manager/loginInfo;1",
+                                           Ci.nsILoginInfo, "init");
 
-// Create some logins just for this form, since we'll be deleting them.
-var nsLoginInfo =
-SpecialPowers.wrap(SpecialPowers.Components).Constructor("@mozilla.org/login-manager/loginInfo;1",
-                          SpecialPowers.Ci.nsILoginInfo, "init");
-ok(nsLoginInfo != null, "nsLoginInfo constructor");
-
+  var login0 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
+                               "name", "pass", "uname", "pword");
 
-var login0 = new nsLoginInfo(
-    "http://mochi.test:8888", "http://autocomplete:8888", null,
-    "name", "pass", "uname", "pword");
+  var login1 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
+                               "Name", "Pass", "uname", "pword");
 
-var login1 = new nsLoginInfo(
-    "http://mochi.test:8888", "http://autocomplete:8888", null,
-    "Name", "Pass", "uname", "pword");
+  var login2 = new nsLoginInfo("http://mochi.test:8888", "http://autocomplete:8888", null,
+                               "USER", "PASS", "uname", "pword");
 
-var login2 = new nsLoginInfo(
-    "http://mochi.test:8888", "http://autocomplete:8888", null,
-    "USER", "PASS", "uname", "pword");
-
-try {
-    pwmgr.addLogin(login0);
-    pwmgr.addLogin(login1);
-    pwmgr.addLogin(login2);
-} catch (e) {
-    ok(false, "addLogin threw: " + e);
-}
-
+  try {
+    Services.logins.addLogin(login0);
+    Services.logins.addLogin(login1);
+    Services.logins.addLogin(login2);
+  } catch (e) {
+    assert.ok(false, "addLogin threw: " + e);
+  }
+});
 </script>
 <p id="display"></p>
 
 <!-- we presumably can't hide the content for this test. -->
 <div id="content">
 
   <!-- form1 tests multiple matching logins -->
   <form id="form1" action="http://autocomplete:8888/formtest.js" onsubmit="return false;">
@@ -60,157 +54,93 @@ try {
     <button type="submit">Submit</button>
   </form>
 
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
-/** Test for Login Manager: multiple login autocomplete. **/
-
-var tester;
+/** Test for Login Manager: autocomplete due to multiple matching logins **/
 
 var uname = $_(1, "uname");
 var pword = $_(1, "pword");
 
 // Restore the form to the default state.
 function restoreForm() {
     uname.value = "";
     pword.value = "";
     uname.focus();
 }
 
-
 // Check for expected username/password in form.
 function checkACForm(expectedUsername, expectedPassword) {
   var formID = uname.parentNode.id;
   is(uname.value, expectedUsername, "Checking " + formID + " username");
   is(pword.value, expectedPassword, "Checking " + formID + " password");
 }
 
-
-function sendFakeAutocompleteEvent(element) {
-    var acEvent = document.createEvent("HTMLEvents");
-    acEvent.initEvent("DOMAutoComplete", true, false);
-    element.dispatchEvent(acEvent);
-}
-
-function addPopupListener(eventName, func, capture) {
-  autocompletePopup.addEventListener(eventName, func, capture);
-}
-
-function removePopupListener(eventName, func, capture) {
-  autocompletePopup.removeEventListener(eventName, func, capture);
-}
-
-/*
- * Main section of test...
- *
- * This is a bit hacky, because the events are either being sent or
- * processes asynchronously, so we need to interrupt our flow with lots of
- * setTimeout() calls. The case statements are executed in order, one per
- * timeout.
- */
-function* runTest() {
-  function runNextTest() {
-    addPopupListener("popupshown", function() {
-      removePopupListener("popupshown", arguments.callee, false);
-
-      window.setTimeout(tester.next.bind(tester), 0);
-    }, false);
-  }
-
-  function waitForCompletion() {
-    var observer = SpecialPowers.wrapCallback(function(subject, topic, data) {
-      SpecialPowers.removeObserver(observer, "passwordmgr-processed-form");
-      tester.next();
-    });
-    SpecialPowers.addObserver(observer, "passwordmgr-processed-form", false);
-  }
-
+add_task(function* test_empty_first_entry() {
   /* test 1 */
   // Make sure initial form is empty.
   checkACForm("", "");
   // Trigger autocomplete popup
   restoreForm();
+  let popupState = yield getPopupState();
+  is(popupState.open, false, "Check popup is initially closed");
+  is(popupState.selectedIndex, -1, "Check no entries are selected");
+  let shownPromise = promiseACShown();
   doKey("down");
-  yield runNextTest();
+  let results = yield shownPromise;
+  checkArrayValues(results, ["name", "Name", "USER"], "initial");
 
-  /* test 2 */
   // Check first entry
+  let index0Promise = notifySelectedIndex(0);
   doKey("down");
+  yield index0Promise;
   checkACForm("", ""); // value shouldn't update
   doKey("return"); // not "enter"!
-  yield waitForCompletion();
+  yield promiseFormsProcessed();
   checkACForm("name", "pass");
-
-  // Trigger autocomplete popup
-  restoreForm();
-  doKey("down");
-  yield runNextTest();
-
-  /* test 3 */
-  // Check second entry
-  doKey("down");
-  doKey("down");
-  doKey("return"); // not "enter"!
-  yield waitForCompletion();
-  checkACForm("Name", "Pass");
+});
 
-  // Trigger autocomplete popup
+add_task(function* test_empty_second_entry() {
   restoreForm();
-  doKey("down");
-  yield runNextTest();
+  let shownPromise = promiseACShown();
+  doKey("down"); // open
+  yield shownPromise;
+  doKey("down"); // first
+  doKey("down"); // second
+  doKey("return"); // not "enter"!
+  yield promiseFormsProcessed();
+  checkACForm("Name", "Pass");
+});
 
-  /* test 4 */
-  // Check third entry
-  doKey("down");
-  doKey("down");
-  doKey("down");
+add_task(function* test_empty_third_entry() {
+  restoreForm();
+  let shownPromise = promiseACShown();
+  doKey("down"); // open
+  yield shownPromise;
+  doKey("down"); // first
+  doKey("down"); // second
+  doKey("down"); // third
   doKey("return");
-  yield waitForCompletion();
+  yield promiseFormsProcessed();
   checkACForm("USER", "PASS");
+});
 
-  // Trigger autocomplete popup
+add_task(function* test_preserve_matching_username_case() {
   restoreForm();
   uname.value = "user";
-  doKey("down");
-  yield runNextTest();
-
-  /* test 5 */
-  // Check that we don't clobber user-entered text when tabbing away
-  doKey("tab");
-  yield waitForCompletion();
-  checkACForm("user", "PASS");
-
-  // Trigger autocomplete popup
-  restoreForm();
-  SimpleTest.finish();
-}
-
-
-var autocompletePopup;
+  let shownPromise = promiseACShown();
+  doKey("down"); // open
+  yield shownPromise;
 
-function startTest() {
-    var Ci = SpecialPowers.Ci;
-    chromeWin = SpecialPowers.wrap(window)
-                    .QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIWebNavigation)
-                    .QueryInterface(Ci.nsIDocShellTreeItem)
-                    .rootTreeItem
-                    .QueryInterface(Ci.nsIInterfaceRequestor)
-                    .getInterface(Ci.nsIDOMWindow)
-                    .QueryInterface(Ci.nsIDOMChromeWindow);
-    // shouldn't reach into browser internals like this and
-    // shouldn't assume ID is consistent across products
-    autocompletePopup = chromeWin.document.getElementById("PopupAutoComplete");
-    ok(autocompletePopup, "Got autocomplete popup");
-    tester = runTest();
-    tester.next();
-}
-
-window.addEventListener("runTests", startTest);
+  // Check that we don't clobber user-entered text when tabbing away
+  // (even with no autocomplete entry selected)
+  doKey("tab");
+  yield promiseFormsProcessed();
+  checkACForm("user", "PASS");
+});
 </script>
 </pre>
 </body>
 </html>
-