Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(261)

Side by Side Diff: components/autofill/browser/phone_number_i18n_unittest.cc

Issue 13488009: Remove application locale cache in autofill code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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/message_loop.h"
6 #include "base/string16.h" 6 #include "base/string16.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "components/autofill/browser/phone_number_i18n.h" 8 #include "components/autofill/browser/phone_number_i18n.h"
9 #include "content/public/test/test_browser_thread.h" 9 #include "content/public/test/test_browser_thread.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 #include "third_party/libphonenumber/src/phonenumber_api.h" 11 #include "third_party/libphonenumber/src/phonenumber_api.h"
12 12
13 using autofill_i18n::NormalizePhoneNumber; 13 using autofill_i18n::NormalizePhoneNumber;
14 using autofill_i18n::ParsePhoneNumber; 14 using autofill_i18n::ParsePhoneNumber;
15 using autofill_i18n::ConstructPhoneNumber; 15 using autofill_i18n::ConstructPhoneNumber;
16 using autofill_i18n::PhoneNumbersMatch; 16 using autofill_i18n::PhoneNumbersMatch;
17 using content::BrowserThread; 17 using content::BrowserThread;
18 18
19 TEST(PhoneNumberI18NTest, NormalizePhoneNumber) { 19 TEST(PhoneNumberI18NTest, NormalizePhoneNumber) {
20 // "Large" digits. 20 // "Large" digits.
21 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"
22 "\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"
23 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); 23 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93"));
24 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); 24 EXPECT_EQ(NormalizePhoneNumber(phone1, "US", "en-US"),
25 ASCIIToUTF16("16507498323"));
25 26
26 // Devanagari script digits. 27 // Devanagari script digits.
27 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" 28 string16 phone2(UTF8ToUTF16("\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3"
28 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9")); 29 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9"));
29 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); 30 EXPECT_EQ(NormalizePhoneNumber(phone2, "US", "en-US"),
31 ASCIIToUTF16("16508323749"));
30 32
31 string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); 33 string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5"));
32 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); 34 EXPECT_EQ(NormalizePhoneNumber(phone3, "US", "en-US"),
35 ASCIIToUTF16("16503334255"));
33 36
34 string16 phone4(UTF8ToUTF16("+1(650)2346789")); 37 string16 phone4(UTF8ToUTF16("+1(650)2346789"));
35 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); 38 EXPECT_EQ(NormalizePhoneNumber(phone4, "US", "en-US"),
39 ASCIIToUTF16("16502346789"));
36 40
37 string16 phone5(UTF8ToUTF16("6502346789")); 41 string16 phone5(UTF8ToUTF16("6502346789"));
38 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); 42 EXPECT_EQ(NormalizePhoneNumber(phone5, "US", "en-US"),
43 ASCIIToUTF16("6502346789"));
39 } 44 }
40 45
41 TEST(PhoneNumberI18NTest, ParsePhoneNumber) { 46 TEST(PhoneNumberI18NTest, ParsePhoneNumber) {
42 string16 number; 47 string16 number;
43 string16 city_code; 48 string16 city_code;
44 string16 country_code; 49 string16 country_code;
45 i18n::phonenumbers::PhoneNumber unused_i18n_number; 50 i18n::phonenumbers::PhoneNumber unused_i18n_number;
46 51
47 // Test for empty string. Should give back empty strings. 52 // Test for empty string. Should give back empty strings.
48 string16 phone0; 53 string16 phone0;
(...skipping 217 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 EXPECT_EQ(ASCIIToUTF16("800"), city_code); 271 EXPECT_EQ(ASCIIToUTF16("800"), city_code);
267 EXPECT_EQ(ASCIIToUTF16("1"), country_code); 272 EXPECT_EQ(ASCIIToUTF16("1"), country_code);
268 } 273 }
269 274
270 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { 275 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) {
271 string16 number; 276 string16 number;
272 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), 277 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"),
273 ASCIIToUTF16("650"), 278 ASCIIToUTF16("650"),
274 ASCIIToUTF16("2345678"), 279 ASCIIToUTF16("2345678"),
275 "US", 280 "US",
281 "en-US",
276 &number)); 282 &number));
277 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); 283 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678"));
278 EXPECT_TRUE(ConstructPhoneNumber(string16(), 284 EXPECT_TRUE(ConstructPhoneNumber(string16(),
279 ASCIIToUTF16("650"), 285 ASCIIToUTF16("650"),
280 ASCIIToUTF16("2345678"), 286 ASCIIToUTF16("2345678"),
281 "US", 287 "US",
288 "en-US",
282 &number)); 289 &number));
283 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); 290 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678"));
284 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), 291 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"),
285 string16(), 292 string16(),
286 ASCIIToUTF16("6502345678"), 293 ASCIIToUTF16("6502345678"),
287 "US", 294 "US",
295 "en-US",
288 &number)); 296 &number));
289 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); 297 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678"));
290 EXPECT_TRUE(ConstructPhoneNumber(string16(), 298 EXPECT_TRUE(ConstructPhoneNumber(string16(),
291 string16(), 299 string16(),
292 ASCIIToUTF16("6502345678"), 300 ASCIIToUTF16("6502345678"),
293 "US", 301 "US",
302 "en-US",
294 &number)); 303 &number));
295 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); 304 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678"));
296 305
297 EXPECT_FALSE(ConstructPhoneNumber(string16(), 306 EXPECT_FALSE(ConstructPhoneNumber(string16(),
298 ASCIIToUTF16("650"), 307 ASCIIToUTF16("650"),
299 ASCIIToUTF16("234567890"), 308 ASCIIToUTF16("234567890"),
300 "US", 309 "US",
310 "en-US",
301 &number)); 311 &number));
302 EXPECT_EQ(number, string16()); 312 EXPECT_EQ(number, string16());
303 // Italian number 313 // Italian number
304 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"), 314 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"),
305 ASCIIToUTF16("347"), 315 ASCIIToUTF16("347"),
306 ASCIIToUTF16("2345678"), 316 ASCIIToUTF16("2345678"),
307 "IT", 317 "IT",
318 "en-US",
308 &number)); 319 &number));
309 EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678")); 320 EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678"));
310 EXPECT_TRUE(ConstructPhoneNumber(string16(), 321 EXPECT_TRUE(ConstructPhoneNumber(string16(),
311 ASCIIToUTF16("347"), 322 ASCIIToUTF16("347"),
312 ASCIIToUTF16("2345678"), 323 ASCIIToUTF16("2345678"),
313 "IT", 324 "IT",
325 "en-US",
314 &number)); 326 &number));
315 EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); 327 EXPECT_EQ(number, ASCIIToUTF16("347 234 5678"));
316 // German number. 328 // German number.
317 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), 329 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"),
318 ASCIIToUTF16("024"), 330 ASCIIToUTF16("024"),
319 ASCIIToUTF16("2345678901"), 331 ASCIIToUTF16("2345678901"),
320 "DE", 332 "DE",
333 "en-US",
321 &number)); 334 &number));
322 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); 335 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901"));
323 EXPECT_TRUE(ConstructPhoneNumber(string16(), 336 EXPECT_TRUE(ConstructPhoneNumber(string16(),
324 ASCIIToUTF16("024"), 337 ASCIIToUTF16("024"),
325 ASCIIToUTF16("2345678901"), 338 ASCIIToUTF16("2345678901"),
326 "DE", 339 "DE",
340 "en-US",
327 &number)); 341 &number));
328 EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); 342 EXPECT_EQ(number, ASCIIToUTF16("02423/45678901"));
329 } 343 }
330 344
331 TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { 345 TEST(PhoneNumberI18NTest, PhoneNumbersMatch) {
332 // Same numbers, defined country code. 346 // Same numbers, defined country code.
333 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 347 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
334 ASCIIToUTF16("4158889999"), 348 ASCIIToUTF16("4158889999"),
335 "US")); 349 "US",
350 "en-US"));
336 // Same numbers, undefined country code. 351 // Same numbers, undefined country code.
337 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 352 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
338 ASCIIToUTF16("4158889999"), 353 ASCIIToUTF16("4158889999"),
339 "")); 354 "",
355 "en-US"));
340 356
341 // Numbers differ by country code only. 357 // Numbers differ by country code only.
342 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), 358 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
343 ASCIIToUTF16("4158889999"), 359 ASCIIToUTF16("4158889999"),
344 "US")); 360 "US",
361 "en-US"));
345 362
346 // Same numbers, different formats. 363 // Same numbers, different formats.
347 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 364 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
348 ASCIIToUTF16("415-888-9999"), 365 ASCIIToUTF16("415-888-9999"),
349 "US")); 366 "US",
367 "en-US"));
350 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 368 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
351 ASCIIToUTF16("(415)888-9999"), 369 ASCIIToUTF16("(415)888-9999"),
352 "US")); 370 "US",
371 "en-US"));
353 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 372 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
354 ASCIIToUTF16("415 888 9999"), 373 ASCIIToUTF16("415 888 9999"),
355 "US")); 374 "US",
375 "en-US"));
356 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), 376 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"),
357 ASCIIToUTF16("415 TUV WXYZ"), 377 ASCIIToUTF16("415 TUV WXYZ"),
358 "US")); 378 "US",
379 "en-US"));
359 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("1(415)888-99-99"), 380 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("1(415)888-99-99"),
360 ASCIIToUTF16("+14158889999"), 381 ASCIIToUTF16("+14158889999"),
361 "US")); 382 "US",
383 "en-US"));
362 384
363 // Partial matches don't count. 385 // Partial matches don't count.
364 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), 386 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
365 ASCIIToUTF16("8889999"), 387 ASCIIToUTF16("8889999"),
366 "US")); 388 "US",
389 "en-US"));
367 390
368 // Different numbers don't match. 391 // Different numbers don't match.
369 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), 392 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"),
370 ASCIIToUTF16("1415888"), 393 ASCIIToUTF16("1415888"),
371 "US")); 394 "US",
395 "en-US"));
372 } 396 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698