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