Bug 1394854 - [Form Autofill] Identify country code from "country" attribute as well. r=ralin
MozReview-Commit-ID: 1lfncEEMgyZ
--- a/browser/extensions/formautofill/ProfileStorage.jsm
+++ b/browser/extensions/formautofill/ProfileStorage.jsm
@@ -1276,19 +1276,27 @@ class Addresses extends AutofillRecords
STREET_ADDRESS_COMPONENTS.forEach(c => delete address[c]);
}
_normalizeCountry(address) {
let country;
if (address.country) {
+ country = FormAutofillUtils.identifyCountryCode(address.country);
+ }
+ if (!country && address["country-name"]) {
+ country = FormAutofillUtils.identifyCountryCode(address["country-name"]);
+ }
+
+ // The "identifyCountryCode" can only identify currently-supported countries
+ // ("US" in MVP). Uses "address.country" as the final fallback so we won't
+ // lose any valid country code.
+ if (!country && address.country) {
country = address.country.toUpperCase();
- } else if (address["country-name"]) {
- country = FormAutofillUtils.identifyCountryCode(address["country-name"]);
}
// Only values included in the region list will be saved.
if (country && REGION_NAMES[country]) {
address.country = country;
} else {
delete address.country;
}
--- a/browser/extensions/formautofill/test/unit/test_transformFields.js
+++ b/browser/extensions/formautofill/test/unit/test_transformFields.js
@@ -295,25 +295,37 @@ const ADDRESS_NORMALIZE_TESTCASES = [
// Country
{
description: "Has \"country\" in lowercase",
address: {
"country": "us",
},
expectedResult: {
"country": "US",
+ "country-name": "United States",
+ },
+ },
+ {
+ description: "Has \"country\" with full country name",
+ address: {
+ "country": "united states",
+ },
+ expectedResult: {
+ "country": "US",
+ "country-name": "United States",
},
},
{
description: "Has unknown \"country\"",
address: {
"country": "AA",
},
expectedResult: {
"country": undefined,
+ "country-name": undefined,
},
},
{
description: "Has \"country-name\"",
address: {
"country-name": "united states",
},
expectedResult: {
@@ -374,18 +386,18 @@ const ADDRESS_NORMALIZE_TESTCASES = [
},
{
description: "Has \"country-name\" and unknown \"country\"",
address: {
"country": "AA",
"country-name": "united states",
},
expectedResult: {
- "country": undefined,
- "country-name": undefined,
+ "country": "US",
+ "country-name": "United States",
},
},
{
description: "Has unsupported \"country\"",
address: {
"country": "CA",
},
expectedResult: {