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

Side by Side Diff: ios/web/payments/payment_request_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
« no previous file with comments | « ios/web/payments/payment_request.cc ('k') | ios/web/public/payments/payment_request.h » ('j') | 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 "ios/web/public/payments/payment_request.h" 5 #include "ios/web/public/payments/payment_request.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/strings/utf_string_conversions.h" 9 #include "base/strings/utf_string_conversions.h"
10 #include "base/values.h" 10 #include "base/values.h"
11 #include "components/payments/core/basic_card_response.h" 11 #include "components/payments/core/basic_card_response.h"
12 #include "components/payments/core/payment_address.h" 12 #include "components/payments/core/payment_address.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 namespace web { 15 namespace web {
16 16
17 // PaymentRequest parsing tests. 17 // PaymentRequest parsing tests.
18 18
19 // Tests the success case when populating a PaymentMethodData from a dictionary.
20 TEST(PaymentRequestTest, PaymentMethodDataFromDictionaryValueSuccess) {
21 PaymentMethodData expected;
22 std::vector<base::string16> supported_methods;
23 supported_methods.push_back(base::ASCIIToUTF16("Visa"));
24 supported_methods.push_back(base::ASCIIToUTF16("Bitcoin"));
25 expected.supported_methods = supported_methods;
26 expected.data = base::ASCIIToUTF16("{merchantId: 'af22fke9'}");
27
28 base::DictionaryValue method_data_dict;
29 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
30 supported_methods_list->AppendString("Visa");
31 supported_methods_list->AppendString("Bitcoin");
32 method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
33 method_data_dict.SetString("data", "{merchantId: 'af22fke9'}");
34
35 PaymentMethodData actual;
36 EXPECT_TRUE(actual.FromDictionaryValue(method_data_dict));
37
38 EXPECT_EQ(expected, actual);
39 }
40
41 // Tests the failure case when populating a PaymentMethodData from a dictionary.
42 TEST(PaymentRequestTest, PaymentMethodDataFromDictionaryValueFailure) {
43 // At least one supported method is required.
44 PaymentMethodData actual;
45 base::DictionaryValue method_data_dict;
46 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
47
48 // The value in the supported methods list must be a string.
49 std::unique_ptr<base::ListValue> supported_methods_list(new base::ListValue);
50 supported_methods_list->AppendInteger(13);
51 method_data_dict.Set("supportedMethods", std::move(supported_methods_list));
52 EXPECT_FALSE(actual.FromDictionaryValue(method_data_dict));
53 }
54
55 // Tests the success case when populating a PaymentCurrencyAmount from a 19 // Tests the success case when populating a PaymentCurrencyAmount from a
56 // dictionary. 20 // dictionary.
57 TEST(PaymentRequestTest, PaymentCurrencyAmountFromDictionaryValueSuccess) { 21 TEST(PaymentRequestTest, PaymentCurrencyAmountFromDictionaryValueSuccess) {
58 PaymentCurrencyAmount expected; 22 PaymentCurrencyAmount expected;
59 expected.currency = base::ASCIIToUTF16("AUD"); 23 expected.currency = base::ASCIIToUTF16("AUD");
60 expected.value = base::ASCIIToUTF16("-438.23"); 24 expected.value = base::ASCIIToUTF16("-438.23");
61 25
62 base::DictionaryValue amount_dict; 26 base::DictionaryValue amount_dict;
63 amount_dict.SetString("currency", "AUD"); 27 amount_dict.SetString("currency", "AUD");
64 amount_dict.SetString("value", "-438.23"); 28 amount_dict.SetString("value", "-438.23");
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
236 PaymentRequest expected_request; 200 PaymentRequest expected_request;
237 PaymentRequest output_request; 201 PaymentRequest output_request;
238 base::DictionaryValue request_dict; 202 base::DictionaryValue request_dict;
239 203
240 // Add the expected values to expected_request. 204 // Add the expected values to expected_request.
241 expected_request.details.total.label = base::ASCIIToUTF16("TOTAL"); 205 expected_request.details.total.label = base::ASCIIToUTF16("TOTAL");
242 expected_request.details.total.amount.currency = base::ASCIIToUTF16("GBP"); 206 expected_request.details.total.amount.currency = base::ASCIIToUTF16("GBP");
243 expected_request.details.total.amount.value = base::ASCIIToUTF16("6.66"); 207 expected_request.details.total.amount.value = base::ASCIIToUTF16("6.66");
244 expected_request.details.error = base::ASCIIToUTF16("Error in details"); 208 expected_request.details.error = base::ASCIIToUTF16("Error in details");
245 209
246 PaymentMethodData method_data; 210 payments::PaymentMethodData method_data;
247 std::vector<base::string16> supported_methods; 211 std::vector<base::string16> supported_methods;
248 supported_methods.push_back(base::ASCIIToUTF16("Visa")); 212 supported_methods.push_back(base::ASCIIToUTF16("Visa"));
249 method_data.supported_methods = supported_methods; 213 method_data.supported_methods = supported_methods;
250 expected_request.method_data.push_back(method_data); 214 expected_request.method_data.push_back(method_data);
251 215
252 // Add the same values to the dictionary to be parsed. 216 // Add the same values to the dictionary to be parsed.
253 std::unique_ptr<base::DictionaryValue> details_dict( 217 std::unique_ptr<base::DictionaryValue> details_dict(
254 new base::DictionaryValue); 218 new base::DictionaryValue);
255 std::unique_ptr<base::DictionaryValue> total_dict(new base::DictionaryValue); 219 std::unique_ptr<base::DictionaryValue> total_dict(new base::DictionaryValue);
256 total_dict->SetString("label", "TOTAL"); 220 total_dict->SetString("label", "TOTAL");
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after
352 payment_response.shipping_option = base::ASCIIToUTF16("666"); 316 payment_response.shipping_option = base::ASCIIToUTF16("666");
353 payment_response.payer_name = base::ASCIIToUTF16("Jane Doe"); 317 payment_response.payer_name = base::ASCIIToUTF16("Jane Doe");
354 payment_response.payer_email = base::ASCIIToUTF16("jane@example.com"); 318 payment_response.payer_email = base::ASCIIToUTF16("jane@example.com");
355 payment_response.payer_phone = base::ASCIIToUTF16("1234-567-890"); 319 payment_response.payer_phone = base::ASCIIToUTF16("1234-567-890");
356 EXPECT_TRUE( 320 EXPECT_TRUE(
357 expected_value.Equals(payment_response.ToDictionaryValue().get())); 321 expected_value.Equals(payment_response.ToDictionaryValue().get()));
358 } 322 }
359 323
360 // Value equality tests. 324 // Value equality tests.
361 325
362 // Tests that two method data objects are not equal if their property values
363 // differ or one is missing a value present in the other, and equal otherwise.
364 TEST(PaymentRequestTest, PaymentMethodDataEquality) {
365 PaymentMethodData method_data1;
366 PaymentMethodData method_data2;
367 EXPECT_EQ(method_data1, method_data2);
368
369 std::vector<base::string16> supported_methods1;
370 supported_methods1.push_back(base::ASCIIToUTF16("Visa"));
371 supported_methods1.push_back(base::ASCIIToUTF16("BobPay"));
372 method_data1.supported_methods = supported_methods1;
373 EXPECT_NE(method_data1, method_data2);
374 std::vector<base::string16> supported_methods2;
375 supported_methods2.push_back(base::ASCIIToUTF16("BobPay"));
376 method_data2.supported_methods = supported_methods2;
377 EXPECT_NE(method_data1, method_data2);
378 method_data2.supported_methods = supported_methods1;
379 EXPECT_EQ(method_data1, method_data2);
380
381 method_data1.data = base::ASCIIToUTF16("{merchantId: '123456'}");
382 EXPECT_NE(method_data1, method_data2);
383 method_data2.data = base::ASCIIToUTF16("{merchantId: '9999-88'}");
384 EXPECT_NE(method_data1, method_data2);
385 method_data2.data = base::ASCIIToUTF16("{merchantId: '123456'}");
386 EXPECT_EQ(method_data1, method_data2);
387 }
388
389 // Tests that two currency amount objects are not equal if their property values 326 // Tests that two currency amount objects are not equal if their property values
390 // differ or one is missing a value present in the other, and equal otherwise. 327 // differ or one is missing a value present in the other, and equal otherwise.
391 TEST(PaymentRequestTest, PaymentCurrencyAmountEquality) { 328 TEST(PaymentRequestTest, PaymentCurrencyAmountEquality) {
392 PaymentCurrencyAmount currency_amount1; 329 PaymentCurrencyAmount currency_amount1;
393 PaymentCurrencyAmount currency_amount2; 330 PaymentCurrencyAmount currency_amount2;
394 EXPECT_EQ(currency_amount1, currency_amount2); 331 EXPECT_EQ(currency_amount1, currency_amount2);
395 332
396 currency_amount1.currency = base::ASCIIToUTF16("HKD"); 333 currency_amount1.currency = base::ASCIIToUTF16("HKD");
397 EXPECT_NE(currency_amount1, currency_amount2); 334 EXPECT_NE(currency_amount1, currency_amount2);
398 currency_amount2.currency = base::ASCIIToUTF16("USD"); 335 currency_amount2.currency = base::ASCIIToUTF16("USD");
(...skipping 237 matching lines...) Expand 10 before | Expand all | Expand 10 after
636 request2.shipping_address = address1; 573 request2.shipping_address = address1;
637 EXPECT_EQ(request1, request2); 574 EXPECT_EQ(request1, request2);
638 575
639 request1.shipping_option = base::ASCIIToUTF16("2-Day"); 576 request1.shipping_option = base::ASCIIToUTF16("2-Day");
640 EXPECT_NE(request1, request2); 577 EXPECT_NE(request1, request2);
641 request2.shipping_option = base::ASCIIToUTF16("3-Day"); 578 request2.shipping_option = base::ASCIIToUTF16("3-Day");
642 EXPECT_NE(request1, request2); 579 EXPECT_NE(request1, request2);
643 request2.shipping_option = base::ASCIIToUTF16("2-Day"); 580 request2.shipping_option = base::ASCIIToUTF16("2-Day");
644 EXPECT_EQ(request1, request2); 581 EXPECT_EQ(request1, request2);
645 582
646 PaymentMethodData method_datum; 583 payments::PaymentMethodData method_datum;
647 method_datum.data = base::ASCIIToUTF16("{merchantId: '123456'}"); 584 method_datum.data = base::ASCIIToUTF16("{merchantId: '123456'}");
648 std::vector<PaymentMethodData> method_data1; 585 std::vector<payments::PaymentMethodData> method_data1;
649 method_data1.push_back(method_datum); 586 method_data1.push_back(method_datum);
650 request1.method_data = method_data1; 587 request1.method_data = method_data1;
651 EXPECT_NE(request1, request2); 588 EXPECT_NE(request1, request2);
652 std::vector<PaymentMethodData> method_data2; 589 std::vector<payments::PaymentMethodData> method_data2;
653 request2.method_data = method_data2; 590 request2.method_data = method_data2;
654 EXPECT_NE(request1, request2); 591 EXPECT_NE(request1, request2);
655 request2.method_data = method_data1; 592 request2.method_data = method_data1;
656 EXPECT_EQ(request1, request2); 593 EXPECT_EQ(request1, request2);
657 594
658 PaymentDetails details1; 595 PaymentDetails details1;
659 details1.total.label = base::ASCIIToUTF16("Total"); 596 details1.total.label = base::ASCIIToUTF16("Total");
660 request1.details = details1; 597 request1.details = details1;
661 EXPECT_NE(request1, request2); 598 EXPECT_NE(request1, request2);
662 PaymentDetails details2; 599 PaymentDetails details2;
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
696 card_response2.card_number = base::ASCIIToUTF16("8888"); 633 card_response2.card_number = base::ASCIIToUTF16("8888");
697 response1.details = card_response1; 634 response1.details = card_response1;
698 EXPECT_NE(response1, response2); 635 EXPECT_NE(response1, response2);
699 response2.details = card_response2; 636 response2.details = card_response2;
700 EXPECT_NE(response1, response2); 637 EXPECT_NE(response1, response2);
701 response2.details = card_response1; 638 response2.details = card_response1;
702 EXPECT_EQ(response1, response2); 639 EXPECT_EQ(response1, response2);
703 } 640 }
704 641
705 } // namespace web 642 } // namespace web
OLDNEW
« no previous file with comments | « ios/web/payments/payment_request.cc ('k') | ios/web/public/payments/payment_request.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698