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

Side by Side Diff: components/payments/core/payment_request_data_util_unittest.cc

Issue 2905283002: [Payments] Allow international phone from different country in shipping editor. (Closed)
Patch Set: Changed test expectations Created 3 years, 6 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
« no previous file with comments | « components/payments/core/payment_request_data_util.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 1 // Copyright 2017 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 "components/payments/core/payment_request_data_util.h" 5 #include "components/payments/core/payment_request_data_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
11 #include "base/values.h" 12 #include "base/values.h"
12 #include "components/autofill/core/browser/autofill_profile.h" 13 #include "components/autofill/core/browser/autofill_profile.h"
13 #include "components/autofill/core/browser/autofill_test_utils.h" 14 #include "components/autofill/core/browser/autofill_test_utils.h"
14 #include "components/autofill/core/browser/credit_card.h" 15 #include "components/autofill/core/browser/credit_card.h"
15 #include "components/payments/core/basic_card_response.h" 16 #include "components/payments/core/basic_card_response.h"
16 #include "components/payments/core/payment_address.h" 17 #include "components/payments/core/payment_address.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 19
19 namespace payments { 20 namespace payments {
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 } 84 }
84 85
85 // Tests that the phone numbers are correctly formatted to display to the user. 86 // Tests that the phone numbers are correctly formatted to display to the user.
86 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) { 87 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) {
87 EXPECT_EQ("+1 515-123-1234", 88 EXPECT_EQ("+1 515-123-1234",
88 payments::data_util::FormatPhoneForDisplay("5151231234", "US")); 89 payments::data_util::FormatPhoneForDisplay("5151231234", "US"));
89 EXPECT_EQ("+33 1 42 68 53 00", 90 EXPECT_EQ("+33 1 42 68 53 00",
90 payments::data_util::FormatPhoneForDisplay("142685300", "FR")); 91 payments::data_util::FormatPhoneForDisplay("142685300", "FR"));
91 } 92 }
92 93
94 // Test for the GetFormattedPhoneNumberForDisplay method.
95 struct PhoneNumberFormatCase {
96 PhoneNumberFormatCase(const char* phone,
97 const char* country,
98 const char* expected_format)
99 : phone(phone),
100 country(country),
101 expected_format(expected_format),
102 locale("") {}
103
104 PhoneNumberFormatCase(const char* phone,
105 const char* country,
106 const char* expected_format,
107 const char* locale)
Mathieu 2017/05/29 20:29:03 = "" ?
sebsg 2017/05/29 20:32:26 Ah sweet! thanks!
108 : phone(phone),
109 country(country),
110 expected_format(expected_format),
111 locale(locale) {}
112
113 const char* phone;
114 const char* country;
115 const char* expected_format;
116 const char* locale;
117 };
118
119 class GetFormattedPhoneNumberForDisplayTest
120 : public testing::TestWithParam<PhoneNumberFormatCase> {};
121
122 TEST_P(GetFormattedPhoneNumberForDisplayTest,
123 GetFormattedPhoneNumberForDisplay) {
124 autofill::AutofillProfile profile;
125 profile.SetRawInfo(autofill::PHONE_HOME_WHOLE_NUMBER,
126 base::UTF8ToUTF16(GetParam().phone));
127 profile.SetRawInfo(autofill::ADDRESS_HOME_COUNTRY,
128 base::UTF8ToUTF16(GetParam().country));
129 EXPECT_EQ(GetParam().expected_format,
130 base::UTF16ToUTF8(
131 GetFormattedPhoneNumberForDisplay(profile, GetParam().locale)));
132 }
133
134 INSTANTIATE_TEST_CASE_P(
135 GetFormattedPhoneNumberForDisplay,
136 GetFormattedPhoneNumberForDisplayTest,
137 testing::Values(
138 //////////////////////////
139 // US phone in US.
140 //////////////////////////
141 // Formatted phone numbers.
142 PhoneNumberFormatCase("+1 415-555-5555", "US", "+1 415-555-5555"),
143 PhoneNumberFormatCase("1 415-555-5555", "US", "+1 415-555-5555"),
144 PhoneNumberFormatCase("415-555-5555", "US", "+1 415-555-5555"),
145 // Raw phone numbers.
146 PhoneNumberFormatCase("+14155555555", "US", "+1 415-555-5555"),
147 PhoneNumberFormatCase("14155555555", "US", "+1 415-555-5555"),
148 PhoneNumberFormatCase("4155555555", "US", "+1 415-555-5555"),
149
150 //////////////////////////
151 // US phone in CA.
152 //////////////////////////
153 // Formatted phone numbers.
154 PhoneNumberFormatCase("+1 415-555-5555", "CA", "+1 415-555-5555"),
155 PhoneNumberFormatCase("1 415-555-5555", "CA", "+1 415-555-5555"),
156 PhoneNumberFormatCase("415-555-5555", "CA", "+1 415-555-5555"),
157 // Raw phone numbers.
158 PhoneNumberFormatCase("+14155555555", "CA", "+1 415-555-5555"),
159 PhoneNumberFormatCase("14155555555", "CA", "+1 415-555-5555"),
160 PhoneNumberFormatCase("4155555555", "CA", "+1 415-555-5555"),
161
162 //////////////////////////
163 // US phone in AU.
164 //////////////////////////
165 // A US phone with the country code is correctly formatted as an US
166 // number.
167 PhoneNumberFormatCase("+1 415-555-5555", "AU", "+1 415-555-5555"),
168 PhoneNumberFormatCase("1 415-555-5555", "AU", "+1 415-555-5555"),
169 // Without a country code, the phone is formatted for the profile's
170 // country, even if it's invalid.
171 PhoneNumberFormatCase("415-555-5555", "AU", "+61 4155555555"),
172
173 //////////////////////////
174 // US phone in MX.
175 //////////////////////////
176 // A US phone with the country code is correctly formatted as an US
177 // number.
178 PhoneNumberFormatCase("+1 415-555-5555", "MX", "+1 415-555-5555"),
179 // "+52 1 415 555 5555" is a valid number for Mexico,
180 PhoneNumberFormatCase("1 415-555-5555", "MX", "+52 1 415 555 5555"),
181 // Without a country code, the phone is formatted for the profile's
182 // country.
183 PhoneNumberFormatCase("415-555-5555", "MX", "+52 415 555 5555"),
184
185 //////////////////////////
186 // AU phone in AU.
187 //////////////////////////
188 // Formatted phone numbers.
189 PhoneNumberFormatCase("+61 2 9374 4000", "AU", "+61 2 9374 4000"),
190 PhoneNumberFormatCase("61 2 9374 4000", "AU", "+61 2 9374 4000"),
191 PhoneNumberFormatCase("02 9374 4000", "AU", "+61 2 9374 4000"),
192 PhoneNumberFormatCase("2 9374 4000", "AU", "+61 2 9374 4000"),
193 // Raw phone numbers.
194 PhoneNumberFormatCase("+61293744000", "AU", "+61 2 9374 4000"),
195 PhoneNumberFormatCase("61293744000", "AU", "+61 2 9374 4000"),
196 PhoneNumberFormatCase("0293744000", "AU", "+61 2 9374 4000"),
197 PhoneNumberFormatCase("293744000", "AU", "+61 2 9374 4000"),
198
199 //////////////////////////
200 // AU phone in US.
201 //////////////////////////
202 // An AU phone with the country code is correctly formatted as an AU
203 // number.
204 PhoneNumberFormatCase("+61 2 9374 4000", "US", "+61 2 9374 4000"),
205 PhoneNumberFormatCase("61 2 9374 4000", "US", "+61 2 9374 4000"),
206 // Without a country code, the phone is formatted for the profile's
207 // country.
208 // This local AU number fits the length of a US number, so it's
209 // formatted for US.
210 PhoneNumberFormatCase("02 9374 4000", "US", "+1 029-374-4000"),
211 // This local AU number is formatted as an US number, even if it's
212 // invlaid.
213 PhoneNumberFormatCase("2 9374 4000", "US", "+1 293744000"),
214
215 //////////////////////////
216 // MX phone in MX.
217 //////////////////////////
218 // Formatted phone numbers.
219 PhoneNumberFormatCase("+52 55 5342 8400", "MX", "+52 55 5342 8400"),
220 PhoneNumberFormatCase("52 55 5342 8400", "MX", "+52 55 5342 8400"),
221 PhoneNumberFormatCase("55 5342 8400", "MX", "+52 55 5342 8400"),
222 // Raw phone numbers.
223 PhoneNumberFormatCase("+525553428400", "MX", "+52 55 5342 8400"),
224 PhoneNumberFormatCase("525553428400", "MX", "+52 55 5342 8400"),
225 PhoneNumberFormatCase("5553428400", "MX", "+52 55 5342 8400"),
226
227 //////////////////////////
228 // MX phone in US.
229 //////////////////////////
230 // A MX phone with the country code is correctly formatted as a MX
231 // number.
232 PhoneNumberFormatCase("+52 55 5342 8400", "US", "+52 55 5342 8400"),
233 PhoneNumberFormatCase("52 55 5342 8400", "US", "+52 55 5342 8400"),
234 // This local MX number fits the length of a US number, so it's
235 // formatted for US.
236 PhoneNumberFormatCase("55 5342 8400", "US", "+1 555-342-8400")));
237
238 INSTANTIATE_TEST_CASE_P(
239 GetFormattedPhoneNumberForDisplay_EdgeCases,
240 GetFormattedPhoneNumberForDisplayTest,
241 testing::Values(
242 //////////////////////////
243 // No country.
244 //////////////////////////
245 // Fallback to locale if no country is set.
246 PhoneNumberFormatCase("52 55 5342 8400",
247 "",
248 "+52 55 5342 8400",
249 "es_MX"),
250 PhoneNumberFormatCase("55 5342 8400", "", "+52 55 5342 8400", "es_MX"),
251 PhoneNumberFormatCase("55 5342 8400", "", "+1 555-342-8400", "en_US"),
252 PhoneNumberFormatCase("61 2 9374 4000", "", "+61 2 9374 4000", "en_AU"),
253 PhoneNumberFormatCase("02 9374 4000", "", "+61 2 9374 4000", "en_AU"),
254
255 //////////////////////////
256 // No country or locale.
257 //////////////////////////
258 // Format according to the country code.
259 PhoneNumberFormatCase("61 2 9374 4000", "", "+61 2 9374 4000"),
260 PhoneNumberFormatCase("52 55 5342 8400", "", "+52 55 5342 8400"),
261 PhoneNumberFormatCase("1 415 555 5555", "", "+1 415-555-5555"),
262 // If no country code is found, formats for US.
263 PhoneNumberFormatCase("02 9374 4000", "", "+1 029-374-4000"),
264 PhoneNumberFormatCase("2 9374 4000", "", "+1 293744000"),
265 PhoneNumberFormatCase("55 5342 8400", "", "+1 555-342-8400"),
266 PhoneNumberFormatCase("52 55 5342 8400", "", "+52 55 5342 8400"),
267 PhoneNumberFormatCase("415-555-5555", "", "+1 415-555-5555")));
93 } // namespace data_util 268 } // namespace data_util
94 } // namespace payments 269 } // namespace payments
OLDNEW
« no previous file with comments | « components/payments/core/payment_request_data_util.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698