Bug 1370475 - Part 3: Add a custom field "-moz-street-address-one-line" for popup label and filling street-address. r=lchang
MozReview-Commit-ID: Jh178WQZ5Qs
--- a/browser/extensions/formautofill/FormAutofillHandler.jsm
+++ b/browser/extensions/formautofill/FormAutofillHandler.jsm
@@ -120,17 +120,24 @@ FormAutofillHandler.prototype = {
if (!this._cacheValue.oneLineStreetAddress[address]) {
this._cacheValue.oneLineStreetAddress[address] = FormAutofillUtils.toOneLineAddress(address);
}
return this._cacheValue.oneLineStreetAddress[address];
},
_addressTransformer(profile) {
if (profile["street-address"]) {
- profile["street-address"] = this._getOneLineStreetAddress(profile["street-address"]);
+ // "-moz-street-address-one-line" is used by the labels in
+ // ProfileAutoCompleteResult.
+ profile["-moz-street-address-one-line"] = this._getOneLineStreetAddress(profile["street-address"]);
+ let streetAddressDetail = this.getFieldDetailByName("street-address");
+ if (streetAddressDetail &&
+ (streetAddressDetail.elementWeakRef.get() instanceof Ci.nsIDOMHTMLInputElement)) {
+ profile["street-address"] = profile["-moz-street-address-one-line"];
+ }
let waitForConcat = [];
for (let f of ["address-line3", "address-line2", "address-line1"]) {
waitForConcat.unshift(profile[f]);
if (this.getFieldDetailByName(f)) {
if (waitForConcat.length > 1) {
profile[f] = FormAutofillUtils.toOneLineAddress(waitForConcat);
}
--- a/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
+++ b/browser/extensions/formautofill/ProfileAutoCompleteResult.jsm
@@ -138,30 +138,39 @@ ProfileAutoCompleteResult.prototype = {
continue;
}
let matching = GROUP_FIELDS[currentFieldName] ?
allFieldNames.some(fieldName => GROUP_FIELDS[currentFieldName].includes(fieldName)) :
allFieldNames.includes(currentFieldName);
if (matching) {
+ if (currentFieldName == "street-address" &&
+ profile["-moz-street-address-one-line"]) {
+ return profile["-moz-street-address-one-line"];
+ }
return profile[currentFieldName];
}
}
return ""; // Nothing matched.
},
_generateLabels(focusedFieldName, allFieldNames, profiles) {
// Skip results without a primary label.
return profiles.filter(profile => {
return !!profile[focusedFieldName];
}).map(profile => {
+ let primaryLabel = profile[focusedFieldName];
+ if (focusedFieldName == "street-address" &&
+ profile["-moz-street-address-one-line"]) {
+ primaryLabel = profile["-moz-street-address-one-line"];
+ }
return {
- primary: profile[focusedFieldName],
+ primary: primaryLabel,
secondary: this._getSecondaryLabel(focusedFieldName,
allFieldNames,
profile),
};
});
},
/**
--- a/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
+++ b/browser/extensions/formautofill/test/unit/test_autofillFormFields.js
@@ -40,24 +40,25 @@ const TESTCASES = [
{"section": "", "addressType": "", "contactType": "", "fieldName": "street-address", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "address-level2", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "country", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "email", "element": {}},
{"section": "", "addressType": "", "contactType": "", "fieldName": "tel", "element": {}},
],
profileData: {
"guid": "123",
- "street-address": "2 Harrison St",
+ "street-address": "2 Harrison St line2",
+ "-moz-street-address-one-line": "2 Harrison St line2",
"address-level2": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
expectedResult: {
- "street-addr": "2 Harrison St",
+ "street-addr": "2 Harrison St line2",
"city": "San Francisco",
"country": "US",
"email": "foo@mozilla.com",
"tel": "1234567",
},
},
{
description: "Form with autocomplete properties and 2 tokens",
--- a/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
+++ b/browser/extensions/formautofill/test/unit/test_profileAutocompleteResult.js
@@ -19,16 +19,17 @@ let matchingProfiles = [{
organization: "Mozilla",
"street-address": "331 E. Evelyn Avenue",
"address-line1": "331 E. Evelyn Avenue",
tel: "1-650-903-0800",
}, {
guid: "test-guid-3",
organization: "",
"street-address": "321, No Name St. 2nd line 3rd line",
+ "-moz-street-address-one-line": "321, No Name St. 2nd line 3rd line",
"address-line1": "321, No Name St.",
"address-line2": "2nd line",
"address-line3": "3rd line",
tel: "1-000-000-0000",
}];
let allFieldNames = [
"given-name",