Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java |
| index 60db7943644fa51fd8d218ea045981b5d9037bca..f5fe9872f8b7927495643329c42b2a368da0ad33 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/payments/PaymentRequestMetricsTest.java |
| @@ -7,11 +7,13 @@ package org.chromium.chrome.browser.payments; |
| import android.content.DialogInterface; |
| import android.test.suitebuilder.annotation.MediumTest; |
| +import org.chromium.base.ThreadUtils; |
| import org.chromium.base.metrics.RecordHistogram; |
| import org.chromium.chrome.R; |
| import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| +import org.chromium.chrome.test.util.ChromeTabUtils; |
| import java.util.concurrent.ExecutionException; |
| import java.util.concurrent.TimeoutException; |
| @@ -21,7 +23,7 @@ import java.util.concurrent.TimeoutException; |
| */ |
| public class PaymentRequestMetricsTest extends PaymentRequestTestBase { |
| public PaymentRequestMetricsTest() { |
| - super("payment_request_free_shipping_test.html"); |
| + super("payment_request_metrics_test.html"); |
| } |
| @Override |
| @@ -69,4 +71,176 @@ public class PaymentRequestMetricsTest extends PaymentRequestTestBase { |
| assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( |
| "PaymentRequest.CheckoutFunnel.Completed", 1)); |
| } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user cancels a |
| + * Payment Request. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_AbortedByUser_CancelButton() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait(mReadyToPay); |
| + clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| + |
| + // Cancel the Payment Request. |
| + int callCount = mDismissed.getCallCount(); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + mUI.getDialogForTest().findViewById(R.id.button_secondary).performClick(); |
| + } |
| + }); |
| + mDismissed.waitForCallback(callCount); |
| + expectResultContains(new String[] {"Request cancelled"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
|
Bernhard Bauer
2016/08/04 08:14:38
It might be worth extracting this into a method th
sebsg
2016/08/04 20:47:49
Done.
|
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on |
| + * the [X] button in the Payment Request dialog. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_AbortedByUser_XButton() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait(mReadyToPay); |
| + clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| + |
| + // Press the [X] button. |
| + clickAndWait(R.id.close_button, mDismissed); |
| + expectResultContains(new String[] {"Request cancelled"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when a user presses on |
| + * the back button on their phone during a Payment Request. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_AbortedByUser_BackButton() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait(mReadyToPay); |
| + clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| + |
| + // Press the back button. |
| + int callCount = mDismissed.getCallCount(); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + mUI.getDialogForTest().onBackPressed(); |
| + } |
| + }); |
| + mDismissed.waitForCallback(callCount); |
| + expectResultContains(new String[] {"Request cancelled"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_MOJO_RENDERER_CLOSING enum value gets logged when a user closes |
| + * the tab during a Payment Request. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_AbortedByUser_TabClosed() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait(mReadyToPay); |
| + clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| + |
| + // Press the back button. |
| + ChromeTabUtils.closeCurrentTab(getInstrumentation(), getActivity()); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_MOJO_RENDERER_CLOSING ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_ABORTED_BY_MERCHANT enum value gets logged when a Payment |
| + * Request gets cancelled by the merchant. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_AbortedByMerchant() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait(mReadyToPay); |
| + clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| + |
| + // Press the back button. |
| + int callCount = mDismissed.getCallCount(); |
| + ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| + @Override |
| + public void run() { |
| + mUI.getDialogForTest().onBackPressed(); |
| + } |
| + }); |
| + mDismissed.waitForCallback(callCount); |
| + expectResultContains(new String[] {"Request cancelled"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_NO_MATCHING_PAYMENT_METHOD enum value gets logged when a Payment |
| + * Request gets cancelled because the user does not have any of the payment methods accepted by |
| + * the merchant and the merchant does not accept credit cards. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_NoMatchingPaymentMethod() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + // Bob pay is supported but no instruments are present. |
| + installPaymentApp(NO_INSTRUMENTS, DELAYED_RESPONSE); |
| + triggerUIAndWait("noMatching", mShowFailed); |
| + expectResultContains(new String[] {"The payment method is not supported"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_NO_MATCHING_PAYMENT_METHOD |
| + ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| + |
| + /** |
| + * Expect only the ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD enum value gets logged when a |
| + * Payment Request gets cancelled because the merchant only accepts payment methods we don't |
| + * support. |
| + */ |
| + @MediumTest |
| + public void testAbortMetrics_NoSupportedPaymentMethod() throws InterruptedException, |
| + ExecutionException, TimeoutException { |
| + triggerUIAndWait("noSupported", mShowFailed); |
| + expectResultContains(new String[] {"The payment method is not supported"}); |
| + |
| + // Make sure only the appropriate abort enum value was logged. |
| + for (int i = 0; i < PaymentRequestMetrics.ABORT_REASON_MAX; ++i) { |
| + assertEquals((i == PaymentRequestMetrics.ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD |
| + ? 1 : 0), |
| + RecordHistogram.getHistogramValueCountForTesting( |
| + "PaymentRequest.CheckoutFunnel.Aborted", i)); |
| + } |
| + } |
| } |