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

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

Issue 2410143003: Add currencySystem field to PaymentCurrencyAmount (Closed)
Patch Set: Fix tests in Win builds Created 4 years, 2 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 | « third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp ('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 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 { 12 namespace {
13 13
14 struct TestCase { 14 struct CurrencyCodeTestCase {
15 TestCase(const char* input, bool expectedValid) 15 CurrencyCodeTestCase(const char* code, const char* system, bool expectedValid)
16 : input(input), expectedValid(expectedValid) {} 16 : code(code), system(system), expectedValid(expectedValid) {}
17 ~TestCase() {} 17 ~CurrencyCodeTestCase() {}
18 18
19 const char* input; 19 const char* code;
20 const char* system;
20 bool expectedValid; 21 bool expectedValid;
21 }; 22 };
22 23
23 std::ostream& operator<<(std::ostream& out, const TestCase& testCase) { 24 class PaymentsCurrencyValidatorTest
24 out << "'" << testCase.input << "' is expected to be " 25 : public testing::TestWithParam<CurrencyCodeTestCase> {};
25 << (testCase.expectedValid ? "valid" : "invalid");
26 return out;
27 }
28
29 class PaymentsCurrencyValidatorTest : public testing::TestWithParam<TestCase> {
30 };
31 26
32 const char* longString2048() { 27 const char* longString2048() {
33 static char longString[2049]; 28 static char longString[2049];
34 for (int i = 0; i < 2048; i++) 29 for (int i = 0; i < 2048; i++)
35 longString[i] = 'a'; 30 longString[i] = 'a';
36 longString[2048] = '\0'; 31 longString[2048] = '\0';
37 return longString; 32 return longString;
38 } 33 }
39 34
40 const char* longString2049() { 35 const char* longString2049() {
41 static char longString[2050]; 36 static char longString[2050];
42 for (int i = 0; i < 2049; i++) 37 for (int i = 0; i < 2049; i++)
43 longString[i] = 'a'; 38 longString[i] = 'a';
44 longString[2049] = '\0'; 39 longString[2049] = '\0';
45 return longString; 40 return longString;
46 } 41 }
47 42
48 TEST_P(PaymentsCurrencyValidatorTest, IsValidCurrencyCodeFormat) { 43 TEST_P(PaymentsCurrencyValidatorTest, IsValidCurrencyCodeFormat) {
49 String errorMessage; 44 String errorMessage;
50 EXPECT_EQ(GetParam().expectedValid, 45 EXPECT_EQ(GetParam().expectedValid,
51 PaymentsValidators::isValidCurrencyCodeFormat(GetParam().input, 46 PaymentsValidators::isValidCurrencyCodeFormat(
52 &errorMessage)) 47 GetParam().code, GetParam().system, &errorMessage))
53 << errorMessage; 48 << errorMessage;
54 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; 49 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
55 50
56 EXPECT_EQ( 51 EXPECT_EQ(GetParam().expectedValid,
57 GetParam().expectedValid, 52 PaymentsValidators::isValidCurrencyCodeFormat(
58 PaymentsValidators::isValidCurrencyCodeFormat(GetParam().input, nullptr)); 53 GetParam().code, GetParam().system, nullptr));
59 } 54 }
60 55
61 INSTANTIATE_TEST_CASE_P( 56 INSTANTIATE_TEST_CASE_P(
62 CurrencyCodes, 57 CurrencyCodes,
63 PaymentsCurrencyValidatorTest, 58 PaymentsCurrencyValidatorTest,
64 testing::Values( 59 testing::Values(
65 // Any string of at most 2048 characters can be a valid currency code 60 // The most common identifiers are three-letter alphabetic codes as
66 TestCase("USD", true), 61 // defined by [ISO4217] (for example, "USD" for US Dollars).
67 TestCase("US1", true), 62 // |system| is a URL that indicates the currency system that the
68 TestCase("US", true), 63 // currency identifier belongs to. By default,
69 TestCase("USDO", true), 64 // the value is urn:iso:std:iso:4217 indicating that currency is defined
70 TestCase("usd", true), 65 // by [[ISO4217]], however any string of at most 2048
71 TestCase("ANYSTRING", true), 66 // characters is considered valid in other currencySystem. Returns false
72 TestCase("", true), 67 // if currency |code| is too long (greater than 2048).
73 TestCase(longString2048(), true), 68 CurrencyCodeTestCase("USD", "urn:iso:std:iso:4217", true),
74 TestCase(longString2049(), false))); 69 CurrencyCodeTestCase("US1", "http://www.example.com", true),
70 CurrencyCodeTestCase("US1", "urn:iso:std:iso:4217", false),
71 CurrencyCodeTestCase("US", "http://www.example.com", true),
72 CurrencyCodeTestCase("US", "urn:iso:std:iso:4217", false),
73 CurrencyCodeTestCase("USDO", "http://www.example.com", true),
74 CurrencyCodeTestCase("USDO", "urn:iso:std:iso:4217", false),
75 CurrencyCodeTestCase("usd", "http://www.example.com", true),
76 CurrencyCodeTestCase("usd", "urn:iso:std:iso:4217", false),
77 CurrencyCodeTestCase("ANYSTRING", "http://www.example.com", true),
78 CurrencyCodeTestCase("ANYSTRING", "urn:iso:std:iso:4217", false),
79 CurrencyCodeTestCase("", "http://www.example.com", true),
80 CurrencyCodeTestCase("", "urn:iso:std:iso:4217", false),
81 CurrencyCodeTestCase(longString2048(), "http://www.example.com", true),
82 CurrencyCodeTestCase(longString2048(), "urn:iso:std:iso:4217", false),
83 CurrencyCodeTestCase(longString2049(),
84 "http://www.example.com",
85 false)));
86
87 struct TestCase {
88 TestCase(const char* input, bool expectedValid)
89 : input(input), expectedValid(expectedValid) {}
90 ~TestCase() {}
91
92 const char* input;
93 bool expectedValid;
94 };
95
96 std::ostream& operator<<(std::ostream& out, const TestCase& testCase) {
97 out << "'" << testCase.input << "' is expected to be "
98 << (testCase.expectedValid ? "valid" : "invalid");
99 return out;
100 }
75 101
76 class PaymentsAmountValidatorTest : public testing::TestWithParam<TestCase> {}; 102 class PaymentsAmountValidatorTest : public testing::TestWithParam<TestCase> {};
77 103
78 TEST_P(PaymentsAmountValidatorTest, IsValidAmountFormat) { 104 TEST_P(PaymentsAmountValidatorTest, IsValidAmountFormat) {
79 String errorMessage; 105 String errorMessage;
80 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidAmountFormat( 106 EXPECT_EQ(GetParam().expectedValid, PaymentsValidators::isValidAmountFormat(
81 GetParam().input, &errorMessage)) 107 GetParam().input, &errorMessage))
82 << errorMessage; 108 << errorMessage;
83 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage; 109 EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
84 110
(...skipping 156 matching lines...) Expand 10 before | Expand all | Expand 10 after
241 ShippingAddressTestCase("US", "", "", true), 267 ShippingAddressTestCase("US", "", "", true),
242 // Invalid shipping addresses 268 // Invalid shipping addresses
243 ShippingAddressTestCase("", "", "", false), 269 ShippingAddressTestCase("", "", "", false),
244 ShippingAddressTestCase("InvalidCountryCode", "", "", false), 270 ShippingAddressTestCase("InvalidCountryCode", "", "", false),
245 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false), 271 ShippingAddressTestCase("US", "InvalidLanguageCode", "", false),
246 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false), 272 ShippingAddressTestCase("US", "en", "InvalidScriptCode", false),
247 ShippingAddressTestCase("US", "", "Latn", false))); 273 ShippingAddressTestCase("US", "", "Latn", false)));
248 274
249 } // namespace 275 } // namespace
250 } // namespace blink 276 } // namespace blink
OLDNEW
« no previous file with comments | « third_party/WebKit/Source/modules/payments/PaymentsValidators.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698