| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/autofill/phone_number_i18n.h" | 6 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 7 #include "chrome/test/testing_browser_process_test.h" |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 9 |
| 9 using autofill_i18n::NormalizePhoneNumber; | 10 using autofill_i18n::NormalizePhoneNumber; |
| 10 using autofill_i18n::ParsePhoneNumber; | 11 using autofill_i18n::ParsePhoneNumber; |
| 11 using autofill_i18n::ConstructPhoneNumber; | 12 using autofill_i18n::ConstructPhoneNumber; |
| 12 using autofill_i18n::FormatPhone; | 13 using autofill_i18n::FormatPhone; |
| 13 using autofill_i18n::ComparePhones; | 14 using autofill_i18n::ComparePhones; |
| 14 using autofill_i18n::PhoneNumbersMatch; | 15 using autofill_i18n::PhoneNumbersMatch; |
| 15 | 16 |
| 16 TEST(PhoneNumberI18NTest, NormalizePhoneNumber) { | 17 typedef TestingBrowserProcessTest PhoneNumberI18NTest; |
| 18 |
| 19 TEST_F(PhoneNumberI18NTest, NormalizePhoneNumber) { |
| 17 // "Large" digits. | 20 // "Large" digits. |
| 18 string16 phone1(UTF8ToUTF16("\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90" | 21 string16 phone1(UTF8ToUTF16("\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90" |
| 19 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" | 22 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" |
| 20 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); | 23 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); |
| 21 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); | 24 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); |
| 22 | 25 |
| 23 // Devanagari script digits. | 26 // Devanagari script digits. |
| 24 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" | 27 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" |
| 25 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9")); | 28 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9")); |
| 26 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); | 29 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); |
| 27 | 30 |
| 28 string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); | 31 string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); |
| 29 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); | 32 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); |
| 30 | 33 |
| 31 string16 phone4(UTF8ToUTF16("+1(650)2346789")); | 34 string16 phone4(UTF8ToUTF16("+1(650)2346789")); |
| 32 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); | 35 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); |
| 33 | 36 |
| 34 string16 phone5(UTF8ToUTF16("6502346789")); | 37 string16 phone5(UTF8ToUTF16("6502346789")); |
| 35 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); | 38 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); |
| 36 } | 39 } |
| 37 | 40 |
| 38 TEST(PhoneNumberI18NTest, ParsePhoneNumber) { | 41 TEST_F(PhoneNumberI18NTest, ParsePhoneNumber) { |
| 39 string16 number; | 42 string16 number; |
| 40 string16 city_code; | 43 string16 city_code; |
| 41 string16 country_code; | 44 string16 country_code; |
| 42 | 45 |
| 43 // Test for empty string. Should give back empty strings. | 46 // Test for empty string. Should give back empty strings. |
| 44 string16 phone0; | 47 string16 phone0; |
| 45 EXPECT_FALSE(ParsePhoneNumber(phone0, "US", | 48 EXPECT_FALSE(ParsePhoneNumber(phone0, "US", |
| 46 &country_code, | 49 &country_code, |
| 47 &city_code, | 50 &city_code, |
| 48 &number)); | 51 &number)); |
| (...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 236 string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); | 239 string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); |
| 237 EXPECT_TRUE(ParsePhoneNumber(phone15, "US", | 240 EXPECT_TRUE(ParsePhoneNumber(phone15, "US", |
| 238 &country_code, | 241 &country_code, |
| 239 &city_code, | 242 &city_code, |
| 240 &number)); | 243 &number)); |
| 241 EXPECT_EQ(ASCIIToUTF16("3569377"), number); | 244 EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 242 EXPECT_EQ(ASCIIToUTF16("800"), city_code); | 245 EXPECT_EQ(ASCIIToUTF16("800"), city_code); |
| 243 EXPECT_EQ(ASCIIToUTF16("1"), country_code); | 246 EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 244 } | 247 } |
| 245 | 248 |
| 246 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { | 249 TEST_F(PhoneNumberI18NTest, ConstructPhoneNumber) { |
| 247 string16 number; | 250 string16 number; |
| 248 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), | 251 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 249 ASCIIToUTF16("650"), | 252 ASCIIToUTF16("650"), |
| 250 ASCIIToUTF16("2345678"), | 253 ASCIIToUTF16("2345678"), |
| 251 "US", | 254 "US", |
| 252 autofill_i18n::E164, | 255 autofill_i18n::E164, |
| 253 &number)); | 256 &number)); |
| 254 EXPECT_EQ(number, ASCIIToUTF16("+16502345678")); | 257 EXPECT_EQ(number, ASCIIToUTF16("+16502345678")); |
| 255 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), | 258 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 256 ASCIIToUTF16("650"), | 259 ASCIIToUTF16("650"), |
| (...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 314 | 317 |
| 315 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), | 318 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), |
| 316 ASCIIToUTF16("024"), | 319 ASCIIToUTF16("024"), |
| 317 ASCIIToUTF16("2345678901"), | 320 ASCIIToUTF16("2345678901"), |
| 318 "DE", | 321 "DE", |
| 319 autofill_i18n::INTERNATIONAL, | 322 autofill_i18n::INTERNATIONAL, |
| 320 &number)); | 323 &number)); |
| 321 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); | 324 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); |
| 322 } | 325 } |
| 323 | 326 |
| 324 TEST(PhoneNumberI18NTest, FormatPhone) { | 327 TEST_F(PhoneNumberI18NTest, FormatPhone) { |
| 325 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1[650]234-56-78"), "US", | 328 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1[650]234-56-78"), "US", |
| 326 autofill_i18n::NATIONAL), | 329 autofill_i18n::NATIONAL), |
| 327 ASCIIToUTF16("(650) 234-5678")); | 330 ASCIIToUTF16("(650) 234-5678")); |
| 328 EXPECT_EQ(FormatPhone(ASCIIToUTF16("(650)234-56-78"), "US", | 331 EXPECT_EQ(FormatPhone(ASCIIToUTF16("(650)234-56-78"), "US", |
| 329 autofill_i18n::NATIONAL), | 332 autofill_i18n::NATIONAL), |
| 330 ASCIIToUTF16("(650) 234-5678")); | 333 ASCIIToUTF16("(650) 234-5678")); |
| 331 EXPECT_EQ(FormatPhone(ASCIIToUTF16("(650)234-56-78"), "US", | 334 EXPECT_EQ(FormatPhone(ASCIIToUTF16("(650)234-56-78"), "US", |
| 332 autofill_i18n::INTERNATIONAL), | 335 autofill_i18n::INTERNATIONAL), |
| 333 ASCIIToUTF16("+1 650-234-5678")); | 336 ASCIIToUTF16("+1 650-234-5678")); |
| 334 EXPECT_EQ(FormatPhone(ASCIIToUTF16("01139236618300"), "US", | 337 EXPECT_EQ(FormatPhone(ASCIIToUTF16("01139236618300"), "US", |
| 335 autofill_i18n::INTERNATIONAL), | 338 autofill_i18n::INTERNATIONAL), |
| 336 ASCIIToUTF16("+39 236618300")); | 339 ASCIIToUTF16("+39 236618300")); |
| 337 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1(650)234-56-78"), "CZ", | 340 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1(650)234-56-78"), "CZ", |
| 338 autofill_i18n::NATIONAL), | 341 autofill_i18n::NATIONAL), |
| 339 ASCIIToUTF16("16502345678")); | 342 ASCIIToUTF16("16502345678")); |
| 340 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1(650)234-56-78"), "CZ", | 343 EXPECT_EQ(FormatPhone(ASCIIToUTF16("1(650)234-56-78"), "CZ", |
| 341 autofill_i18n::INTERNATIONAL), | 344 autofill_i18n::INTERNATIONAL), |
| 342 ASCIIToUTF16("+420 16502345678")); | 345 ASCIIToUTF16("+420 16502345678")); |
| 343 } | 346 } |
| 344 | 347 |
| 345 TEST(PhoneNumberI18NTest, ComparePhones) { | 348 TEST_F(PhoneNumberI18NTest, ComparePhones) { |
| 346 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), | 349 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), |
| 347 ASCIIToUTF16("+16502345678"), | 350 ASCIIToUTF16("+16502345678"), |
| 348 "US"), | 351 "US"), |
| 349 autofill_i18n::PHONES_EQUAL); | 352 autofill_i18n::PHONES_EQUAL); |
| 350 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), | 353 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), |
| 351 ASCIIToUTF16("6502345678"), | 354 ASCIIToUTF16("6502345678"), |
| 352 "US"), | 355 "US"), |
| 353 autofill_i18n::PHONES_EQUAL); | 356 autofill_i18n::PHONES_EQUAL); |
| 354 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1-800-FLOWERS"), | 357 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1-800-FLOWERS"), |
| 355 ASCIIToUTF16("18003569377"), | 358 ASCIIToUTF16("18003569377"), |
| 356 "US"), | 359 "US"), |
| 357 autofill_i18n::PHONES_EQUAL); | 360 autofill_i18n::PHONES_EQUAL); |
| 358 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), | 361 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1(650)234-56-78"), |
| 359 ASCIIToUTF16("2345678"), | 362 ASCIIToUTF16("2345678"), |
| 360 "US"), | 363 "US"), |
| 361 autofill_i18n::PHONES_SUBMATCH); | 364 autofill_i18n::PHONES_SUBMATCH); |
| 362 EXPECT_EQ(ComparePhones(ASCIIToUTF16("234-56-78"), | 365 EXPECT_EQ(ComparePhones(ASCIIToUTF16("234-56-78"), |
| 363 ASCIIToUTF16("+16502345678"), | 366 ASCIIToUTF16("+16502345678"), |
| 364 "US"), | 367 "US"), |
| 365 autofill_i18n::PHONES_SUBMATCH); | 368 autofill_i18n::PHONES_SUBMATCH); |
| 366 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1650234"), | 369 EXPECT_EQ(ComparePhones(ASCIIToUTF16("1650234"), |
| 367 ASCIIToUTF16("+16502345678"), | 370 ASCIIToUTF16("+16502345678"), |
| 368 "US"), | 371 "US"), |
| 369 autofill_i18n::PHONES_NOT_EQUAL); | 372 autofill_i18n::PHONES_NOT_EQUAL); |
| 370 } | 373 } |
| 371 | 374 |
| 372 TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { | 375 TEST_F(PhoneNumberI18NTest, PhoneNumbersMatch) { |
| 373 // Same numbers, defined country code. | 376 // Same numbers, defined country code. |
| 374 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), | 377 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 375 ASCIIToUTF16("4158889999"), | 378 ASCIIToUTF16("4158889999"), |
| 376 "US")); | 379 "US")); |
| 377 // Same numbers, undefined country code. | 380 // Same numbers, undefined country code. |
| 378 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), | 381 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 379 ASCIIToUTF16("4158889999"), | 382 ASCIIToUTF16("4158889999"), |
| 380 "")); | 383 "")); |
| 381 | 384 |
| 382 // Numbers differ by country code only. | 385 // Numbers differ by country code only. |
| (...skipping 13 matching lines...) Expand all Loading... |
| 396 "US")); | 399 "US")); |
| 397 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), | 400 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 398 ASCIIToUTF16("415 TUV WXYZ"), | 401 ASCIIToUTF16("415 TUV WXYZ"), |
| 399 "US")); | 402 "US")); |
| 400 | 403 |
| 401 // Partial matches don't count. | 404 // Partial matches don't count. |
| 402 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 405 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 403 ASCIIToUTF16("8889999"), | 406 ASCIIToUTF16("8889999"), |
| 404 "US")); | 407 "US")); |
| 405 } | 408 } |
| OLD | NEW |