Bug 1629143 - enable password manager on sites with <= 5 password fields;r=MattN
authorSeverin <srudie@mozilla.com>
Fri, 17 Apr 2020 19:19:57 +0000
changeset 524640 853b0e791775ce726149209092a003ed5f001b0c
parent 524639 94d6a3fe4b57da0e8cccba448f7d40aa43d9b5ae
child 524641 08be5b95d8bb2f114ccb2b6c45d92ecdf3d3c03d
push id37324
push usershindli@mozilla.com
push dateFri, 17 Apr 2020 21:46:50 +0000
treeherdermozilla-central@853b0e791775 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersMattN
bugs1629143
milestone77.0a1
first release with
nightly linux32
853b0e791775 / 77.0a1 / 20200417214650 / files
nightly linux64
853b0e791775 / 77.0a1 / 20200417214650 / files
nightly mac
853b0e791775 / 77.0a1 / 20200417214650 / files
nightly win32
853b0e791775 / 77.0a1 / 20200417214650 / files
nightly win64
853b0e791775 / 77.0a1 / 20200417214650 / files
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
releases
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1629143 - enable password manager on sites with <= 5 password fields;r=MattN Differential Revision: https://phabricator.services.mozilla.com/D71230
toolkit/components/passwordmgr/LoginManagerChild.jsm
toolkit/components/passwordmgr/test/mochitest/test_basic_form_pwonly.html
toolkit/components/passwordmgr/test/unit/test_getFormFields.js
toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js
--- a/toolkit/components/passwordmgr/LoginManagerChild.jsm
+++ b/toolkit/components/passwordmgr/LoginManagerChild.jsm
@@ -1102,17 +1102,17 @@ this.LoginManagerChild = class LoginMana
   /**
    * @param {LoginForm} form - the LoginForm to look for password fields in.
    * @param {Object} options
    * @param {bool} [options.skipEmptyFields=false] - Whether to ignore password fields with no value.
    *                                                 Used at capture time since saving empty values isn't
    *                                                 useful.
    * @param {Object} [options.fieldOverrideRecipe=null] - A relevant field override recipe to use.
    * @return {Array|null} Array of password field elements for the specified form.
-   *                      If no pw fields are found, or if more than 3 are found, then null
+   *                      If no pw fields are found, or if more than 5 are found, then null
    *                      is returned.
    */
   _getPasswordFields(
     form,
     { fieldOverrideRecipe = null, minPasswordLength = 0 } = {}
   ) {
     // Locate the password fields in the form.
     let pwFields = [];
@@ -1164,17 +1164,17 @@ this.LoginManagerChild = class LoginMana
         element,
       };
     }
 
     // If too few or too many fields, bail out.
     if (!pwFields.length) {
       log("(form ignored -- no password fields.)");
       return null;
-    } else if (pwFields.length > 3) {
+    } else if (pwFields.length > 5) {
       log(
         "(form ignored -- too many password fields. [ got ",
         pwFields.length,
         "])"
       );
       return null;
     }
 
