[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] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 13 | using autofill_i18n::NormalizePhoneNumber; |
| 14 | using autofill_i18n::ParsePhoneNumber; |
| 15 | using autofill_i18n::ConstructPhoneNumber; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 16 | using autofill_i18n::PhoneNumbersMatch; |
[email protected] | 631bb74 | 2011-11-02 11:29:39 | [diff] [blame] | 17 | using content::BrowserThread; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 18 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 19 | TEST(PhoneNumberI18NTest, NormalizePhoneNumber) { |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 20 | // "Large" digits. |
| 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" |
| 23 | "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); |
| 24 | EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 25 | |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 26 | // Devanagari script digits. |
| 27 | 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 | EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 30 | |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 31 | string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); |
| 32 | EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 33 | |
| 34 | string16 phone4(UTF8ToUTF16("+1(650)2346789")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 35 | EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 36 | |
| 37 | string16 phone5(UTF8ToUTF16("6502346789")); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 38 | EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 39 | } |
| 40 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 41 | TEST(PhoneNumberI18NTest, ParsePhoneNumber) { |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 42 | string16 number; |
| 43 | string16 city_code; |
| 44 | string16 country_code; |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 45 | i18n::phonenumbers::PhoneNumber unused_i18n_number; |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 46 | |
| 47 | // Test for empty string. Should give back empty strings. |
| 48 | string16 phone0; |
| 49 | EXPECT_FALSE(ParsePhoneNumber(phone0, "US", |
| 50 | &country_code, |
| 51 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 52 | &number, |
| 53 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 54 | EXPECT_EQ(string16(), number); |
| 55 | EXPECT_EQ(string16(), city_code); |
| 56 | EXPECT_EQ(string16(), country_code); |
| 57 | |
| 58 | // Test for string with less than 7 digits. Should give back empty strings. |
| 59 | string16 phone1(ASCIIToUTF16("1234")); |
| 60 | EXPECT_FALSE(ParsePhoneNumber(phone1, "US", |
| 61 | &country_code, |
| 62 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 63 | &number, |
| 64 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 65 | EXPECT_EQ(string16(), number); |
| 66 | EXPECT_EQ(string16(), city_code); |
| 67 | EXPECT_EQ(string16(), country_code); |
| 68 | |
| 69 | // Test for string with exactly 7 digits. |
| 70 | // Not a valid number - starts with 1 |
| 71 | string16 phone2(ASCIIToUTF16("1234567")); |
| 72 | EXPECT_FALSE(ParsePhoneNumber(phone2, "US", |
| 73 | &country_code, |
| 74 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 75 | &number, |
| 76 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 77 | EXPECT_EQ(string16(), number); |
| 78 | EXPECT_EQ(string16(), city_code); |
| 79 | EXPECT_EQ(string16(), country_code); |
| 80 | |
| 81 | // Not a valid number - does not have area code. |
| 82 | string16 phone3(ASCIIToUTF16("2234567")); |
| 83 | EXPECT_FALSE(ParsePhoneNumber(phone3, "US", |
| 84 | &country_code, |
| 85 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 86 | &number, |
| 87 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 88 | EXPECT_EQ(string16(), number); |
| 89 | EXPECT_EQ(string16(), city_code); |
| 90 | EXPECT_EQ(string16(), country_code); |
| 91 | |
| 92 | // Test for string with greater than 7 digits but less than 10 digits. |
| 93 | // Should fail parsing in US. |
| 94 | string16 phone4(ASCIIToUTF16("123456789")); |
| 95 | EXPECT_FALSE(ParsePhoneNumber(phone4, "US", |
| 96 | &country_code, |
| 97 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 98 | &number, |
| 99 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 100 | EXPECT_EQ(string16(), number); |
| 101 | EXPECT_EQ(string16(), city_code); |
| 102 | EXPECT_EQ(string16(), country_code); |
| 103 | |
| 104 | // Test for string with greater than 7 digits but less than 10 digits and |
| 105 | // separators. |
| 106 | // Should fail parsing in US. |
| 107 | string16 phone_separator4(ASCIIToUTF16("12.345-6789")); |
| 108 | EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US", |
| 109 | &country_code, |
| 110 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 111 | &number, |
| 112 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 113 | EXPECT_EQ(string16(), number); |
| 114 | EXPECT_EQ(string16(), city_code); |
| 115 | EXPECT_EQ(string16(), country_code); |
| 116 | |
| 117 | // Test for string with exactly 10 digits. |
| 118 | // Should give back phone number and city code. |
| 119 | // This one going to fail because of the incorrect area code. |
| 120 | string16 phone5(ASCIIToUTF16("1234567890")); |
| 121 | EXPECT_FALSE(ParsePhoneNumber(phone5, "US", |
| 122 | &country_code, |
| 123 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 124 | &number, |
| 125 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 126 | EXPECT_EQ(string16(), number); |
| 127 | EXPECT_EQ(string16(), city_code); |
| 128 | EXPECT_EQ(string16(), country_code); |
| 129 | |
| 130 | string16 phone6(ASCIIToUTF16("6501567890")); |
| 131 | // This one going to fail because of the incorrect number (starts with 1). |
| 132 | EXPECT_FALSE(ParsePhoneNumber(phone6, "US", |
| 133 | &country_code, |
| 134 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 135 | &number, |
| 136 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 137 | EXPECT_EQ(string16(), number); |
| 138 | EXPECT_EQ(string16(), city_code); |
| 139 | EXPECT_EQ(string16(), country_code); |
| 140 | |
| 141 | string16 phone7(ASCIIToUTF16("6504567890")); |
| 142 | EXPECT_TRUE(ParsePhoneNumber(phone7, "US", |
| 143 | &country_code, |
| 144 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 145 | &number, |
| 146 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 147 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 148 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 149 | EXPECT_EQ(string16(), country_code); |
| 150 | |
| 151 | // Test for string with exactly 10 digits and separators. |
| 152 | // Should give back phone number and city code. |
| 153 | string16 phone_separator7(ASCIIToUTF16("(650) 456-7890")); |
| 154 | EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US", |
| 155 | &country_code, |
| 156 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 157 | &number, |
| 158 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 159 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 160 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 161 | EXPECT_EQ(string16(), country_code); |
| 162 | |
| 163 | // Tests for string with over 10 digits. |
| 164 | // 01 is incorrect prefix in the USA, and if we interpret 011 as prefix, the |
| 165 | // rest is too short for international number - the parsing should fail. |
| 166 | string16 phone8(ASCIIToUTF16("0116504567890")); |
| 167 | EXPECT_FALSE(ParsePhoneNumber(phone8, "US", |
| 168 | &country_code, |
| 169 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 170 | &number, |
| 171 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 172 | EXPECT_EQ(string16(), number); |
| 173 | EXPECT_EQ(string16(), city_code); |
| 174 | EXPECT_EQ(string16(), country_code); |
| 175 | |
| 176 | // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. |
| 177 | string16 phone9(ASCIIToUTF16("01116504567890")); |
| 178 | EXPECT_TRUE(ParsePhoneNumber(phone9, "US", |
| 179 | &country_code, |
| 180 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 181 | &number, |
| 182 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 183 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 184 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 185 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 186 | |
| 187 | // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. |
| 188 | string16 phone10(ASCIIToUTF16("01178124567890")); |
| 189 | EXPECT_TRUE(ParsePhoneNumber(phone10, "US", |
| 190 | &country_code, |
| 191 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 192 | &number, |
| 193 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 194 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 195 | EXPECT_EQ(ASCIIToUTF16("812"), city_code); |
| 196 | EXPECT_EQ(ASCIIToUTF16("7"), country_code); |
| 197 | |
| 198 | // Test for string with over 10 digits with separator characters. |
| 199 | // Should give back phone number, city code, and country code. "011" is |
| 200 | // US "dial out" code, which is discarded. |
| 201 | string16 phone11(ASCIIToUTF16("(0111) 650-456.7890")); |
| 202 | EXPECT_TRUE(ParsePhoneNumber(phone11, "US", |
| 203 | &country_code, |
| 204 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 205 | &number, |
| 206 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 207 | EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 208 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 209 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 210 | |
| 211 | // Now try phone from Chech republic - it has 00 dial out code, 420 country |
| 212 | // code and variable length area codes. |
| 213 | string16 phone12(ASCIIToUTF16("+420 27-89.10.112")); |
| 214 | EXPECT_TRUE(ParsePhoneNumber(phone12, "US", |
| 215 | &country_code, |
| 216 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 217 | &number, |
| 218 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 219 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 220 | EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 221 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 222 | |
| 223 | EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ", |
| 224 | &country_code, |
| 225 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 226 | &number, |
| 227 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 228 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 229 | EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 230 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 231 | |
| 232 | string16 phone13(ASCIIToUTF16("420 57-89.10.112")); |
| 233 | EXPECT_FALSE(ParsePhoneNumber(phone13, "US", |
| 234 | &country_code, |
| 235 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 236 | &number, |
| 237 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 238 | EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ", |
| 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] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 243 | EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 244 | EXPECT_EQ(ASCIIToUTF16("578"), city_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 245 | EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 246 | |
| 247 | string16 phone14(ASCIIToUTF16("1-650-FLOWERS")); |
| 248 | EXPECT_TRUE(ParsePhoneNumber(phone14, "US", |
| 249 | &country_code, |
| 250 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 251 | &number, |
| 252 | &unused_i18n_number)); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 253 | EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 254 | EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 255 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 256 | |
| 257 | // 800 is not an area code, but the destination code. In our library these |
| 258 | // codes should be treated the same as area codes. |
| 259 | string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); |
| 260 | EXPECT_TRUE(ParsePhoneNumber(phone15, "US", |
| 261 | &country_code, |
| 262 | &city_code, |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 263 | &number, |
| 264 | &unused_i18n_number)); |
[email protected] | f467247 | 2011-05-27 07:21:01 | [diff] [blame] | 265 | EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 266 | EXPECT_EQ(ASCIIToUTF16("800"), city_code); |
| 267 | EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 268 | } |
| 269 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 270 | TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 271 | string16 number; |
| 272 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 273 | ASCIIToUTF16("650"), |
| 274 | ASCIIToUTF16("2345678"), |
| 275 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 276 | &number)); |
| 277 | EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
[email protected] | 7a8edaf | 2011-11-28 20:58:48 | [diff] [blame] | 278 | EXPECT_TRUE(ConstructPhoneNumber(string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 279 | ASCIIToUTF16("650"), |
| 280 | ASCIIToUTF16("2345678"), |
| 281 | "US", |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 282 | &number)); |
| 283 | EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
| 284 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 285 | string16(), |
| 286 | ASCIIToUTF16("6502345678"), |
| 287 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 288 | &number)); |
| 289 | EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
[email protected] | 7a8edaf | 2011-11-28 20:58:48 | [diff] [blame] | 290 | EXPECT_TRUE(ConstructPhoneNumber(string16(), |
| 291 | string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 292 | ASCIIToUTF16("6502345678"), |
| 293 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 294 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 295 | EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 296 | |
[email protected] | 7a8edaf | 2011-11-28 20:58:48 | [diff] [blame] | 297 | EXPECT_FALSE(ConstructPhoneNumber(string16(), |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 298 | ASCIIToUTF16("650"), |
| 299 | ASCIIToUTF16("234567890"), |
| 300 | "US", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 301 | &number)); |
| 302 | EXPECT_EQ(number, string16()); |
| 303 | // Italian number |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 304 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"), |
| 305 | ASCIIToUTF16("347"), |
| 306 | ASCIIToUTF16("2345678"), |
| 307 | "IT", |
| 308 | &number)); |
| 309 | EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678")); |
[email protected] | 7a8edaf | 2011-11-28 20:58:48 | [diff] [blame] | 310 | EXPECT_TRUE(ConstructPhoneNumber(string16(), |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 311 | ASCIIToUTF16("347"), |
| 312 | ASCIIToUTF16("2345678"), |
| 313 | "IT", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 314 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 315 | EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 316 | // German number. |
| 317 | EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), |
| 318 | ASCIIToUTF16("024"), |
| 319 | ASCIIToUTF16("2345678901"), |
| 320 | "DE", |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 321 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 322 | EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); |
| 323 | EXPECT_TRUE(ConstructPhoneNumber(string16(), |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 324 | ASCIIToUTF16("024"), |
| 325 | ASCIIToUTF16("2345678901"), |
| 326 | "DE", |
[email protected] | 11c2bdd1 | 2011-05-23 18:24:32 | [diff] [blame] | 327 | &number)); |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 328 | EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); |
[email protected] | 5b37cb72 | 2011-05-10 18:24:56 | [diff] [blame] | 329 | } |
| 330 | |
[email protected] | 7df904d | 2013-01-15 22:33:22 | [diff] [blame] | 331 | TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 332 | // Same numbers, defined country code. |
| 333 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 334 | ASCIIToUTF16("4158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 335 | "US", |
| 336 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 337 | // Same numbers, undefined country code. |
| 338 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 339 | ASCIIToUTF16("4158889999"), |
[email protected] | 007b3f8 | 2013-04-09 08:46:45 | [diff] [blame^] | 340 | std::string(), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 341 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 342 | |
| 343 | // Numbers differ by country code only. |
| 344 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 345 | ASCIIToUTF16("4158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 346 | "US", |
| 347 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 348 | |
| 349 | // Same numbers, different formats. |
| 350 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 351 | ASCIIToUTF16("415-888-9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 352 | "US", |
| 353 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 354 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 355 | ASCIIToUTF16("(415)888-9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 356 | "US", |
| 357 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 358 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 359 | ASCIIToUTF16("415 888 9999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 360 | "US", |
| 361 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 362 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| 363 | ASCIIToUTF16("415 TUV WXYZ"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 364 | "US", |
| 365 | "en-US")); |
[email protected] | 944a5cd8 | 2011-10-19 23:42:29 | [diff] [blame] | 366 | EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("1(415)888-99-99"), |
| 367 | ASCIIToUTF16("+14158889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 368 | "US", |
| 369 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 370 | |
| 371 | // Partial matches don't count. |
| 372 | EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 373 | ASCIIToUTF16("8889999"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 374 | "US", |
| 375 | "en-US")); |
[email protected] | 944a5cd8 | 2011-10-19 23:42:29 | [diff] [blame] | 376 | |
| 377 | // Different numbers don't match. |
| 378 | EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 379 | ASCIIToUTF16("1415888"), |
[email protected] | 0b2f513b | 2013-04-05 20:13:23 | [diff] [blame] | 380 | "US", |
| 381 | "en-US")); |
[email protected] | c50a948 | 2011-05-06 22:53:34 | [diff] [blame] | 382 | } |