Chromium Code Reviews| 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/message_loop.h" | |
| 5 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 6 #include "chrome/browser/autofill/phone_number_i18n.h" | 7 #include "chrome/browser/autofill/phone_number_i18n.h" |
| 8 #include "content/browser/browser_thread.h" | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 8 | 10 |
| 9 using autofill_i18n::NormalizePhoneNumber; | 11 using autofill_i18n::NormalizePhoneNumber; |
| 10 using autofill_i18n::ParsePhoneNumber; | 12 using autofill_i18n::ParsePhoneNumber; |
| 11 using autofill_i18n::ConstructPhoneNumber; | 13 using autofill_i18n::ConstructPhoneNumber; |
| 12 using autofill_i18n::PhoneNumbersMatch; | 14 using autofill_i18n::PhoneNumbersMatch; |
| 13 | 15 |
| 14 typedef testing::Test PhoneNumberI18NTest; | 16 class PhoneNumberI18NTest : public testing::Test { |
| 17 public: | |
| 18 // In order to access the application locale -- which the tested functions do | |
| 19 // internally -- this test must run on the UI thread. | |
| 20 PhoneNumberI18NTest() : ui_thread_(BrowserThread::UI, &message_loop_) {} | |
|
dhollowa
2011/10/20 15:34:27
I may be missing something here, but how does this
GeorgeY
2011/10/20 19:40:00
AFAIK, yes, creating BrowserThread::UI thread does
| |
| 21 | |
| 22 private: | |
| 23 MessageLoopForUI message_loop_; | |
| 24 BrowserThread ui_thread_; | |
| 25 }; | |
| 15 | 26 |
| 16 TEST_F(PhoneNumberI18NTest, NormalizePhoneNumber) { | 27 TEST_F(PhoneNumberI18NTest, NormalizePhoneNumber) { |
| 17 // "Large" digits. | 28 // "Large" digits. |
| 18 string16 phone1(UTF8ToUTF16("\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90" | 29 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" | 30 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" |
| 20 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); | 31 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); |
| 21 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); | 32 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); |
| 22 | 33 |
| 23 // Devanagari script digits. | 34 // Devanagari script digits. |
| 24 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" | 35 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" |
| (...skipping 331 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 356 // Partial matches don't count. | 367 // Partial matches don't count. |
| 357 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 368 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 358 ASCIIToUTF16("8889999"), | 369 ASCIIToUTF16("8889999"), |
| 359 "US")); | 370 "US")); |
| 360 | 371 |
| 361 // Different numbers don't match. | 372 // Different numbers don't match. |
| 362 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 373 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 363 ASCIIToUTF16("1415888"), | 374 ASCIIToUTF16("1415888"), |
| 364 "US")); | 375 "US")); |
| 365 } | 376 } |
| OLD | NEW |