diff options
author | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 22:33:22 +0000 |
---|---|---|
committer | isherman@chromium.org <isherman@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2013-01-15 22:33:22 +0000 |
commit | 7df904dfce777e1714bed6a0c549cd5725dd1d0e (patch) | |
tree | 73919fd7a6d7551508738574351cff9d9a4f78fa /chrome/browser/autofill/phone_number_i18n_unittest.cc | |
parent | dc65b35c0805d3fd4359f4ed81dae84e08a71253 (diff) | |
download | chromium_src-7df904dfce777e1714bed6a0c549cd5725dd1d0e.zip chromium_src-7df904dfce777e1714bed6a0c549cd5725dd1d0e.tar.gz chromium_src-7df904dfce777e1714bed6a0c549cd5725dd1d0e.tar.bz2 |
[Autofill] Phone number cleanup.
Lots of little things:
* In PhoneNumber, use the cached_parsed_phone_ for requests for the whole number as well as for other requests.
* Updated the comment within PhoneNumber::SetInfo() to reflect what the method actually does.
* Add a test to verify that cached phone numbers are correctly invalidated and updated.
* Remove ParsePhoneNumberInternal() in favor of using ParsePhoneNumber() throughout.
* Remove a redundant parameter to ConstructPhoneNumber()
* Use hacker_case for simple accessors in PhoneObject
* Factor out shared code in phone_number_i18n.cc
* Make sure to clear the incoming PhoneNumber argument to ParsePhoneNumber(), as libphonenumber doesn't do this for us.
* Dramatically simplify the implementations for NormalizePhoneNumber(), ConstructPhoneNumber(), and PhoneObject::GetWholeNumber() by relying on factored out shared code.
* Fix PhoneObject::operator=() to copy the whole_number_ as well as the other fields. (FWIW, since whole_number_ is usually computed from i18n_number_, this only rarely caused problems.)
* Remove the explicit UI thread and MessageLoop from PhoneNumberI18NTest now that they're no longer needed.
BUG=none
Review URL: https://chromiumcodereview.appspot.com/11879013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@176993 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/autofill/phone_number_i18n_unittest.cc')
-rw-r--r-- | chrome/browser/autofill/phone_number_i18n_unittest.cc | 128 |
1 files changed, 60 insertions, 68 deletions
diff --git a/chrome/browser/autofill/phone_number_i18n_unittest.cc b/chrome/browser/autofill/phone_number_i18n_unittest.cc index f869d9c..fb03759 100644 --- a/chrome/browser/autofill/phone_number_i18n_unittest.cc +++ b/chrome/browser/autofill/phone_number_i18n_unittest.cc @@ -8,6 +8,7 @@ #include "chrome/browser/autofill/phone_number_i18n.h" #include "content/public/test/test_browser_thread.h" #include "testing/gtest/include/gtest/gtest.h" +#include "third_party/libphonenumber/src/phonenumber_api.h" using autofill_i18n::NormalizePhoneNumber; using autofill_i18n::ParsePhoneNumber; @@ -15,20 +16,7 @@ using autofill_i18n::ConstructPhoneNumber; using autofill_i18n::PhoneNumbersMatch; using content::BrowserThread; -class PhoneNumberI18NTest : public testing::Test { - public: - // In order to access the application locale -- which the tested functions do - // internally -- this test must run on the UI thread. - PhoneNumberI18NTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} - - private: - MessageLoopForUI message_loop_; - content::TestBrowserThread ui_thread_; - - DISALLOW_COPY_AND_ASSIGN(PhoneNumberI18NTest); -}; - -TEST_F(PhoneNumberI18NTest, NormalizePhoneNumber) { +TEST(PhoneNumberI18NTest, NormalizePhoneNumber) { // "Large" digits. string16 phone1(UTF8ToUTF16("\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90" "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" @@ -50,17 +38,19 @@ TEST_F(PhoneNumberI18NTest, NormalizePhoneNumber) { EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); } -TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { +TEST(PhoneNumberI18NTest, ParsePhoneNumber) { string16 number; string16 city_code; string16 country_code; + i18n::phonenumbers::PhoneNumber unused_i18n_number; // Test for empty string. Should give back empty strings. string16 phone0; EXPECT_FALSE(ParsePhoneNumber(phone0, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -70,7 +60,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone1, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -81,7 +72,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone2, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -91,7 +83,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone3, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -102,7 +95,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone4, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -114,7 +108,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -126,7 +121,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone5, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -136,7 +132,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone6, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -145,7 +142,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone7, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("4567890"), number); EXPECT_EQ(ASCIIToUTF16("650"), city_code); EXPECT_EQ(string16(), country_code); @@ -156,7 +154,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("4567890"), number); EXPECT_EQ(ASCIIToUTF16("650"), city_code); EXPECT_EQ(string16(), country_code); @@ -168,7 +167,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone8, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(string16(), number); EXPECT_EQ(string16(), city_code); EXPECT_EQ(string16(), country_code); @@ -178,7 +178,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone9, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("4567890"), number); EXPECT_EQ(ASCIIToUTF16("650"), city_code); EXPECT_EQ(ASCIIToUTF16("1"), country_code); @@ -188,7 +189,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone10, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("4567890"), number); EXPECT_EQ(ASCIIToUTF16("812"), city_code); EXPECT_EQ(ASCIIToUTF16("7"), country_code); @@ -200,7 +202,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone11, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("4567890"), number); EXPECT_EQ(ASCIIToUTF16("650"), city_code); EXPECT_EQ(ASCIIToUTF16("1"), country_code); @@ -211,7 +214,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone12, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("910112"), number); EXPECT_EQ(ASCIIToUTF16("278"), city_code); EXPECT_EQ(ASCIIToUTF16("420"), country_code); @@ -219,7 +223,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("910112"), number); EXPECT_EQ(ASCIIToUTF16("278"), city_code); EXPECT_EQ(ASCIIToUTF16("420"), country_code); @@ -228,11 +233,13 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_FALSE(ParsePhoneNumber(phone13, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("910112"), number); EXPECT_EQ(ASCIIToUTF16("578"), city_code); EXPECT_EQ(ASCIIToUTF16("420"), country_code); @@ -241,7 +248,8 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone14, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("3569377"), number); EXPECT_EQ(ASCIIToUTF16("650"), city_code); EXPECT_EQ(ASCIIToUTF16("1"), country_code); @@ -252,91 +260,75 @@ TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { EXPECT_TRUE(ParsePhoneNumber(phone15, "US", &country_code, &city_code, - &number)); + &number, + &unused_i18n_number)); EXPECT_EQ(ASCIIToUTF16("3569377"), number); EXPECT_EQ(ASCIIToUTF16("800"), city_code); EXPECT_EQ(ASCIIToUTF16("1"), country_code); } -TEST_F(PhoneNumberI18NTest, ConstructPhoneNumber) { +TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { string16 number; EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), ASCIIToUTF16("650"), ASCIIToUTF16("2345678"), "US", - autofill_i18n::E164, - &number)); - EXPECT_EQ(number, ASCIIToUTF16("+16502345678")); - EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), - ASCIIToUTF16("650"), - ASCIIToUTF16("2345678"), - "US", - autofill_i18n::INTERNATIONAL, &number)); EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); - EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), + EXPECT_TRUE(ConstructPhoneNumber(string16(), ASCIIToUTF16("650"), ASCIIToUTF16("2345678"), "US", - autofill_i18n::NATIONAL, &number)); EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), - ASCIIToUTF16("650"), - ASCIIToUTF16("2345678"), - "US", - autofill_i18n::RFC3966, - &number)); - EXPECT_EQ(number, ASCIIToUTF16("tel:+1-650-234-5678")); - EXPECT_TRUE(ConstructPhoneNumber(string16(), - ASCIIToUTF16("650"), - ASCIIToUTF16("2345678"), + string16(), + ASCIIToUTF16("6502345678"), "US", - autofill_i18n::INTERNATIONAL, &number)); EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); EXPECT_TRUE(ConstructPhoneNumber(string16(), string16(), ASCIIToUTF16("6502345678"), "US", - autofill_i18n::INTERNATIONAL, &number)); - EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); + EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); EXPECT_FALSE(ConstructPhoneNumber(string16(), ASCIIToUTF16("650"), ASCIIToUTF16("234567890"), "US", - autofill_i18n::INTERNATIONAL, &number)); EXPECT_EQ(number, string16()); // Italian number - EXPECT_TRUE(ConstructPhoneNumber(string16(), + EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"), ASCIIToUTF16("347"), ASCIIToUTF16("2345678"), "IT", - autofill_i18n::INTERNATIONAL, &number)); EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678")); + EXPECT_TRUE(ConstructPhoneNumber(string16(), + ASCIIToUTF16("347"), + ASCIIToUTF16("2345678"), + "IT", + &number)); + EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); // German number. EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), ASCIIToUTF16("024"), ASCIIToUTF16("2345678901"), "DE", - autofill_i18n::NATIONAL, &number)); - EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); - - EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), + EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); + EXPECT_TRUE(ConstructPhoneNumber(string16(), ASCIIToUTF16("024"), ASCIIToUTF16("2345678901"), "DE", - autofill_i18n::INTERNATIONAL, &number)); - EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); + EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); } -TEST_F(PhoneNumberI18NTest, PhoneNumbersMatch) { +TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { // Same numbers, defined country code. EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), ASCIIToUTF16("4158889999"), |