| OLD | NEW |
| (Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "components/payments/core/payment_request_data_util.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "base/json/json_writer.h" |
| 10 #include "base/strings/utf_string_conversions.h" |
| 11 #include "base/values.h" |
| 12 #include "components/autofill/core/browser/autofill_profile.h" |
| 13 #include "components/autofill/core/browser/autofill_test_utils.h" |
| 14 #include "components/autofill/core/browser/credit_card.h" |
| 15 #include "components/payments/core/basic_card_response.h" |
| 16 #include "components/payments/core/payment_address.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 |
| 19 namespace payments { |
| 20 namespace data_util { |
| 21 |
| 22 // Tests that the serialized version of the PaymentAddress is according to the |
| 23 // PaymentAddress spec. |
| 24 TEST(PaymentRequestDataUtilTest, GetPaymentAddressFromAutofillProfile) { |
| 25 autofill::AutofillProfile address = autofill::test::GetFullProfile(); |
| 26 std::unique_ptr<base::DictionaryValue> address_value = |
| 27 payments::data_util::GetPaymentAddressFromAutofillProfile(address, |
| 28 "en-US") |
| 29 .ToDictionaryValue(); |
| 30 std::string json_address; |
| 31 base::JSONWriter::Write(*address_value, &json_address); |
| 32 EXPECT_EQ( |
| 33 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"]," |
| 34 "\"city\":\"Elysium\"," |
| 35 "\"country\":\"US\"," |
| 36 "\"organization\":\"Underworld\"," |
| 37 "\"phone\":\"16502111111\"," |
| 38 "\"postalCode\":\"91111\"," |
| 39 "\"recipient\":\"John H. Doe\"," |
| 40 "\"region\":\"CA\"}", |
| 41 json_address); |
| 42 } |
| 43 |
| 44 // Tests that the basic card response constructed from a credit card with |
| 45 // associated billing address has the right structure once serialized. |
| 46 TEST(PaymentRequestDataUtilTest, GetBasicCardResponseFromAutofillCreditCard) { |
| 47 autofill::AutofillProfile address = autofill::test::GetFullProfile(); |
| 48 autofill::CreditCard card = autofill::test::GetCreditCard(); |
| 49 card.set_billing_address_id(address.guid()); |
| 50 std::unique_ptr<base::DictionaryValue> response_value = |
| 51 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( |
| 52 card, base::ASCIIToUTF16("123"), |
| 53 std::vector<autofill::AutofillProfile*>{&address}, "en-US") |
| 54 .ToDictionaryValue(); |
| 55 std::string json_response; |
| 56 base::JSONWriter::Write(*response_value, &json_response); |
| 57 EXPECT_EQ( |
| 58 "{\"billingAddress\":" |
| 59 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"]," |
| 60 "\"city\":\"Elysium\"," |
| 61 "\"country\":\"US\"," |
| 62 "\"organization\":\"Underworld\"," |
| 63 "\"phone\":\"16502111111\"," |
| 64 "\"postalCode\":\"91111\"," |
| 65 "\"recipient\":\"John H. Doe\"," |
| 66 "\"region\":\"CA\"}," |
| 67 "\"cardNumber\":\"4111111111111111\"," |
| 68 "\"cardSecurityCode\":\"123\"," |
| 69 "\"cardholderName\":\"Test User\"," |
| 70 "\"expiryMonth\":\"11\"," |
| 71 "\"expiryYear\":\"2017\"}", |
| 72 json_response); |
| 73 } |
| 74 |
| 75 } // namespace data_util |
| 76 } // namespace payments |
| OLD | NEW |