Bug 1548381 - Simplify test_autocomplete_new_password and use more common patterns. r=sfoster
☠☠ backed out by 2690e619a493 ☠ ☠
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Mon, 20 May 2019 19:56:20 +0000
changeset 474625 738ce5e88e05ae37464b0e94889a5156c5497435
parent 474624 38e35b6d8d80300cb306a782d1167ec5343acd36
child 474626 0e7d8f96bf123f5d0f491fe7780223bde509e841
push id36042
push userdvarga@mozilla.com
push dateTue, 21 May 2019 04:19:40 +0000
treeherdermozilla-central@ca560ff55451 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster
bugs1548381
milestone69.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 1548381 - Simplify test_autocomplete_new_password and use more common patterns. r=sfoster Differential Revision: https://phabricator.services.mozilla.com/D31575
toolkit/components/passwordmgr/test/mochitest/mochitest.ini
toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js
toolkit/components/passwordmgr/test/mochitest/test_autocomplete_new_password.html
--- a/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
+++ b/toolkit/components/passwordmgr/test/mochitest/mochitest.ini
@@ -27,16 +27,19 @@ skip-if = toolkit == 'android' && !is_fe
 [test_autocomplete_highlight.html]
 scheme = https
 skip-if = toolkit == 'android' # autocomplete
 [test_autocomplete_highlight_non_login.html]
 scheme = https
 skip-if = toolkit == 'android' # autocomplete
 [test_autocomplete_https_upgrade.html]
 skip-if = toolkit == 'android' # autocomplete
+[test_autocomplete_new_password.html]
+scheme = https
+skip-if = toolkit == 'android' # autocomplete
 [test_autocomplete_password_open.html]
 scheme = https
 skip-if = toolkit == 'android' # autocomplete
 [test_autocomplete_sandboxed.html]
 scheme = https
 skip-if = toolkit == 'android' # autocomplete
 [test_autofill_autocomplete_types.html]
 scheme = https
@@ -106,19 +109,16 @@ scheme = https
 skip-if = os != 'mac' # Tests desktop prompts and bug 1333264
 support-files =
   chrome_timeout.js
   subtst_master_pass.html
 [test_maxlength.html]
 [test_munged_username.html]
 scheme = https
 skip-if = toolkit == 'android' # bug 1527403
-[test_autocomplete_new_password.html]
-scheme = https
-skip-if = toolkit == 'android' # autocomplete
 [test_one_doorhanger_per_un_pw.html]
 scheme = https
 skip-if = toolkit == 'android' # bug 1535505
 [test_onsubmit_value_change.html]
 [test_passwords_in_type_password.html]
 [test_prompt.html]
 skip-if = os == "linux" || toolkit == 'android' # Tests desktop prompts
 [test_prompt_async.html]
