OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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/home_phone_number.h" | 6 #include "chrome/browser/autofill/home_phone_number.h" |
7 #include "chrome/browser/autofill/phone_number.h" | 7 #include "chrome/browser/autofill/phone_number.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 | 9 |
10 class PhoneNumberTest : public testing::Test { | |
11 public: | |
12 PhoneNumberTest() {} | |
13 | |
14 void set_whole_number(PhoneNumber* phone_number, | |
15 const string16& whole_number) { | |
16 phone_number->set_whole_number(whole_number); | |
17 } | |
18 | |
19 bool IsNumber(PhoneNumber* phone_number, const string16& text) const { | |
20 return phone_number->IsNumber(text); | |
21 } | |
22 | |
23 bool IsCityCode(PhoneNumber* phone_number, const string16& text) const { | |
24 return phone_number->IsCityCode(text); | |
25 } | |
26 | |
27 bool IsCountryCode(PhoneNumber* phone_number, const string16& text) const { | |
28 return phone_number->IsCountryCode(text); | |
29 } | |
30 | |
31 private: | |
32 DISALLOW_COPY_AND_ASSIGN(PhoneNumberTest); | |
33 }; | |
34 | |
35 // Tests the phone number parser. | 10 // Tests the phone number parser. |
36 TEST_F(PhoneNumberTest, Parser) { | 11 TEST(PhoneNumberTest, Parser) { |
37 string16 number; | 12 string16 number; |
38 string16 city_code; | 13 string16 city_code; |
39 string16 country_code; | 14 string16 country_code; |
40 | 15 |
41 // Test for empty string. Should give back empty strings. | 16 // Test for empty string. Should give back empty strings. |
42 string16 phone0; | 17 string16 phone0; |
43 PhoneNumber::ParsePhoneNumber(phone0, &number, &city_code, &country_code); | 18 PhoneNumber::ParsePhoneNumber(phone0, &number, &city_code, &country_code); |
44 EXPECT_EQ(string16(), number); | 19 EXPECT_EQ(string16(), number); |
45 EXPECT_EQ(string16(), city_code); | 20 EXPECT_EQ(string16(), city_code); |
46 EXPECT_EQ(string16(), country_code); | 21 EXPECT_EQ(string16(), country_code); |
(...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
112 | 87 |
113 // Test for string with over 10 digits with separator characters. | 88 // Test for string with over 10 digits with separator characters. |
114 // Should give back phone number, city code, and country code. | 89 // Should give back phone number, city code, and country code. |
115 string16 phone6(ASCIIToUTF16("(01) 123-456.7890")); | 90 string16 phone6(ASCIIToUTF16("(01) 123-456.7890")); |
116 PhoneNumber::ParsePhoneNumber(phone6, &number, &city_code, &country_code); | 91 PhoneNumber::ParsePhoneNumber(phone6, &number, &city_code, &country_code); |
117 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 92 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
118 EXPECT_EQ(ASCIIToUTF16("123"), city_code); | 93 EXPECT_EQ(ASCIIToUTF16("123"), city_code); |
119 EXPECT_EQ(ASCIIToUTF16("01"), country_code); | 94 EXPECT_EQ(ASCIIToUTF16("01"), country_code); |
120 } | 95 } |
121 | 96 |
122 TEST_F(PhoneNumberTest, Matcher) { | 97 TEST(PhoneNumberTest, Matcher) { |
123 string16 phone(ASCIIToUTF16("121231234567")); | 98 string16 phone(ASCIIToUTF16("121231234567")); |
124 HomePhoneNumber phone_number; | 99 HomePhoneNumber phone_number; |
125 set_whole_number(&phone_number, phone); | 100 phone_number.set_whole_number(phone); |
126 // Phone number is now country_code == 12, city_code = 123, number = 1234567. | 101 // Phone number is now country_code == 12, city_code = 123, number = 1234567. |
127 char test_number[] = "1234567890"; | 102 char test_number[] = "1234567890"; |
128 for (int i = arraysize(test_number) - 1; i >= 0; --i) { | 103 for (int i = arraysize(test_number) - 1; i >= 0; --i) { |
129 test_number[i] = 0; // Cut the string. | 104 test_number[i] = 0; // Cut the string. |
130 if (i > 7) { | 105 if (i > 7) { |
131 EXPECT_FALSE(IsNumber(&phone_number, ASCIIToUTF16(test_number))); | 106 EXPECT_FALSE(phone_number.IsNumber(ASCIIToUTF16(test_number))); |
132 } else { | 107 } else { |
133 EXPECT_TRUE(IsNumber(&phone_number, ASCIIToUTF16(test_number))); | 108 EXPECT_TRUE(phone_number.IsNumber(ASCIIToUTF16(test_number))); |
134 } | 109 } |
135 if (i > 3) { | 110 if (i > 3) { |
136 EXPECT_FALSE(IsCityCode(&phone_number, ASCIIToUTF16(test_number))); | 111 EXPECT_FALSE(phone_number.IsCityCode(ASCIIToUTF16(test_number))); |
137 } else { | 112 } else { |
138 EXPECT_TRUE(IsCityCode(&phone_number, ASCIIToUTF16(test_number))); | 113 EXPECT_TRUE(phone_number.IsCityCode(ASCIIToUTF16(test_number))); |
139 } | 114 } |
140 if (i > 2) { | 115 if (i > 2) { |
141 EXPECT_FALSE(IsCountryCode(&phone_number, ASCIIToUTF16(test_number))); | 116 EXPECT_FALSE(phone_number.IsCountryCode(ASCIIToUTF16(test_number))); |
142 } else { | 117 } else { |
143 EXPECT_TRUE(IsCountryCode(&phone_number, ASCIIToUTF16(test_number))); | 118 EXPECT_TRUE(phone_number.IsCountryCode(ASCIIToUTF16(test_number))); |
144 } | 119 } |
145 } | 120 } |
146 } | 121 } |
147 | 122 |
OLD | NEW |