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

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

Issue 2874873002: [Payments] Record use stats after payment request completion. (Closed)
Patch Set: Removed billing address log Created 3 years, 7 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/autofill/core/browser/personal_data_manager.h"
17 #include "components/autofill/core/browser/test_autofill_clock.h"
18 #include "components/web_modal/web_contents_modal_dialog_manager.h"
19 #include "content/public/test/browser_test_utils.h"
20
21 namespace payments {
22
23 namespace {
24
25 const base::Time kSomeDate = base::Time::FromDoubleT(1484505871);
26 const base::Time kSomeLaterDate = base::Time::FromDoubleT(1497552271);
27
28 } // namespace
29
30 class PaymentRequestAutofillInstrumentUseStatsTest
31 : public PaymentRequestBrowserTestBase {
32 protected:
33 PaymentRequestAutofillInstrumentUseStatsTest()
34 : PaymentRequestBrowserTestBase(
35 "/payment_request_no_shipping_test.html") {}
36
37 private:
38 DISALLOW_COPY_AND_ASSIGN(PaymentRequestAutofillInstrumentUseStatsTest);
39 };
40
41 // Tests that use stats for the autofill payment instrument used in a Payment
42 // Request are properly updated upon completion.
43 IN_PROC_BROWSER_TEST_F(PaymentRequestAutofillInstrumentUseStatsTest,
44 RecordUse) {
45 autofill::TestAutofillClock test_clock;
46 test_clock.SetNow(kSomeDate);
47
48 // Setup a credit card with an associated billing address.
49 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
50 AddAutofillProfile(billing_address);
51 autofill::CreditCard card = autofill::test::GetCreditCard();
52 card.set_billing_address_id(billing_address.guid());
53 AddCreditCard(card); // Visa.
54
55 // Check that the initial use stats were set correctly.
56 autofill::CreditCard* initial_card =
57 GetDataManager()->GetCreditCardByGUID(card.guid());
58 EXPECT_EQ(1U, initial_card->use_count());
59 EXPECT_EQ(kSomeDate, initial_card->use_date());
60
61 // Complete the Payment Request.
62 test_clock.SetNow(kSomeLaterDate);
63 InvokePaymentRequestUI();
64 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
65 PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
66
67 // Check that the usage of the card was recorded.
68 autofill::CreditCard* updated_card =
69 GetDataManager()->GetCreditCardByGUID(card.guid());
70 EXPECT_EQ(2U, updated_card->use_count());
71 EXPECT_EQ(kSomeLaterDate, updated_card->use_date());
72 }
73
74 class PaymentRequestShippingAddressUseStatsTest
75 : public PaymentRequestBrowserTestBase {
76 protected:
77 PaymentRequestShippingAddressUseStatsTest()
78 : PaymentRequestBrowserTestBase(
79 "/payment_request_free_shipping_test.html") {}
80
81 private:
82 DISALLOW_COPY_AND_ASSIGN(PaymentRequestShippingAddressUseStatsTest);
83 };
84
85 // Tests that use stats for the shipping address used in a Payment Request are
86 // properly updated upon completion.
87 IN_PROC_BROWSER_TEST_F(PaymentRequestShippingAddressUseStatsTest, RecordUse) {
88 autofill::TestAutofillClock test_clock;
89 test_clock.SetNow(kSomeDate);
90
91 // Create a billing address and a card that uses it.
92 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
93 AddAutofillProfile(billing_address);
94 autofill::CreditCard card = autofill::test::GetCreditCard();
95 card.set_billing_address_id(billing_address.guid());
96 AddCreditCard(card); // Visa.
97
98 // Create a shipping address with a higher frecency score, so that it is
99 // selected as the default shipping address.
100 autofill::AutofillProfile shipping_address =
101 autofill::test::GetFullProfile2();
102 shipping_address.set_use_count(3);
103 AddAutofillProfile(shipping_address);
104
105 // Check that the initial use stats were set correctly.
106 autofill::AutofillProfile* initial_shipping =
107 GetDataManager()->GetProfileByGUID(shipping_address.guid());
108 EXPECT_EQ(3U, initial_shipping->use_count());
109 EXPECT_EQ(kSomeDate, initial_shipping->use_date());
110
111 // Complete the Payment Request.
112 test_clock.SetNow(kSomeLaterDate);
113 InvokePaymentRequestUI();
114 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
115 PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
116
117 // Check that the usage of the profile was recorded.
118 autofill::AutofillProfile* updated_shipping =
119 GetDataManager()->GetProfileByGUID(shipping_address.guid());
120 EXPECT_EQ(4U, updated_shipping->use_count());
121 EXPECT_EQ(kSomeLaterDate, updated_shipping->use_date());
122 }
123
124 class PaymentRequestContactAddressUseStatsTest
125 : public PaymentRequestBrowserTestBase {
126 protected:
127 PaymentRequestContactAddressUseStatsTest()
128 : PaymentRequestBrowserTestBase("/payment_request_name_test.html") {}
129
130 private:
131 DISALLOW_COPY_AND_ASSIGN(PaymentRequestContactAddressUseStatsTest);
132 };
133
134 // Tests that use stats for the contact address used in a Payment Request are
135 // properly updated upon completion.
136 IN_PROC_BROWSER_TEST_F(PaymentRequestContactAddressUseStatsTest, RecordUse) {
137 autofill::TestAutofillClock test_clock;
138 test_clock.SetNow(kSomeDate);
139
140 // Setup a credit card with an associated billing address.
141 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
142 AddAutofillProfile(billing_address);
143 autofill::CreditCard card = autofill::test::GetCreditCard();
144 card.set_billing_address_id(billing_address.guid());
145 AddCreditCard(card); // Visa.
146
147 // Create a contact address with a higher frecency score, so that it is
148 // selected as the default contact address.
149 autofill::AutofillProfile contact_address = autofill::test::GetFullProfile2();
150 contact_address.set_use_count(3);
151 AddAutofillProfile(contact_address);
152
153 // Check that the initial use stats were set correctly.
154 autofill::AutofillProfile* initial_contact =
155 GetDataManager()->GetProfileByGUID(contact_address.guid());
156 EXPECT_EQ(3U, initial_contact->use_count());
157 EXPECT_EQ(kSomeDate, initial_contact->use_date());
158
159 // Complete the Payment Request.
160 test_clock.SetNow(kSomeLaterDate);
161 InvokePaymentRequestUI();
162 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
163 PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
164
165 // Check that the usage of the profile was recorded.
166 autofill::AutofillProfile* updated_contact =
167 GetDataManager()->GetProfileByGUID(contact_address.guid());
168 EXPECT_EQ(4U, updated_contact->use_count());
169 EXPECT_EQ(kSomeLaterDate, updated_contact->use_date());
170 }
171
172 class PaymentRequestSameShippingAndContactAddressUseStatsTest
173 : public PaymentRequestBrowserTestBase {
174 protected:
175 PaymentRequestSameShippingAndContactAddressUseStatsTest()
176 : PaymentRequestBrowserTestBase(
177 "/payment_request_contact_details_and_free_shipping_test.html") {}
178
179 private:
180 DISALLOW_COPY_AND_ASSIGN(
181 PaymentRequestSameShippingAndContactAddressUseStatsTest);
182 };
183
184 // Tests that use stats for an address that was used both as a shipping and
185 // contact address in a Payment Request are properly updated upon completion.
186 IN_PROC_BROWSER_TEST_F(PaymentRequestSameShippingAndContactAddressUseStatsTest,
187 RecordUse) {
188 autofill::TestAutofillClock test_clock;
189 test_clock.SetNow(kSomeDate);
190
191 // Setup a credit card with an associated billing address.
192 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
193 AddAutofillProfile(billing_address);
194 autofill::CreditCard card = autofill::test::GetCreditCard();
195 card.set_billing_address_id(billing_address.guid());
196 AddCreditCard(card); // Visa.
197
198 // Create an address with a higher frecency score, so that it is selected as
199 // the default shipping and contact address.
200 autofill::AutofillProfile multi_address = autofill::test::GetFullProfile2();
201 multi_address.set_use_count(3);
202 AddAutofillProfile(multi_address);
203
204 // Check that the initial use stats were set correctly.
205 autofill::AutofillProfile* initial_multi =
206 GetDataManager()->GetProfileByGUID(multi_address.guid());
207 EXPECT_EQ(3U, initial_multi->use_count());
208 EXPECT_EQ(kSomeDate, initial_multi->use_date());
209
210 // Complete the Payment Request.
211 test_clock.SetNow(kSomeLaterDate);
212 InvokePaymentRequestUI();
213 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
214 PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
215
216 // Check that the usage of the profile was only recorded once.
217 autofill::AutofillProfile* updated_multi =
218 GetDataManager()->GetProfileByGUID(multi_address.guid());
219 EXPECT_EQ(4U, updated_multi->use_count());
220 EXPECT_EQ(kSomeLaterDate, updated_multi->use_date());
221 }
222
223 } // 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