Bug 1413118 - [Form Autofill] Fill "tel-national" to a recognized "tel" field even the international format passes "maxlength". r=seanlee
MozReview-Commit-ID: KOyFeaORTWV
--- 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">