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

Unified 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, 8 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 side-by-side diff with in-line comments
Download patch
Index: third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
diff --git a/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp b/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
index 7ea0bac9e05a504aba563cccc0de5106afc1238e..274d4eae060f54638ed368afd2b66fe232407bf2 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
+++ b/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
@@ -167,5 +167,51 @@ INSTANTIATE_TEST_CASE_P(ScriptCodes,
TestCase("latn", false),
TestCase("LATN", false)));
+struct ShippingAddressTestCase {
+ ShippingAddressTestCase(const char* regionCode, const char* languageCode, const char* scriptCode, bool expectedValid)
+ : regionCode(regionCode)
+ , languageCode(languageCode)
+ , scriptCode(scriptCode)
+ , expectedValid(expectedValid)
+ {
+ }
+ ~ShippingAddressTestCase() {}
+
+ const char* regionCode;
+ const char* languageCode;
+ const char* scriptCode;
+ bool expectedValid;
+};
+
+class PaymentsShippingAddressValidatorTest : public testing::TestWithParam<ShippingAddressTestCase> {
+};
+
+TEST_P(PaymentsShippingAddressValidatorTest, IsValidShippingAddress)
+{
+ mojom::blink::ShippingAddressPtr address = mojom::blink::ShippingAddress::New();
+ address->region_code = GetParam().regionCode;
+ address->language_code = GetParam().languageCode;
+ address->script_code = GetParam().scriptCode;
+
+ String errorMessage;
+ EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddress(address, &errorMessage)) << errorMessage;
+ EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
+
+ EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddress(address, nullptr));
+}
+
+INSTANTIATE_TEST_CASE_P(ShippingAddresses,
+ PaymentsShippingAddressValidatorTest,
+ testing::Values(
+ ShippingAddressTestCase("US", "en", "Latn", true),
+ ShippingAddressTestCase("US", "en", "", true),
+ ShippingAddressTestCase("US", "", "", true),
+ // Invalid shipping addresses
+ ShippingAddressTestCase("", "", "", false),
+ ShippingAddressTestCase("InvalidRegionCode", "", "", false),
+ ShippingAddressTestCase("US", "InvalidLanguageCode", "", false),
+ ShippingAddressTestCase("US", "en", "InvalidScriptCode", false),
+ ShippingAddressTestCase("US", "", "Latn", false)));
+
} // namespace
} // namespace blink

Powered by Google App Engine
This is Rietveld 408576698