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