OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include "base/macros.h" | 7 #include "base/macros.h" |
8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
(...skipping 106 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
117 // Parses vanity numbers. | 117 // Parses vanity numbers. |
118 {true, "1-650-FLOWERS", "US", "3569377", "650", "1", "US"}, | 118 {true, "1-650-FLOWERS", "US", "3569377", "650", "1", "US"}, |
119 // 800 is not an area code, but the destination code. In our library | 119 // 800 is not an area code, but the destination code. In our library |
120 // these | 120 // these |
121 // codes should be treated the same as area codes. | 121 // codes should be treated the same as area codes. |
122 {true, "1-800-FLOWERS", "US", "3569377", "800", "1", "US"}, | 122 {true, "1-800-FLOWERS", "US", "3569377", "800", "1", "US"}, |
123 // Don't add a country code where there was none. | 123 // Don't add a country code where there was none. |
124 {true, "(08) 450 777 7777", "DE", "7777777", "8450", "", "DE"}, | 124 {true, "(08) 450 777 7777", "DE", "7777777", "8450", "", "DE"}, |
125 }; | 125 }; |
126 | 126 |
127 for (const auto& test_case : test_cases) { | 127 for (size_t i = 0; i < arraysize(test_cases); ++i) { |
128 SCOPED_TRACE("Testing phone number " + test_case.input); | 128 SCOPED_TRACE("Testing phone number " + test_cases[i].input); |
129 | 129 |
130 base::string16 country_code, city_code, number; | 130 base::string16 country_code, city_code, number; |
131 std::string deduced_region; | 131 std::string deduced_region; |
132 ::i18n::phonenumbers::PhoneNumber unused_i18n_number; | 132 ::i18n::phonenumbers::PhoneNumber unused_i18n_number; |
133 EXPECT_EQ( | 133 EXPECT_EQ(test_cases[i].valid, |
134 test_case.valid, | 134 ParsePhoneNumber(ASCIIToUTF16(test_cases[i].input), |
135 ParsePhoneNumber(ASCIIToUTF16(test_case.input), | 135 test_cases[i].assumed_region, |
136 test_case.assumed_region, &country_code, &city_code, | 136 &country_code, |
137 &number, &deduced_region, &unused_i18n_number)); | 137 &city_code, |
138 EXPECT_EQ(ASCIIToUTF16(test_case.number), number); | 138 &number, |
139 EXPECT_EQ(ASCIIToUTF16(test_case.city_code), city_code); | 139 &deduced_region, |
140 EXPECT_EQ(ASCIIToUTF16(test_case.country_code), country_code); | 140 &unused_i18n_number)); |
141 EXPECT_EQ(test_case.deduced_region, deduced_region); | 141 EXPECT_EQ(ASCIIToUTF16(test_cases[i].number), number); |
| 142 EXPECT_EQ(ASCIIToUTF16(test_cases[i].city_code), city_code); |
| 143 EXPECT_EQ(ASCIIToUTF16(test_cases[i].country_code), country_code); |
| 144 EXPECT_EQ(test_cases[i].deduced_region, deduced_region); |
142 } | 145 } |
143 } | 146 } |
144 | 147 |
145 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { | 148 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { |
146 base::string16 number; | 149 base::string16 number; |
147 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), | 150 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
148 ASCIIToUTF16("650"), | 151 ASCIIToUTF16("650"), |
149 ASCIIToUTF16("2345678"), | 152 ASCIIToUTF16("2345678"), |
150 "US", | 153 "US", |
151 &number)); | 154 &number)); |
(...skipping 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
250 "en-US")); | 253 "en-US")); |
251 | 254 |
252 // Different numbers don't match. | 255 // Different numbers don't match. |
253 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 256 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
254 ASCIIToUTF16("1415888"), | 257 ASCIIToUTF16("1415888"), |
255 "US", | 258 "US", |
256 "en-US")); | 259 "en-US")); |
257 } | 260 } |
258 | 261 |
259 } // namespace autofill | 262 } // namespace autofill |
OLD | NEW |