[email protected] | a3e4003 | 2012-05-29 23:00:12 | [diff] [blame] | 1 | // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
[email protected] | 05871b3 | 2011-10-22 00:46:18 | [diff] [blame] | 5 | #include "base/message_loop.h" |
[email protected] | 7a8edaf | 2011-11-28 20:58:48 | [diff] [blame] | 6 | #include "base/string16.h" |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 7 | #include "base/utf_string_conversions.h" |
[email protected] | e4b2fa3 | 2013-03-09 22:56:56 | [diff] [blame] | 8 | #include "components/autofill/browser/phone_number_i18n.h" |
[email protected] | e97882f | 2012-06-04 02:23:17 | [diff] [blame] | 9 | #include "content/public/test/test_browser_thread.h" |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 10 | #include "testing/gtest/include/gtest/gtest.h" |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 11 | #include "third_party/libphonenumber/src/phonenumber_api.h" |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 12 | |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 13 | using content::BrowserThread; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 14 | |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 15 | namespace autofill { |
| 16 | |
| 17 | using i18n::NormalizePhoneNumber; |
| 18 | using i18n::ParsePhoneNumber; |
| 19 | using i18n::ConstructPhoneNumber; |
| 20 | using i18n::PhoneNumbersMatch; |
| 21 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 22 | TEST(PhoneNumberI18NTest, NormalizePhoneNumber) { |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 23 | // "Large" digits. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 24 | 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] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 28 | EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 29 | |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 30 | // Devanagari script digits. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 31 | 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] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 34 | EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 35 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 36 | base::string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 37 | EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 38 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 39 | base::string16 phone4(UTF8ToUTF16("+1(650)2346789")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 40 | EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 41 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 42 | base::string16 phone5(UTF8ToUTF16("6502346789")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 43 | EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 44 | } |
| 45 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 46 | TEST(PhoneNumberI18NTest, ParsePhoneNumber) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 47 | base::string16 number; |
| 48 | base::string16 city_code; |
| 49 | base::string16 country_code; |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 50 | ::i18n::phonenumbers::PhoneNumber unused_i18n_number; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 51 | |
| 52 | // Test for empty string. Should give back empty strings. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 53 | base::string16 phone0; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 54 | EXPECT_FALSE(ParsePhoneNumber(phone0, "US", |
| 55 | &country_code, |
| 56 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 57 | &number, |
| 58 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 59 | EXPECT_EQ(base::string16(), number); |
| 60 | EXPECT_EQ(base::string16(), city_code); |
| 61 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 62 | |
| 63 | // Test for string with less than 7 digits. Should give back empty strings. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 64 | base::string16 phone1(ASCIIToUTF16("1234")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 65 | EXPECT_FALSE(ParsePhoneNumber(phone1, "US", |
| 66 | &country_code, |
| 67 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 68 | &number, |
| 69 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 70 | EXPECT_EQ(base::string16(), number); |
| 71 | EXPECT_EQ(base::string16(), city_code); |
| 72 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 73 | |
| 74 | // Test for string with exactly 7 digits. |
| 75 | // Not a valid number - starts with 1 |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 76 | base::string16 phone2(ASCIIToUTF16("1234567")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 77 | EXPECT_FALSE(ParsePhoneNumber(phone2, "US", |
| 78 | &country_code, |
| 79 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 80 | &number, |
| 81 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 82 | EXPECT_EQ(base::string16(), number); |
| 83 | EXPECT_EQ(base::string16(), city_code); |
| 84 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 85 | |
| 86 | // Not a valid number - does not have area code. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 87 | base::string16 phone3(ASCIIToUTF16("2234567")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 88 | EXPECT_FALSE(ParsePhoneNumber(phone3, "US", |
| 89 | &country_code, |
| 90 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 91 | &number, |
| 92 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 93 | EXPECT_EQ(base::string16(), number); |
| 94 | EXPECT_EQ(base::string16(), city_code); |
| 95 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 96 | |
| 97 | // Test for string with greater than 7 digits but less than 10 digits. |
| 98 | // Should fail parsing in US. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 99 | base::string16 phone4(ASCIIToUTF16("123456789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 100 | EXPECT_FALSE(ParsePhoneNumber(phone4, "US", |
| 101 | &country_code, |
| 102 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 103 | &number, |
| 104 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 105 | EXPECT_EQ(base::string16(), number); |
| 106 | EXPECT_EQ(base::string16(), city_code); |
| 107 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 108 | |
| 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 112 | base::string16 phone_separator4(ASCIIToUTF16("12.345-6789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 113 | EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US", |
| 114 | &country_code, |
| 115 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 116 | &number, |
| 117 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 118 | EXPECT_EQ(base::string16(), number); |
| 119 | EXPECT_EQ(base::string16(), city_code); |
| 120 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 121 | |
| 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 125 | base::string16 phone5(ASCIIToUTF16("1234567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 126 | EXPECT_FALSE(ParsePhoneNumber(phone5, "US", |
| 127 | &country_code, |
| 128 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 129 | &number, |
| 130 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 131 | EXPECT_EQ(base::string16(), number); |
| 132 | EXPECT_EQ(base::string16(), city_code); |
| 133 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 134 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 135 | base::string16 phone6(ASCIIToUTF16("6501567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 136 | // 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] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 140 | &number, |
| 141 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 142 | EXPECT_EQ(base::string16(), number); |
| 143 | EXPECT_EQ(base::string16(), city_code); |
| 144 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 145 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 146 | base::string16 phone7(ASCIIToUTF16("6504567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 147 | EXPECT_TRUE(ParsePhoneNumber(phone7, "US", |
| 148 | &country_code, |
| 149 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 150 | &number, |
| 151 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 152 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 153 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 154 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 155 | |
| 156 | // Test for string with exactly 10 digits and separators. |
| 157 | // Should give back phone number and city code. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 158 | base::string16 phone_separator7(ASCIIToUTF16("(650) 456-7890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 159 | EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US", |
| 160 | &country_code, |
| 161 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 162 | &number, |
| 163 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 164 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 165 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 166 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 167 | |
| 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 171 | base::string16 phone8(ASCIIToUTF16("0116504567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 172 | EXPECT_FALSE(ParsePhoneNumber(phone8, "US", |
| 173 | &country_code, |
| 174 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 175 | &number, |
| 176 | &unused_i18n_number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 177 | EXPECT_EQ(base::string16(), number); |
| 178 | EXPECT_EQ(base::string16(), city_code); |
| 179 | EXPECT_EQ(base::string16(), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 180 | |
| 181 | // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 182 | base::string16 phone9(ASCIIToUTF16("01116504567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 183 | EXPECT_TRUE(ParsePhoneNumber(phone9, "US", |
| 184 | &country_code, |
| 185 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 186 | &number, |
| 187 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 188 | 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 193 | base::string16 phone10(ASCIIToUTF16("01178124567890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 194 | EXPECT_TRUE(ParsePhoneNumber(phone10, "US", |
| 195 | &country_code, |
| 196 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 197 | &number, |
| 198 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 199 | 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 206 | base::string16 phone11(ASCIIToUTF16("(0111) 650-456.7890")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 207 | EXPECT_TRUE(ParsePhoneNumber(phone11, "US", |
| 208 | &country_code, |
| 209 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 210 | &number, |
| 211 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 212 | 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 218 | base::string16 phone12(ASCIIToUTF16("+420 27-89.10.112")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 219 | EXPECT_TRUE(ParsePhoneNumber(phone12, "US", |
| 220 | &country_code, |
| 221 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 222 | &number, |
| 223 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 224 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 225 | EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 226 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 227 | |
| 228 | EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ", |
| 229 | &country_code, |
| 230 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 231 | &number, |
| 232 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 233 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 234 | EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 235 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 236 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 237 | base::string16 phone13(ASCIIToUTF16("420 57-89.10.112")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 238 | EXPECT_FALSE(ParsePhoneNumber(phone13, "US", |
| 239 | &country_code, |
| 240 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 241 | &number, |
| 242 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 243 | EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ", |
| 244 | &country_code, |
| 245 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 246 | &number, |
| 247 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 248 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 249 | EXPECT_EQ(ASCIIToUTF16("578"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 250 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 251 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 252 | base::string16 phone14(ASCIIToUTF16("1-650-FLOWERS")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 253 | EXPECT_TRUE(ParsePhoneNumber(phone14, "US", |
| 254 | &country_code, |
| 255 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 256 | &number, |
| 257 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 258 | EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 259 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 260 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 261 | |
| 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 264 | base::string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 265 | EXPECT_TRUE(ParsePhoneNumber(phone15, "US", |
| 266 | &country_code, |
| 267 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 268 | &number, |
| 269 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 270 | EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 271 | EXPECT_EQ(ASCIIToUTF16("800"), city_code); |
| 272 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 273 | } |
| 274 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 275 | TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 276 | base::string16 number; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 277 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 278 | ASCIIToUTF16("650"), |
| 279 | ASCIIToUTF16("2345678"), |
| 280 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 281 | &number)); |
| 282 | EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 283 | EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 284 | ASCIIToUTF16("650"), |
| 285 | ASCIIToUTF16("2345678"), |
| 286 | "US", |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 287 | &number)); |
| 288 | EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
| 289 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 290 | base::string16(), |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 291 | ASCIIToUTF16("6502345678"), |
| 292 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 293 | &number)); |
| 294 | EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 295 | EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
| 296 | base::string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 297 | ASCIIToUTF16("6502345678"), |
| 298 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 299 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 300 | EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 301 | |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 302 | EXPECT_FALSE(ConstructPhoneNumber(base::string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 303 | ASCIIToUTF16("650"), |
| 304 | ASCIIToUTF16("234567890"), |
| 305 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 306 | &number)); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 307 | EXPECT_EQ(number, base::string16()); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 308 | // Italian number |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 309 | 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] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 315 | EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 316 | ASCIIToUTF16("347"), |
| 317 | ASCIIToUTF16("2345678"), |
| 318 | "IT", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 319 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 320 | EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 321 | // German number. |
| 322 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), |
| 323 | ASCIIToUTF16("024"), |
| 324 | ASCIIToUTF16("2345678901"), |
| 325 | "DE", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 326 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 327 | EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); |
[email protected] | d5ca8fb | 2013-04-11 17:54:31 | [diff] [blame] | 328 | EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 329 | ASCIIToUTF16("024"), |
| 330 | ASCIIToUTF16("2345678901"), |
| 331 | "DE", |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 332 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 333 | EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 334 | } |
| 335 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 336 | TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 337 | // Same numbers, defined country code. |
| 338 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 339 | ASCIIToUTF16("4158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 340 | "US", |
| 341 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 342 | // Same numbers, undefined country code. |
| 343 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 344 | ASCIIToUTF16("4158889999"), |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame] | 345 | std::string(), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 346 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 347 | |
| 348 | // Numbers differ by country code only. |
| 349 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 350 | ASCIIToUTF16("4158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 351 | "US", |
| 352 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 353 | |
| 354 | // Same numbers, different formats. |
| 355 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 356 | ASCIIToUTF16("415-888-9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 357 | "US", |
| 358 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 359 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 360 | ASCIIToUTF16("(415)888-9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 361 | "US", |
| 362 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 363 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 364 | ASCIIToUTF16("415 888 9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 365 | "US", |
| 366 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 367 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 368 | ASCIIToUTF16("415 TUV WXYZ"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 369 | "US", |
| 370 | "en-US")); |
[email protected] | 944a5cd8 | 2011-10-19 23:42:29 | [diff] [blame] | 371 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("1(415)888-99-99"), |
| 372 | ASCIIToUTF16("+14158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 373 | "US", |
| 374 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 375 | |
| 376 | // Partial matches don't count. |
| 377 | EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 378 | ASCIIToUTF16("8889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 379 | "US", |
| 380 | "en-US")); |
[email protected] | 944a5cd8 | 2011-10-19 23:42:29 | [diff] [blame] | 381 | |
| 382 | // Different numbers don't match. |
| 383 | EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 384 | ASCIIToUTF16("1415888"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 385 | "US", |
| 386 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 387 | } |
[email protected] | e217c563 | 2013-04-12 19:11:48 | [diff] [blame^] | 388 | |
| 389 | } // namespace autofill |