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

Unified Diff: components/payments/payments_validators_test.cc

Issue 2373103002: [Web Payments] Common Payments validation (Closed)
Patch Set: Deps 2 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 side-by-side diff with in-line comments
Download patch
Index: components/payments/payments_validators_test.cc
diff --git a/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp b/components/payments/payments_validators_test.cc
similarity index 78%
copy from third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
copy to components/payments/payments_validators_test.cc
index 6b68029fd3a94c9f4d0d06de59bb32a410bde8bd..d08bd7a014b4f436c3565cd734b9b4573e676b33 100644
--- a/third_party/WebKit/Source/modules/payments/PaymentsValidatorsTest.cpp
+++ b/components/payments/payments_validators_test.cc
@@ -2,27 +2,31 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "modules/payments/PaymentsValidators.h"
+#include "components/payments/payments_validators.h"
#include "testing/gtest/include/gtest/gtest.h"
-#include "wtf/text/WTFString.h"
#include <ostream> // NOLINT
namespace blink {
namespace {
-struct CurrencyCodeTestCase {
- CurrencyCodeTestCase(const char* code, const char* system, bool expectedValid)
- : code(code), system(system), expectedValid(expectedValid) {}
- ~CurrencyCodeTestCase() {}
+struct TestCase {
+ TestCase(const char* input, bool expectedValid)
+ : input(input), expectedValid(expectedValid) {}
+ ~TestCase() {}
- const char* code;
- const char* system;
+ const char* input;
bool expectedValid;
};
-class PaymentsCurrencyValidatorTest
- : public testing::TestWithParam<CurrencyCodeTestCase> {};
+std::ostream& operator<<(std::ostream& out, const TestCase& testCase) {
+ out << "'" << testCase.input << "' is expected to be "
+ << (testCase.expectedValid ? "valid" : "invalid");
+ return out;
+}
+
+class PaymentsCurrencyValidatorTest : public testing::TestWithParam<TestCase> {
+};
const char* longString2048() {
static char longString[2049];
@@ -43,61 +47,30 @@ const char* longString2049() {
TEST_P(PaymentsCurrencyValidatorTest, IsValidCurrencyCodeFormat) {
String errorMessage;
EXPECT_EQ(GetParam().expectedValid,
- PaymentsValidators::isValidCurrencyCodeFormat(
- GetParam().code, GetParam().system, &errorMessage))
+ PaymentsValidators::isValidCurrencyCodeFormat(GetParam().input,
+ &errorMessage))
<< errorMessage;
EXPECT_EQ(GetParam().expectedValid, errorMessage.isEmpty()) << errorMessage;
- EXPECT_EQ(GetParam().expectedValid,
- PaymentsValidators::isValidCurrencyCodeFormat(
- GetParam().code, GetParam().system, nullptr));
+ EXPECT_EQ(
+ GetParam().expectedValid,
+ PaymentsValidators::isValidCurrencyCodeFormat(GetParam().input, nullptr));
}
INSTANTIATE_TEST_CASE_P(
CurrencyCodes,
PaymentsCurrencyValidatorTest,
testing::Values(
- // The most common identifiers are three-letter alphabetic codes as
- // defined by [ISO4217] (for example, "USD" for US Dollars).
- // |system| is a URL that indicates the currency system that the
- // currency identifier belongs to. By default,
- // the value is urn:iso:std:iso:4217 indicating that currency is defined
- // by [[ISO4217]], however any string of at most 2048
- // characters is considered valid in other currencySystem. Returns false
- // if currency |code| is too long (greater than 2048).
- CurrencyCodeTestCase("USD", "urn:iso:std:iso:4217", true),
- CurrencyCodeTestCase("US1", "http://www.example.com", true),
- CurrencyCodeTestCase("US1", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase("US", "http://www.example.com", true),
- CurrencyCodeTestCase("US", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase("USDO", "http://www.example.com", true),
- CurrencyCodeTestCase("USDO", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase("usd", "http://www.example.com", true),
- CurrencyCodeTestCase("usd", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase("ANYSTRING", "http://www.example.com", true),
- CurrencyCodeTestCase("ANYSTRING", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase("", "http://www.example.com", true),
- CurrencyCodeTestCase("", "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase(longString2048(), "http://www.example.com", true),
- CurrencyCodeTestCase(longString2048(), "urn:iso:std:iso:4217", false),
- CurrencyCodeTestCase(longString2049(),
- "http://www.example.com",
- false)));
-
-struct TestCase {
- TestCase(const char* input, bool expectedValid)
- : input(input), expectedValid(expectedValid) {}
- ~TestCase() {}
-
- const char* input;
- bool expectedValid;
-};
-
-std::ostream& operator<<(std::ostream& out, const TestCase& testCase) {
- out << "'" << testCase.input << "' is expected to be "
- << (testCase.expectedValid ? "valid" : "invalid");
- return out;
-}
+ // Any string of at most 2048 characters can be a valid currency code
+ TestCase("USD", true),
+ TestCase("US1", true),
+ TestCase("US", true),
+ TestCase("USDO", true),
+ TestCase("usd", true),
+ TestCase("ANYSTRING", true),
+ TestCase("", true),
+ TestCase(longString2048(), true),
+ TestCase(longString2049(), false)));
class PaymentsAmountValidatorTest : public testing::TestWithParam<TestCase> {};
« components/payments/payments_validators.cc ('K') | « components/payments/payments_validators.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698