Bug 1413118 - [Form Autofill] Fill "tel-national" to a recognized "tel" field even the international format passes "maxlength". r=seanlee draft
authorLuke Chang <lchang@mozilla.com>
Thu, 02 Nov 2017 13:17:24 +0800
changeset 693484 5eb0dfd33b3235701403276dffe884791b879717
parent 693376 179dae92e4d794e7f45ad080ff01908c80691f31
child 739055 01be5cf7d02cb020eacd68007437f8915e6c2d88
push id87826
push userbmo:lchang@mozilla.com
push dateMon, 06 Nov 2017 10:53:18 +0000
reviewersseanlee
bugs1413118
milestone58.0a1
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">