summaryrefslogtreecommitdiffstats
path: root/components
diff options
context:
space:
mode:
authorMathieu Perreault <mathp@chromium.org>2016-01-28 16:00:55 -0500
committerMathieu Perreault <mathp@chromium.org>2016-01-28 21:02:00 +0000
commit9719a052e54b469f11b4fb51c8e585e7c7c932e5 (patch)
tree7901c0e6d8b7fa38205d2dc3c438638fc917d2e5 /components
parent662aed60b889672f028f1c4b8a357d7f36348efd (diff)
downloadchromium_src-9719a052e54b469f11b4fb51c8e585e7c7c932e5.zip
chromium_src-9719a052e54b469f11b4fb51c8e585e7c7c932e5.tar.gz
chromium_src-9719a052e54b469f11b4fb51c8e585e7c7c932e5.tar.bz2
[Merge M49][Autofill]When determining what field type to upload, if both PHONE_HOME_CITY_AND_NUMBER and PHONE_HOME_WHOLE_NUMBER are matched, it means there is no country code in the profile's phone number. In that case, only match PHONE_HOME_CITY_AND_NUMBER because it's more precise.
BUG=580629 TEST=AutofillManagerTest Review URL: https://codereview.chromium.org/1623803002 Cr-Commit-Position: refs/heads/master@{#371867} (cherry picked from commit 03c71f5c105e04f15a5b761f67dbcb9e74d178d0) Review URL: https://codereview.chromium.org/1646533006 . Cr-Commit-Position: refs/branch-heads/2623@{#178} Cr-Branched-From: 92d77538a86529ca35f9220bd3cd512cbea1f086-refs/heads/master@{#369907}
Diffstat (limited to 'components')
-rw-r--r--components/autofill/core/browser/autofill_manager_unittest.cc144
-rw-r--r--components/autofill/core/browser/autofill_metrics_unittest.cc6
-rw-r--r--components/autofill/core/browser/phone_number.cc40
3 files changed, 120 insertions, 70 deletions
diff --git a/components/autofill/core/browser/autofill_manager_unittest.cc b/components/autofill/core/browser/autofill_manager_unittest.cc
index dd4d0f1..e047d43 100644
--- a/components/autofill/core/browser/autofill_manager_unittest.cc
+++ b/components/autofill/core/browser/autofill_manager_unittest.cc
@@ -3200,14 +3200,20 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
test::SetProfileInfo(&profile, "Elvis", "Aaron", "Presley",
"theking@gmail.com", "RCA", "3734 Elvis Presley Blvd.",
"Apt. 10", "Memphis", "Tennessee", "38116", "US",
- "12345678901");
+ "+1 (234) 567-8901");
profile.set_guid("00000000-0000-0000-0000-000000000001");
profiles.push_back(profile);
test::SetProfileInfo(&profile, "Charles", "", "Holley", "buddy@gmail.com",
"Decca", "123 Apple St.", "unit 6", "Lubbock", "Texas",
- "79401", "US", "23456789012");
+ "79401", "US", "5142821292");
profile.set_guid("00000000-0000-0000-0000-000000000002");
profiles.push_back(profile);
+ test::SetProfileInfo(&profile, "Charles", "", "Baudelaire",
+ "lesfleursdumal@gmail.com", "", "108 Rue Saint-Lazare",
+ "Apt. 10", "Paris", "Ile de France", "75008", "FR",
+ "+33 2 49 19 70 70");
+ profile.set_guid("00000000-0000-0000-0000-000000000001");
+ profiles.push_back(profile);
// Set up the test credit cards.
std::vector<CreditCard> credit_cards;
@@ -3223,64 +3229,80 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
} TestCase;
TestCase test_cases[] = {
- // Profile fields matches.
- {"Elvis", NAME_FIRST},
- {"Aaron", NAME_MIDDLE},
- {"A", NAME_MIDDLE_INITIAL},
- {"Presley", NAME_LAST},
- {"Elvis Aaron Presley", NAME_FULL},
- {"theking@gmail.com", EMAIL_ADDRESS},
- {"RCA", COMPANY_NAME},
- {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
- {"Apt. 10", ADDRESS_HOME_LINE2},
- {"Memphis", ADDRESS_HOME_CITY},
- {"Tennessee", ADDRESS_HOME_STATE},
- {"38116", ADDRESS_HOME_ZIP},
- {"USA", ADDRESS_HOME_COUNTRY},
- {"United States", ADDRESS_HOME_COUNTRY},
- {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER},
- {"2345678901", PHONE_HOME_CITY_AND_NUMBER},
- {"1", PHONE_HOME_COUNTRY_CODE},
- {"234", PHONE_HOME_CITY_CODE},
- {"5678901", PHONE_HOME_NUMBER},
- {"567", PHONE_HOME_NUMBER},
- {"8901", PHONE_HOME_NUMBER},
-
- // Make sure matches for a second profile work.
- {"Charles Holley", NAME_FULL},
-
- // Credit card fields matches.
- {"Elvis Presley", CREDIT_CARD_NAME},
- {"4234-5678-9012-3456", CREDIT_CARD_NUMBER},
- {"04", CREDIT_CARD_EXP_MONTH},
- {"April", CREDIT_CARD_EXP_MONTH},
- {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR},
- {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR},
- {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
-
- // Make sure whitespaces are trimmed properly.
- {"", EMPTY_TYPE},
- {" ", EMPTY_TYPE},
- {" Elvis", NAME_FIRST},
- {"Elvis ", NAME_FIRST},
-
- // Make sure fields that differ by case match.
- {"elvis ", NAME_FIRST},
- {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY},
-
- // Make sure fields that differ by punctuation match.
- {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1},
- {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
-
- // Make sure unsupported variants do not match.
- {"Elvis Aaron", UNKNOWN_TYPE},
- {"Mr. Presley", UNKNOWN_TYPE},
- {"3734 Elvis Presley", UNKNOWN_TYPE},
- {"TN", UNKNOWN_TYPE},
- {"38116-1023", UNKNOWN_TYPE},
- {"5", UNKNOWN_TYPE},
- {"56", UNKNOWN_TYPE},
- {"901", UNKNOWN_TYPE}};
+ // Profile fields matches.
+ {"Elvis", NAME_FIRST},
+ {"Aaron", NAME_MIDDLE},
+ {"A", NAME_MIDDLE_INITIAL},
+ {"Presley", NAME_LAST},
+ {"Elvis Aaron Presley", NAME_FULL},
+ {"theking@gmail.com", EMAIL_ADDRESS},
+ {"RCA", COMPANY_NAME},
+ {"3734 Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
+ {"Apt. 10", ADDRESS_HOME_LINE2},
+ {"Memphis", ADDRESS_HOME_CITY},
+ {"Tennessee", ADDRESS_HOME_STATE},
+ {"38116", ADDRESS_HOME_ZIP},
+ {"USA", ADDRESS_HOME_COUNTRY},
+ {"United States", ADDRESS_HOME_COUNTRY},
+ {"12345678901", PHONE_HOME_WHOLE_NUMBER},
+ {"+1 (234) 567-8901", PHONE_HOME_WHOLE_NUMBER},
+ {"(234)567-8901", PHONE_HOME_CITY_AND_NUMBER},
+ {"2345678901", PHONE_HOME_CITY_AND_NUMBER},
+ {"1", PHONE_HOME_COUNTRY_CODE},
+ {"234", PHONE_HOME_CITY_CODE},
+ {"5678901", PHONE_HOME_NUMBER},
+ {"567", PHONE_HOME_NUMBER},
+ {"8901", PHONE_HOME_NUMBER},
+
+ // Test an european profile.
+ {"Paris", ADDRESS_HOME_CITY},
+ {"Ile de France", ADDRESS_HOME_STATE},
+ {"75008", ADDRESS_HOME_ZIP},
+ {"FR", ADDRESS_HOME_COUNTRY},
+ {"France", ADDRESS_HOME_COUNTRY},
+ {"33249197070", PHONE_HOME_WHOLE_NUMBER},
+ {"+33 2 49 19 70 70", PHONE_HOME_WHOLE_NUMBER},
+ {"2 49 19 70 70", PHONE_HOME_CITY_AND_NUMBER},
+ {"249197070", PHONE_HOME_CITY_AND_NUMBER},
+ {"33", PHONE_HOME_COUNTRY_CODE},
+ {"2", PHONE_HOME_CITY_CODE},
+
+ // Credit card fields matches.
+ {"Elvis Presley", CREDIT_CARD_NAME},
+ {"4234-5678-9012-3456", CREDIT_CARD_NUMBER},
+ {"04", CREDIT_CARD_EXP_MONTH},
+ {"April", CREDIT_CARD_EXP_MONTH},
+ {"2012", CREDIT_CARD_EXP_4_DIGIT_YEAR},
+ {"12", CREDIT_CARD_EXP_2_DIGIT_YEAR},
+ {"04/2012", CREDIT_CARD_EXP_DATE_4_DIGIT_YEAR},
+
+ // Make sure whitespaces are trimmed properly.
+ {"", EMPTY_TYPE},
+ {" ", EMPTY_TYPE},
+ {" Elvis", NAME_FIRST},
+ {"Elvis ", NAME_FIRST},
+
+ // Make sure fields that differ by case match.
+ {"elvis ", NAME_FIRST},
+ {"UnItEd StAtEs", ADDRESS_HOME_COUNTRY},
+
+ // Make sure fields that differ by punctuation match.
+ {"3734 Elvis Presley Blvd", ADDRESS_HOME_LINE1},
+ {"3734, Elvis Presley Blvd.", ADDRESS_HOME_LINE1},
+
+ // Special phone number case. A profile with no country code should only
+ // match PHONE_HOME_CITY_AND_NUMBER.
+ {"5142821292", PHONE_HOME_CITY_AND_NUMBER},
+
+ // Make sure unsupported variants do not match.
+ {"Elvis Aaron", UNKNOWN_TYPE},
+ {"Mr. Presley", UNKNOWN_TYPE},
+ {"3734 Elvis Presley", UNKNOWN_TYPE},
+ {"TN", UNKNOWN_TYPE},
+ {"38116-1023", UNKNOWN_TYPE},
+ {"5", UNKNOWN_TYPE},
+ {"56", UNKNOWN_TYPE},
+ {"901", UNKNOWN_TYPE}};
for (TestCase test_case : test_cases) {
FormData form;
@@ -3304,6 +3326,8 @@ TEST_F(AutofillManagerTest, DeterminePossibleFieldTypesForUpload) {
ASSERT_EQ(1U, form_structure.field_count());
ServerFieldTypeSet possible_types =
form_structure.field(0)->possible_types();
+ EXPECT_EQ(1U, possible_types.size());
+
EXPECT_NE(possible_types.end(), possible_types.find(test_case.field_type));
}
}
diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc
index 7fa8faa..c9b790a 100644
--- a/components/autofill/core/browser/autofill_metrics_unittest.cc
+++ b/components/autofill/core/browser/autofill_metrics_unittest.cc
@@ -423,7 +423,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics) {
field.is_autofilled = true;
form.fields.push_back(field);
heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
- server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
+ server_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
// Simulate having seen this form on page load.
autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
@@ -449,7 +449,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics) {
GetFieldTypeGroupMetric(NAME_FULL, AutofillMetrics::TYPE_MATCH), 1);
histogram_tester.ExpectBucketCount(
"Autofill.Quality.HeuristicType.ByFieldType",
- GetFieldTypeGroupMetric(PHONE_HOME_WHOLE_NUMBER,
+ GetFieldTypeGroupMetric(PHONE_HOME_CITY_AND_NUMBER,
AutofillMetrics::TYPE_MATCH),
1);
// Mismatch:
@@ -563,7 +563,7 @@ TEST_F(AutofillMetricsTest, QualityMetrics_NoSubmission) {
field.is_autofilled = true;
form.fields.push_back(field);
heuristic_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
- server_types.push_back(PHONE_HOME_WHOLE_NUMBER);
+ server_types.push_back(PHONE_HOME_CITY_AND_NUMBER);
// Simulate having seen this form on page load.
autofill_manager_->AddSeenForm(form, heuristic_types, server_types);
diff --git a/components/autofill/core/browser/phone_number.cc b/components/autofill/core/browser/phone_number.cc
index 1952e58..550b106 100644
--- a/components/autofill/core/browser/phone_number.cc
+++ b/components/autofill/core/browser/phone_number.cc
@@ -149,6 +149,11 @@ bool PhoneNumber::SetInfo(const AutofillType& type,
void PhoneNumber::GetMatchingTypes(const base::string16& text,
const std::string& app_locale,
ServerFieldTypeSet* matching_types) const {
+ // Strip the common phone number non numerical characters before calling the
+ // base matching type function. For example, the |text| "(514) 121-1523"
+ // would become the stripped text "5141211523". Since the base matching
+ // function only does simple canonicalization to match against the stored
+ // data, some domain specific cases will be covered below.
base::string16 stripped_text = text;
base::RemoveChars(stripped_text, base::ASCIIToUTF16(" .()-"), &stripped_text);
FormGroup::GetMatchingTypes(stripped_text, app_locale, matching_types);
@@ -164,13 +169,34 @@ void PhoneNumber::GetMatchingTypes(const base::string16& text,
matching_types->insert(PHONE_HOME_NUMBER);
}
- base::string16 whole_number =
- GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale);
- if (!whole_number.empty()) {
- base::string16 normalized_number =
- i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale));
- if (normalized_number == whole_number)
- matching_types->insert(PHONE_HOME_WHOLE_NUMBER);
+ // TODO(crbug.com/581391): Investigate the use of PhoneNumberUtil when
+ // matching phone numbers for upload.
+ // If there is not already a match for PHONE_HOME_WHOLE_NUMBER, normalize the
+ // |text| based on the app_locale before comparing it to the whole number. For
+ // example, the France number "33 2 49 19 70 70" would be normalized to
+ // "+33249197070" whereas the US number "+1 (234) 567-8901" would be
+ // normalized to "12345678901".
+ if (matching_types->find(PHONE_HOME_WHOLE_NUMBER) == matching_types->end()) {
+ base::string16 whole_number =
+ GetInfo(AutofillType(PHONE_HOME_WHOLE_NUMBER), app_locale);
+ if (!whole_number.empty()) {
+ base::string16 normalized_number =
+ i18n::NormalizePhoneNumber(text, GetRegion(*profile_, app_locale));
+ if (normalized_number == whole_number)
+ matching_types->insert(PHONE_HOME_WHOLE_NUMBER);
+ }
+ }
+
+ // If both PHONE_HOME_CITY_AND_NUMBER and PHONE_HOME_WHOLE_NUMBER are matched,
+ // it means there is no country code in the profile's phone number. In that
+ // case, we should only return PHONE_HOME_CITY_AND_NUMBER because it's more
+ // precise.
+ ServerFieldTypeSet::iterator whole_number_iterator =
+ matching_types->find(PHONE_HOME_WHOLE_NUMBER);
+ if (whole_number_iterator != matching_types->end() &&
+ matching_types->find(PHONE_HOME_CITY_AND_NUMBER) !=
+ matching_types->end()) {
+ matching_types->erase(whole_number_iterator);
}
}