| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/message_loop.h" | 5 #include "base/message_loop/message_loop.h" |
| 6 #include "base/strings/string16.h" | 6 #include "base/strings/string16.h" |
| 7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
| 8 #include "components/autofill/core/browser/phone_number_i18n.h" | 8 #include "components/autofill/core/browser/phone_number_i18n.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 #include "third_party/libphonenumber/src/phonenumber_api.h" | 10 #include "third_party/libphonenumber/src/phonenumber_api.h" |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 49 bool valid; | 49 bool valid; |
| 50 // Inputs. | 50 // Inputs. |
| 51 std::string input; | 51 std::string input; |
| 52 std::string assumed_region; | 52 std::string assumed_region; |
| 53 // Further expectations. | 53 // Further expectations. |
| 54 std::string number; | 54 std::string number; |
| 55 std::string city_code; | 55 std::string city_code; |
| 56 std::string country_code; | 56 std::string country_code; |
| 57 std::string deduced_region; | 57 std::string deduced_region; |
| 58 } test_cases[] = { | 58 } test_cases[] = { |
| 59 // Test for empty string. Should give back empty strings. | 59 // Test for empty string. Should give back empty strings. |
| 60 { false, "", "US" }, | 60 {false, "", "US"}, |
| 61 // Test for string with less than 7 digits. Should give back empty strings. | 61 // Test for string with less than 7 digits. Should give back empty |
| 62 { false, "1234", "US" }, | 62 // strings. |
| 63 // Test for string with exactly 7 digits. | 63 {false, "1234", "US"}, |
| 64 // Not a valid number - starts with 1 | 64 // Test for string with exactly 7 digits. |
| 65 { false, "17134567", "US" }, | 65 // Not a valid number - starts with 1 |
| 66 // Not a valid number - does not have area code. | 66 {false, "17134567", "US"}, |
| 67 { false, "7134567", "US" }, | 67 // Not a valid number - does not have area code. |
| 68 // Valid Canadian toll-free number. | 68 {false, "7134567", "US"}, |
| 69 { true, "3101234", "US", "3101234", "", "", "CA" }, | 69 // Valid Canadian toll-free number. |
| 70 // Test for string with greater than 7 digits but less than 10 digits. | 70 {true, "3101234", "US", "3101234", "", "", "CA"}, |
| 71 // Should fail parsing in US. | 71 // Test for string with greater than 7 digits but less than 10 digits. |
| 72 { false, "123456789", "US" }, | 72 // Should fail parsing in US. |
| 73 // Test for string with greater than 7 digits but less than 10 digits and | 73 {false, "123456789", "US"}, |
| 74 // separators. | 74 // Test for string with greater than 7 digits but less than 10 digits |
| 75 // Should fail parsing in US. | 75 // and |
| 76 { false, "12.345-6789", "US" }, | 76 // separators. |
| 77 // Test for string with exactly 10 digits. | 77 // Should fail parsing in US. |
| 78 // Should give back phone number and city code. | 78 {false, "12.345-6789", "US"}, |
| 79 // This one going to fail because of the incorrect area code. | 79 // Test for string with exactly 10 digits. |
| 80 { false, "1234567890", "US" }, | 80 // Should give back phone number and city code. |
| 81 // This one going to fail because of the incorrect number (starts with 1). | 81 // This one going to fail because of the incorrect area code. |
| 82 { false, "6501567890", "US" }, | 82 {false, "1234567890", "US"}, |
| 83 { true, "6504567890", "US", "4567890", "650", "", "US" }, | 83 // This one going to fail because of the incorrect number (starts with |
| 84 // Test for string with exactly 10 digits and separators. | 84 // 1). |
| 85 // Should give back phone number and city code. | 85 {false, "6501567890", "US"}, |
| 86 { true, "(650) 456-7890", "US", "4567890", "650", "", "US" }, | 86 {true, "6504567890", "US", "4567890", "650", "", "US"}, |
| 87 // Tests for string with over 10 digits. | 87 // Test for string with exactly 10 digits and separators. |
| 88 // 01 is incorrect prefix in the USA, and if we interpret 011 as prefix, the | 88 // Should give back phone number and city code. |
| 89 // rest is too short for international number - the parsing should fail. | 89 {true, "(650) 456-7890", "US", "4567890", "650", "", "US"}, |
| 90 { false, "0116504567890", "US" }, | 90 // Tests for string with over 10 digits. |
| 91 // 011 is a correct "dial out" prefix in the USA - the parsing should | 91 // 01 is incorrect prefix in the USA, and if we interpret 011 as prefix, |
| 92 // succeed. | 92 // the |
| 93 { true, "01116504567890", "US", "4567890", "650", "1", "US" }, | 93 // rest is too short for international number - the parsing should fail. |
| 94 // 011 is a correct "dial out" prefix in the USA but the rest of the number | 94 {false, "0116504567890", "US"}, |
| 95 // can't parse as a US number. | 95 // 011 is a correct "dial out" prefix in the USA - the parsing should |
| 96 { true, "01178124567890", "US", "4567890", "812", "7", "RU" }, | 96 // succeed. |
| 97 // Test for string with over 10 digits with separator characters. | 97 {true, "01116504567890", "US", "4567890", "650", "1", "US"}, |
| 98 // Should give back phone number, city code, and country code. "011" is | 98 // 011 is a correct "dial out" prefix in the USA but the rest of the |
| 99 // US "dial out" code, which is discarded. | 99 // number |
| 100 { true, "(0111) 650-456.7890", "US", "4567890", "650", "1" , "US" }, | 100 // can't parse as a US number. |
| 101 // Now try phone from Czech republic - it has 00 dial out code, 420 country | 101 {true, "01178124567890", "US", "4567890", "812", "7", "RU"}, |
| 102 // code and variable length area codes. | 102 // Test for string with over 10 digits with separator characters. |
| 103 { true, "+420 27-89.10.112", "US", "910112", "278", "420", "CZ" }, | 103 // Should give back phone number, city code, and country code. "011" is |
| 104 { false, "27-89.10.112", "US" }, | 104 // US "dial out" code, which is discarded. |
| 105 { true, "27-89.10.112", "CZ", "910112", "278", "", "CZ" }, | 105 {true, "(0111) 650-456.7890", "US", "4567890", "650", "1", "US"}, |
| 106 { false, "420 57-89.10.112", "US" }, | 106 // Now try phone from Czech republic - it has 00 dial out code, 420 |
| 107 { true, "420 57-89.10.112", "CZ", "910112", "578", "420", "CZ" }, | 107 // country |
| 108 // Parses vanity numbers. | 108 // code and variable length area codes. |
| 109 { true, "1-650-FLOWERS", "US", "3569377", "650", "1", "US" }, | 109 {true, "+420 27-89.10.112", "US", "910112", "278", "420", "CZ"}, |
| 110 // 800 is not an area code, but the destination code. In our library these | 110 {false, "27-89.10.112", "US"}, |
| 111 // codes should be treated the same as area codes. | 111 {true, "27-89.10.112", "CZ", "910112", "278", "", "CZ"}, |
| 112 { true, "1-800-FLOWERS", "US", "3569377", "800", "1", "US" }, | 112 {false, "420 57-89.10.112", "US"}, |
| 113 }; | 113 {true, "420 57-89.10.112", "CZ", "910112", "578", "420", "CZ"}, |
| 114 // Parses vanity numbers. |
| 115 {true, "1-650-FLOWERS", "US", "3569377", "650", "1", "US"}, |
| 116 // 800 is not an area code, but the destination code. In our library |
| 117 // these |
| 118 // codes should be treated the same as area codes. |
| 119 {true, "1-800-FLOWERS", "US", "3569377", "800", "1", "US"}, |
| 120 // Don't add a country code where there was none. |
| 121 {true, "(08) 450 777 7777", "DE", "7777777", "8450", "", "DE"}, |
| 122 }; |
| 114 | 123 |
| 115 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { | 124 for (size_t i = 0; i < ARRAYSIZE_UNSAFE(test_cases); ++i) { |
| 116 SCOPED_TRACE("Testing phone number " + test_cases[i].input); | 125 SCOPED_TRACE("Testing phone number " + test_cases[i].input); |
| 117 | 126 |
| 118 base::string16 country_code, city_code, number; | 127 base::string16 country_code, city_code, number; |
| 119 std::string deduced_region; | 128 std::string deduced_region; |
| 120 ::i18n::phonenumbers::PhoneNumber unused_i18n_number; | 129 ::i18n::phonenumbers::PhoneNumber unused_i18n_number; |
| 121 EXPECT_EQ(test_cases[i].valid, | 130 EXPECT_EQ(test_cases[i].valid, |
| 122 ParsePhoneNumber(ASCIIToUTF16(test_cases[i].input), | 131 ParsePhoneNumber(ASCIIToUTF16(test_cases[i].input), |
| 123 test_cases[i].assumed_region, | 132 test_cases[i].assumed_region, |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 241 "en-US")); | 250 "en-US")); |
| 242 | 251 |
| 243 // Different numbers don't match. | 252 // Different numbers don't match. |
| 244 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), | 253 EXPECT_FALSE(PhoneNumbersMatch(ASCIIToUTF16("14158889999"), |
| 245 ASCIIToUTF16("1415888"), | 254 ASCIIToUTF16("1415888"), |
| 246 "US", | 255 "US", |
| 247 "en-US")); | 256 "en-US")); |
| 248 } | 257 } |
| 249 | 258 |
| 250 } // namespace autofill | 259 } // namespace autofill |
| OLD | NEW |