| OLD | NEW |
| 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 base::string16 phone1(UTF8ToUTF16( |
| 22 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" | 22 "\xEF\xBC\x91\xEF\xBC\x96\xEF\xBC\x95\xEF\xBC\x90" |
| 23 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); | 23 "\xEF\xBC\x97\xEF\xBC\x94\xEF\xBC\x99\xEF\xBC\x98" |
| 24 "\xEF\xBC\x93\xEF\xBC\x92\xEF\xBC\x93")); |
| 24 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), ASCIIToUTF16("16507498323")); | 25 EXPECT_EQ(NormalizePhoneNumber(phone1, "US"), 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 base::string16 phone2(UTF8ToUTF16( |
| 28 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9")); | 29 "\xD9\xA1\xD9\xA6\xD9\xA5\xD9\xA0\xD9\xA8\xD9\xA3" |
| 30 "\xD9\xA2\xD9\xA3\xD9\xA7\xD9\xA4\xD9\xA9")); |
| 29 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); | 31 EXPECT_EQ(NormalizePhoneNumber(phone2, "US"), ASCIIToUTF16("16508323749")); |
| 30 | 32 |
| 31 string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); | 33 base::string16 phone3(UTF8ToUTF16("16503334\xef\xbc\x92\x35\xd9\xa5")); |
| 32 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); | 34 EXPECT_EQ(NormalizePhoneNumber(phone3, "US"), ASCIIToUTF16("16503334255")); |
| 33 | 35 |
| 34 string16 phone4(UTF8ToUTF16("+1(650)2346789")); | 36 base::string16 phone4(UTF8ToUTF16("+1(650)2346789")); |
| 35 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); | 37 EXPECT_EQ(NormalizePhoneNumber(phone4, "US"), ASCIIToUTF16("16502346789")); |
| 36 | 38 |
| 37 string16 phone5(UTF8ToUTF16("6502346789")); | 39 base::string16 phone5(UTF8ToUTF16("6502346789")); |
| 38 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); | 40 EXPECT_EQ(NormalizePhoneNumber(phone5, "US"), ASCIIToUTF16("6502346789")); |
| 39 } | 41 } |
| 40 | 42 |
| 41 TEST(PhoneNumberI18NTest, ParsePhoneNumber) { | 43 TEST(PhoneNumberI18NTest, ParsePhoneNumber) { |
| 42 string16 number; | 44 base::string16 number; |
| 43 string16 city_code; | 45 base::string16 city_code; |
| 44 string16 country_code; | 46 base::string16 country_code; |
| 45 i18n::phonenumbers::PhoneNumber unused_i18n_number; | 47 i18n::phonenumbers::PhoneNumber unused_i18n_number; |
| 46 | 48 |
| 47 // Test for empty string. Should give back empty strings. | 49 // Test for empty string. Should give back empty strings. |
| 48 string16 phone0; | 50 base::string16 phone0; |
| 49 EXPECT_FALSE(ParsePhoneNumber(phone0, "US", | 51 EXPECT_FALSE(ParsePhoneNumber(phone0, "US", |
| 50 &country_code, | 52 &country_code, |
| 51 &city_code, | 53 &city_code, |
| 52 &number, | 54 &number, |
| 53 &unused_i18n_number)); | 55 &unused_i18n_number)); |
| 54 EXPECT_EQ(string16(), number); | 56 EXPECT_EQ(base::string16(), number); |
| 55 EXPECT_EQ(string16(), city_code); | 57 EXPECT_EQ(base::string16(), city_code); |
| 56 EXPECT_EQ(string16(), country_code); | 58 EXPECT_EQ(base::string16(), country_code); |
| 57 | 59 |
| 58 // Test for string with less than 7 digits. Should give back empty strings. | 60 // Test for string with less than 7 digits. Should give back empty strings. |
| 59 string16 phone1(ASCIIToUTF16("1234")); | 61 base::string16 phone1(ASCIIToUTF16("1234")); |
| 60 EXPECT_FALSE(ParsePhoneNumber(phone1, "US", | 62 EXPECT_FALSE(ParsePhoneNumber(phone1, "US", |
| 61 &country_code, | 63 &country_code, |
| 62 &city_code, | 64 &city_code, |
| 63 &number, | 65 &number, |
| 64 &unused_i18n_number)); | 66 &unused_i18n_number)); |
| 65 EXPECT_EQ(string16(), number); | 67 EXPECT_EQ(base::string16(), number); |
| 66 EXPECT_EQ(string16(), city_code); | 68 EXPECT_EQ(base::string16(), city_code); |
| 67 EXPECT_EQ(string16(), country_code); | 69 EXPECT_EQ(base::string16(), country_code); |
| 68 | 70 |
| 69 // Test for string with exactly 7 digits. | 71 // Test for string with exactly 7 digits. |
| 70 // Not a valid number - starts with 1 | 72 // Not a valid number - starts with 1 |
| 71 string16 phone2(ASCIIToUTF16("1234567")); | 73 base::string16 phone2(ASCIIToUTF16("1234567")); |
| 72 EXPECT_FALSE(ParsePhoneNumber(phone2, "US", | 74 EXPECT_FALSE(ParsePhoneNumber(phone2, "US", |
| 73 &country_code, | 75 &country_code, |
| 74 &city_code, | 76 &city_code, |
| 75 &number, | 77 &number, |
| 76 &unused_i18n_number)); | 78 &unused_i18n_number)); |
| 77 EXPECT_EQ(string16(), number); | 79 EXPECT_EQ(base::string16(), number); |
| 78 EXPECT_EQ(string16(), city_code); | 80 EXPECT_EQ(base::string16(), city_code); |
| 79 EXPECT_EQ(string16(), country_code); | 81 EXPECT_EQ(base::string16(), country_code); |
| 80 | 82 |
| 81 // Not a valid number - does not have area code. | 83 // Not a valid number - does not have area code. |
| 82 string16 phone3(ASCIIToUTF16("2234567")); | 84 base::string16 phone3(ASCIIToUTF16("2234567")); |
| 83 EXPECT_FALSE(ParsePhoneNumber(phone3, "US", | 85 EXPECT_FALSE(ParsePhoneNumber(phone3, "US", |
| 84 &country_code, | 86 &country_code, |
| 85 &city_code, | 87 &city_code, |
| 86 &number, | 88 &number, |
| 87 &unused_i18n_number)); | 89 &unused_i18n_number)); |
| 88 EXPECT_EQ(string16(), number); | 90 EXPECT_EQ(base::string16(), number); |
| 89 EXPECT_EQ(string16(), city_code); | 91 EXPECT_EQ(base::string16(), city_code); |
| 90 EXPECT_EQ(string16(), country_code); | 92 EXPECT_EQ(base::string16(), country_code); |
| 91 | 93 |
| 92 // Test for string with greater than 7 digits but less than 10 digits. | 94 // Test for string with greater than 7 digits but less than 10 digits. |
| 93 // Should fail parsing in US. | 95 // Should fail parsing in US. |
| 94 string16 phone4(ASCIIToUTF16("123456789")); | 96 base::string16 phone4(ASCIIToUTF16("123456789")); |
| 95 EXPECT_FALSE(ParsePhoneNumber(phone4, "US", | 97 EXPECT_FALSE(ParsePhoneNumber(phone4, "US", |
| 96 &country_code, | 98 &country_code, |
| 97 &city_code, | 99 &city_code, |
| 98 &number, | 100 &number, |
| 99 &unused_i18n_number)); | 101 &unused_i18n_number)); |
| 100 EXPECT_EQ(string16(), number); | 102 EXPECT_EQ(base::string16(), number); |
| 101 EXPECT_EQ(string16(), city_code); | 103 EXPECT_EQ(base::string16(), city_code); |
| 102 EXPECT_EQ(string16(), country_code); | 104 EXPECT_EQ(base::string16(), country_code); |
| 103 | 105 |
| 104 // Test for string with greater than 7 digits but less than 10 digits and | 106 // Test for string with greater than 7 digits but less than 10 digits and |
| 105 // separators. | 107 // separators. |
| 106 // Should fail parsing in US. | 108 // Should fail parsing in US. |
| 107 string16 phone_separator4(ASCIIToUTF16("12.345-6789")); | 109 base::string16 phone_separator4(ASCIIToUTF16("12.345-6789")); |
| 108 EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US", | 110 EXPECT_FALSE(ParsePhoneNumber(phone_separator4, "US", |
| 109 &country_code, | 111 &country_code, |
| 110 &city_code, | 112 &city_code, |
| 111 &number, | 113 &number, |
| 112 &unused_i18n_number)); | 114 &unused_i18n_number)); |
| 113 EXPECT_EQ(string16(), number); | 115 EXPECT_EQ(base::string16(), number); |
| 114 EXPECT_EQ(string16(), city_code); | 116 EXPECT_EQ(base::string16(), city_code); |
| 115 EXPECT_EQ(string16(), country_code); | 117 EXPECT_EQ(base::string16(), country_code); |
| 116 | 118 |
| 117 // Test for string with exactly 10 digits. | 119 // Test for string with exactly 10 digits. |
| 118 // Should give back phone number and city code. | 120 // Should give back phone number and city code. |
| 119 // This one going to fail because of the incorrect area code. | 121 // This one going to fail because of the incorrect area code. |
| 120 string16 phone5(ASCIIToUTF16("1234567890")); | 122 base::string16 phone5(ASCIIToUTF16("1234567890")); |
| 121 EXPECT_FALSE(ParsePhoneNumber(phone5, "US", | 123 EXPECT_FALSE(ParsePhoneNumber(phone5, "US", |
| 122 &country_code, | 124 &country_code, |
| 123 &city_code, | 125 &city_code, |
| 124 &number, | 126 &number, |
| 125 &unused_i18n_number)); | 127 &unused_i18n_number)); |
| 126 EXPECT_EQ(string16(), number); | 128 EXPECT_EQ(base::string16(), number); |
| 127 EXPECT_EQ(string16(), city_code); | 129 EXPECT_EQ(base::string16(), city_code); |
| 128 EXPECT_EQ(string16(), country_code); | 130 EXPECT_EQ(base::string16(), country_code); |
| 129 | 131 |
| 130 string16 phone6(ASCIIToUTF16("6501567890")); | 132 base::string16 phone6(ASCIIToUTF16("6501567890")); |
| 131 // This one going to fail because of the incorrect number (starts with 1). | 133 // This one going to fail because of the incorrect number (starts with 1). |
| 132 EXPECT_FALSE(ParsePhoneNumber(phone6, "US", | 134 EXPECT_FALSE(ParsePhoneNumber(phone6, "US", |
| 133 &country_code, | 135 &country_code, |
| 134 &city_code, | 136 &city_code, |
| 135 &number, | 137 &number, |
| 136 &unused_i18n_number)); | 138 &unused_i18n_number)); |
| 137 EXPECT_EQ(string16(), number); | 139 EXPECT_EQ(base::string16(), number); |
| 138 EXPECT_EQ(string16(), city_code); | 140 EXPECT_EQ(base::string16(), city_code); |
| 139 EXPECT_EQ(string16(), country_code); | 141 EXPECT_EQ(base::string16(), country_code); |
| 140 | 142 |
| 141 string16 phone7(ASCIIToUTF16("6504567890")); | 143 base::string16 phone7(ASCIIToUTF16("6504567890")); |
| 142 EXPECT_TRUE(ParsePhoneNumber(phone7, "US", | 144 EXPECT_TRUE(ParsePhoneNumber(phone7, "US", |
| 143 &country_code, | 145 &country_code, |
| 144 &city_code, | 146 &city_code, |
| 145 &number, | 147 &number, |
| 146 &unused_i18n_number)); | 148 &unused_i18n_number)); |
| 147 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 149 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 148 EXPECT_EQ(ASCIIToUTF16("650"), city_code); | 150 EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 149 EXPECT_EQ(string16(), country_code); | 151 EXPECT_EQ(base::string16(), country_code); |
| 150 | 152 |
| 151 // Test for string with exactly 10 digits and separators. | 153 // Test for string with exactly 10 digits and separators. |
| 152 // Should give back phone number and city code. | 154 // Should give back phone number and city code. |
| 153 string16 phone_separator7(ASCIIToUTF16("(650) 456-7890")); | 155 base::string16 phone_separator7(ASCIIToUTF16("(650) 456-7890")); |
| 154 EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US", | 156 EXPECT_TRUE(ParsePhoneNumber(phone_separator7, "US", |
| 155 &country_code, | 157 &country_code, |
| 156 &city_code, | 158 &city_code, |
| 157 &number, | 159 &number, |
| 158 &unused_i18n_number)); | 160 &unused_i18n_number)); |
| 159 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 161 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 160 EXPECT_EQ(ASCIIToUTF16("650"), city_code); | 162 EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 161 EXPECT_EQ(string16(), country_code); | 163 EXPECT_EQ(base::string16(), country_code); |
| 162 | 164 |
| 163 // Tests for string with over 10 digits. | 165 // Tests for string with over 10 digits. |
| 164 // 01 is incorrect prefix in the USA, and if we interpret 011 as prefix, the | 166 // 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. | 167 // rest is too short for international number - the parsing should fail. |
| 166 string16 phone8(ASCIIToUTF16("0116504567890")); | 168 base::string16 phone8(ASCIIToUTF16("0116504567890")); |
| 167 EXPECT_FALSE(ParsePhoneNumber(phone8, "US", | 169 EXPECT_FALSE(ParsePhoneNumber(phone8, "US", |
| 168 &country_code, | 170 &country_code, |
| 169 &city_code, | 171 &city_code, |
| 170 &number, | 172 &number, |
| 171 &unused_i18n_number)); | 173 &unused_i18n_number)); |
| 172 EXPECT_EQ(string16(), number); | 174 EXPECT_EQ(base::string16(), number); |
| 173 EXPECT_EQ(string16(), city_code); | 175 EXPECT_EQ(base::string16(), city_code); |
| 174 EXPECT_EQ(string16(), country_code); | 176 EXPECT_EQ(base::string16(), country_code); |
| 175 | 177 |
| 176 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. | 178 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. |
| 177 string16 phone9(ASCIIToUTF16("01116504567890")); | 179 base::string16 phone9(ASCIIToUTF16("01116504567890")); |
| 178 EXPECT_TRUE(ParsePhoneNumber(phone9, "US", | 180 EXPECT_TRUE(ParsePhoneNumber(phone9, "US", |
| 179 &country_code, | 181 &country_code, |
| 180 &city_code, | 182 &city_code, |
| 181 &number, | 183 &number, |
| 182 &unused_i18n_number)); | 184 &unused_i18n_number)); |
| 183 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 185 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 184 EXPECT_EQ(ASCIIToUTF16("650"), city_code); | 186 EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 185 EXPECT_EQ(ASCIIToUTF16("1"), country_code); | 187 EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 186 | 188 |
| 187 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. | 189 // 011 is a correct "dial out" prefix in the USA - the parsing should succeed. |
| 188 string16 phone10(ASCIIToUTF16("01178124567890")); | 190 base::string16 phone10(ASCIIToUTF16("01178124567890")); |
| 189 EXPECT_TRUE(ParsePhoneNumber(phone10, "US", | 191 EXPECT_TRUE(ParsePhoneNumber(phone10, "US", |
| 190 &country_code, | 192 &country_code, |
| 191 &city_code, | 193 &city_code, |
| 192 &number, | 194 &number, |
| 193 &unused_i18n_number)); | 195 &unused_i18n_number)); |
| 194 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 196 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 195 EXPECT_EQ(ASCIIToUTF16("812"), city_code); | 197 EXPECT_EQ(ASCIIToUTF16("812"), city_code); |
| 196 EXPECT_EQ(ASCIIToUTF16("7"), country_code); | 198 EXPECT_EQ(ASCIIToUTF16("7"), country_code); |
| 197 | 199 |
| 198 // Test for string with over 10 digits with separator characters. | 200 // Test for string with over 10 digits with separator characters. |
| 199 // Should give back phone number, city code, and country code. "011" is | 201 // Should give back phone number, city code, and country code. "011" is |
| 200 // US "dial out" code, which is discarded. | 202 // US "dial out" code, which is discarded. |
| 201 string16 phone11(ASCIIToUTF16("(0111) 650-456.7890")); | 203 base::string16 phone11(ASCIIToUTF16("(0111) 650-456.7890")); |
| 202 EXPECT_TRUE(ParsePhoneNumber(phone11, "US", | 204 EXPECT_TRUE(ParsePhoneNumber(phone11, "US", |
| 203 &country_code, | 205 &country_code, |
| 204 &city_code, | 206 &city_code, |
| 205 &number, | 207 &number, |
| 206 &unused_i18n_number)); | 208 &unused_i18n_number)); |
| 207 EXPECT_EQ(ASCIIToUTF16("4567890"), number); | 209 EXPECT_EQ(ASCIIToUTF16("4567890"), number); |
| 208 EXPECT_EQ(ASCIIToUTF16("650"), city_code); | 210 EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 209 EXPECT_EQ(ASCIIToUTF16("1"), country_code); | 211 EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 210 | 212 |
| 211 // Now try phone from Chech republic - it has 00 dial out code, 420 country | 213 // Now try phone from Chech republic - it has 00 dial out code, 420 country |
| 212 // code and variable length area codes. | 214 // code and variable length area codes. |
| 213 string16 phone12(ASCIIToUTF16("+420 27-89.10.112")); | 215 base::string16 phone12(ASCIIToUTF16("+420 27-89.10.112")); |
| 214 EXPECT_TRUE(ParsePhoneNumber(phone12, "US", | 216 EXPECT_TRUE(ParsePhoneNumber(phone12, "US", |
| 215 &country_code, | 217 &country_code, |
| 216 &city_code, | 218 &city_code, |
| 217 &number, | 219 &number, |
| 218 &unused_i18n_number)); | 220 &unused_i18n_number)); |
| 219 EXPECT_EQ(ASCIIToUTF16("910112"), number); | 221 EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 220 EXPECT_EQ(ASCIIToUTF16("278"), city_code); | 222 EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
| 221 EXPECT_EQ(ASCIIToUTF16("420"), country_code); | 223 EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 222 | 224 |
| 223 EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ", | 225 EXPECT_TRUE(ParsePhoneNumber(phone12, "CZ", |
| 224 &country_code, | 226 &country_code, |
| 225 &city_code, | 227 &city_code, |
| 226 &number, | 228 &number, |
| 227 &unused_i18n_number)); | 229 &unused_i18n_number)); |
| 228 EXPECT_EQ(ASCIIToUTF16("910112"), number); | 230 EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 229 EXPECT_EQ(ASCIIToUTF16("278"), city_code); | 231 EXPECT_EQ(ASCIIToUTF16("278"), city_code); |
| 230 EXPECT_EQ(ASCIIToUTF16("420"), country_code); | 232 EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 231 | 233 |
| 232 string16 phone13(ASCIIToUTF16("420 57-89.10.112")); | 234 base::string16 phone13(ASCIIToUTF16("420 57-89.10.112")); |
| 233 EXPECT_FALSE(ParsePhoneNumber(phone13, "US", | 235 EXPECT_FALSE(ParsePhoneNumber(phone13, "US", |
| 234 &country_code, | 236 &country_code, |
| 235 &city_code, | 237 &city_code, |
| 236 &number, | 238 &number, |
| 237 &unused_i18n_number)); | 239 &unused_i18n_number)); |
| 238 EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ", | 240 EXPECT_TRUE(ParsePhoneNumber(phone13, "CZ", |
| 239 &country_code, | 241 &country_code, |
| 240 &city_code, | 242 &city_code, |
| 241 &number, | 243 &number, |
| 242 &unused_i18n_number)); | 244 &unused_i18n_number)); |
| 243 EXPECT_EQ(ASCIIToUTF16("910112"), number); | 245 EXPECT_EQ(ASCIIToUTF16("910112"), number); |
| 244 EXPECT_EQ(ASCIIToUTF16("578"), city_code); | 246 EXPECT_EQ(ASCIIToUTF16("578"), city_code); |
| 245 EXPECT_EQ(ASCIIToUTF16("420"), country_code); | 247 EXPECT_EQ(ASCIIToUTF16("420"), country_code); |
| 246 | 248 |
| 247 string16 phone14(ASCIIToUTF16("1-650-FLOWERS")); | 249 base::string16 phone14(ASCIIToUTF16("1-650-FLOWERS")); |
| 248 EXPECT_TRUE(ParsePhoneNumber(phone14, "US", | 250 EXPECT_TRUE(ParsePhoneNumber(phone14, "US", |
| 249 &country_code, | 251 &country_code, |
| 250 &city_code, | 252 &city_code, |
| 251 &number, | 253 &number, |
| 252 &unused_i18n_number)); | 254 &unused_i18n_number)); |
| 253 EXPECT_EQ(ASCIIToUTF16("3569377"), number); | 255 EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 254 EXPECT_EQ(ASCIIToUTF16("650"), city_code); | 256 EXPECT_EQ(ASCIIToUTF16("650"), city_code); |
| 255 EXPECT_EQ(ASCIIToUTF16("1"), country_code); | 257 EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 256 | 258 |
| 257 // 800 is not an area code, but the destination code. In our library these | 259 // 800 is not an area code, but the destination code. In our library these |
| 258 // codes should be treated the same as area codes. | 260 // codes should be treated the same as area codes. |
| 259 string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); | 261 base::string16 phone15(ASCIIToUTF16("1-800-FLOWERS")); |
| 260 EXPECT_TRUE(ParsePhoneNumber(phone15, "US", | 262 EXPECT_TRUE(ParsePhoneNumber(phone15, "US", |
| 261 &country_code, | 263 &country_code, |
| 262 &city_code, | 264 &city_code, |
| 263 &number, | 265 &number, |
| 264 &unused_i18n_number)); | 266 &unused_i18n_number)); |
| 265 EXPECT_EQ(ASCIIToUTF16("3569377"), number); | 267 EXPECT_EQ(ASCIIToUTF16("3569377"), number); |
| 266 EXPECT_EQ(ASCIIToUTF16("800"), city_code); | 268 EXPECT_EQ(ASCIIToUTF16("800"), city_code); |
| 267 EXPECT_EQ(ASCIIToUTF16("1"), country_code); | 269 EXPECT_EQ(ASCIIToUTF16("1"), country_code); |
| 268 } | 270 } |
| 269 | 271 |
| 270 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { | 272 TEST(PhoneNumberI18NTest, ConstructPhoneNumber) { |
| 271 string16 number; | 273 base::string16 number; |
| 272 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), | 274 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 273 ASCIIToUTF16("650"), | 275 ASCIIToUTF16("650"), |
| 274 ASCIIToUTF16("2345678"), | 276 ASCIIToUTF16("2345678"), |
| 275 "US", | 277 "US", |
| 276 &number)); | 278 &number)); |
| 277 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); | 279 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
| 278 EXPECT_TRUE(ConstructPhoneNumber(string16(), | 280 EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
| 279 ASCIIToUTF16("650"), | 281 ASCIIToUTF16("650"), |
| 280 ASCIIToUTF16("2345678"), | 282 ASCIIToUTF16("2345678"), |
| 281 "US", | 283 "US", |
| 282 &number)); | 284 &number)); |
| 283 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); | 285 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
| 284 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), | 286 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("1"), |
| 285 string16(), | 287 base::string16(), |
| 286 ASCIIToUTF16("6502345678"), | 288 ASCIIToUTF16("6502345678"), |
| 287 "US", | 289 "US", |
| 288 &number)); | 290 &number)); |
| 289 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); | 291 EXPECT_EQ(number, ASCIIToUTF16("+1 650-234-5678")); |
| 290 EXPECT_TRUE(ConstructPhoneNumber(string16(), | 292 EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
| 291 string16(), | 293 base::string16(), |
| 292 ASCIIToUTF16("6502345678"), | 294 ASCIIToUTF16("6502345678"), |
| 293 "US", | 295 "US", |
| 294 &number)); | 296 &number)); |
| 295 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); | 297 EXPECT_EQ(number, ASCIIToUTF16("(650) 234-5678")); |
| 296 | 298 |
| 297 EXPECT_FALSE(ConstructPhoneNumber(string16(), | 299 EXPECT_FALSE(ConstructPhoneNumber(base::string16(), |
| 298 ASCIIToUTF16("650"), | 300 ASCIIToUTF16("650"), |
| 299 ASCIIToUTF16("234567890"), | 301 ASCIIToUTF16("234567890"), |
| 300 "US", | 302 "US", |
| 301 &number)); | 303 &number)); |
| 302 EXPECT_EQ(number, string16()); | 304 EXPECT_EQ(number, base::string16()); |
| 303 // Italian number | 305 // Italian number |
| 304 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"), | 306 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("39"), |
| 305 ASCIIToUTF16("347"), | 307 ASCIIToUTF16("347"), |
| 306 ASCIIToUTF16("2345678"), | 308 ASCIIToUTF16("2345678"), |
| 307 "IT", | 309 "IT", |
| 308 &number)); | 310 &number)); |
| 309 EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678")); | 311 EXPECT_EQ(number, ASCIIToUTF16("+39 347 234 5678")); |
| 310 EXPECT_TRUE(ConstructPhoneNumber(string16(), | 312 EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
| 311 ASCIIToUTF16("347"), | 313 ASCIIToUTF16("347"), |
| 312 ASCIIToUTF16("2345678"), | 314 ASCIIToUTF16("2345678"), |
| 313 "IT", | 315 "IT", |
| 314 &number)); | 316 &number)); |
| 315 EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); | 317 EXPECT_EQ(number, ASCIIToUTF16("347 234 5678")); |
| 316 // German number. | 318 // German number. |
| 317 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), | 319 EXPECT_TRUE(ConstructPhoneNumber(ASCIIToUTF16("49"), |
| 318 ASCIIToUTF16("024"), | 320 ASCIIToUTF16("024"), |
| 319 ASCIIToUTF16("2345678901"), | 321 ASCIIToUTF16("2345678901"), |
| 320 "DE", | 322 "DE", |
| 321 &number)); | 323 &number)); |
| 322 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); | 324 EXPECT_EQ(number, ASCIIToUTF16("+49 2423/45678901")); |
| 323 EXPECT_TRUE(ConstructPhoneNumber(string16(), | 325 EXPECT_TRUE(ConstructPhoneNumber(base::string16(), |
| 324 ASCIIToUTF16("024"), | 326 ASCIIToUTF16("024"), |
| 325 ASCIIToUTF16("2345678901"), | 327 ASCIIToUTF16("2345678901"), |
| 326 "DE", | 328 "DE", |
| 327 &number)); | 329 &number)); |
| 328 EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); | 330 EXPECT_EQ(number, ASCIIToUTF16("02423/45678901")); |
| 329 } | 331 } |
| 330 | 332 |
| 331 TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { | 333 TEST(PhoneNumberI18NTest, PhoneNumbersMatch) { |
| 332 // Same numbers, defined country code. | 334 // Same numbers, defined country code. |
| 333 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), | 335 EXPECT_TRUE(PhoneNumbersMatch(ASCIIToUTF16("4158889999"), |
| (...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 373 ASCIIToUTF16("8889999"), | 375 ASCIIToUTF16("8889999"), |
| 374 "US", | 376 "US", |
| 375 "en-US")); | 377 "en-US")); |
| 376 | 378 |
| 377 // Different numbers don't match. | 379 // Different numbers don't match. |
| 378 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 380 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 379 ASCIIToUTF16("1415888"), | 381 ASCIIToUTF16("1415888"), |
| 380 "US", | 382 "US", |
| 381 "en-US")); | 383 "en-US")); |
| 382 } | 384 } |
| OLD | NEW |