--- a/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js
+++ b/toolkit/components/passwordmgr/test/mochitest/pwmgr_common.js
@@ -62,16 +62,27 @@ function checkAutoCompleteResults(actual
     return;
   }
 
   // Check the rest of the autocomplete item values.
   checkArrayValues(actualValues.slice(0, -1), expectedValues, msg);
 }
 
 /**
+ * Check for expected username/password in form.
+ * @see `checkForm` below for a similar function.
+ */
+function checkLoginForm(usernameField, expectedUsername, passwordField, expectedPassword) {
+  let formID = usernameField.parentNode.id;
+  is(usernameField.value, expectedUsername, "Checking " + formID + " username is: " + expectedUsername);
+  is(passwordField.value, expectedPassword, "Checking " + formID + " password is: " + expectedPassword);
+}
+
+
+/**
  * Check a form for expected values. If an argument is null, a field's
  * expected value will be the default value.
  *
  * <form id="form#">
  * checkForm(#, "foo");
  */
 function checkForm(formNum, val1, val2, val3) {
   var e, form = document.getElementById("form" + formNum);
@@ -204,17 +215,17 @@ function isLoggedIn() {
 function logoutMasterPassword() {
   runInParent(function parent_logoutMasterPassword() {
     var sdr = Cc["@mozilla.org/security/sdr;1"].getService(Ci.nsISecretDecoderRing);
     sdr.logoutAndTeardown();
   });
 }
 
 /**
- * Resolves when a specified number of forms have been processed.
+ * Resolves when a specified number of forms have been processed for (potential) filling.
  */
 function promiseFormsProcessed(expectedCount = 1) {
   var processedCount = 0;
   return new Promise((resolve, reject) => {
     function onProcessedForm(subject, topic, data) {
       processedCount++;
       if (processedCount == expectedCount) {
         SpecialPowers.removeObserver(onProcessedForm, "passwordmgr-processed-form");
@@ -390,14 +401,8 @@ this.LoginManager = new Proxy({}, {
         args: cloneableArgs,
         loginInfoIndices,
         methodName: prop,
       })[0][0];
     };
   },
 });
 
-// Check for expected username/password in form.
-function checkLoginForm(usernameField, expectedUsername, passwordField, expectedPassword) {
-  let formID = usernameField.parentNode.id;
-  is(usernameField.value, expectedUsername, "Checking " + formID + " username is: " + expectedUsername);
-  is(passwordField.value, expectedPassword, "Checking " + formID + " password is: " + expectedPassword);
-}
--- a/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_new_password.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autocomplete_new_password.html
@@ -1,18 +1,18 @@
 <!DOCTYPE HTML>
 <html>
 <head>
   <meta charset="utf-8">
   <title>Test autofill with autocomplete=new-password fields</title>
   <script src="/tests/SimpleTest/SimpleTest.js"></script>
   <script src="/tests/SimpleTest/EventUtils.js"></script>
-  <script type="text/javascript" src="pwmgr_common.js"></script>
-  <script type="text/javascript" src="../../../satchel/test/satchel_common.js"></script>
-  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
+  <script src="pwmgr_common.js"></script>
+  <script src="../../../satchel/test/satchel_common.js"></script>
+  <link rel="stylesheet" href="/tests/SimpleTest/test.css" />
 </head>
 <body>
 Login Manager test: autofill with autocomplete=new-password fields
 
 <script>
 let chromeScript = runInParent(function initLogins() {
   const {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
 
@@ -46,61 +46,38 @@ let readyPromise = registerRunTests();
   </form>
 </div>
 
 <pre id="test">
 <script class="testbody" type="text/javascript">
 const {ContentTaskUtils} =
   SpecialPowers.Cu.import("resource://testing-common/ContentTaskUtils.jsm", {});
 
-async function getAutocompleteResult(input, expectedValues) {
-  input.focus();
-
+async function fillFirstAutocompleteResult(input) {
   const shownPromise = promiseACShown();
   synthesizeKey("KEY_ArrowDown");
   await shownPromise;
   synthesizeKey("KEY_ArrowDown");
   await synthesizeKey("KEY_Enter");
-
-  let didAutocomplete;
-  try {
-    await ContentTaskUtils.waitForCondition(() => {
-      for (let [selector, expectedValue] of Object.entries(expectedValues)) {
-        if (document.querySelector(selector).value !== expectedValue) {
-          return false;
-        }
-      }
-      return true;
-    });
-    didAutocomplete = true;
-  } catch (ex) {
-    info("waitForCondition exception: " + ex.message);
-    didAutocomplete = false;
-  }
-  return didAutocomplete;
 }
 
 add_task(async function setup() {
   ok(readyPromise, "check promise is available");
   await readyPromise;
 });
 
 add_task(async function test_autofillAutocompleteNewPassword() {
   // reference form was filled as expected?
   checkForm(1, "user1", "pass1");
 
   // 2nd form should not be filled
   checkForm(2, "", "");
 
-  let form = document.getElementById("form2");
-  let userInput = form.querySelector("[name='uname']");
-
-  const didAutocomplete = await getAutocompleteResult(userInput, {
-    "#form2 [name='uname']": "user1",
-    "#form2 [type='password']": "pass1",
-  });
-  ok(didAutocomplete, "Autocomplete of user and password fields should happen");
+  $_(2, "uname").focus();
+  await fillFirstAutocompleteResult();
+  await promiseFormsProcessed();
+  checkForm(2, "user1", "pass1");
 });
 
 </script>
 </pre>
 </body>
 </html>