| OLD | NEW |
| 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 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 TestCase("-10.", false), | 90 TestCase("-10.", false), |
| 91 TestCase("-.99", false), | 91 TestCase("-.99", false), |
| 92 TestCase("10-", false), | 92 TestCase("10-", false), |
| 93 TestCase("1-0", false), | 93 TestCase("1-0", false), |
| 94 TestCase("1.0.0", false), | 94 TestCase("1.0.0", false), |
| 95 TestCase("1/3", false))); | 95 TestCase("1/3", false))); |
| 96 | 96 |
| 97 class PaymentsRegionValidatorTest : public testing::TestWithParam<TestCase> { | 97 class PaymentsRegionValidatorTest : public testing::TestWithParam<TestCase> { |
| 98 }; | 98 }; |
| 99 | 99 |
| 100 TEST_P(PaymentsRegionValidatorTest, IsValidRegionCodeFormat) | 100 TEST_P(PaymentsRegionValidatorTest, IsValidCountryCodeFormat) |
| 101 { | 101 { |
| 102 String errorMessage; | 102 String errorMessage; |
| 103 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidRegionCodeFor
mat(GetParam().input, &errorMessage)) << errorMessage; | 103 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCountryCodeFo
rmat(GetParam().input, &errorMessage)) << errorMessage; |
| 104 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; | 104 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; |
| 105 | 105 |
| 106 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidRegionCodeFor
mat(GetParam().input, nullptr)); | 106 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidCountryCodeFo
rmat(GetParam().input, nullptr)); |
| 107 } | 107 } |
| 108 | 108 |
| 109 INSTANTIATE_TEST_CASE_P(RegionCodes, | 109 INSTANTIATE_TEST_CASE_P(CountryCodes, |
| 110 PaymentsRegionValidatorTest, | 110 PaymentsRegionValidatorTest, |
| 111 testing::Values( | 111 testing::Values( |
| 112 TestCase("US", true), | 112 TestCase("US", true), |
| 113 // Invalid region code formats | 113 // Invalid country code formats |
| 114 TestCase("U1", false), | 114 TestCase("U1", false), |
| 115 TestCase("U", false), | 115 TestCase("U", false), |
| 116 TestCase("us", false), | 116 TestCase("us", false), |
| 117 TestCase("USA", false), | 117 TestCase("USA", false), |
| 118 TestCase("", false))); | 118 TestCase("", false))); |
| 119 | 119 |
| 120 class PaymentsLanguageValidatorTest : public testing::TestWithParam<TestCase> { | 120 class PaymentsLanguageValidatorTest : public testing::TestWithParam<TestCase> { |
| 121 }; | 121 }; |
| 122 | 122 |
| 123 TEST_P(PaymentsLanguageValidatorTest, IsValidLanguageCodeFormat) | 123 TEST_P(PaymentsLanguageValidatorTest, IsValidLanguageCodeFormat) |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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 { | 170 struct ShippingAddressTestCase { |
| 171 ShippingAddressTestCase(const char* regionCode, const char* languageCode, co
nst char* scriptCode, bool expectedValid) | 171 ShippingAddressTestCase(const char* countryCode, const char* languageCode, c
onst char* scriptCode, bool expectedValid) |
| 172 : regionCode(regionCode) | 172 : countryCode(countryCode) |
| 173 , languageCode(languageCode) | 173 , languageCode(languageCode) |
| 174 , scriptCode(scriptCode) | 174 , scriptCode(scriptCode) |
| 175 , expectedValid(expectedValid) | 175 , expectedValid(expectedValid) |
| 176 { | 176 { |
| 177 } | 177 } |
| 178 ~ShippingAddressTestCase() {} | 178 ~ShippingAddressTestCase() {} |
| 179 | 179 |
| 180 const char* regionCode; | 180 const char* countryCode; |
| 181 const char* languageCode; | 181 const char* languageCode; |
| 182 const char* scriptCode; | 182 const char* scriptCode; |
| 183 bool expectedValid; | 183 bool expectedValid; |
| 184 }; | 184 }; |
| 185 | 185 |
| 186 class PaymentsShippingAddressValidatorTest : public testing::TestWithParam<Shipp
ingAddressTestCase> { | 186 class PaymentsShippingAddressValidatorTest : public testing::TestWithParam<Shipp
ingAddressTestCase> { |
| 187 }; | 187 }; |
| 188 | 188 |
| 189 TEST_P(PaymentsShippingAddressValidatorTest, IsValidShippingAddress) | 189 TEST_P(PaymentsShippingAddressValidatorTest, IsValidShippingAddress) |
| 190 { | 190 { |
| 191 mojom::blink::PaymentAddressPtr address = mojom::blink::PaymentAddress::New(
); | 191 mojom::blink::PaymentAddressPtr address = mojom::blink::PaymentAddress::New(
); |
| 192 address->region_code = GetParam().regionCode; | 192 address->country = GetParam().countryCode; |
| 193 address->language_code = GetParam().languageCode; | 193 address->language_code = GetParam().languageCode; |
| 194 address->script_code = GetParam().scriptCode; | 194 address->script_code = GetParam().scriptCode; |
| 195 | 195 |
| 196 String errorMessage; | 196 String errorMessage; |
| 197 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre
ss(address, &errorMessage)) << errorMessage; | 197 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre
ss(address, &errorMessage)) << errorMessage; |
| 198 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; | 198 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; |
| 199 | 199 |
| 200 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre
ss(address, nullptr)); | 200 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidShippingAddre
ss(address, nullptr)); |
| 201 } | 201 } |
| 202 | 202 |
| 203 INSTANTIATE_TEST_CASE_P(ShippingAddresses, | 203 INSTANTIATE_TEST_CASE_P(ShippingAddresses, |
| 204 PaymentsShippingAddressValidatorTest, | 204 PaymentsShippingAddressValidatorTest, |
| 205 testing::Values( | 205 testing::Values( |
| 206 ShippingAddressTestCase("US", "en", "Latn", true), | 206 ShippingAddressTestCase("US", "en", "Latn", true), |
| 207 ShippingAddressTestCase("US", "en", "", true), | 207 ShippingAddressTestCase("US", "en", "", true), |
| 208 ShippingAddressTestCase("US", "", "", true), | 208 ShippingAddressTestCase("US", "", "", true), |
| 209 // Invalid shipping addresses | 209 // Invalid shipping addresses |
| 210 ShippingAddressTestCase("", "", "", false), | 210 ShippingAddressTestCase("", "", "", false), |
| 211 ShippingAddressTestCase("InvalidRegionCode", "", "", false), | 211 ShippingAddressTestCase("InvalidCountryCode", "", "", false), |
| 212 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false), | 212 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false), |
| 213 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false), | 213 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false), |
| 214 ShippingAddressTestCase("US", "", "Latn", false))); | 214 ShippingAddressTestCase("US", "", "Latn", false))); |
| 215 | 215 |
| 216 } // namespace | 216 } // namespace |
| 217 } // namespace blink | 217 } // namespace blink |
| OLD | NEW |