Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(4524)

Unified Diff: chrome/browser/autofill/phone_number_unittest.cc

Issue 11783045: [Autofill] Ensure that clients pass the correct region info when parsing phone numbers. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix compile Created 7 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/autofill/phone_number_unittest.cc
diff --git a/chrome/browser/autofill/phone_number_unittest.cc b/chrome/browser/autofill/phone_number_unittest.cc
index c2c77e1c48249dfa70c21713ef60ad60bd0c4535..0aa83edfdd04b55ccb5e6bd1b8e70e6e403c68b7 100644
--- a/chrome/browser/autofill/phone_number_unittest.cc
+++ b/chrome/browser/autofill/phone_number_unittest.cc
@@ -81,6 +81,9 @@ TEST(PhoneNumberTest, Matcher) {
}
TEST(PhoneNumberTest, PhoneCombineHelper) {
+ AutofillProfile profile;
+ profile.SetCountryCode("US");
+
PhoneNumber::PhoneCombineHelper number1;
EXPECT_FALSE(number1.SetInfo(ADDRESS_BILLING_CITY,
ASCIIToUTF16("1")));
@@ -91,7 +94,7 @@ TEST(PhoneNumberTest, PhoneCombineHelper) {
EXPECT_TRUE(number1.SetInfo(PHONE_HOME_NUMBER,
ASCIIToUTF16("2345678")));
string16 parsed_phone;
- EXPECT_TRUE(number1.ParseNumber("US", &parsed_phone));
+ EXPECT_TRUE(number1.ParseNumber(profile, "en-US", &parsed_phone));
// International format as it has a country code.
EXPECT_EQ(ASCIIToUTF16("+1 650-234-5678"), parsed_phone);
@@ -100,7 +103,7 @@ TEST(PhoneNumberTest, PhoneCombineHelper) {
ASCIIToUTF16("650")));
EXPECT_TRUE(number3.SetInfo(PHONE_HOME_NUMBER,
ASCIIToUTF16("2345680")));
- EXPECT_TRUE(number3.ParseNumber("US", &parsed_phone));
+ EXPECT_TRUE(number3.ParseNumber(profile, "en-US", &parsed_phone));
// National format as it does not have a country code.
EXPECT_EQ(ASCIIToUTF16("(650) 234-5680"), parsed_phone);
@@ -109,13 +112,13 @@ TEST(PhoneNumberTest, PhoneCombineHelper) {
ASCIIToUTF16("123"))); // Incorrect city code.
EXPECT_TRUE(number4.SetInfo(PHONE_HOME_NUMBER,
ASCIIToUTF16("2345680")));
- EXPECT_FALSE(number4.ParseNumber("US", &parsed_phone));
+ EXPECT_FALSE(number4.ParseNumber(profile, "en-US", &parsed_phone));
EXPECT_EQ(string16(), parsed_phone);
PhoneNumber::PhoneCombineHelper number5;
EXPECT_TRUE(number5.SetInfo(PHONE_HOME_CITY_AND_NUMBER,
ASCIIToUTF16("6502345681")));
- EXPECT_TRUE(number5.ParseNumber("US", &parsed_phone));
+ EXPECT_TRUE(number5.ParseNumber(profile, "en-US", &parsed_phone));
EXPECT_EQ(ASCIIToUTF16("(650) 234-5681"), parsed_phone);
PhoneNumber::PhoneCombineHelper number6;
@@ -125,6 +128,18 @@ TEST(PhoneNumberTest, PhoneCombineHelper) {
ASCIIToUTF16("234")));
EXPECT_TRUE(number6.SetInfo(PHONE_HOME_NUMBER,
ASCIIToUTF16("5682")));
- EXPECT_TRUE(number6.ParseNumber("US", &parsed_phone));
+ EXPECT_TRUE(number6.ParseNumber(profile, "en-US", &parsed_phone));
+ EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone);
+
+ // Ensure parsing is possible when falling back to detecting the country code
+ // based on the app locale.
+ PhoneNumber::PhoneCombineHelper number7;
+ EXPECT_TRUE(number7.SetInfo(PHONE_HOME_CITY_CODE,
+ ASCIIToUTF16("650")));
+ EXPECT_TRUE(number7.SetInfo(PHONE_HOME_NUMBER,
+ ASCIIToUTF16("234")));
+ EXPECT_TRUE(number7.SetInfo(PHONE_HOME_NUMBER,
+ ASCIIToUTF16("5682")));
+ EXPECT_TRUE(number7.ParseNumber(AutofillProfile(), "en-US", &parsed_phone));
EXPECT_EQ(ASCIIToUTF16("(650) 234-5682"), parsed_phone);
}
« no previous file with comments | « chrome/browser/autofill/phone_number.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698