OLD | NEW |
---|---|
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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 "ios/chrome/browser/payments/payment_request.h" | 5 #include "ios/chrome/browser/payments/payment_request.h" |
6 | 6 |
7 #include "base/strings/utf_string_conversions.h" | 7 #include "base/strings/utf_string_conversions.h" |
8 #include "components/autofill/core/browser/autofill_test_utils.h" | 8 #include "components/autofill/core/browser/autofill_test_utils.h" |
9 #include "components/autofill/core/browser/test_personal_data_manager.h" | 9 #include "components/autofill/core/browser/test_personal_data_manager.h" |
10 #include "components/payments/core/currency_formatter.h" | 10 #include "components/payments/core/currency_formatter.h" |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
58 payments::PaymentMethodData method_datum2; | 58 payments::PaymentMethodData method_datum2; |
59 method_datum2.supported_methods.push_back("mastercard"); | 59 method_datum2.supported_methods.push_back("mastercard"); |
60 web_payment_request.method_data.push_back(method_datum2); | 60 web_payment_request.method_data.push_back(method_datum2); |
61 | 61 |
62 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | 62 PaymentRequest payment_request(web_payment_request, &personal_data_manager); |
63 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | 63 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); |
64 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | 64 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); |
65 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | 65 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); |
66 } | 66 } |
67 | 67 |
68 // Test that parsing supported methods (with invalid values and duplicates) | |
69 // works as expected. | |
70 TEST(PaymentRequestTest, SupportedMethods) { | |
71 web::PaymentRequest web_payment_request; | |
72 autofill::TestPersonalDataManager personal_data_manager; | |
73 | |
74 payments::PaymentMethodData method_datum1; | |
75 method_datum1.supported_methods.push_back("visa"); | |
76 method_datum1.supported_methods.push_back("mastercard"); | |
77 method_datum1.supported_methods.push_back("invalid"); | |
78 method_datum1.supported_methods.push_back(""); | |
79 method_datum1.supported_methods.push_back("visa"); | |
80 web_payment_request.method_data.push_back(method_datum1); | |
81 | |
82 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
83 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | |
84 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | |
85 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | |
86 } | |
87 | |
88 // Test that parsing supported methods in different method data entries (with | |
89 // invalid values and duplicates) works as expected. | |
90 TEST(PaymentRequestTest, SupportedMethods_MultipleEntries) { | |
91 web::PaymentRequest web_payment_request; | |
92 autofill::TestPersonalDataManager personal_data_manager; | |
93 | |
94 payments::PaymentMethodData method_datum1; | |
95 method_datum1.supported_methods.push_back("visa"); | |
96 web_payment_request.method_data.push_back(method_datum1); | |
97 payments::PaymentMethodData method_datum2; | |
98 method_datum2.supported_methods.push_back("mastercard"); | |
99 web_payment_request.method_data.push_back(method_datum2); | |
100 payments::PaymentMethodData method_datum3; | |
101 method_datum3.supported_methods.push_back("visa"); | |
102 web_payment_request.method_data.push_back(method_datum3); | |
103 | |
104 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
105 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | |
106 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | |
107 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | |
108 } | |
109 | |
110 // Test that parsing supported methods in different method data entries fails as | |
111 // soon as one entry doesn't specify anything in supported_methods. | |
Moe
2017/04/06 20:51:03
Should we combine this test with the previous one?
Mathieu
2017/04/06 21:04:41
Good point
| |
112 TEST(PaymentRequestTest, SupportedMethods_MultipleEntries_OneEmpty) { | |
113 web::PaymentRequest web_payment_request; | |
114 autofill::TestPersonalDataManager personal_data_manager; | |
115 | |
116 payments::PaymentMethodData method_datum1; | |
117 method_datum1.supported_methods.push_back("visa"); | |
118 web_payment_request.method_data.push_back(method_datum1); | |
119 payments::PaymentMethodData method_datum2; | |
120 method_datum2.supported_methods.push_back(""); | |
121 web_payment_request.method_data.push_back(method_datum2); | |
122 payments::PaymentMethodData method_datum3; | |
123 method_datum3.supported_methods.push_back("mastercard"); | |
124 web_payment_request.method_data.push_back(method_datum3); | |
125 | |
126 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
127 ASSERT_EQ(2U, payment_request.supported_card_networks().size()); | |
128 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | |
129 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[1]); | |
130 } | |
131 | |
132 // Test that only specifying basic-card means that all are supported. | |
133 TEST(PaymentRequestTest, SupportedMethods_OnlyBasicCard) { | |
134 web::PaymentRequest web_payment_request; | |
135 autofill::TestPersonalDataManager personal_data_manager; | |
136 | |
137 payments::PaymentMethodData method_datum1; | |
138 method_datum1.supported_methods.push_back("basic-card"); | |
139 web_payment_request.method_data.push_back(method_datum1); | |
140 | |
141 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
142 | |
143 // All of the basic card networks are supported. | |
144 ASSERT_EQ(8U, payment_request.supported_card_networks().size()); | |
145 EXPECT_EQ("amex", payment_request.supported_card_networks()[0]); | |
146 EXPECT_EQ("diners", payment_request.supported_card_networks()[1]); | |
147 EXPECT_EQ("discover", payment_request.supported_card_networks()[2]); | |
148 EXPECT_EQ("jcb", payment_request.supported_card_networks()[3]); | |
149 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); | |
150 EXPECT_EQ("mir", payment_request.supported_card_networks()[5]); | |
151 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[6]); | |
152 EXPECT_EQ("visa", payment_request.supported_card_networks()[7]); | |
153 } | |
154 | |
155 // Test that specifying a method AND basic-card means that all are supported, | |
156 // but with the method as first. | |
157 TEST(PaymentRequestTest, SupportedMethods_BasicCard_WithSpecificMethod) { | |
158 web::PaymentRequest web_payment_request; | |
159 autofill::TestPersonalDataManager personal_data_manager; | |
160 | |
161 payments::PaymentMethodData method_datum1; | |
162 method_datum1.supported_methods.push_back("jcb"); | |
163 method_datum1.supported_methods.push_back("basic-card"); | |
164 web_payment_request.method_data.push_back(method_datum1); | |
165 | |
166 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
167 | |
168 // All of the basic card networks are supported, but JCB is first because it | |
169 // was specified first. | |
170 EXPECT_EQ(8u, payment_request.supported_card_networks().size()); | |
171 EXPECT_EQ("jcb", payment_request.supported_card_networks()[0]); | |
172 EXPECT_EQ("amex", payment_request.supported_card_networks()[1]); | |
173 EXPECT_EQ("diners", payment_request.supported_card_networks()[2]); | |
174 EXPECT_EQ("discover", payment_request.supported_card_networks()[3]); | |
175 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[4]); | |
176 EXPECT_EQ("mir", payment_request.supported_card_networks()[5]); | |
177 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[6]); | |
178 EXPECT_EQ("visa", payment_request.supported_card_networks()[7]); | |
179 } | |
180 | |
181 // Test that specifying basic-card with a supported network (with previous | |
182 // supported methods) will work as expected | |
183 TEST(PaymentRequestTest, SupportedMethods_BasicCard_Overlap) { | |
184 web::PaymentRequest web_payment_request; | |
185 autofill::TestPersonalDataManager personal_data_manager; | |
186 | |
187 payments::PaymentMethodData method_datum1; | |
188 method_datum1.supported_methods.push_back("mastercard"); | |
189 method_datum1.supported_methods.push_back("visa"); | |
190 web_payment_request.method_data.push_back(method_datum1); | |
191 payments::PaymentMethodData method_datum2; | |
192 method_datum2.supported_methods.push_back("basic-card"); | |
193 method_datum2.supported_networks.push_back("visa"); | |
194 method_datum2.supported_networks.push_back("mastercard"); | |
195 method_datum2.supported_networks.push_back("unionpay"); | |
196 web_payment_request.method_data.push_back(method_datum2); | |
197 | |
198 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
199 | |
200 EXPECT_EQ(3u, payment_request.supported_card_networks().size()); | |
201 EXPECT_EQ("mastercard", payment_request.supported_card_networks()[0]); | |
202 EXPECT_EQ("visa", payment_request.supported_card_networks()[1]); | |
203 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[2]); | |
204 } | |
205 | |
206 // Test that specifying basic-card with supported networks after specifying | |
207 // some methods | |
Moe
2017/04/06 20:51:03
what is this testing?
Mathieu
2017/04/06 21:04:41
Specifying basic-card with supported networks. It'
| |
208 TEST(PaymentRequestTest, SupportedMethods_BasicCard_WithSupportedNetworks) { | |
209 web::PaymentRequest web_payment_request; | |
210 autofill::TestPersonalDataManager personal_data_manager; | |
211 | |
212 payments::PaymentMethodData method_datum1; | |
213 method_datum1.supported_methods.push_back("basic-card"); | |
214 method_datum1.supported_networks.push_back("visa"); | |
215 method_datum1.supported_networks.push_back("unionpay"); | |
216 web_payment_request.method_data.push_back(method_datum1); | |
217 | |
218 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | |
219 | |
220 // Only the specified networks are supported. | |
221 EXPECT_EQ(2u, payment_request.supported_card_networks().size()); | |
222 EXPECT_EQ("visa", payment_request.supported_card_networks()[0]); | |
223 EXPECT_EQ("unionpay", payment_request.supported_card_networks()[1]); | |
224 } | |
225 | |
68 // Tests that credit cards can be added to the list of cached credit cards. | 226 // Tests that credit cards can be added to the list of cached credit cards. |
69 TEST(PaymentRequestTest, AddCreditCard) { | 227 TEST(PaymentRequestTest, AddCreditCard) { |
70 web::PaymentRequest web_payment_request; | 228 web::PaymentRequest web_payment_request; |
71 autofill::TestPersonalDataManager personal_data_manager; | 229 autofill::TestPersonalDataManager personal_data_manager; |
72 | 230 |
73 PaymentRequest payment_request(web_payment_request, &personal_data_manager); | 231 PaymentRequest payment_request(web_payment_request, &personal_data_manager); |
74 EXPECT_EQ(0U, payment_request.credit_cards().size()); | 232 EXPECT_EQ(0U, payment_request.credit_cards().size()); |
75 | 233 |
76 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); | 234 autofill::CreditCard credit_card = autofill::test::GetCreditCard(); |
77 autofill::CreditCard* added_credit_card = | 235 autofill::CreditCard* added_credit_card = |
78 payment_request.AddCreditCard(credit_card); | 236 payment_request.AddCreditCard(credit_card); |
79 | 237 |
80 ASSERT_EQ(1U, payment_request.credit_cards().size()); | 238 ASSERT_EQ(1U, payment_request.credit_cards().size()); |
81 EXPECT_EQ(credit_card, *added_credit_card); | 239 EXPECT_EQ(credit_card, *added_credit_card); |
82 } | 240 } |
OLD | NEW |