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

Unified Diff: components/payments/core/payment_method_data_unittest.cc

Issue 2797633002: [Payments] Move PaymentMethodData to components/payments/core (Closed)
Patch Set: clean Created 3 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: components/payments/core/payment_method_data_unittest.cc
diff --git a/components/payments/core/payment_method_data_unittest.cc b/components/payments/core/payment_method_data_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..ce07ad9d2ccde260c0cb898f59b5422c4b24915b
--- /dev/null
+++ b/components/payments/core/payment_method_data_unittest.cc
@@ -0,0 +1,111 @@
+// Copyright 2017 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "components/payments/core/payment_method_data.h"
+
+#include "base/strings/utf_string_conversions.h"
+#include "base/values.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace payments {
+
+// Tests the success case when populating a PaymentMethodData from a dictionary.
+TEST(PaymentMethodData, FromDictionaryValueSuccess) {
+ PaymentMethodData expected;
+ std::vector<base::string16> supported_methods;
+ supported_methods.push_back(base::ASCIIToUTF16("visa"));
+ supported_methods.push_back(base::ASCIIToUTF16("basic-card"));
+ expected.supported_methods = supported_methods;
+ expected.data = base::ASCIIToUTF16(
+ "{\"supportedNetworks\":[\"mastercard\"],"
+ "\"supportedTypes\":[\"debit\",\"credit\"]}");
+ std::vector<base::string16> supported_networks;
+ supported_networks.push_back(base::ASCIIToUTF16("mastercard"));
+ expected.supported_networks = supported_networks;
+ std::vector<base::string16> supported_types;
+ supported_types.push_back(base::ASCIIToUTF16("debit"));
+ supported_types.push_back(base::ASCIIToUTF16("credit"));
+ expected.supported_types = supported_types;
+
+ base::DictionaryValue method_data_dict;
+ std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
+ supported_methods_list->AppendString("visa");
+ supported_methods_list->AppendString("basic-card");
+ method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
+ std::unique_ptr<base::DictionaryValue> data_dict(new base::DictionaryValue);
+ std::unique_ptr<base::ListValue> supported_networks_list(new base::ListValue);
+ supported_networks_list->AppendString("mastercard");
+ data_dict->Set("supportedNetworks", std::move(supported_networks_list));
+ std::unique_ptr<base::ListValue> supported_types_list(new base::ListValue);
+ supported_types_list->AppendString("debit");
+ supported_types_list->AppendString("credit");
+ data_dict->Set("supportedTypes", std::move(supported_types_list));
+ method_data_dict.Set("data", std::move(data_dict));
+
+ PaymentMethodData actual;
+ EXPECT_TRUE(actual.FromDictionaryValue(method_data_dict));
+
+ EXPECT_EQ(expected, actual);
+}
+
+// Tests the failure case when populating a PaymentMethodData from a dictionary.
+TEST(PaymentMethodData, FromDictionaryValueFailure) {
+ // At least one supported method is required.
+ PaymentMethodData actual;
+ base::DictionaryValue method_data_dict;
+ EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
+
+ // The value in the supported methods list must be a string.
+ std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
+ supported_methods_list->AppendInteger(13);
+ method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
+ EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
+}
+
+// Tests that two method data objects are not equal if their property values
+// differ or one is missing a value present in the other, and equal otherwise.
+TEST(PaymentMethodData, Equality) {
+ PaymentMethodData method_data1;
+ PaymentMethodData method_data2;
+ EXPECT_EQ(method_data1, method_data2);
+
+ std::vector<base::string16> supported_methods1;
+ supported_methods1.push_back(base::ASCIIToUTF16("basic-card"));
+ supported_methods1.push_back(base::ASCIIToUTF16("http://bobpay.com"));
+ method_data1.supported_methods = supported_methods1;
+ EXPECT_NE(method_data1, method_data2);
+ std::vector<base::string16> supported_methods2;
+ supported_methods2.push_back(base::ASCIIToUTF16("http://bobpay.com"));
+ method_data2.supported_methods = supported_methods2;
+ EXPECT_NE(method_data1, method_data2);
+ method_data2.supported_methods = supported_methods1;
+ EXPECT_EQ(method_data1, method_data2);
+
+ method_data1.data = base::ASCIIToUTF16("{merchantId: '123456'}");
+ EXPECT_NE(method_data1, method_data2);
+ method_data2.data = base::ASCIIToUTF16("{merchantId: '9999-88'}");
+ EXPECT_NE(method_data1, method_data2);
+ method_data2.data = base::ASCIIToUTF16("{merchantId: '123456'}");
+ EXPECT_EQ(method_data1, method_data2);
+
+ std::vector<base::string16> supported_networks1{base::ASCIIToUTF16("visa")};
+ method_data1.supported_networks = supported_networks1;
+ EXPECT_NE(method_data1, method_data2);
+ std::vector<base::string16> supported_networks2{base::ASCIIToUTF16("jcb")};
+ method_data2.supported_networks = supported_networks2;
+ EXPECT_NE(method_data1, method_data2);
+ method_data2.supported_networks = supported_networks1;
+ EXPECT_EQ(method_data1, method_data2);
+
+ std::vector<base::string16> supported_types1{base::ASCIIToUTF16("credit")};
+ method_data1.supported_types = supported_types1;
+ EXPECT_NE(method_data1, method_data2);
+ std::vector<base::string16> supported_types2{base::ASCIIToUTF16("debit")};
+ method_data2.supported_types = supported_types2;
+ EXPECT_NE(method_data1, method_data2);
+ method_data2.supported_types = supported_types1;
+ EXPECT_EQ(method_data1, method_data2);
+}
+
+} // namespace payments
« no previous file with comments | « components/payments/core/payment_method_data.cc ('k') | ios/chrome/browser/payments/payment_request_test_util.mm » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698