--- a/toolkit/components/passwordmgr/test/mochitest/test_basic_form_pwonly.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_basic_form_pwonly.html
@@ -63,41 +63,55 @@ runInParent(() => {
     <input type='password' name='pname1' value=''>
     <input type='password' name='pname2' value=''>
     <input type='password' name='pname3' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
-<!-- 4 password fields, should be ignored. -->
+<!-- simple form: no username field, 5 password fields -->
 <form id='form4' action='http://mochi.test:1111/formtest.js'> 4
     <input type='password' name='pname1' value=''>
     <input type='password' name='pname2' value=''>
     <input type='password' name='pname3' value=''>
     <input type='password' name='pname4' value=''>
+    <input type='password' name='pname5' value=''>
+
+    <button type='submit'>Submit</button>
+    <button type='reset'> Reset </button>
+</form>
+
+<!-- 6 password fields, should be ignored. -->
+<form id='form5' action='http://mochi.test:1111/formtest.js'> 4
+    <input type='password' name='pname1' value=''>
+    <input type='password' name='pname2' value=''>
+    <input type='password' name='pname3' value=''>
+    <input type='password' name='pname4' value=''>
+    <input type='password' name='pname5' value=''>
+    <input type='password' name='pname6' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 
 
 <!-- 1 username field -->
-<form id='form5' action='http://mochi.test:1111/formtest.js'> 5
+<form id='form6' action='http://mochi.test:1111/formtest.js'> 5
     <input type='text'     name='uname' value=''>
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 
 <!-- 1 username field, with a value set -->
-<form id='form6' action='http://mochi.test:1111/formtest.js'> 6
+<form id='form7' action='http://mochi.test:1111/formtest.js'> 6
     <input type='text'     name='uname' value='someuser'>
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 
@@ -105,73 +119,73 @@ runInParent(() => {
 <!--
 (The following forms have 2 potentially-matching logins, on is
 password-only, the other is username+password)
 -->
 
 
 
 <!-- 1 username field, with value set. Fill in the matching U+P login -->
-<form id='form7' action='formtest.js'> 7
+<form id='form8' action='formtest.js'> 7
     <input type='text'     name='uname' value='testuser'>
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 <!-- 1 username field, with value set. Don't fill in U+P login-->
-<form id='form8' action='formtest.js'> 8
+<form id='form9' action='formtest.js'> 8
     <input type='text'     name='uname' value='someuser'>
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 
 
 <!-- 1 username field, too small for U+P login -->
-<form id='form9' action='formtest.js'> 9
+<form id='form10' action='formtest.js'> 9
     <input type='text'     name='uname' value='' maxlength="4">
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 <!-- 1 username field, too small for U+P login -->
-<form id='form10' action='formtest.js'> 10
+<form id='form11' action='formtest.js'> 10
     <input type='text'     name='uname' value='' maxlength="0">
     <input type='password' name='pname' value=''>
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 <!-- 1 username field, too small for U+P login -->
-<form id='form11' action='formtest.js'> 11
+<form id='form12' action='formtest.js'> 11
     <input type='text'     name='uname' value=''>
     <input type='password' name='pname' value='' maxlength="4">
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 <!-- 1 username field, too small for either login -->
-<form id='form12' action='formtest.js'> 12
+<form id='form13' action='formtest.js'> 12
     <input type='text'     name='uname' value=''>
     <input type='password' name='pname' value='' maxlength="1">
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 <!-- 1 username field, too small for either login -->
-<form id='form13' action='formtest.js'> 13
+<form id='form14' action='formtest.js'> 13
     <input type='text'     name='uname' value=''>
     <input type='password' name='pname' value='' maxlength="0">
 
     <button type='submit'>Submit</button>
     <button type='reset'> Reset </button>
 </form>
 
 
@@ -181,29 +195,30 @@ password-only, the other is username+pas
 <pre id="test">
 <script class="testbody" type="text/javascript">
 
 /** Test for Login Manager: password-only logins **/
 function startTest() {
   checkForm(1, "1234");
   checkForm(2, "1234", "");
   checkForm(3, "1234", "", "");
-  checkUnmodifiedForm(4);
-
-  checkForm(5, "", "1234");
-  checkForm(6, "someuser", "");
+  checkForm(4, "1234");
+  checkUnmodifiedForm(5);
 
-  checkForm(7, "testuser", "testpass");
-  checkForm(8, "someuser", "");
+  checkForm(6, "", "1234");
+  checkForm(7, "someuser", "");
 
-  checkForm(9, "", "1234");
+  checkForm(8, "testuser", "testpass");
+  checkForm(9, "someuser", "");
+
   checkForm(10, "", "1234");
   checkForm(11, "", "1234");
+  checkForm(12, "", "1234");
 
-  checkUnmodifiedForm(12);
   checkUnmodifiedForm(13);
+  checkUnmodifiedForm(14);
 
   SimpleTest.finish();
 }
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/components/passwordmgr/test/unit/test_getFormFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getFormFields.js
@@ -55,21 +55,33 @@ const TESTCASES = [
     document: `<form>
       <input id="un1">
       <input id="pw1" type=password>
       </form>`,
     returnedFieldIDs: ["un1", "pw1", null],
     skipEmptyFields: undefined,
   },
   {
-    description: "4 empty password fields outside of a <form>",
+    description: "5 empty password fields outside of a <form>",
     document: `<input id="pw1" type=password>
       <input id="pw2" type=password>
       <input id="pw3" type=password>
-      <input id="pw4" type=password>`,
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>`,
+    returnedFieldIDs: [null, "pw1", null],
+    skipEmptyFields: undefined,
+  },
+  {
+    description: "6 empty password fields outside of a <form>",
+    document: `<input id="pw1" type=password>
+      <input id="pw2" type=password>
+      <input id="pw3" type=password>
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>
+      <input id="pw6" type=password>`,
     returnedFieldIDs: [null, null, null],
     skipEmptyFields: undefined,
   },
   {
     description:
       "4 password fields outside of a <form> (1 empty, 3 full) with skipEmpty",
     document: `<input id="pw1" type=password>
       <input id="pw2" type=password value="pass2">
--- a/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getPasswordFields.js
@@ -29,21 +29,33 @@ const TESTCASES = [
   },
   {
     description: "1 password field outside of a <form>",
     document: `<input id="pw1" type=password>`,
     returnedFieldIDsByFormLike: [["pw1"]],
     minPasswordLength: undefined,
   },
   {
-    description: "4 empty password fields outside of a <form>",
+    description: "5 empty password fields outside of a <form>",
     document: `<input id="pw1" type=password>
       <input id="pw2" type=password>
       <input id="pw3" type=password>
-      <input id="pw4" type=password>`,
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>`,
+    returnedFieldIDsByFormLike: [["pw1", "pw2", "pw3", "pw4", "pw5"]],
+    minPasswordLength: undefined,
+  },
+  {
+    description: "6 empty password fields outside of a <form>",
+    document: `<input id="pw1" type=password>
+      <input id="pw2" type=password>
+      <input id="pw3" type=password>
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>
+      <input id="pw6" type=password>`,
     returnedFieldIDsByFormLike: [[]],
     minPasswordLength: undefined,
   },
   {
     description:
       "4 password fields outside of a <form> (1 empty, 3 full) with minPasswordLength=2",
     document: `<input id="pw1" type=password>
       <input id="pw2" type=password value="pass2">
--- a/toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js
+++ b/toolkit/components/passwordmgr/test/unit/test_getUserNameAndPasswordFields.js
@@ -32,21 +32,32 @@ const TESTCASES = [
     description: "1 username & password field in a <form>",
     document: `<form>
       <input id="un1">
       <input id="pw1" type=password>
       </form>`,
     returnedFieldIDs: ["un1", "pw1", null],
   },
   {
-    description: "4 empty password fields outside of a <form>",
+    description: "5 empty password fields outside of a <form>",
     document: `<input id="pw1" type=password>
       <input id="pw2" type=password>
       <input id="pw3" type=password>
-      <input id="pw4" type=password>`,
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>`,
+    returnedFieldIDs: [null, "pw1", null],
+  },
+  {
+    description: "6 empty password fields outside of a <form>",
+    document: `<input id="pw1" type=password>
+      <input id="pw2" type=password>
+      <input id="pw3" type=password>
+      <input id="pw4" type=password>
+      <input id="pw5" type=password>
+      <input id="pw6" type=password>`,
     returnedFieldIDs: [null, null, null],
   },
   {
     description: "Form with 1 password field",
     document: `<form><input id="pw1" type=password></form>`,
     returnedFieldIDs: [null, "pw1", null],
   },
   {