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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java

Issue 2914563002: Merge-60 [Payments] Move the logging for checkout flow to native. (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
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 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 package org.chromium.chrome.browser.payments; 5 package org.chromium.chrome.browser.payments;
6 6
7 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.DELAYE D_RESPONSE; 7 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.DELAYE D_RESPONSE;
8 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.HAVE_I NSTRUMENTS; 8 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.HAVE_I NSTRUMENTS;
9 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.IMMEDI ATE_RESPONSE; 9 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.IMMEDI ATE_RESPONSE;
10 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.NO_INS TRUMENTS; 10 import static org.chromium.chrome.browser.payments.PaymentRequestTestRule.NO_INS TRUMENTS;
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after
122 mPaymentRequestTestRule.getPaymentRequestUI() 122 mPaymentRequestTestRule.getPaymentRequestUI()
123 .getDialogForTest() 123 .getDialogForTest()
124 .findViewById(R.id.button_secondary) 124 .findViewById(R.id.button_secondary)
125 .performClick(); 125 .performClick();
126 } 126 }
127 }); 127 });
128 mPaymentRequestTestRule.getDismissed().waitForCallback(callCount); 128 mPaymentRequestTestRule.getDismissed().waitForCallback(callCount);
129 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"}); 129 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"});
130 130
131 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged( 131 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(
132 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER); 132 JourneyLogger.ABORT_REASON_ABORTED_BY_USER);
133 } 133 }
134 134
135 /** 135 /**
136 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on 136 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on
137 * the [X] button in the Payment Request dialog. 137 * the [X] button in the Payment Request dialog.
138 */ 138 */
139 @Test 139 @Test
140 @MediumTest 140 @MediumTest
141 @Feature({"Payments"}) 141 @Feature({"Payments"})
142 public void testAbortMetrics_AbortedByUser_XButton() 142 public void testAbortMetrics_AbortedByUser_XButton()
143 throws InterruptedException, ExecutionException, TimeoutException { 143 throws InterruptedException, ExecutionException, TimeoutException {
144 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay()); 144 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay());
145 mPaymentRequestTestRule.clickInShippingSummaryAndWait( 145 mPaymentRequestTestRule.clickInShippingSummaryAndWait(
146 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( )); 146 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( ));
147 147
148 // Press the [X] button. 148 // Press the [X] button.
149 mPaymentRequestTestRule.clickAndWait( 149 mPaymentRequestTestRule.clickAndWait(
150 R.id.close_button, mPaymentRequestTestRule.getDismissed()); 150 R.id.close_button, mPaymentRequestTestRule.getDismissed());
151 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"}); 151 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"});
152 152
153 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged( 153 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(
154 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER); 154 JourneyLogger.ABORT_REASON_ABORTED_BY_USER);
155 } 155 }
156 156
157 /** 157 /**
158 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on 158 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on
159 * the back button on their phone during a Payment Request. 159 * the back button on their phone during a Payment Request.
160 */ 160 */
161 @Test 161 @Test
162 @MediumTest 162 @MediumTest
163 @Feature({"Payments"}) 163 @Feature({"Payments"})
164 public void testAbortMetrics_AbortedByUser_BackButton() 164 public void testAbortMetrics_AbortedByUser_BackButton()
165 throws InterruptedException, ExecutionException, TimeoutException { 165 throws InterruptedException, ExecutionException, TimeoutException {
166 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay()); 166 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay());
167 mPaymentRequestTestRule.clickInShippingSummaryAndWait( 167 mPaymentRequestTestRule.clickInShippingSummaryAndWait(
168 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( )); 168 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( ));
169 169
170 // Press the back button. 170 // Press the back button.
171 int callCount = mPaymentRequestTestRule.getDismissed().getCallCount(); 171 int callCount = mPaymentRequestTestRule.getDismissed().getCallCount();
172 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 172 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
173 @Override 173 @Override
174 public void run() { 174 public void run() {
175 mPaymentRequestTestRule.getPaymentRequestUI().getDialogForTest() .onBackPressed(); 175 mPaymentRequestTestRule.getPaymentRequestUI().getDialogForTest() .onBackPressed();
176 } 176 }
177 }); 177 });
178 mPaymentRequestTestRule.getDismissed().waitForCallback(callCount); 178 mPaymentRequestTestRule.getDismissed().waitForCallback(callCount);
179 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"}); 179 mPaymentRequestTestRule.expectResultContains(new String[] {"Request canc elled"});
180 180
181 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged( 181 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(
182 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER); 182 JourneyLogger.ABORT_REASON_ABORTED_BY_USER);
183 } 183 }
184 184
185 /** 185 /**
186 * Expect only the ABORT_REASON_MOJO_RENDERER_CLOSING enum value gets logged when a user closes 186 * Expect only the ABORT_REASON_MOJO_RENDERER_CLOSING enum value gets logged when a user closes
187 * the tab during a Payment Request. 187 * the tab during a Payment Request.
188 */ 188 */
189 @Test 189 @Test
190 @MediumTest 190 @MediumTest
191 @Feature({"Payments"}) 191 @Feature({"Payments"})
192 public void testAbortMetrics_AbortedByUser_TabClosed() 192 public void testAbortMetrics_AbortedByUser_TabClosed()
193 throws InterruptedException, ExecutionException, TimeoutException { 193 throws InterruptedException, ExecutionException, TimeoutException {
194 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay()); 194 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay());
195 mPaymentRequestTestRule.clickInShippingSummaryAndWait( 195 mPaymentRequestTestRule.clickInShippingSummaryAndWait(
196 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( )); 196 R.id.payments_section, mPaymentRequestTestRule.getReadyForInput( ));
197 197
198 // Press the back button. 198 // Press the back button.
199 ChromeTabUtils.closeCurrentTab(InstrumentationRegistry.getInstrumentatio n(), 199 ChromeTabUtils.closeCurrentTab(InstrumentationRegistry.getInstrumentatio n(),
200 mPaymentRequestTestRule.getActivity()); 200 mPaymentRequestTestRule.getActivity());
201 201
202 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged( 202 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(
203 PaymentRequestMetrics.ABORT_REASON_MOJO_RENDERER_CLOSING); 203 JourneyLogger.ABORT_REASON_MOJO_RENDERER_CLOSING);
204 } 204 }
205 205
206 /** 206 /**
207 * Expect only the ABORT_REASON_ABORTED_BY_MERCHANT enum value gets logged w hen a Payment 207 * Expect only the ABORT_REASON_ABORTED_BY_MERCHANT enum value gets logged w hen a Payment
208 * Request gets cancelled by the merchant. 208 * Request gets cancelled by the merchant.
209 */ 209 */
210 @Test 210 @Test
211 @MediumTest 211 @MediumTest
212 @Feature({"Payments"}) 212 @Feature({"Payments"})
213 public void testAbortMetrics_AbortedByMerchant() 213 public void testAbortMetrics_AbortedByMerchant()
214 throws InterruptedException, ExecutionException, TimeoutException { 214 throws InterruptedException, ExecutionException, TimeoutException {
215 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay()); 215 mPaymentRequestTestRule.triggerUIAndWait("ccBuy", mPaymentRequestTestRul e.getReadyToPay());
216 216
217 // Simulate an abort by the merchant. 217 // Simulate an abort by the merchant.
218 mPaymentRequestTestRule.clickNodeAndWait("abort", mPaymentRequestTestRul e.getDismissed()); 218 mPaymentRequestTestRule.clickNodeAndWait("abort", mPaymentRequestTestRul e.getDismissed());
219 mPaymentRequestTestRule.expectResultContains(new String[] {"Abort"}); 219 mPaymentRequestTestRule.expectResultContains(new String[] {"Abort"});
220 220
221 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged( 221 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(
222 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_MERCHANT); 222 JourneyLogger.ABORT_REASON_ABORTED_BY_MERCHANT);
223 } 223 }
224 224
225 /** 225 /**
226 * Expect no abort metrics to be logged even if there are no matching paymen t methods because 226 * Expect no abort metrics to be logged even if there are no matching paymen t methods because
227 * the Payment Request was not shown to the user (a Payment Request gets can celled because the 227 * the Payment Request was not shown to the user (a Payment Request gets can celled because the
228 * user does not have any of the payment methods accepted by the merchant an d the merchant does 228 * user does not have any of the payment methods accepted by the merchant an d the merchant does
229 * not accept credit cards). It should instead be logged as a reason why the Payment Request was 229 * not accept credit cards). It should instead be logged as a reason why the Payment Request was
230 * not shown to the user. 230 * not shown to the user.
231 */ 231 */
232 @Test 232 @Test
233 @MediumTest 233 @MediumTest
234 @Feature({"Payments"}) 234 @Feature({"Payments"})
235 public void testMetrics_NoMatchingPaymentMethod() 235 public void testMetrics_NoMatchingPaymentMethod()
236 throws InterruptedException, ExecutionException, TimeoutException { 236 throws InterruptedException, ExecutionException, TimeoutException {
237 // Android Pay is supported but no instruments are present. 237 // Android Pay is supported but no instruments are present.
238 mPaymentRequestTestRule.installPaymentApp( 238 mPaymentRequestTestRule.installPaymentApp(
239 "https://android.com/pay", NO_INSTRUMENTS, DELAYED_RESPONSE); 239 "https://android.com/pay", NO_INSTRUMENTS, DELAYED_RESPONSE);
240 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 240 mPaymentRequestTestRule.openPageAndClickNodeAndWait(
241 "androidPayBuy", mPaymentRequestTestRule.getShowFailed()); 241 "androidPayBuy", mPaymentRequestTestRule.getShowFailed());
242 mPaymentRequestTestRule.expectResultContains( 242 mPaymentRequestTestRule.expectResultContains(
243 new String[] {"The payment method is not supported"}); 243 new String[] {"The payment method is not supported"});
244 244
245 // Make sure that it is not logged as an abort. 245 // Make sure that it is not logged as an abort.
246 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none * /); 246 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none * /);
247 // Make sure that it was logged as a reason why the Payment Request was not shown. 247 // Make sure that it was logged as a reason why the Payment Request was not shown.
248 Assert.assertEquals(1, 248 Assert.assertEquals(1,
249 RecordHistogram.getHistogramValueCountForTesting( 249 RecordHistogram.getHistogramValueCountForTesting(
250 "PaymentRequest.CheckoutFunnel.NoShow", 250 "PaymentRequest.CheckoutFunnel.NoShow",
251 PaymentRequestMetrics.NO_SHOW_NO_MATCHING_PAYMENT_METHOD )); 251 JourneyLogger.NO_SHOW_NO_MATCHING_PAYMENT_METHOD));
252 } 252 }
253 253
254 /** 254 /**
255 * Expect no abort metrics to be logged even if there are no matching paymen t methods because 255 * Expect no abort metrics to be logged even if there are no matching paymen t methods because
256 * the Payment Request was not shown to the user (a Payment Request gets can celled because the 256 * the Payment Request was not shown to the user (a Payment Request gets can celled because the
257 * merchant only accepts payment methods we don't support. It should instead be logged as a 257 * merchant only accepts payment methods we don't support. It should instead be logged as a
258 * reason why the Payment Request was not shown to the user. 258 * reason why the Payment Request was not shown to the user.
259 */ 259 */
260 @Test 260 @Test
261 @MediumTest 261 @MediumTest
262 @Feature({"Payments"}) 262 @Feature({"Payments"})
263 public void testMetrics_NoSupportedPaymentMethod() 263 public void testMetrics_NoSupportedPaymentMethod()
264 throws InterruptedException, ExecutionException, TimeoutException { 264 throws InterruptedException, ExecutionException, TimeoutException {
265 mPaymentRequestTestRule.openPageAndClickNodeAndWait( 265 mPaymentRequestTestRule.openPageAndClickNodeAndWait(
266 "noSupported", mPaymentRequestTestRule.getShowFailed()); 266 "noSupported", mPaymentRequestTestRule.getShowFailed());
267 mPaymentRequestTestRule.expectResultContains( 267 mPaymentRequestTestRule.expectResultContains(
268 new String[] {"The payment method is not supported"}); 268 new String[] {"The payment method is not supported"});
269 269
270 // Make sure that it is not logged as an abort. 270 // Make sure that it is not logged as an abort.
271 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none * /); 271 mPaymentRequestTestRule.assertOnlySpecificAbortMetricLogged(-1 /* none * /);
272 // Make sure that it was logged as a reason why the Payment Request was not shown. 272 // Make sure that it was logged as a reason why the Payment Request was not shown.
273 Assert.assertEquals(1, 273 Assert.assertEquals(1,
274 RecordHistogram.getHistogramValueCountForTesting( 274 RecordHistogram.getHistogramValueCountForTesting(
275 "PaymentRequest.CheckoutFunnel.NoShow", 275 "PaymentRequest.CheckoutFunnel.NoShow",
276 PaymentRequestMetrics.NO_SHOW_NO_SUPPORTED_PAYMENT_METHO D)); 276 JourneyLogger.NO_SHOW_NO_SUPPORTED_PAYMENT_METHOD));
277 } 277 }
278 278
279 /** 279 /**
280 * Expect only the SELECTED_METHOD_CREDIT_CARD enum value to be logged for t he 280 * Expect only the SELECTED_METHOD_CREDIT_CARD enum value to be logged for t he
281 * "SelectedPaymentMethod" histogram when completing a Payment Request with a credit card. 281 * "SelectedPaymentMethod" histogram when completing a Payment Request with a credit card.
282 */ 282 */
283 @Test 283 @Test
284 @MediumTest 284 @MediumTest
285 @Feature({"Payments"}) 285 @Feature({"Payments"})
286 public void testSelectedPaymentMethod_CreditCard() 286 public void testSelectedPaymentMethod_CreditCard()
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
414 * have a record. 414 * have a record.
415 */ 415 */
416 private void assertOnlySpecificSelectedPaymentMethodMetricLogged(int payment Method) { 416 private void assertOnlySpecificSelectedPaymentMethodMetricLogged(int payment Method) {
417 for (int i = 0; i < PaymentRequestMetrics.SELECTED_METHOD_MAX; ++i) { 417 for (int i = 0; i < PaymentRequestMetrics.SELECTED_METHOD_MAX; ++i) {
418 Assert.assertEquals((i == paymentMethod ? 1 : 0), 418 Assert.assertEquals((i == paymentMethod ? 1 : 0),
419 RecordHistogram.getHistogramValueCountForTesting( 419 RecordHistogram.getHistogramValueCountForTesting(
420 "PaymentRequest.SelectedPaymentMethod", i)); 420 "PaymentRequest.SelectedPaymentMethod", i));
421 } 421 }
422 } 422 }
423 } 423 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698