blob: ddb6868bd910c69af3129115de228c0c0ce41b2e [file] [log] [blame]
[email protected]a3e40032012-05-29 23:00:121// Copyright (c) 2012 The Chromium Authors. All rights reserved.
[email protected]c50a9482011-05-06 22:53:342// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
[email protected]05871b32011-10-22 00:46:185#include "base/message_loop.h"
[email protected]7a8edaf2011-11-28 20:58:486#include "base/string16.h"
[email protected]c50a9482011-05-06 22:53:347#include "base/utf_string_conversions.h"
[email protected]e4b2fa32013-03-09 22:56:568#include "components/autofill/browser/phone_number_i18n.h"
[email protected]e97882f2012-06-04 02:23:179#include "content/public/test/test_browser_thread.h"
[email protected]c50a9482011-05-06 22:53:3410#include "testing/gtest/include/gtest/gtest.h"
[email protected]7df904d2013-01-15 22:33:2211#include "third_party/libphonenumber/src/phonenumber_api.h"
[email protected]c50a9482011-05-06 22:53:3412
[email protected]631bb742011-11-02 11:29:3913using content::BrowserThread;
[email protected]5b37cb722011-05-10 18:24:5614
[email protected]e217c5632013-04-12 19:11:4815namespace autofill {
16
17using i18n::NormalizePhoneNumber;
18using i18n::ParsePhoneNumber;
19using i18n::ConstructPhoneNumber;
20using i18n::PhoneNumbersMatch;
21
[email protected]7df904d2013-01-15 22:33:2222TEST(PhoneNumberI18NTest, NormalizePhoneNumber) {
[email protected]f4672472011-05-27 07:21:0123 // "Large" digits.
[email protected]d5ca8fb2013-04-11 17:54:3124 base::string16 phone1(UTF8ToUTF16(
25 "\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90"
26 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98"
27 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93"));
[email protected]f4672472011-05-27 07:21:0128 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323"));
[email protected]5b37cb722011-05-10 18:24:5629
[email protected]f4672472011-05-27 07:21:0130 // Devanagari script digits.
[email protected]d5ca8fb2013-04-11 17:54:3131 base::string16 phone2(UTF8ToUTF16(
32 "\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3"
33 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9"));
[email protected]f4672472011-05-27 07:21:0134 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749"));
[email protected]5b37cb722011-05-10 18:24:5635
[email protected]d5ca8fb2013-04-11 17:54:3136 base::string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5"));
[email protected]f4672472011-05-27 07:21:0137 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255"));
[email protected]5b37cb722011-05-10 18:24:5638
[email protected]d5ca8fb2013-04-11 17:54:3139 base::string16 phone4(UTF8ToUTF16("+1(650)2346789"));
[email protected]f4672472011-05-27 07:21:0140 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789"));
[email protected]5b37cb722011-05-10 18:24:5641
[email protected]d5ca8fb2013-04-11 17:54:3142 base::string16 phone5(UTF8ToUTF16("6502346789"));
[email protected]f4672472011-05-27 07:21:0143 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789"));
[email protected]5b37cb722011-05-10 18:24:5644}
45
[email protected]7df904d2013-01-15 22:33:2246TEST(PhoneNumberI18NTest, ParsePhoneNumber) {
[email protected]d5ca8fb2013-04-11 17:54:3147 base::string16 number;
48 base::string16 city_code;
49 base::string16 country_code;
[email protected]e217c5632013-04-12 19:11:4850 ::i18n::phonenumbers::PhoneNumber unused_i18n_number;
[email protected]5b37cb722011-05-10 18:24:5651
52 // Test for empty string. Should give back empty strings.
[email protected]d5ca8fb2013-04-11 17:54:3153 base::string16 phone0;
[email protected]5b37cb722011-05-10 18:24:5654 EXPECT_FALSE(ParsePhoneNumber(phone0, "US",
55 &country_code,
56 &city_code,
[email protected]7df904d2013-01-15 22:33:2257 &number,
58 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:3159 EXPECT_EQ(base::string16(), number);
60 EXPECT_EQ(base::string16(), city_code);
61 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:5662
63 // Test for string with less than 7 digits. Should give back empty strings.
[email protected]d5ca8fb2013-04-11 17:54:3164 base::string16 phone1(ASCIIToUTF16("1234"));
[email protected]5b37cb722011-05-10 18:24:5665 EXPECT_FALSE(ParsePhoneNumber(phone1, "US",
66 &country_code,
67 &city_code,
[email protected]7df904d2013-01-15 22:33:2268 &number,
69 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:3170 EXPECT_EQ(base::string16(), number);
71 EXPECT_EQ(base::string16(), city_code);
72 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:5673
74 // Test for string with exactly 7 digits.
75 // Not a valid number - starts with 1
[email protected]d5ca8fb2013-04-11 17:54:3176 base::string16 phone2(ASCIIToUTF16("1234567"));
[email protected]5b37cb722011-05-10 18:24:5677 EXPECT_FALSE(ParsePhoneNumber(phone2, "US",
78 &country_code,
79 &city_code,
[email protected]7df904d2013-01-15 22:33:2280 &number,
81 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:3182 EXPECT_EQ(base::string16(), number);
83 EXPECT_EQ(base::string16(), city_code);
84 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:5685
86 // Not a valid number - does not have area code.
[email protected]d5ca8fb2013-04-11 17:54:3187 base::string16 phone3(ASCIIToUTF16("2234567"));
[email protected]5b37cb722011-05-10 18:24:5688 EXPECT_FALSE(ParsePhoneNumber(phone3, "US",
89 &country_code,
90 &city_code,
[email protected]7df904d2013-01-15 22:33:2291 &number,
92 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:3193 EXPECT_EQ(base::string16(), number);
94 EXPECT_EQ(base::string16(), city_code);
95 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:5696
97 // Test for string with greater than 7 digits but less than 10 digits.
98 // Should fail parsing in US.
[email protected]d5ca8fb2013-04-11 17:54:3199 base::string16 phone4(ASCIIToUTF16("123456789"));
[email protected]5b37cb722011-05-10 18:24:56100 EXPECT_FALSE(ParsePhoneNumber(phone4, "US",
101 &country_code,
102 &city_code,
[email protected]7df904d2013-01-15 22:33:22103 &number,
104 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:31105 EXPECT_EQ(base::string16(), number);
106 EXPECT_EQ(base::string16(), city_code);
107 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56108
109 // Test for string with greater than 7 digits but less than 10 digits and
110 // separators.
111 // Should fail parsing in US.
[email protected]d5ca8fb2013-04-11 17:54:31112 base::string16 phone_separator4(ASCIIToUTF16("12.345-6789"));
[email protected]5b37cb722011-05-10 18:24:56113 EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US",
114 &country_code,
115 &city_code,
[email protected]7df904d2013-01-15 22:33:22116 &number,
117 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:31118 EXPECT_EQ(base::string16(), number);
119 EXPECT_EQ(base::string16(), city_code);
120 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56121
122 // Test for string with exactly 10 digits.
123 // Should give back phone number and city code.
124 // This one going to fail because of the incorrect area code.
[email protected]d5ca8fb2013-04-11 17:54:31125 base::string16 phone5(ASCIIToUTF16("1234567890"));
[email protected]5b37cb722011-05-10 18:24:56126 EXPECT_FALSE(ParsePhoneNumber(phone5, "US",
127 &country_code,
128 &city_code,
[email protected]7df904d2013-01-15 22:33:22129 &number,
130 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:31131 EXPECT_EQ(base::string16(), number);
132 EXPECT_EQ(base::string16(), city_code);
133 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56134
[email protected]d5ca8fb2013-04-11 17:54:31135 base::string16 phone6(ASCIIToUTF16("6501567890"));
[email protected]5b37cb722011-05-10 18:24:56136 // This one going to fail because of the incorrect number (starts with 1).
137 EXPECT_FALSE(ParsePhoneNumber(phone6, "US",
138 &country_code,
139 &city_code,
[email protected]7df904d2013-01-15 22:33:22140 &number,
141 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:31142 EXPECT_EQ(base::string16(), number);
143 EXPECT_EQ(base::string16(), city_code);
144 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56145
[email protected]d5ca8fb2013-04-11 17:54:31146 base::string16 phone7(ASCIIToUTF16("6504567890"));
[email protected]5b37cb722011-05-10 18:24:56147 EXPECT_TRUE(ParsePhoneNumber(phone7, "US",
148 &country_code,
149 &city_code,
[email protected]7df904d2013-01-15 22:33:22150 &number,
151 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56152 EXPECT_EQ(ASCIIToUTF16("4567890"), number);
153 EXPECT_EQ(ASCIIToUTF16("650"), city_code);
[email protected]d5ca8fb2013-04-11 17:54:31154 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56155
156 // Test for string with exactly 10 digits and separators.
157 // Should give back phone number and city code.
[email protected]d5ca8fb2013-04-11 17:54:31158 base::string16 phone_separator7(ASCIIToUTF16("(650) 456-7890"));
[email protected]5b37cb722011-05-10 18:24:56159 EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US",
160 &country_code,
161 &city_code,
[email protected]7df904d2013-01-15 22:33:22162 &number,
163 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56164 EXPECT_EQ(ASCIIToUTF16("4567890"), number);
165 EXPECT_EQ(ASCIIToUTF16("650"), city_code);
[email protected]d5ca8fb2013-04-11 17:54:31166 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56167
168 // Tests for string with over 10 digits.
169 // 01 is incorrect prefix in the USA, and if we interpret 011 as prefix, the
170 // rest is too short for international number - the parsing should fail.
[email protected]d5ca8fb2013-04-11 17:54:31171 base::string16 phone8(ASCIIToUTF16("0116504567890"));
[email protected]5b37cb722011-05-10 18:24:56172 EXPECT_FALSE(ParsePhoneNumber(phone8, "US",
173 &country_code,
174 &city_code,
[email protected]7df904d2013-01-15 22:33:22175 &number,
176 &unused_i18n_number));
[email protected]d5ca8fb2013-04-11 17:54:31177 EXPECT_EQ(base::string16(), number);
178 EXPECT_EQ(base::string16(), city_code);
179 EXPECT_EQ(base::string16(), country_code);
[email protected]5b37cb722011-05-10 18:24:56180
181 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed.
[email protected]d5ca8fb2013-04-11 17:54:31182 base::string16 phone9(ASCIIToUTF16("01116504567890"));
[email protected]5b37cb722011-05-10 18:24:56183 EXPECT_TRUE(ParsePhoneNumber(phone9, "US",
184 &country_code,
185 &city_code,
[email protected]7df904d2013-01-15 22:33:22186 &number,
187 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56188 EXPECT_EQ(ASCIIToUTF16("4567890"), number);
189 EXPECT_EQ(ASCIIToUTF16("650"), city_code);
190 EXPECT_EQ(ASCIIToUTF16("1"), country_code);
191
192 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed.
[email protected]d5ca8fb2013-04-11 17:54:31193 base::string16 phone10(ASCIIToUTF16("01178124567890"));
[email protected]5b37cb722011-05-10 18:24:56194 EXPECT_TRUE(ParsePhoneNumber(phone10, "US",
195 &country_code,
196 &city_code,
[email protected]7df904d2013-01-15 22:33:22197 &number,
198 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56199 EXPECT_EQ(ASCIIToUTF16("4567890"), number);
200 EXPECT_EQ(ASCIIToUTF16("812"), city_code);
201 EXPECT_EQ(ASCIIToUTF16("7"), country_code);
202
203 // Test for string with over 10 digits with separator characters.
204 // Should give back phone number, city code, and country code. "011" is
205 // US "dial out" code, which is discarded.
[email protected]d5ca8fb2013-04-11 17:54:31206 base::string16 phone11(ASCIIToUTF16("(0111) 650-456.7890"));
[email protected]5b37cb722011-05-10 18:24:56207 EXPECT_TRUE(ParsePhoneNumber(phone11, "US",
208 &country_code,
209 &city_code,
[email protected]7df904d2013-01-15 22:33:22210 &number,
211 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56212 EXPECT_EQ(ASCIIToUTF16("4567890"), number);
213 EXPECT_EQ(ASCIIToUTF16("650"), city_code);
214 EXPECT_EQ(ASCIIToUTF16("1"), country_code);
215
216 // Now try phone from Chech republic - it has 00 dial out code, 420 country
217 // code and variable length area codes.
[email protected]d5ca8fb2013-04-11 17:54:31218 base::string16 phone12(ASCIIToUTF16("+420 27-89.10.112"));
[email protected]5b37cb722011-05-10 18:24:56219 EXPECT_TRUE(ParsePhoneNumber(phone12, "US",
220 &country_code,
221 &city_code,
[email protected]7df904d2013-01-15 22:33:22222 &number,
223 &unused_i18n_number));
[email protected]f4672472011-05-27 07:21:01224 EXPECT_EQ(ASCIIToUTF16("910112"), number);
225 EXPECT_EQ(ASCIIToUTF16("278"), city_code);
[email protected]5b37cb722011-05-10 18:24:56226 EXPECT_EQ(ASCIIToUTF16("420"), country_code);
227
228 EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ",
229 &country_code,
230 &city_code,
[email protected]7df904d2013-01-15 22:33:22231 &number,
232 &unused_i18n_number));
[email protected]f4672472011-05-27 07:21:01233 EXPECT_EQ(ASCIIToUTF16("910112"), number);
234 EXPECT_EQ(ASCIIToUTF16("278"), city_code);
[email protected]5b37cb722011-05-10 18:24:56235 EXPECT_EQ(ASCIIToUTF16("420"), country_code);
236
[email protected]d5ca8fb2013-04-11 17:54:31237 base::string16 phone13(ASCIIToUTF16("420 57-89.10.112"));
[email protected]5b37cb722011-05-10 18:24:56238 EXPECT_FALSE(ParsePhoneNumber(phone13, "US",
239 &country_code,
240 &city_code,
[email protected]7df904d2013-01-15 22:33:22241 &number,
242 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56243 EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ",
244 &country_code,
245 &city_code,
[email protected]7df904d2013-01-15 22:33:22246 &number,
247 &unused_i18n_number));
[email protected]f4672472011-05-27 07:21:01248 EXPECT_EQ(ASCIIToUTF16("910112"), number);
249 EXPECT_EQ(ASCIIToUTF16("578"), city_code);
[email protected]5b37cb722011-05-10 18:24:56250 EXPECT_EQ(ASCIIToUTF16("420"), country_code);
251
[email protected]d5ca8fb2013-04-11 17:54:31252 base::string16 phone14(ASCIIToUTF16("1-650-FLOWERS"));
[email protected]5b37cb722011-05-10 18:24:56253 EXPECT_TRUE(ParsePhoneNumber(phone14, "US",
254 &country_code,
255 &city_code,
[email protected]7df904d2013-01-15 22:33:22256 &number,
257 &unused_i18n_number));
[email protected]5b37cb722011-05-10 18:24:56258 EXPECT_EQ(ASCIIToUTF16("3569377"), number);
259 EXPECT_EQ(ASCIIToUTF16("650"), city_code);
260 EXPECT_EQ(ASCIIToUTF16("1"), country_code);
[email protected]f4672472011-05-27 07:21:01261
262 // 800 is not an area code, but the destination code. In our library these
263 // codes should be treated the same as area codes.
[email protected]d5ca8fb2013-04-11 17:54:31264 base::string16 phone15(ASCIIToUTF16("1-800-FLOWERS"));
[email protected]f4672472011-05-27 07:21:01265 EXPECT_TRUE(ParsePhoneNumber(phone15, "US",
266 &country_code,
267 &city_code,
[email protected]7df904d2013-01-15 22:33:22268 &number,
269 &unused_i18n_number));
[email protected]f4672472011-05-27 07:21:01270 EXPECT_EQ(ASCIIToUTF16("3569377"), number);
271 EXPECT_EQ(ASCIIToUTF16("800"), city_code);
272 EXPECT_EQ(ASCIIToUTF16("1"), country_code);
[email protected]5b37cb722011-05-10 18:24:56273}
274
[email protected]7df904d2013-01-15 22:33:22275TEST(PhoneNumberI18NTest, ConstructPhoneNumber) {
[email protected]d5ca8fb2013-04-11 17:54:31276 base::string16 number;
[email protected]5b37cb722011-05-10 18:24:56277 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"),
278 ASCIIToUTF16("650"),
279 ASCIIToUTF16("2345678"),
280 "US",
[email protected]5b37cb722011-05-10 18:24:56281 &number));
282 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678"));
[email protected]d5ca8fb2013-04-11 17:54:31283 EXPECT_TRUE(ConstructPhoneNumber(base::string16(),
[email protected]5b37cb722011-05-10 18:24:56284 ASCIIToUTF16("650"),
285 ASCIIToUTF16("2345678"),
286 "US",
[email protected]7df904d2013-01-15 22:33:22287 &number));
288 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678"));
289 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"),
[email protected]d5ca8fb2013-04-11 17:54:31290 base::string16(),
[email protected]7df904d2013-01-15 22:33:22291 ASCIIToUTF16("6502345678"),
292 "US",
[email protected]5b37cb722011-05-10 18:24:56293 &number));
294 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678"));
[email protected]d5ca8fb2013-04-11 17:54:31295 EXPECT_TRUE(ConstructPhoneNumber(base::string16(),
296 base::string16(),
[email protected]5b37cb722011-05-10 18:24:56297 ASCIIToUTF16("6502345678"),
298 "US",
[email protected]5b37cb722011-05-10 18:24:56299 &number));
[email protected]7df904d2013-01-15 22:33:22300 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678"));
[email protected]5b37cb722011-05-10 18:24:56301
[email protected]d5ca8fb2013-04-11 17:54:31302 EXPECT_FALSE(ConstructPhoneNumber(base::string16(),
[email protected]5b37cb722011-05-10 18:24:56303 ASCIIToUTF16("650"),
304 ASCIIToUTF16("234567890"),
305 "US",
[email protected]5b37cb722011-05-10 18:24:56306 &number));
[email protected]d5ca8fb2013-04-11 17:54:31307 EXPECT_EQ(number, base::string16());
[email protected]5b37cb722011-05-10 18:24:56308 // Italian number
[email protected]7df904d2013-01-15 22:33:22309 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"),
310 ASCIIToUTF16("347"),
311 ASCIIToUTF16("2345678"),
312 "IT",
313 &number));
314 EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678"));
[email protected]d5ca8fb2013-04-11 17:54:31315 EXPECT_TRUE(ConstructPhoneNumber(base::string16(),
[email protected]11c2bdd12011-05-23 18:24:32316 ASCIIToUTF16("347"),
317 ASCIIToUTF16("2345678"),
318 "IT",
[email protected]5b37cb722011-05-10 18:24:56319 &number));
[email protected]7df904d2013-01-15 22:33:22320 EXPECT_EQ(number, ASCIIToUTF16("347 234 5678"));
[email protected]11c2bdd12011-05-23 18:24:32321 // German number.
322 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"),
323 ASCIIToUTF16("024"),
324 ASCIIToUTF16("2345678901"),
325 "DE",
[email protected]5b37cb722011-05-10 18:24:56326 &number));
[email protected]7df904d2013-01-15 22:33:22327 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901"));
[email protected]d5ca8fb2013-04-11 17:54:31328 EXPECT_TRUE(ConstructPhoneNumber(base::string16(),
[email protected]11c2bdd12011-05-23 18:24:32329 ASCIIToUTF16("024"),
330 ASCIIToUTF16("2345678901"),
331 "DE",
[email protected]11c2bdd12011-05-23 18:24:32332 &number));
[email protected]7df904d2013-01-15 22:33:22333 EXPECT_EQ(number, ASCIIToUTF16("02423/45678901"));
[email protected]5b37cb722011-05-10 18:24:56334}
335
[email protected]7df904d2013-01-15 22:33:22336TEST(PhoneNumberI18NTest, PhoneNumbersMatch) {
[email protected]c50a9482011-05-06 22:53:34337 // Same numbers, defined country code.
338 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
339 ASCIIToUTF16("4158889999"),
[email protected]0b2f513b2013-04-05 20:13:23340 "US",
341 "en-US"));
[email protected]c50a9482011-05-06 22:53:34342 // Same numbers, undefined country code.
343 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
344 ASCIIToUTF16("4158889999"),
[email protected]007b3f82013-04-09 08:46:45345 std::string(),
[email protected]0b2f513b2013-04-05 20:13:23346 "en-US"));
[email protected]c50a9482011-05-06 22:53:34347
348 // Numbers differ by country code only.
349 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
350 ASCIIToUTF16("4158889999"),
[email protected]0b2f513b2013-04-05 20:13:23351 "US",
352 "en-US"));
[email protected]c50a9482011-05-06 22:53:34353
354 // Same numbers, different formats.
355 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
356 ASCIIToUTF16("415-888-9999"),
[email protected]0b2f513b2013-04-05 20:13:23357 "US",
358 "en-US"));
[email protected]c50a9482011-05-06 22:53:34359 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
360 ASCIIToUTF16("(415)888-9999"),
[email protected]0b2f513b2013-04-05 20:13:23361 "US",
362 "en-US"));
[email protected]c50a9482011-05-06 22:53:34363 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
364 ASCIIToUTF16("415 888 9999"),
[email protected]0b2f513b2013-04-05 20:13:23365 "US",
366 "en-US"));
[email protected]c50a9482011-05-06 22:53:34367 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
368 ASCIIToUTF16("415 TUV WXYZ"),
[email protected]0b2f513b2013-04-05 20:13:23369 "US",
370 "en-US"));
[email protected]944a5cd82011-10-19 23:42:29371 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("1(415)888-99-99"),
372 ASCIIToUTF16("+14158889999"),
[email protected]0b2f513b2013-04-05 20:13:23373 "US",
374 "en-US"));
[email protected]c50a9482011-05-06 22:53:34375
376 // Partial matches don't count.
377 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
378 ASCIIToUTF16("8889999"),
[email protected]0b2f513b2013-04-05 20:13:23379 "US",
380 "en-US"));
[email protected]944a5cd82011-10-19 23:42:29381
382 // Different numbers don't match.
383 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
384 ASCIIToUTF16("1415888"),
[email protected]0b2f513b2013-04-05 20:13:23385 "US",
386 "en-US"));
[email protected]c50a9482011-05-06 22:53:34387}
[email protected]e217c5632013-04-12 19:11:48388
389} // namespace autofill