OLD | NEW |
1 // Copyright 2017 The Chromium Authors. All rights reserved. | 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 | 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.support.test.filters.MediumTest; | 8 import android.support.test.filters.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.chrome.R; | 13 import org.chromium.chrome.R; |
14 import org.chromium.chrome.browser.autofill.AutofillTestHelper; | 14 import org.chromium.chrome.browser.autofill.AutofillTestHelper; |
15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; | 15 import org.chromium.chrome.browser.autofill.PersonalDataManager.AutofillProfile; |
| 16 import org.chromium.components.payments.JourneyLogger; |
16 | 17 |
17 import java.util.concurrent.ExecutionException; | 18 import java.util.concurrent.ExecutionException; |
18 import java.util.concurrent.TimeoutException; | 19 import java.util.concurrent.TimeoutException; |
19 | 20 |
20 /** | 21 /** |
21 * A payment integration test for the correct log of the CanMakePayment metrics. | 22 * A payment integration test for the correct log of the CanMakePayment metrics. |
22 */ | 23 */ |
23 public class PaymentRequestCanMakePaymentMetricsTest extends PaymentRequestTestB
ase { | 24 public class PaymentRequestCanMakePaymentMetricsTest extends PaymentRequestTestB
ase { |
24 public PaymentRequestCanMakePaymentMetricsTest() { | 25 public PaymentRequestCanMakePaymentMetricsTest() { |
25 super("payment_request_can_make_payment_metrics_test.html"); | 26 super("payment_request_can_make_payment_metrics_test.html"); |
(...skipping 25 matching lines...) Expand all Loading... |
51 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 52 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
52 @Override | 53 @Override |
53 public void run() { | 54 public void run() { |
54 mUI.getDialogForTest().onBackPressed(); | 55 mUI.getDialogForTest().onBackPressed(); |
55 } | 56 } |
56 }); | 57 }); |
57 mDismissed.waitForCallback(callCount); | 58 mDismissed.waitForCallback(callCount); |
58 expectResultContains(new String[] {"Request cancelled"}); | 59 expectResultContains(new String[] {"Request cancelled"}); |
59 | 60 |
60 // CanMakePayment was queried. | 61 // CanMakePayment was queried. |
61 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 62 assertEquals(1, |
62 "PaymentRequest.CanMakePayment.Usage", | 63 RecordHistogram.getHistogramValueCountForTesting( |
63 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_USE
D)); | 64 "PaymentRequest.CanMakePayment.Usage", |
| 65 JourneyLogger.CAN_MAKE_PAYMENT_USED)); |
64 | 66 |
65 // The CanMakePayment effect on show should be recorded as being false a
nd shown. | 67 // The CanMakePayment effect on show should be recorded as being false a
nd shown. |
66 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 68 assertEquals(1, |
67 "PaymentRequest.CanMakePayment.Used.EffetOnShow"
, | 69 RecordHistogram.getHistogramValueCountForTesting( |
68 PaymentRequestJourneyLogger.CMP_SHOW_DID_SHOW)); | 70 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 71 JourneyLogger.CMP_SHOW_DID_SHOW)); |
69 | 72 |
70 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to | 73 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to |
71 // the user. | 74 // the user. |
72 assertEquals( | 75 assertEquals(1, |
73 1, RecordHistogram.getHistogramValueCountForTesting( | 76 RecordHistogram.getHistogramValueCountForTesting( |
74 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffe
ctOnCompletion", | 77 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectO
nCompletion", |
75 PaymentRequestJourneyLogger.COMPLETION_STATUS_ABORTED
)); | 78 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); |
76 } | 79 } |
77 | 80 |
78 /** | 81 /** |
79 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant | 82 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant |
80 * calling it, receiving no as a response, still showing the Payment Request
and the user | 83 * calling it, receiving no as a response, still showing the Payment Request
and the user |
81 * completes the flow. | 84 * completes the flow. |
82 */ | 85 */ |
83 @MediumTest | 86 @MediumTest |
84 @Feature({"Payments"}) | 87 @Feature({"Payments"}) |
85 public void testCannotMakePayment_Complete() | 88 public void testCannotMakePayment_Complete() |
86 throws InterruptedException, ExecutionException, TimeoutException { | 89 throws InterruptedException, ExecutionException, TimeoutException { |
87 triggerUIAndWait("queryShow", mReadyForInput); | 90 triggerUIAndWait("queryShow", mReadyForInput); |
88 | 91 |
89 // Add a new credit card. | 92 // Add a new credit card. |
90 clickInPaymentMethodAndWait(R.id.payments_section, mReadyToEdit); | 93 clickInPaymentMethodAndWait(R.id.payments_section, mReadyToEdit); |
91 setSpinnerSelectionsInCardEditorAndWait( | 94 setSpinnerSelectionsInCardEditorAndWait( |
92 new int[] {11, 1, 0}, mBillingAddressChangeProcessed); | 95 new int[] {11, 1, 0}, mBillingAddressChangeProcessed); |
93 setTextInCardEditorAndWait(new String[] {"4111111111111111", "Jon Doe"},
mEditorTextUpdate); | 96 setTextInCardEditorAndWait(new String[] {"4111111111111111", "Jon Doe"},
mEditorTextUpdate); |
94 clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); | 97 clickInCardEditorAndWait(R.id.payments_edit_done_button, mReadyToPay); |
95 | 98 |
96 // Complete the transaction. | 99 // Complete the transaction. |
97 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); | 100 clickAndWait(R.id.button_primary, mReadyForUnmaskInput); |
98 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); | 101 setTextInCardUnmaskDialogAndWait(R.id.card_unmask_input, "123", mReadyTo
Unmask); |
99 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); | 102 clickCardUnmaskButtonAndWait(DialogInterface.BUTTON_POSITIVE, mDismissed
); |
100 | 103 |
101 // CanMakePayment was queried. | 104 // CanMakePayment was queried. |
102 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 105 assertEquals(1, |
103 "PaymentRequest.CanMakePayment.Usage", | 106 RecordHistogram.getHistogramValueCountForTesting( |
104 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_USE
D)); | 107 "PaymentRequest.CanMakePayment.Usage", |
| 108 JourneyLogger.CAN_MAKE_PAYMENT_USED)); |
105 | 109 |
106 // The CanMakePayment effect on show should be recorded as being false a
nd shown. | 110 // The CanMakePayment effect on show should be recorded as being false a
nd shown. |
107 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 111 assertEquals(1, |
108 "PaymentRequest.CanMakePayment.Used.EffetOnShow"
, | 112 RecordHistogram.getHistogramValueCountForTesting( |
109 PaymentRequestJourneyLogger.CMP_SHOW_DID_SHOW)); | 113 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 114 JourneyLogger.CMP_SHOW_DID_SHOW)); |
110 | 115 |
111 // There should be a record for a completion when CanMakePayment is fals
e but the PR is | 116 // There should be a record for a completion when CanMakePayment is fals
e but the PR is |
112 // shown to the user. | 117 // shown to the user. |
113 assertEquals( | 118 assertEquals(1, |
114 1, RecordHistogram.getHistogramValueCountForTesting( | 119 RecordHistogram.getHistogramValueCountForTesting( |
115 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffe
ctOnCompletion", | 120 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectO
nCompletion", |
116 PaymentRequestJourneyLogger.COMPLETION_STATUS_COMPLET
ED)); | 121 JourneyLogger.COMPLETION_STATUS_COMPLETED)); |
117 } | 122 } |
118 | 123 |
119 /** | 124 /** |
120 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant | 125 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant |
121 * calling it, receiving yeas as a response, showing the Payment Request and
the user aborts the | 126 * calling it, receiving yeas as a response, showing the Payment Request and
the user aborts the |
122 * flow. | 127 * flow. |
123 */ | 128 */ |
124 @MediumTest | 129 @MediumTest |
125 @Feature({"Payments"}) | 130 @Feature({"Payments"}) |
126 public void testCanMakePayment_Abort() | 131 public void testCanMakePayment_Abort() |
127 throws InterruptedException, ExecutionException, TimeoutException { | 132 throws InterruptedException, ExecutionException, TimeoutException { |
128 // Install the app so CanMakePayment returns true. | 133 // Install the app so CanMakePayment returns true. |
129 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); | 134 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); |
130 | 135 |
131 // Initiate a payment request. | 136 // Initiate a payment request. |
132 triggerUIAndWait("queryShow", mReadyForInput); | 137 triggerUIAndWait("queryShow", mReadyForInput); |
133 | 138 |
134 // Press the back button. | 139 // Press the back button. |
135 int callCount = mDismissed.getCallCount(); | 140 int callCount = mDismissed.getCallCount(); |
136 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 141 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
137 @Override | 142 @Override |
138 public void run() { | 143 public void run() { |
139 mUI.getDialogForTest().onBackPressed(); | 144 mUI.getDialogForTest().onBackPressed(); |
140 } | 145 } |
141 }); | 146 }); |
142 mDismissed.waitForCallback(callCount); | 147 mDismissed.waitForCallback(callCount); |
143 expectResultContains(new String[] {"Request cancelled"}); | 148 expectResultContains(new String[] {"Request cancelled"}); |
144 | 149 |
145 // CanMakePayment was queried. | 150 // CanMakePayment was queried. |
146 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 151 assertEquals(1, |
147 "PaymentRequest.CanMakePayment.Usage", | 152 RecordHistogram.getHistogramValueCountForTesting( |
148 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_USE
D)); | 153 "PaymentRequest.CanMakePayment.Usage", |
| 154 JourneyLogger.CAN_MAKE_PAYMENT_USED)); |
149 | 155 |
150 // The CanMakePayment effect on show should be recorded as being false a
nd shown. | 156 // The CanMakePayment effect on show should be recorded as being false a
nd shown. |
151 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 157 assertEquals(1, |
152 "PaymentRequest.CanMakePayment.Used.EffetOnShow"
, | 158 RecordHistogram.getHistogramValueCountForTesting( |
153 PaymentRequestJourneyLogger.CMP_SHOW_DID_SHOW | 159 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
154 | PaymentRequestJourneyLogger.CMP_SHOW_C
OULD_MAKE_PAYMENT)); | 160 JourneyLogger.CMP_SHOW_DID_SHOW |
| 161 | JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); |
155 | 162 |
156 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to | 163 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to |
157 // the user. | 164 // the user. |
158 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 165 assertEquals(1, |
159 "PaymentRequest.CanMakePayment.Used.TrueWithShow
EffectOnCompletion", | 166 RecordHistogram.getHistogramValueCountForTesting( |
160 PaymentRequestJourneyLogger.COMPLETION_STATUS_AB
ORTED)); | 167 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", |
| 168 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); |
161 } | 169 } |
162 | 170 |
163 /** | 171 /** |
164 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant | 172 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant |
165 * calling it, receiving yeas as a response, showing the Payment Request and
the user completes | 173 * calling it, receiving yeas as a response, showing the Payment Request and
the user completes |
166 * the flow. | 174 * the flow. |
167 */ | 175 */ |
168 @MediumTest | 176 @MediumTest |
169 @Feature({"Payments"}) | 177 @Feature({"Payments"}) |
170 public void testCanMakePayment_Complete() | 178 public void testCanMakePayment_Complete() |
171 throws InterruptedException, ExecutionException, TimeoutException { | 179 throws InterruptedException, ExecutionException, TimeoutException { |
172 // Install the app so CanMakePayment returns true. | 180 // Install the app so CanMakePayment returns true. |
173 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); | 181 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); |
174 | 182 |
175 // Initiate an complete a payment request. | 183 // Initiate an complete a payment request. |
176 triggerUIAndWait("queryShow", mReadyForInput); | 184 triggerUIAndWait("queryShow", mReadyForInput); |
177 clickAndWait(R.id.button_primary, mDismissed); | 185 clickAndWait(R.id.button_primary, mDismissed); |
178 | 186 |
179 // CanMakePayment was queried. | 187 // CanMakePayment was queried. |
180 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 188 assertEquals(1, |
181 "PaymentRequest.CanMakePayment.Usage", | 189 RecordHistogram.getHistogramValueCountForTesting( |
182 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_USE
D)); | 190 "PaymentRequest.CanMakePayment.Usage", |
| 191 JourneyLogger.CAN_MAKE_PAYMENT_USED)); |
183 | 192 |
184 // The CanMakePayment effect on show should be recorded as being false a
nd shown. | 193 // The CanMakePayment effect on show should be recorded as being false a
nd shown. |
185 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 194 assertEquals(1, |
186 "PaymentRequest.CanMakePayment.Used.EffetOnShow"
, | 195 RecordHistogram.getHistogramValueCountForTesting( |
187 PaymentRequestJourneyLogger.CMP_SHOW_DID_SHOW | 196 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
188 | PaymentRequestJourneyLogger.CMP_SHOW_C
OULD_MAKE_PAYMENT)); | 197 JourneyLogger.CMP_SHOW_DID_SHOW |
| 198 | JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); |
189 | 199 |
190 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to | 200 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to |
191 // the user. | 201 // the user. |
192 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 202 assertEquals(1, |
193 "PaymentRequest.CanMakePayment.Used.TrueWithShow
EffectOnCompletion", | 203 RecordHistogram.getHistogramValueCountForTesting( |
194 PaymentRequestJourneyLogger.COMPLETION_STATUS_CO
MPLETED)); | 204 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", |
| 205 JourneyLogger.COMPLETION_STATUS_COMPLETED)); |
195 } | 206 } |
196 | 207 |
197 /** | 208 /** |
198 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant | 209 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant |
199 * not calling it but still showing the Payment Request and the user aborts
the flow. | 210 * not calling it but still showing the Payment Request and the user aborts
the flow. |
200 */ | 211 */ |
201 @MediumTest | 212 @MediumTest |
202 @Feature({"Payments"}) | 213 @Feature({"Payments"}) |
203 public void testNoQuery_Abort() | 214 public void testNoQuery_Abort() |
204 throws InterruptedException, ExecutionException, TimeoutException { | 215 throws InterruptedException, ExecutionException, TimeoutException { |
205 // Initiate a payment request. | 216 // Initiate a payment request. |
206 triggerUIAndWait("noQueryShow", mReadyForInput); | 217 triggerUIAndWait("noQueryShow", mReadyForInput); |
207 | 218 |
208 // Press the back button. | 219 // Press the back button. |
209 int callCount = mDismissed.getCallCount(); | 220 int callCount = mDismissed.getCallCount(); |
210 ThreadUtils.runOnUiThreadBlocking(new Runnable() { | 221 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
211 @Override | 222 @Override |
212 public void run() { | 223 public void run() { |
213 mUI.getDialogForTest().onBackPressed(); | 224 mUI.getDialogForTest().onBackPressed(); |
214 } | 225 } |
215 }); | 226 }); |
216 mDismissed.waitForCallback(callCount); | 227 mDismissed.waitForCallback(callCount); |
217 expectResultContains(new String[] {"Request cancelled"}); | 228 expectResultContains(new String[] {"Request cancelled"}); |
218 | 229 |
219 // CanMakePayment was not queried. | 230 // CanMakePayment was not queried. |
220 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 231 assertEquals(1, |
221 "PaymentRequest.CanMakePayment.Usage", | 232 RecordHistogram.getHistogramValueCountForTesting( |
222 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_NOT
_USED)); | 233 "PaymentRequest.CanMakePayment.Usage", |
| 234 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); |
223 | 235 |
224 // There should be a record for an abort when CanMakePayment is not call
ed but the PR is | 236 // There should be a record for an abort when CanMakePayment is not call
ed but the PR is |
225 // shown to the user. | 237 // shown to the user. |
226 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 238 assertEquals(1, |
227 "PaymentRequest.CanMakePayment.NotUsed.WithShowE
ffectOnCompletion", | 239 RecordHistogram.getHistogramValueCountForTesting( |
228 PaymentRequestJourneyLogger.COMPLETION_STATUS_AB
ORTED)); | 240 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", |
| 241 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); |
229 } | 242 } |
230 | 243 |
231 /** | 244 /** |
232 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant | 245 * Tests that the CanMakePayment metrics are correctly logged for the case o
f a merchant |
233 * not calling it but still showing the Payment Request and the user complet
es the flow. | 246 * not calling it but still showing the Payment Request and the user complet
es the flow. |
234 */ | 247 */ |
235 @MediumTest | 248 @MediumTest |
236 @Feature({"Payments"}) | 249 @Feature({"Payments"}) |
237 public void testNoQuery_Completes() | 250 public void testNoQuery_Completes() |
238 throws InterruptedException, ExecutionException, TimeoutException { | 251 throws InterruptedException, ExecutionException, TimeoutException { |
239 // Install the app so the user can complete the Payment Request. | 252 // Install the app so the user can complete the Payment Request. |
240 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); | 253 installPaymentApp(HAVE_INSTRUMENTS, IMMEDIATE_RESPONSE); |
241 | 254 |
242 // Initiate a payment request. | 255 // Initiate a payment request. |
243 triggerUIAndWait("noQueryShow", mReadyForInput); | 256 triggerUIAndWait("noQueryShow", mReadyForInput); |
244 clickAndWait(R.id.button_primary, mDismissed); | 257 clickAndWait(R.id.button_primary, mDismissed); |
245 | 258 |
246 // CanMakePayment was not queried. | 259 // CanMakePayment was not queried. |
247 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 260 assertEquals(1, |
248 "PaymentRequest.CanMakePayment.Usage", | 261 RecordHistogram.getHistogramValueCountForTesting( |
249 PaymentRequestJourneyLogger.CAN_MAKE_PAYMENT_NOT
_USED)); | 262 "PaymentRequest.CanMakePayment.Usage", |
| 263 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); |
250 | 264 |
251 // There should be a record for a completion when CanMakePayment is not
called but the PR is | 265 // There should be a record for a completion when CanMakePayment is not
called but the PR is |
252 // shown to the user. | 266 // shown to the user. |
253 assertEquals(1, RecordHistogram.getHistogramValueCountForTesting( | 267 assertEquals(1, |
254 "PaymentRequest.CanMakePayment.NotUsed.WithShowE
ffectOnCompletion", | 268 RecordHistogram.getHistogramValueCountForTesting( |
255 PaymentRequestJourneyLogger.COMPLETION_STATUS_CO
MPLETED)); | 269 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", |
| 270 JourneyLogger.COMPLETION_STATUS_COMPLETED)); |
256 } | 271 } |
257 } | 272 } |
OLD | NEW |