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

Side by Side Diff: third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp

Issue 1937783002: Provide shipping in PaymentRequest response (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 7 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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 "modules/payments/PaymentsValidators.h" 5 #include "modules/payments/PaymentsValidators.h"
6 6
7 #include "testing/gtest/include/gtest/gtest.h" 7 #include "testing/gtest/include/gtest/gtest.h"
8 #include "wtf/text/WTFString.h" 8 #include "wtf/text/WTFString.h"
9 #include <ostream> // NOLINT 9 #include <ostream> // NOLINT
10 10
11 namespace blink { 11 namespace blink {
12 namespace {
13 12
14 struct TestCase { 13 struct TestCase {
Marijn Kruisselbrink 2016/05/02 19:02:27 Here you really need an anonymous namespace to not
please use gerrit instead 2016/05/02 20:34:45 Done.
15 TestCase(const char* input, bool expectedValid) 14 TestCase(const char* input, bool expectedValid)
16 : input(input) 15 : input(input)
17 , expectedValid(expectedValid) 16 , expectedValid(expectedValid)
18 { 17 {
19 } 18 }
20 ~TestCase() {} 19 ~TestCase() {}
21 20
22 const char* input; 21 const char* input;
23 bool expectedValid; 22 bool expectedValid;
24 }; 23 };
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 TestCase("", true), 159 TestCase("", true),
161 TestCase("Latn", true), 160 TestCase("Latn", true),
162 // Invalid script code formats 161 // Invalid script code formats
163 TestCase("Lat1", false), 162 TestCase("Lat1", false),
164 TestCase("1lat", false), 163 TestCase("1lat", false),
165 TestCase("Latin", false), 164 TestCase("Latin", false),
166 TestCase("Lat", false), 165 TestCase("Lat", false),
167 TestCase("latn", false), 166 TestCase("latn", false),
168 TestCase("LATN", false))); 167 TestCase("LATN", false)));
169 168
170 } // namespace 169 struct ShippingAddressTestCase {
170 ShippingAddressTestCase(const char* regionCode, const char* languageCode, co nst char* scriptCode, bool expectedValid)
171 : regionCode(regionCode)
172 , languageCode(languageCode)
173 , scriptCode(scriptCode)
174 , expectedValid(expectedValid)
175 {
176 }
177 ~ShippingAddressTestCase() {}
178
179 const char* regionCode;
180 const char* languageCode;
181 const char* scriptCode;
182 bool expectedValid;
183 };
184
185 class PaymentsShippingAddressValidatorTest : public testing::TestWithParam<Shipp ingAddressTestCase> {
186 };
187
188 TEST_P(PaymentsShippingAddressValidatorTest, IsValidShippingAddress)
189 {
190 mojom::blink::ShippingAddressPtr address = mojom::blink::ShippingAddress::Ne w();
191 address->region_code = GetParam().regionCode;
192 address->language_code = GetParam().languageCode;
193 address->script_code = GetParam().scriptCode;
194
195 String errorMessage;
196 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre ss(address, &errorMessage)) << errorMessage;
197 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
198
199 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre ss(address, nullptr));
200 }
201
202 INSTANTIATE_TEST_CASE_P(ShippingAddresses,
203 PaymentsShippingAddressValidatorTest,
204 testing::Values(
205 ShippingAddressTestCase("US", "en", "Latn", true),
206 ShippingAddressTestCase("US", "en", "", true),
207 ShippingAddressTestCase("US", "", "", true),
208 // Invalid shipping addresses
209 ShippingAddressTestCase("", "", "", false),
210 ShippingAddressTestCase("InvalidRegionCode", "", "", false),
211 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false),
212 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false),
213 ShippingAddressTestCase("US", "", "Latn", false)));
214
171 } // namespace blink 215 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698