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

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

Issue 2929133004: Merge-60 [Payments] Record abort reasons on desktop. (Closed)
Patch Set: Created 3 years, 6 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 "base/test/histogram_tester.h"
10 #include "chrome/browser/ui/browser_commands.h"
11 #include "chrome/browser/ui/views/payments/payment_request_browsertest_base.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/journey_logger.h"
16 #include "content/public/test/browser_test_utils.h"
17 #include "url/gurl.h"
18
19 namespace payments {
20
21 class PaymentRequestCompletionStatusMetricsTest
22 : public PaymentRequestBrowserTestBase {
23 protected:
24 PaymentRequestCompletionStatusMetricsTest()
25 : PaymentRequestBrowserTestBase(
26 "/payment_request_can_make_payment_metrics_test.html") {}
27
28 private:
29 DISALLOW_COPY_AND_ASSIGN(PaymentRequestCompletionStatusMetricsTest);
30 };
31
32 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest, Completed) {
33 base::HistogramTester histogram_tester;
34
35 // Setup a credit card with an associated billing address so CanMakePayment
36 // returns true.
37 autofill::AutofillProfile billing_address = autofill::test::GetFullProfile();
38 AddAutofillProfile(billing_address);
39 autofill::CreditCard card = autofill::test::GetCreditCard();
40 card.set_billing_address_id(billing_address.guid());
41 AddCreditCard(card);
42
43 // Start the Payment Request and expect CanMakePayment to be called before the
44 // Payment Request is shown.
45 ResetEventObserverForSequence(
46 {DialogEvent::CAN_MAKE_PAYMENT_CALLED, DialogEvent::DIALOG_OPENED});
47 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "queryShow();"));
48 WaitForObservedEvent();
49
50 // Complete the Payment Request.
51 PayWithCreditCardAndWait(base::ASCIIToUTF16("123"));
52
53 // Make sure the metrics are logged correctly.
54 histogram_tester.ExpectUniqueSample("PaymentRequest.CheckoutFunnel.Completed",
55 1, 1);
56 }
57
58 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
59 MerchantAborted_Reload) {
60 base::HistogramTester histogram_tester;
61
62 // Start the Payment Request.
63 ResetEventObserver(DialogEvent::DIALOG_OPENED);
64 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
65 WaitForObservedEvent();
66
67 // The merchant reloads the page.
68 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
69 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(),
70 "(function() { location.reload(); })();"));
71 WaitForObservedEvent();
72
73 // Make sure the metrics are logged correctly.
74 histogram_tester.ExpectUniqueSample(
75 "PaymentRequest.CheckoutFunnel.Aborted",
76 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1);
77 }
78
79 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
80 MerchantAborted_Navigation) {
81 base::HistogramTester histogram_tester;
82
83 // Start the Payment Request.
84 ResetEventObserver(DialogEvent::DIALOG_OPENED);
85 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
86 WaitForObservedEvent();
87
88 // The merchant navigates away.
89 ResetEventObserver(DialogEvent::DIALOG_CLOSED);
90 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(),
91 "(function() { window.location.href = "
92 "'/payment_request_email_test.html'; "
93 "})();"));
94 WaitForObservedEvent();
95
96 // Make sure the metrics are logged correctly.
97 histogram_tester.ExpectUniqueSample(
98 "PaymentRequest.CheckoutFunnel.Aborted",
99 JourneyLogger::ABORT_REASON_MERCHANT_NAVIGATION, 1);
100 }
101
102 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
103 MerchantAborted_Abort) {
104 base::HistogramTester histogram_tester;
105
106 // Start the Payment Request.
107 ResetEventObserver(DialogEvent::DIALOG_OPENED);
108 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
109 WaitForObservedEvent();
110
111 // The merchant aborts the Payment Request.
112 ResetEventObserverForSequence(
113 {DialogEvent::ABORT_CALLED, DialogEvent::DIALOG_CLOSED});
114 const std::string click_buy_button_js =
115 "(function() { document.getElementById('abort').click(); })();";
116 ASSERT_TRUE(
117 content::ExecuteScript(GetActiveWebContents(), click_buy_button_js));
118 WaitForObservedEvent();
119
120 // Make sure the metrics are logged correctly.
121 histogram_tester.ExpectUniqueSample(
122 "PaymentRequest.CheckoutFunnel.Aborted",
123 JourneyLogger::ABORT_REASON_ABORTED_BY_MERCHANT, 1);
124 }
125
126 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
127 UserAborted_Navigation) {
128 base::HistogramTester histogram_tester;
129
130 // Start the Payment Request.
131 ResetEventObserver(DialogEvent::DIALOG_OPENED);
132 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
133 WaitForObservedEvent();
134
135 // Navigate away.
136 NavigateTo("/payment_request_email_test.html");
137
138 // Make sure the metrics are logged correctly.
139 histogram_tester.ExpectUniqueSample(
140 "PaymentRequest.CheckoutFunnel.Aborted",
141 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1);
142 }
143
144 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
145 UserAborted_CancelButton) {
146 base::HistogramTester histogram_tester;
147
148 // Start the Payment Request.
149 ResetEventObserver(DialogEvent::DIALOG_OPENED);
150 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
151 WaitForObservedEvent();
152
153 // Click on the cancel button.
154 ClickOnCancel();
155
156 // Make sure the metrics are logged correctly.
157 histogram_tester.ExpectUniqueSample(
158 "PaymentRequest.CheckoutFunnel.Aborted",
159 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1);
160 }
161
162 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
163 UserAborted_TabClosed) {
164 base::HistogramTester histogram_tester;
165
166 // Start the Payment Request.
167 ResetEventObserver(DialogEvent::DIALOG_OPENED);
168 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
169 WaitForObservedEvent();
170
171 // Close the tab containing the Payment Request.
172 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED});
173 chrome::CloseTab(browser());
174 WaitForObservedEvent();
175
176 // Make sure the metrics are logged correctly.
177 histogram_tester.ExpectUniqueSample(
178 "PaymentRequest.CheckoutFunnel.Aborted",
179 JourneyLogger::ABORT_REASON_ABORTED_BY_USER, 1);
180 }
181
182 IN_PROC_BROWSER_TEST_F(PaymentRequestCompletionStatusMetricsTest,
183 UserAborted_Reload) {
184 base::HistogramTester histogram_tester;
185
186 // Start the Payment Request.
187 ResetEventObserver(DialogEvent::DIALOG_OPENED);
188 ASSERT_TRUE(content::ExecuteScript(GetActiveWebContents(), "noQueryShow();"));
189 WaitForObservedEvent();
190
191 // Reload the page containing the Payment Request.
192 ResetEventObserverForSequence({DialogEvent::DIALOG_CLOSED});
193 chrome::Reload(browser(), WindowOpenDisposition::CURRENT_TAB);
194 WaitForObservedEvent();
195
196 // Make sure the metrics are logged correctly.
197 histogram_tester.ExpectUniqueSample(
198 "PaymentRequest.CheckoutFunnel.Aborted",
199 JourneyLogger::ABORT_REASON_USER_NAVIGATION, 1);
200 }
201
202 } // 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