| OLD | NEW |
| 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 android.content.DialogInterface; | 7 import android.content.DialogInterface; |
| 8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
| 9 | 9 |
| 10 import org.chromium.base.ThreadUtils; | 10 import org.chromium.base.ThreadUtils; |
| 11 import org.chromium.base.metrics.RecordHistogram; | 11 import org.chromium.base.metrics.RecordHistogram; |
| 12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
| 13 import org.chromium.base.test.util.RetryOnFailure; |
| 13 import org.chromium.chrome.R; | 14 import org.chromium.chrome.R; |
| 14 import org.chromium.chrome.browser.autofill.AutofillTestHelper; | 15 import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
| 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 16 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; | 17 import org.chromium.chrome.browser.autofill.PersonalDataManager.CreditCard; |
| 17 import org.chromium.chrome.test.util.ChromeTabUtils; | 18 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 18 | 19 |
| 19 import java.util.concurrent.ExecutionException; | 20 import java.util.concurrent.ExecutionException; |
| 20 import java.util.concurrent.TimeoutException; | 21 import java.util.concurrent.TimeoutException; |
| 21 | 22 |
| 22 /** | 23 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 38 mHelper.setCreditCard(new CreditCard("", "https://example.com", true, tr
ue, "Jon Doe", | 39 mHelper.setCreditCard(new CreditCard("", "https://example.com", true, tr
ue, "Jon Doe", |
| 39 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, | 40 "4111111111111111", "1111", "12", "2050", "visa", R.drawable.pr_
visa, |
| 40 mBillingAddressId, "" /* serverId */)); | 41 mBillingAddressId, "" /* serverId */)); |
| 41 } | 42 } |
| 42 | 43 |
| 43 /** | 44 /** |
| 44 * Expect that the successful checkout funnel metrics are logged during a su
ccesful checkout. | 45 * Expect that the successful checkout funnel metrics are logged during a su
ccesful checkout. |
| 45 */ | 46 */ |
| 46 @MediumTest | 47 @MediumTest |
| 47 @Feature({"Payments"}) | 48 @Feature({"Payments"}) |
| 49 @RetryOnFailure |
| 48 public void testSuccessCheckoutFunnel() throws InterruptedException, Executi
onException, | 50 public void testSuccessCheckoutFunnel() throws InterruptedException, Executi
onException, |
| 49 TimeoutException { | 51 TimeoutException { |
| 50 // Initiate a payment request. | 52 // Initiate a payment request. |
| 51 triggerUIAndWait("ccBuy", mReadyToPay); | 53 triggerUIAndWait("ccBuy", mReadyToPay); |
| 52 | 54 |
| 53 // Make sure sure that the "Initiated" and "Shown" events were logged. | 55 // Make sure sure that the "Initiated" and "Shown" events were logged. |
| 54 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 56 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( |
| 55 "PaymentRequest.CheckoutFunnel.Initiated", 1)); | 57 "PaymentRequest.CheckoutFunnel.Initiated", 1)); |
| 56 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 58 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( |
| 57 "PaymentRequest.CheckoutFunnel.Shown", 1)); | 59 "PaymentRequest.CheckoutFunnel.Shown", 1)); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 73 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 75 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( |
| 74 "PaymentRequest.CheckoutFunnel.Completed", 1)); | 76 "PaymentRequest.CheckoutFunnel.Completed", 1)); |
| 75 } | 77 } |
| 76 | 78 |
| 77 /** | 79 /** |
| 78 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when
a user cancels a | 80 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when
a user cancels a |
| 79 * Payment Request. | 81 * Payment Request. |
| 80 */ | 82 */ |
| 81 @MediumTest | 83 @MediumTest |
| 82 @Feature({"Payments"}) | 84 @Feature({"Payments"}) |
| 85 @RetryOnFailure |
| 83 public void testAbortMetrics_AbortedByUser_CancelButton() throws Interrupted
Exception, | 86 public void testAbortMetrics_AbortedByUser_CancelButton() throws Interrupted
Exception, |
| 84 ExecutionException, TimeoutException { | 87 ExecutionException, TimeoutException { |
| 85 triggerUIAndWait("ccBuy", mReadyToPay); | 88 triggerUIAndWait("ccBuy", mReadyToPay); |
| 86 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); | 89 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| 87 | 90 |
| 88 // Cancel the Payment Request. | 91 // Cancel the Payment Request. |
| 89 int callCount = mDismissed.getCallCount(); | 92 int callCount = mDismissed.getCallCount(); |
| 90 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 93 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 91 @Override | 94 @Override |
| 92 public void run() { | 95 public void run() { |
| (...skipping 25 matching lines...) Expand all Loading... |
| 118 assertOnlySpecificAbortMetricLogged( | 121 assertOnlySpecificAbortMetricLogged( |
| 119 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER); | 122 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_USER); |
| 120 } | 123 } |
| 121 | 124 |
| 122 /** | 125 /** |
| 123 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when
a user presses on | 126 * Expect only the ABORT_REASON_ABORTED_BY_USER enum value gets logged when
a user presses on |
| 124 * the back button on their phone during a Payment Request. | 127 * the back button on their phone during a Payment Request. |
| 125 */ | 128 */ |
| 126 @MediumTest | 129 @MediumTest |
| 127 @Feature({"Payments"}) | 130 @Feature({"Payments"}) |
| 131 @RetryOnFailure |
| 128 public void testAbortMetrics_AbortedByUser_BackButton() throws InterruptedEx
ception, | 132 public void testAbortMetrics_AbortedByUser_BackButton() throws InterruptedEx
ception, |
| 129 ExecutionException, TimeoutException { | 133 ExecutionException, TimeoutException { |
| 130 triggerUIAndWait("ccBuy", mReadyToPay); | 134 triggerUIAndWait("ccBuy", mReadyToPay); |
| 131 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); | 135 clickInShippingSummaryAndWait(R.id.payments_section, mReadyForInput); |
| 132 | 136 |
| 133 // Press the back button. | 137 // Press the back button. |
| 134 int callCount = mDismissed.getCallCount(); | 138 int callCount = mDismissed.getCallCount(); |
| 135 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 139 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 136 @Override | 140 @Override |
| 137 public void run() { | 141 public void run() { |
| (...skipping 24 matching lines...) Expand all Loading... |
| 162 assertOnlySpecificAbortMetricLogged( | 166 assertOnlySpecificAbortMetricLogged( |
| 163 PaymentRequestMetrics.ABORT_REASON_MOJO_RENDERER_CLOSING); | 167 PaymentRequestMetrics.ABORT_REASON_MOJO_RENDERER_CLOSING); |
| 164 } | 168 } |
| 165 | 169 |
| 166 /** | 170 /** |
| 167 * Expect only the ABORT_REASON_ABORTED_BY_MERCHANT enum value gets logged w
hen a Payment | 171 * Expect only the ABORT_REASON_ABORTED_BY_MERCHANT enum value gets logged w
hen a Payment |
| 168 * Request gets cancelled by the merchant. | 172 * Request gets cancelled by the merchant. |
| 169 */ | 173 */ |
| 170 @MediumTest | 174 @MediumTest |
| 171 @Feature({"Payments"}) | 175 @Feature({"Payments"}) |
| 176 @RetryOnFailure |
| 172 public void testAbortMetrics_AbortedByMerchant() throws InterruptedException
, | 177 public void testAbortMetrics_AbortedByMerchant() throws InterruptedException
, |
| 173 ExecutionException, TimeoutException { | 178 ExecutionException, TimeoutException { |
| 174 triggerUIAndWait("ccBuy", mReadyToPay); | 179 triggerUIAndWait("ccBuy", mReadyToPay); |
| 175 | 180 |
| 176 // Simulate an abort by the merchant. | 181 // Simulate an abort by the merchant. |
| 177 clickNodeAndWait("abort", mDismissed); | 182 clickNodeAndWait("abort", mDismissed); |
| 178 expectResultContains(new String[] {"Abort"}); | 183 expectResultContains(new String[] {"Abort"}); |
| 179 | 184 |
| 180 assertOnlySpecificAbortMetricLogged( | 185 assertOnlySpecificAbortMetricLogged( |
| 181 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_MERCHANT); | 186 PaymentRequestMetrics.ABORT_REASON_ABORTED_BY_MERCHANT); |
| 182 } | 187 } |
| 183 | 188 |
| 184 /** | 189 /** |
| 185 * Expect only the ABORT_REASON_NO_MATCHING_PAYMENT_METHOD enum value gets l
ogged when a Payment | 190 * Expect only the ABORT_REASON_NO_MATCHING_PAYMENT_METHOD enum value gets l
ogged when a Payment |
| 186 * Request gets cancelled because the user does not have any of the payment
methods accepted by | 191 * Request gets cancelled because the user does not have any of the payment
methods accepted by |
| 187 * the merchant and the merchant does not accept credit cards. | 192 * the merchant and the merchant does not accept credit cards. |
| 188 */ | 193 */ |
| 189 @MediumTest | 194 @MediumTest |
| 190 @Feature({"Payments"}) | 195 @Feature({"Payments"}) |
| 196 @RetryOnFailure |
| 191 public void testAbortMetrics_NoMatchingPaymentMethod() throws InterruptedExc
eption, | 197 public void testAbortMetrics_NoMatchingPaymentMethod() throws InterruptedExc
eption, |
| 192 ExecutionException, TimeoutException { | 198 ExecutionException, TimeoutException { |
| 193 // Android Pay is supported but no instruments are present. | 199 // Android Pay is supported but no instruments are present. |
| 194 installPaymentApp("https://android.com/pay", NO_INSTRUMENTS, DELAYED_RES
PONSE); | 200 installPaymentApp("https://android.com/pay", NO_INSTRUMENTS, DELAYED_RES
PONSE); |
| 195 triggerUIAndWait("androidPayBuy", mShowFailed); | 201 triggerUIAndWait("androidPayBuy", mShowFailed); |
| 196 expectResultContains(new String[] {"The payment method is not supported"
}); | 202 expectResultContains(new String[] {"The payment method is not supported"
}); |
| 197 | 203 |
| 198 assertOnlySpecificAbortMetricLogged( | 204 assertOnlySpecificAbortMetricLogged( |
| 199 PaymentRequestMetrics.ABORT_REASON_NO_MATCHING_PAYMENT_METHOD); | 205 PaymentRequestMetrics.ABORT_REASON_NO_MATCHING_PAYMENT_METHOD); |
| 200 } | 206 } |
| 201 | 207 |
| 202 /** | 208 /** |
| 203 * Expect only the ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD enum value gets
logged when a | 209 * Expect only the ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD enum value gets
logged when a |
| 204 * Payment Request gets cancelled because the merchant only accepts payment
methods we don't | 210 * Payment Request gets cancelled because the merchant only accepts payment
methods we don't |
| 205 * support. | 211 * support. |
| 206 */ | 212 */ |
| 207 @MediumTest | 213 @MediumTest |
| 208 @Feature({"Payments"}) | 214 @Feature({"Payments"}) |
| 215 @RetryOnFailure |
| 209 public void testAbortMetrics_NoSupportedPaymentMethod() throws InterruptedEx
ception, | 216 public void testAbortMetrics_NoSupportedPaymentMethod() throws InterruptedEx
ception, |
| 210 ExecutionException, TimeoutException { | 217 ExecutionException, TimeoutException { |
| 211 triggerUIAndWait("noSupported", mShowFailed); | 218 triggerUIAndWait("noSupported", mShowFailed); |
| 212 expectResultContains(new String[] {"The payment method is not supported"
}); | 219 expectResultContains(new String[] {"The payment method is not supported"
}); |
| 213 | 220 |
| 214 assertOnlySpecificAbortMetricLogged( | 221 assertOnlySpecificAbortMetricLogged( |
| 215 PaymentRequestMetrics.ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD); | 222 PaymentRequestMetrics.ABORT_REASON_NO_SUPPORTED_PAYMENT_METHOD); |
| 216 } | 223 } |
| 217 | 224 |
| 218 /** | 225 /** |
| 219 * Expect only the SELECTED_METHOD_CREDIT_CARD enum value to be logged for t
he | 226 * Expect only the SELECTED_METHOD_CREDIT_CARD enum value to be logged for t
he |
| 220 * "SelectedPaymentMethod" histogram when completing a Payment Request with
a credit card. | 227 * "SelectedPaymentMethod" histogram when completing a Payment Request with
a credit card. |
| 221 */ | 228 */ |
| 222 @MediumTest | 229 @MediumTest |
| 223 @Feature({"Payments"}) | 230 @Feature({"Payments"}) |
| 231 @RetryOnFailure |
| 224 public void testSelectedPaymentMethod_CreditCard() throws InterruptedExcepti
on, | 232 public void testSelectedPaymentMethod_CreditCard() throws InterruptedExcepti
on, |
| 225 ExecutionException, TimeoutException { | 233 ExecutionException, TimeoutException { |
| 226 // Complete a Payment Request with a credit card. | 234 // Complete a Payment Request with a credit card. |
| 227 triggerUIAndWait("ccBuy", mReadyToPay); | 235 triggerUIAndWait("ccBuy", mReadyToPay); |
| 228 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); | 236 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
| 229 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); | 237 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
| 230 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); | 238 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
| 231 | 239 |
| 232 assertOnlySpecificSelectedPaymentMethodMetricLogged( | 240 assertOnlySpecificSelectedPaymentMethodMetricLogged( |
| 233 PaymentRequestMetrics.SELECTED_METHOD_CREDIT_CARD); | 241 PaymentRequestMetrics.SELECTED_METHOD_CREDIT_CARD); |
| 234 } | 242 } |
| 235 | 243 |
| 236 /** | 244 /** |
| 237 * Expect only the SELECTED_METHOD_ANDROID_PAY enum value to be logged for t
he | 245 * Expect only the SELECTED_METHOD_ANDROID_PAY enum value to be logged for t
he |
| 238 * "SelectedPaymentMethod" histogram when completing a Payment Request with
Android Pay. | 246 * "SelectedPaymentMethod" histogram when completing a Payment Request with
Android Pay. |
| 239 */ | 247 */ |
| 240 @MediumTest | 248 @MediumTest |
| 241 @Feature({"Payments"}) | 249 @Feature({"Payments"}) |
| 250 @RetryOnFailure |
| 242 public void testSelectedPaymentMethod_AndroidPay() throws InterruptedExcepti
on, | 251 public void testSelectedPaymentMethod_AndroidPay() throws InterruptedExcepti
on, |
| 243 ExecutionException, TimeoutException { | 252 ExecutionException, TimeoutException { |
| 244 // Complete a Payment Request with Android Pay. | 253 // Complete a Payment Request with Android Pay. |
| 245 installPaymentApp("https://android.com/pay", HAVE_INSTRUMENTS, IMMEDIATE
_RESPONSE); | 254 installPaymentApp("https://android.com/pay", HAVE_INSTRUMENTS, IMMEDIATE
_RESPONSE); |
| 246 triggerUIAndWait("androidPayBuy", mReadyToPay); | 255 triggerUIAndWait("androidPayBuy", mReadyToPay); |
| 247 clickAndWait(R.id.button_primary, mDismissed); | 256 clickAndWait(R.id.button_primary, mDismissed); |
| 248 | 257 |
| 249 assertOnlySpecificSelectedPaymentMethodMetricLogged( | 258 assertOnlySpecificSelectedPaymentMethodMetricLogged( |
| 250 PaymentRequestMetrics.SELECTED_METHOD_ANDROID_PAY); | 259 PaymentRequestMetrics.SELECTED_METHOD_ANDROID_PAY); |
| 251 } | 260 } |
| (...skipping 19 matching lines...) Expand all Loading... |
| 271 * have a record. | 280 * have a record. |
| 272 */ | 281 */ |
| 273 private void assertOnlySpecificSelectedPaymentMethodMetricLogged(int payment
Method) { | 282 private void assertOnlySpecificSelectedPaymentMethodMetricLogged(int payment
Method) { |
| 274 for (int i = 0; i < PaymentRequestMetrics.SELECTED_METHOD_MAX; ++i) { | 283 for (int i = 0; i < PaymentRequestMetrics.SELECTED_METHOD_MAX; ++i) { |
| 275 assertEquals((i == paymentMethod ? 1 : 0), | 284 assertEquals((i == paymentMethod ? 1 : 0), |
| 276 RecordHistogram.getHistogramValueCountForTesting( | 285 RecordHistogram.getHistogramValueCountForTesting( |
| 277 "PaymentRequest.SelectedPaymentMethod", i)); | 286 "PaymentRequest.SelectedPaymentMethod", i)); |
| 278 } | 287 } |
| 279 } | 288 } |
| 280 } | 289 } |
| OLD | NEW |