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

Side by Side 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 unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/payments/core/payment_method_data.h"
6
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/values.h"
9 #include "testing/gtest/include/gtest/gtest.h"
10
11 namespace payments {
12
13 // Tests the success case when populating a PaymentMethodData from a dictionary.
14 TEST(PaymentMethodData, FromDictionaryValueSuccess) {
15 PaymentMethodData expected;
16 std::vector<base::string16> supported_methods;
17 supported_methods.push_back(base::ASCIIToUTF16("visa"));
18 supported_methods.push_back(base::ASCIIToUTF16("basic-card"));
19 expected.supported_methods = supported_methods;
20 expected.data = base::ASCIIToUTF16(
21 "{\"supportedNetworks\":[\"mastercard\"],"
22 "\"supportedTypes\":[\"debit\",\"credit\"]}");
23 std::vector<base::string16> supported_networks;
24 supported_networks.push_back(base::ASCIIToUTF16("mastercard"));
25 expected.supported_networks = supported_networks;
26 std::vector<base::string16> supported_types;
27 supported_types.push_back(base::ASCIIToUTF16("debit"));
28 supported_types.push_back(base::ASCIIToUTF16("credit"));
29 expected.supported_types = supported_types;
30
31 base::DictionaryValue method_data_dict;
32 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
33 supported_methods_list->AppendString("visa");
34 supported_methods_list->AppendString("basic-card");
35 method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
36 std::unique_ptr<base::DictionaryValue> data_dict(new base::DictionaryValue);
37 std::unique_ptr<base::ListValue> supported_networks_list(new base::ListValue);
38 supported_networks_list->AppendString("mastercard");
39 data_dict->Set("supportedNetworks", std::move(supported_networks_list));
40 std::unique_ptr<base::ListValue> supported_types_list(new base::ListValue);
41 supported_types_list->AppendString("debit");
42 supported_types_list->AppendString("credit");
43 data_dict->Set("supportedTypes", std::move(supported_types_list));
44 method_data_dict.Set("data", std::move(data_dict));
45
46 PaymentMethodData actual;
47 EXPECT_TRUE(actual.FromDictionaryValue(method_data_dict));
48
49 EXPECT_EQ(expected, actual);
50 }
51
52 // Tests the failure case when populating a PaymentMethodData from a dictionary.
53 TEST(PaymentMethodData, FromDictionaryValueFailure) {
54 // At least one supported method is required.
55 PaymentMethodData actual;
56 base::DictionaryValue method_data_dict;
57 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
58
59 // The value in the supported methods list must be a string.
60 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
61 supported_methods_list->AppendInteger(13);
62 method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
63 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
64 }
65
66 // Tests that two method data objects are not equal if their property values
67 // differ or one is missing a value present in the other, and equal otherwise.
68 TEST(PaymentMethodData, Equality) {
69 PaymentMethodData method_data1;
70 PaymentMethodData method_data2;
71 EXPECT_EQ(method_data1, method_data2);
72
73 std::vector<base::string16> supported_methods1;
74 supported_methods1.push_back(base::ASCIIToUTF16("basic-card"));
75 supported_methods1.push_back(base::ASCIIToUTF16("http://bobpay.com"));
76 method_data1.supported_methods = supported_methods1;
77 EXPECT_NE(method_data1, method_data2);
78 std::vector<base::string16> supported_methods2;
79 supported_methods2.push_back(base::ASCIIToUTF16("http://bobpay.com"));
80 method_data2.supported_methods = supported_methods2;
81 EXPECT_NE(method_data1, method_data2);
82 method_data2.supported_methods = supported_methods1;
83 EXPECT_EQ(method_data1, method_data2);
84
85 method_data1.data = base::ASCIIToUTF16("{merchantId: '123456'}");
86 EXPECT_NE(method_data1, method_data2);
87 method_data2.data = base::ASCIIToUTF16("{merchantId: '9999-88'}");
88 EXPECT_NE(method_data1, method_data2);
89 method_data2.data = base::ASCIIToUTF16("{merchantId: '123456'}");
90 EXPECT_EQ(method_data1, method_data2);
91
92 std::vector<base::string16> supported_networks1{base::ASCIIToUTF16("visa")};
93 method_data1.supported_networks = supported_networks1;
94 EXPECT_NE(method_data1, method_data2);
95 std::vector<base::string16> supported_networks2{base::ASCIIToUTF16("jcb")};
96 method_data2.supported_networks = supported_networks2;
97 EXPECT_NE(method_data1, method_data2);
98 method_data2.supported_networks = supported_networks1;
99 EXPECT_EQ(method_data1, method_data2);
100
101 std::vector<base::string16> supported_types1{base::ASCIIToUTF16("credit")};
102 method_data1.supported_types = supported_types1;
103 EXPECT_NE(method_data1, method_data2);
104 std::vector<base::string16> supported_types2{base::ASCIIToUTF16("debit")};
105 method_data2.supported_types = supported_types2;
106 EXPECT_NE(method_data1, method_data2);
107 method_data2.supported_types = supported_types1;
108 EXPECT_EQ(method_data1, method_data2);
109 }
110
111 } // namespace payments
OLDNEW
« 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