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

Side by Side Diff: chrome/browser/ui/views/payments/payment_request_payment_response_browsertest.cc

Issue 2779813003: [Payments] Add Ship. Addr. & Contact Info in Payment Response on Desktop. (Closed)
Patch Set: Addressed comments 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
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(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 <vector>
6
7 #include "base/macros.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/ui/browser_commands.h"
10 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.h"
11 #include "chrome/browser/ui/views/payments/payment_request_dialog_view_ids.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "components/autofill/core/browser/autofill_profile.h"
14 #include "components/autofill/core/browser/autofill_test_utils.h"
15 #include "components/autofill/core/browser/credit_card.h"
16 #include "components/web_modal/web_contents_modal_dialog_manager.h"
17 #include "content/public/test/browser_test_utils.h"
18
19 namespace payments {
20
21 class PaymentRequestPaymentResponseAutofillPaymentInstrumentTest
22 : public PaymentRequestBrowserTestBase {
23 protected:
24 PaymentRequestPaymentResponseAutofillPaymentInstrumentTest()
25 : PaymentRequestBrowserTestBase(
26 "/payment_request_no_shipping_test.html") {}
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(
30 PaymentRequestPaymentResponseAutofillPaymentInstrumentTest);
31 };
32
33 // Tests that the PaymentResponse contains all the required fields for an
34 // Autofill payment instrument.
35 IN_PROC_BROWSER_TEST_F(
36 PaymentRequestPaymentResponseAutofillPaymentInstrumentTest,
37 TestPaymentResponse) {
38 // Setup a credit card with an associated billing address.
39 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
40 AddAutofillProfile(billing_address);
41 autofill::CreditCard card = autofill::test::GetCreditCard();
42 card.set_billing_address_id(billing_address.guid());
43 AddCreditCard(card); // Visa.
44
45 // Complete the Payment Request.
46 InvokePaymentRequestUI();
47 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
48 ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
49
50 // Test that the card details were sent to the merchant.
51 ExpectBodyContains(std::vector<base::string16>{
52 base::UTF8ToUTF16("\"cardNumber\": \"4111111111111111\""),
53 base::UTF8ToUTF16("\"cardSecurityCode\": \"123\""),
54 base::UTF8ToUTF16("\"cardholderName\": \"Test User\""),
55 base::UTF8ToUTF16("\"expiryMonth\": \"11\""),
56 base::UTF8ToUTF16("\"expiryYear\": \"2017\"")});
57
58 // Test that the billing address was sent to the merchant.
59 ExpectBodyContains(std::vector<base::string16>{
60 base::UTF8ToUTF16("\"billingAddress\": {"),
61 base::UTF8ToUTF16("\"666 Erebus St.\""), base::UTF8ToUTF16("\"Apt 8\""),
62 base::UTF8ToUTF16("\"city\": \"Elysium\""),
63 base::UTF8ToUTF16("\"country\": \"US\""),
64 base::UTF8ToUTF16("\"organization\": \"Underworld\""),
65 base::UTF8ToUTF16("\"phone\": \"16502111111\""),
66 base::UTF8ToUTF16("\"postalCode\": \"91111\""),
67 base::UTF8ToUTF16("\"recipient\": \"John H. Doe\""),
68 base::UTF8ToUTF16("\"region\": \"CA\"")});
69 }
70
71 class PaymentRequestPaymentResponseShippingAddressTest
72 : public PaymentRequestBrowserTestBase {
73 protected:
74 PaymentRequestPaymentResponseShippingAddressTest()
75 : PaymentRequestBrowserTestBase(
76 "/payment_request_free_shipping_test.html") {}
77
78 private:
79 DISALLOW_COPY_AND_ASSIGN(PaymentRequestPaymentResponseShippingAddressTest);
80 };
81
82 // Tests that the PaymentResponse contains all the required fields for a
83 // shipping address and shipping option.
84 IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseShippingAddressTest,
85 TestPaymentResponse) {
86 // Create a billing address and a card that uses it.
87 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
88 AddAutofillProfile(billing_address);
89 autofill::CreditCard card = autofill::test::GetCreditCard();
90 card.set_billing_address_id(billing_address.guid());
91 AddCreditCard(card); // Visa.
92
93 // Create a shipping address with a higher frecency score, so that it is
94 // selected as the defautl shipping address.
95 autofill::AutofillProfile shipping_address =
96 autofill::test::GetFullProfile2();
97 shipping_address.set_use_count(2000);
98 AddAutofillProfile(shipping_address);
99
100 // Complete the Payment Request.
101 InvokePaymentRequestUI();
102 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
103 ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
104
105 // Test that the shipping address was sent to the merchant.
106 ExpectBodyContains(std::vector<base::string16>{
107 base::UTF8ToUTF16("\"country\": \"US\""),
108 base::UTF8ToUTF16("\"123 Main Street\""), base::UTF8ToUTF16("\"Unit 1\""),
109 base::UTF8ToUTF16("\"region\": \"MI\""),
110 base::UTF8ToUTF16("\"city\": \"Greensdale\""),
111 base::UTF8ToUTF16("\"dependentLocality\": \"\""),
112 base::UTF8ToUTF16("\"postalCode\": \"48838\""),
113 base::UTF8ToUTF16("\"sortingCode\": \"\""),
114 base::UTF8ToUTF16("\"languageCode\": \"\""),
115 base::UTF8ToUTF16("\"organization\": \"ACME\""),
116 base::UTF8ToUTF16("\"recipient\": \"Jane A. Smith\""),
117 base::UTF8ToUTF16("\"phone\": \"13105557889\"")});
118
119 // Test that the shipping option was sent to the merchant.
120 ExpectBodyContains(std::vector<base::string16>{
121 base::UTF8ToUTF16("\"shippingOption\": \"freeShippingOption\"")});
122 }
123
124 class PaymentRequestPaymentResponseAllContactDetailsTest
125 : public PaymentRequestBrowserTestBase {
126 protected:
127 PaymentRequestPaymentResponseAllContactDetailsTest()
128 : PaymentRequestBrowserTestBase(
129 "/payment_request_contact_details_and_free_shipping_test.html") {}
130
131 private:
132 DISALLOW_COPY_AND_ASSIGN(PaymentRequestPaymentResponseAllContactDetailsTest);
133 };
134
135 // Tests that the PaymentResponse contains all the required fields for contact
136 // details when all three details are requested.
137 IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseAllContactDetailsTest,
138 TestPaymentResponse) {
139 // Setup a credit card with an associated billing address.
140 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
141 AddAutofillProfile(billing_address);
142 autofill::CreditCard card = autofill::test::GetCreditCard();
143 card.set_billing_address_id(billing_address.guid());
144 AddCreditCard(card); // Visa.
145
146 // Complete the Payment Request.
147 InvokePaymentRequestUI();
148 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
149 ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
150
151 // Test that the contact details were sent to the merchant.
152 ExpectBodyContains(std::vector<base::string16>{
153 base::UTF8ToUTF16("\"payerName\": \"John H. Doe\""),
154 base::UTF8ToUTF16("\"payerEmail\": \"johndoe@hades.com\""),
155 base::UTF8ToUTF16("\"payerPhone\": \"16502111111\"")});
156 }
157
158 class PaymentRequestPaymentResponseOneContactDetailTest
159 : public PaymentRequestBrowserTestBase {
160 protected:
161 PaymentRequestPaymentResponseOneContactDetailTest()
162 : PaymentRequestBrowserTestBase(
163 "/payment_request_email_and_free_shipping_test.html") {}
164
165 private:
166 DISALLOW_COPY_AND_ASSIGN(PaymentRequestPaymentResponseOneContactDetailTest);
167 };
168
169 // Tests that the PaymentResponse contains all the required fields for contact
170 // details when all ont detail is requested.
171 IN_PROC_BROWSER_TEST_F(PaymentRequestPaymentResponseOneContactDetailTest,
172 TestPaymentResponse) {
173 // Setup a credit card with an associated billing address.
174 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
175 AddAutofillProfile(billing_address);
176 autofill::CreditCard card = autofill::test::GetCreditCard();
177 card.set_billing_address_id(billing_address.guid());
178 AddCreditCard(card); // Visa.
179
180 // Complete the Payment Request.
181 InvokePaymentRequestUI();
182 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
183 ClickOnDialogViewAndWait(DialogViewID::PAY_BUTTON);
184
185 // Test that the contact details were sent to the merchant.
186 ExpectBodyContains(std::vector<base::string16>{
187 base::UTF8ToUTF16("\"payerName\": null"),
188 base::UTF8ToUTF16("\"payerEmail\": \"johndoe@hades.com\""),
189 base::UTF8ToUTF16("\"payerPhone\": null")});
190 }
191
192 } // namespace payments
OLDNEW
« no previous file with comments | « no previous file | chrome/test/BUILD.gn » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698