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

Side by Side Diff: components/payments/core/payment_request_data_util_unittest.cc

Issue 2842463002: [Payments] Normalize billing address for response on Desktop. (Closed)
Patch Set: Keep the old version for iOS 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
OLDNEW
1 // Copyright 2017 The Chromium Authors. All rights reserved. 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 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 "components/payments/core/payment_request_data_util.h" 5 #include "components/payments/core/payment_request_data_util.h"
6 6
7 #include <memory> 7 #include <memory>
8 8
9 #include "base/json/json_writer.h" 9 #include "base/json/json_writer.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
42 } 42 }
43 43
44 // Tests that the basic card response constructed from a credit card with 44 // Tests that the basic card response constructed from a credit card with
45 // associated billing address has the right structure once serialized. 45 // associated billing address has the right structure once serialized.
46 TEST(PaymentRequestDataUtilTest, GetBasicCardResponseFromAutofillCreditCard) { 46 TEST(PaymentRequestDataUtilTest, GetBasicCardResponseFromAutofillCreditCard) {
47 autofill::AutofillProfile address = autofill::test::GetFullProfile(); 47 autofill::AutofillProfile address = autofill::test::GetFullProfile();
48 autofill::CreditCard card = autofill::test::GetCreditCard(); 48 autofill::CreditCard card = autofill::test::GetCreditCard();
49 card.set_billing_address_id(address.guid()); 49 card.set_billing_address_id(address.guid());
50 std::unique_ptr<base::DictionaryValue> response_value = 50 std::unique_ptr<base::DictionaryValue> response_value =
51 payments::data_util::GetBasicCardResponseFromAutofillCreditCard( 51 payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
52 card, base::ASCIIToUTF16("123"), address, "en-US")
53 .ToDictionaryValue();
54 std::string json_response;
55 base::JSONWriter::Write(*response_value, &json_response);
56 EXPECT_EQ(
57 "{\"billingAddress\":"
58 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"],"
59 "\"city\":\"Elysium\","
60 "\"country\":\"US\","
61 "\"organization\":\"Underworld\","
62 "\"phone\":\"16502111111\","
63 "\"postalCode\":\"91111\","
64 "\"recipient\":\"John H. Doe\","
65 "\"region\":\"CA\"},"
66 "\"cardNumber\":\"4111111111111111\","
67 "\"cardSecurityCode\":\"123\","
68 "\"cardholderName\":\"Test User\","
69 "\"expiryMonth\":\"11\","
70 "\"expiryYear\":\"2022\"}",
71 json_response);
72 }
73
74 // Tests that the basic card response constructed from a credit card with
75 // associated billing address has the right structure once serialized.
76 // TODO(crbug.com/714655): Once the billing address is checked in the instrument
77 // on iOS, remove this.
78 TEST(PaymentRequestDataUtilTest,
79 GetBasicCardResponseFromAutofillCreditCard_ios) {
80 autofill::AutofillProfile address = autofill::test::GetFullProfile();
81 autofill::CreditCard card = autofill::test::GetCreditCard();
82 card.set_billing_address_id(address.guid());
83 std::unique_ptr<base::DictionaryValue> response_value =
84 payments::data_util::GetBasicCardResponseFromAutofillCreditCard(
52 card, base::ASCIIToUTF16("123"), 85 card, base::ASCIIToUTF16("123"),
53 std::vector<autofill::AutofillProfile*>{&address}, "en-US") 86 std::vector<autofill::AutofillProfile*>{&address}, "en-US")
54 .ToDictionaryValue(); 87 .ToDictionaryValue();
55 std::string json_response; 88 std::string json_response;
56 base::JSONWriter::Write(*response_value, &json_response); 89 base::JSONWriter::Write(*response_value, &json_response);
57 EXPECT_EQ( 90 EXPECT_EQ(
58 "{\"billingAddress\":" 91 "{\"billingAddress\":"
59 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"]," 92 "{\"addressLine\":[\"666 Erebus St.\",\"Apt 8\"],"
60 "\"city\":\"Elysium\"," 93 "\"city\":\"Elysium\","
61 "\"country\":\"US\"," 94 "\"country\":\"US\","
(...skipping 24 matching lines...) Expand all
86 // Tests that the phone numbers are correctly formatted to display to the user. 119 // Tests that the phone numbers are correctly formatted to display to the user.
87 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) { 120 TEST(PaymentRequestDataUtilTest, FormatPhoneForDisplay) {
88 EXPECT_EQ("+1 515-123-1234", 121 EXPECT_EQ("+1 515-123-1234",
89 payments::data_util::FormatPhoneForDisplay("5151231234", "US")); 122 payments::data_util::FormatPhoneForDisplay("5151231234", "US"));
90 EXPECT_EQ("+33 1 42 68 53 00", 123 EXPECT_EQ("+33 1 42 68 53 00",
91 payments::data_util::FormatPhoneForDisplay("142685300", "FR")); 124 payments::data_util::FormatPhoneForDisplay("142685300", "FR"));
92 } 125 }
93 126
94 } // namespace data_util 127 } // namespace data_util
95 } // namespace payments 128 } // namespace payments
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698