Bug 1413118 - [Form Autofill] Fill "tel-national" to a recognized "tel" field even the international format passes "maxlength". r=seanlee
authorLuke Chang <lchang@mozilla.com>
Thu, 02 Nov 2017 13:17:24 +0800
changeset 443581 c760f9b3e6c9b2c8a00e95971f7df33ea4681377
parent 443580 4af5ef27d314d0deeeb87e70798b765a6acc8efb
child 443582 192367ec09cb28841dd2dc85e5ab942c6f3d07dc
push id1618
push userCallek@gmail.com
push dateThu, 11 Jan 2018 17:45:48 +0000
treeherdermozilla-release@882ca853e05a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersseanlee
bugs1413118
milestone58.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 1413118 - [Form Autofill] Fill "tel-national" to a recognized "tel" field even the international format passes "maxlength". r=seanlee MozReview-Commit-ID: KOyFeaORTWV
browser/extensions/formautofill/FormAutofillHandler.jsm
browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -334,17 +334,17 @@ FormAutofillHandler.prototype = {
       }
       return _pattern.test(str);
     };
     if (element.pattern) {
       if (testPattern(profile.tel)) {
         return;
       }
     } else if (element.maxLength) {
-      if (profile.tel.length <= element.maxLength) {
+      if (detail._reason == "autocomplete" && profile.tel.length <= element.maxLength) {
         return;
       }
     }
 
     if (detail._reason != "autocomplete") {
       // Since we only target people living in US and using en-US websites in
       // MVP, it makes more sense to fill `tel-national` instead of `tel`
       // if the field is identified by heuristics and no other clues to
--- a/browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js
+++ b/browser/extensions/formautofill/test/unit/test_getAdaptedProfiles.js
@@ -311,33 +311,54 @@ const TESTCASES = [
       "address-line3": "line3",
       "address-level1": "CA",
       "country": "US",
       "tel": "+19876543210",
       "tel-national": "9876543210",
     }],
   },
   {
-    description: "`tel` field with `maxlength` can be filled with `tel` value.",
+    description: "autocomplete=\"tel\" field with `maxlength` can be filled with `tel` value.",
+    document: `<form>
+               <input id="telephone" autocomplete="tel" maxlength="12">
+               <input id="line1" autocomplete="address-line1">
+               <input id="line2" autocomplete="address-line2">
+               </form>`,
+    profileData: [Object.assign({}, DEFAULT_ADDRESS_RECORD)],
+    expectedResult: [{
+      "guid": "123",
+      "street-address": "2 Harrison St\nline2\nline3",
+      "-moz-street-address-one-line": "2 Harrison St line2 line3",
+      "address-line1": "2 Harrison St",
+      "address-line2": "line2 line3",
+      "address-line3": "line3",
+      "address-level1": "CA",
+      "country": "US",
+      "tel": "+19876543210",
+      "tel-national": "9876543210",
+    }],
+  },
+  {
+    description: "Still fill `tel-national` in a `tel` field with `maxlength` can be filled with `tel` value.",
     document: `<form>
                <input id="telephone" maxlength="12">
                <input id="line1" autocomplete="address-line1">
                <input id="line2" autocomplete="address-line2">
                </form>`,
     profileData: [Object.assign({}, DEFAULT_ADDRESS_RECORD)],
     expectedResult: [{
       "guid": "123",
       "street-address": "2 Harrison St\nline2\nline3",
       "-moz-street-address-one-line": "2 Harrison St line2 line3",
       "address-line1": "2 Harrison St",
       "address-line2": "line2 line3",
       "address-line3": "line3",
       "address-level1": "CA",
       "country": "US",
-      "tel": "+19876543210",
+      "tel": "9876543210",
       "tel-national": "9876543210",
     }],
   },
   {
     description: "`tel` field with `maxlength` can be filled with `tel-national` value.",
     document: `<form>
                <input id="telephone" maxlength="10">
                <input id="line1" autocomplete="address-line1">