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

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: Address comments 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
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after
160 TestCase("", true), 160 TestCase("", true),
161 TestCase("Latn", true), 161 TestCase("Latn", true),
162 // Invalid script code formats 162 // Invalid script code formats
163 TestCase("Lat1", false), 163 TestCase("Lat1", false),
164 TestCase("1lat", false), 164 TestCase("1lat", false),
165 TestCase("Latin", false), 165 TestCase("Latin", false),
166 TestCase("Lat", false), 166 TestCase("Lat", false),
167 TestCase("latn", false), 167 TestCase("latn", false),
168 TestCase("LATN", false))); 168 TestCase("LATN", false)));
169 169
170 struct ShippingAddressTestCase {
171 ShippingAddressTestCase(const char* regionCode, const char* languageCode, co nst char* scriptCode, bool expectedValid)
172 : regionCode(regionCode)
173 , languageCode(languageCode)
174 , scriptCode(scriptCode)
175 , expectedValid(expectedValid)
176 {
177 }
178 ~ShippingAddressTestCase() {}
179
180 const char* regionCode;
181 const char* languageCode;
182 const char* scriptCode;
183 bool expectedValid;
184 };
185
186 class PaymentsShippingAddressValidatorTest : public testing::TestWithParam<Shipp ingAddressTestCase> {
187 };
188
189 TEST_P(PaymentsShippingAddressValidatorTest, IsValidShippingAddress)
190 {
191 mojom::blink::ShippingAddressPtr address = mojom::blink::ShippingAddress::Ne w();
192 address->region_code = GetParam().regionCode;
193 address->language_code = GetParam().languageCode;
194 address->script_code = GetParam().scriptCode;
195
196 String errorMessage;
197 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre ss(address, &errorMessage)) << errorMessage;
198 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
199
200 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre ss(address, nullptr));
201 }
202
203 INSTANTIATE_TEST_CASE_P(ShippingAddresses,
204 PaymentsShippingAddressValidatorTest,
205 testing::Values(
206 ShippingAddressTestCase("US", "en", "Latn", true),
207 ShippingAddressTestCase("US", "en", "", true),
208 ShippingAddressTestCase("US", "", "", true),
209 // Invalid shipping addresses
210 ShippingAddressTestCase("", "", "", false),
211 ShippingAddressTestCase("InvalidRegionCode", "", "", false),
212 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false),
213 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false),
214 ShippingAddressTestCase("US", "", "Latn", false)));
215
170 } // namespace 216 } // namespace
171 } // namespace blink 217 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698