Bug 1540154 - Allow autocomplete=(email|tel|tel-national) to be username fields. r=sfoster a=pascalc
authorMatthew Noorenberghe <mozilla@noorenberghe.ca>
Wed, 03 Apr 2019 15:46:57 +0000
changeset 525974 2c01eafb7bb89195e76f6ea8daf817496b27ec44
parent 525973 7a7eda97a8f280c0cfec5a2968d6d81e2b87999c
child 525975 e0f62b77623697545dd2eb5c7e061a65a723f68e
push id2032
push userffxbld-merge
push dateMon, 13 May 2019 09:36:57 +0000
treeherdermozilla-release@455c1065dcbe [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerssfoster, pascalc
bugs1540154
milestone67.0
Bug 1540154 - Allow autocomplete=(email|tel|tel-national) to be username fields. r=sfoster a=pascalc Some sites use `email`, `tel` and `tel-national` values for @autocomplete even when they are used as the username and 'username' would be more appropriate. We already allowed type=email / type=tel so allowing the autocomplete equivalents is reasonable. Differential Revision: https://phabricator.services.mozilla.com/D25883
toolkit/components/passwordmgr/LoginHelper.jsm
toolkit/components/passwordmgr/test/mochitest/test_autofill_autocomplete_types.html
toolkit/components/passwordmgr/test/unit/test_isUsernameFieldType.js
--- a/toolkit/components/passwordmgr/LoginHelper.jsm
+++ b/toolkit/components/passwordmgr/LoginHelper.jsm
@@ -647,16 +647,20 @@ var LoginHelper = {
           fieldType == "url" ||
           fieldType == "tel" ||
           fieldType == "number")) {
       return false;
     }
 
     let acFieldName = element.getAutocompleteInfo().fieldName;
     if (!(acFieldName == "username" ||
+          // Bug 1540154: Some sites use tel/email on their username fields.
+          acFieldName == "email" ||
+          acFieldName == "tel" ||
+          acFieldName == "tel-national" ||
           acFieldName == "off" ||
           acFieldName == "on" ||
           acFieldName == "")) {
       return false;
     }
     return true;
   },
 
--- a/toolkit/components/passwordmgr/test/mochitest/test_autofill_autocomplete_types.html
+++ b/toolkit/components/passwordmgr/test/mochitest/test_autofill_autocomplete_types.html
@@ -59,16 +59,39 @@ runInParent(function setup() {
     <input  type="text" name="uname">
     <input  type="text" autocomplete="nosuchtype" name="acfield">
     <input  type="password" name="pword">
     <button type="submit">Submit</button>
   </form>
 
   <form id="form5" action="https://autocomplete">
     <input  type="text" name="uname">
+    <input  type="text" autocomplete="email" name="acfield">
+    <input  type="password" name="pword">
+    <button type="submit">Submit</button>
+  </form>
+
+  <form id="form6" action="https://autocomplete">
+    <input  type="text" name="uname">
+    <input  type="text" autocomplete="tel" name="acfield">
+    <input  type="password" name="pword">
+    <button type="submit">Submit</button>
+  </form>
+
+  <form id="form7" action="https://autocomplete">
+    <input  type="text" name="uname">
+    <input  type="text" autocomplete="tel-national" name="acfield">
+    <input  type="password" name="pword">
+    <button type="submit">Submit</button>
+  </form>
+
+  <!-- Begin forms where the first field is skipped for the username -->
+
+  <form id="form101" action="https://autocomplete">
+    <input  type="text" name="uname">
     <input  type="text" autocomplete="cc-number" name="acfield">
     <input  type="password" name="pword">
     <button type="submit">Submit</button>
   </form>
 
 </div>
 <pre id="test">
 <script class="testbody" type="text/javascript">
@@ -83,15 +106,18 @@ add_task(async function setup() {
 
 /* Tests for autofill of single-user forms with various autocomplete types */
 add_task(async function test_autofill_autocomplete_types() {
   checkForm(0, null, "testuser@example.com", "testpass1");
   checkForm(1, null, "testuser@example.com", "testpass1");
   checkForm(2, null, "testuser@example.com", "testpass1");
   checkForm(3, null, "testuser@example.com", "testpass1");
   checkForm(4, null, "testuser@example.com", "testpass1");
-  checkForm(5, "testuser@example.com", null, "testpass1");
+  checkForm(5, null, "testuser@example.com", "testpass1");
+  checkForm(6, null, "testuser@example.com", "testpass1");
+  checkForm(7, null, "testuser@example.com", "testpass1");
+  checkForm(101, "testuser@example.com", null, "testpass1");
 });
 
 </script>
 </pre>
 </body>
 </html>
--- a/toolkit/components/passwordmgr/test/unit/test_isUsernameFieldType.js
+++ b/toolkit/components/passwordmgr/test/unit/test_isUsernameFieldType.js
@@ -45,25 +45,25 @@ const autocompleteTypes = {
   "language": false,
   "bday": false,
   "bday-day": false,
   "bday-month": false,
   "bday-year": false,
   "sex": false,
   "url": false,
   "photo": false,
-  "tel": false,
+  "tel": true,
   "tel-country-code": false,
-  "tel-national": false,
+  "tel-national": true,
   "tel-area-code": false,
   "tel-local": false,
   "tel-local-prefix": false,
   "tel-local-suffix": false,
   "tel-extension": false,
-  "email": false,
+  "email": true,
   "impp": false,
 };
 
 const TESTCASES = [
   {
     description: "type=text",
     document: `<input type="text">`,
     expected: true,