OLD | NEW |
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" |
(...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
97 | 97 |
98 EXPECT_TRUE(output_request.FromDictionaryValue(request_dict)); | 98 EXPECT_TRUE(output_request.FromDictionaryValue(request_dict)); |
99 EXPECT_EQ(expected_request, output_request); | 99 EXPECT_EQ(expected_request, output_request); |
100 } | 100 } |
101 | 101 |
102 // PaymentResponse serialization tests. | 102 // PaymentResponse serialization tests. |
103 | 103 |
104 // Tests that serializing a default PaymentResponse yields an empty dictionary. | 104 // Tests that serializing a default PaymentResponse yields an empty dictionary. |
105 TEST(PaymentRequestTest, EmptyResponseDictionary) { | 105 TEST(PaymentRequestTest, EmptyResponseDictionary) { |
106 base::DictionaryValue expected_value; | 106 base::DictionaryValue expected_value; |
107 base::DictionaryValue output_value; | 107 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
| 108 std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue); |
| 109 details->Set("billingAddress", std::move(address)); |
| 110 expected_value.Set("details", std::move(details)); |
108 | 111 |
109 PaymentResponse payment_response; | 112 PaymentResponse payment_response; |
110 payment_response.ToDictionaryValue(&output_value); | 113 EXPECT_TRUE( |
111 EXPECT_TRUE(expected_value.Equals(&output_value)); | 114 expected_value.Equals(payment_response.ToDictionaryValue().get())); |
112 } | 115 } |
113 | 116 |
114 // Tests that serializing a populated PaymentResponse yields the expected | 117 // Tests that serializing a populated PaymentResponse yields the expected |
115 // result. | 118 // result. |
116 TEST(PaymentRequestTest, PopulatedResponseDictionary) { | 119 TEST(PaymentRequestTest, PopulatedResponseDictionary) { |
117 base::DictionaryValue expected_value; | 120 base::DictionaryValue expected_value; |
118 base::DictionaryValue output_value; | 121 std::unique_ptr<base::DictionaryValue> details(new base::DictionaryValue); |
| 122 std::unique_ptr<base::DictionaryValue> address(new base::DictionaryValue); |
| 123 details->Set("billingAddress", std::move(address)); |
| 124 expected_value.Set("details", std::move(details)); |
119 | 125 |
120 expected_value.SetString("methodName", "American Express"); | 126 expected_value.SetString("methodName", "American Express"); |
121 PaymentResponse payment_response; | 127 PaymentResponse payment_response; |
122 payment_response.method_name = base::ASCIIToUTF16("American Express"); | 128 payment_response.method_name = base::ASCIIToUTF16("American Express"); |
123 payment_response.ToDictionaryValue(&output_value); | 129 EXPECT_TRUE( |
124 EXPECT_TRUE(expected_value.Equals(&output_value)); | 130 expected_value.Equals(payment_response.ToDictionaryValue().get())); |
125 | 131 |
126 expected_value.SetString("details", "{cardSecurityCode: '123'}"); | 132 details.reset(new base::DictionaryValue); |
127 payment_response.details = base::ASCIIToUTF16("{cardSecurityCode: '123'}"); | 133 address.reset(new base::DictionaryValue); |
128 payment_response.ToDictionaryValue(&output_value); | 134 address->SetString("postalCode", "90210"); |
129 EXPECT_TRUE(expected_value.Equals(&output_value)); | 135 details->Set("billingAddress", std::move(address)); |
| 136 expected_value.Set("details", std::move(details)); |
| 137 payment_response.details.billing_address.postal_code = |
| 138 base::ASCIIToUTF16("90210"); |
| 139 EXPECT_TRUE( |
| 140 expected_value.Equals(payment_response.ToDictionaryValue().get())); |
130 } | 141 } |
131 | 142 |
132 // Value equality tests. | 143 // Value equality tests. |
133 | 144 |
134 // Tests that two addresses are not equal if their property values differ or | 145 // Tests that two addresses are not equal if their property values differ or |
135 // one is missing a value present in the other, and equal otherwise. | 146 // one is missing a value present in the other, and equal otherwise. |
136 TEST(PaymentRequestTest, PaymentAddressEquality) { | 147 TEST(PaymentRequestTest, PaymentAddressEquality) { |
137 PaymentAddress address1; | 148 PaymentAddress address1; |
138 PaymentAddress address2; | 149 PaymentAddress address2; |
139 EXPECT_EQ(address1, address2); | 150 EXPECT_EQ(address1, address2); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
512 EXPECT_EQ(request1, request2); | 523 EXPECT_EQ(request1, request2); |
513 | 524 |
514 PaymentOptions options; | 525 PaymentOptions options; |
515 options.request_shipping = true; | 526 options.request_shipping = true; |
516 request1.options = options; | 527 request1.options = options; |
517 EXPECT_NE(request1, request2); | 528 EXPECT_NE(request1, request2); |
518 request2.options = options; | 529 request2.options = options; |
519 EXPECT_EQ(request1, request2); | 530 EXPECT_EQ(request1, request2); |
520 } | 531 } |
521 | 532 |
| 533 // Tests that two credit card response objects are not equal if their property |
| 534 // values differ or one is missing a value present in the other, and equal |
| 535 // otherwise. Doesn't test all properties of child objects, relying instead on |
| 536 // their respective tests. |
| 537 TEST(PaymentRequestTest, BasicCardResponseEquality) { |
| 538 BasicCardResponse card_response1; |
| 539 BasicCardResponse card_response2; |
| 540 EXPECT_EQ(card_response1, card_response2); |
| 541 |
| 542 card_response1.cardholder_name = base::ASCIIToUTF16("Shadow Moon"); |
| 543 EXPECT_NE(card_response1, card_response2); |
| 544 card_response2.cardholder_name = base::ASCIIToUTF16("Mad Sweeney"); |
| 545 EXPECT_NE(card_response1, card_response2); |
| 546 card_response2.cardholder_name = base::ASCIIToUTF16("Shadow Moon"); |
| 547 EXPECT_EQ(card_response1, card_response2); |
| 548 |
| 549 card_response1.card_number = base::ASCIIToUTF16("4111111111111111"); |
| 550 EXPECT_NE(card_response1, card_response2); |
| 551 card_response2.card_number = base::ASCIIToUTF16("1111"); |
| 552 EXPECT_NE(card_response1, card_response2); |
| 553 card_response2.card_number = base::ASCIIToUTF16("4111111111111111"); |
| 554 EXPECT_EQ(card_response1, card_response2); |
| 555 |
| 556 card_response1.expiry_month = base::ASCIIToUTF16("01"); |
| 557 EXPECT_NE(card_response1, card_response2); |
| 558 card_response2.expiry_month = base::ASCIIToUTF16("11"); |
| 559 EXPECT_NE(card_response1, card_response2); |
| 560 card_response2.expiry_month = base::ASCIIToUTF16("01"); |
| 561 EXPECT_EQ(card_response1, card_response2); |
| 562 |
| 563 card_response1.expiry_year = base::ASCIIToUTF16("27"); |
| 564 EXPECT_NE(card_response1, card_response2); |
| 565 card_response2.expiry_year = base::ASCIIToUTF16("72"); |
| 566 EXPECT_NE(card_response1, card_response2); |
| 567 card_response2.expiry_year = base::ASCIIToUTF16("27"); |
| 568 EXPECT_EQ(card_response1, card_response2); |
| 569 |
| 570 card_response1.expiry_year = base::ASCIIToUTF16("123"); |
| 571 EXPECT_NE(card_response1, card_response2); |
| 572 card_response2.expiry_year = base::ASCIIToUTF16("999"); |
| 573 EXPECT_NE(card_response1, card_response2); |
| 574 card_response2.expiry_year = base::ASCIIToUTF16("123"); |
| 575 EXPECT_EQ(card_response1, card_response2); |
| 576 |
| 577 PaymentAddress billing_address1; |
| 578 billing_address1.postal_code = base::ASCIIToUTF16("90210"); |
| 579 PaymentAddress billing_address2; |
| 580 billing_address2.postal_code = base::ASCIIToUTF16("01209"); |
| 581 card_response1.billing_address = billing_address1; |
| 582 EXPECT_NE(card_response1, card_response2); |
| 583 card_response2.billing_address = billing_address2; |
| 584 EXPECT_NE(card_response1, card_response2); |
| 585 card_response2.billing_address = billing_address1; |
| 586 EXPECT_EQ(card_response1, card_response2); |
| 587 } |
| 588 |
522 // Tests that two payment response objects are not equal if their property | 589 // Tests that two payment response objects are not equal if their property |
523 // values differ or one is missing a value present in the other, and equal | 590 // values differ or one is missing a value present in the other, and equal |
524 // otherwise. | 591 // otherwise. Doesn't test all properties of child objects, relying instead on |
| 592 // their respective tests. |
525 TEST(PaymentRequestTest, PaymentResponseEquality) { | 593 TEST(PaymentRequestTest, PaymentResponseEquality) { |
526 PaymentResponse response1; | 594 PaymentResponse response1; |
527 PaymentResponse response2; | 595 PaymentResponse response2; |
528 EXPECT_EQ(response1, response2); | 596 EXPECT_EQ(response1, response2); |
529 | 597 |
530 response1.method_name = base::ASCIIToUTF16("Visa"); | 598 response1.method_name = base::ASCIIToUTF16("Visa"); |
531 EXPECT_NE(response1, response2); | 599 EXPECT_NE(response1, response2); |
532 response2.method_name = base::ASCIIToUTF16("Mastercard"); | 600 response2.method_name = base::ASCIIToUTF16("Mastercard"); |
533 EXPECT_NE(response1, response2); | 601 EXPECT_NE(response1, response2); |
534 response2.method_name = base::ASCIIToUTF16("Visa"); | 602 response2.method_name = base::ASCIIToUTF16("Visa"); |
535 EXPECT_EQ(response1, response2); | 603 EXPECT_EQ(response1, response2); |
536 | 604 |
537 response1.details = base::ASCIIToUTF16("{cardSecurityCode: '123'}"); | 605 BasicCardResponse card_response1; |
| 606 card_response1.card_number = base::ASCIIToUTF16("1234"); |
| 607 BasicCardResponse card_response2; |
| 608 card_response2.card_number = base::ASCIIToUTF16("8888"); |
| 609 response1.details = card_response1; |
538 EXPECT_NE(response1, response2); | 610 EXPECT_NE(response1, response2); |
539 response2.details = base::ASCIIToUTF16("{cardSecurityCode: '---'}"); | 611 response2.details = card_response2; |
540 EXPECT_NE(response1, response2); | 612 EXPECT_NE(response1, response2); |
541 response2.details = base::ASCIIToUTF16("{cardSecurityCode: '123'}"); | 613 response2.details = card_response1; |
542 EXPECT_EQ(response1, response2); | 614 EXPECT_EQ(response1, response2); |
543 } | 615 } |
544 | 616 |
545 } // namespace web | 617 } // namespace web |
OLD | NEW |