| OLD | NEW |
| (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 package org.chromium.chrome.browser.payments; | |
| 6 | |
| 7 import android.support.test.InstrumentationRegistry; | |
| 8 import android.support.test.filters.SmallTest; | |
| 9 | |
| 10 import org.junit.Assert; | |
| 11 import org.junit.Before; | |
| 12 import org.junit.Rule; | |
| 13 import org.junit.Test; | |
| 14 import org.junit.runner.RunWith; | |
| 15 | |
| 16 import org.chromium.base.metrics.RecordHistogram; | |
| 17 import org.chromium.base.test.BaseJUnit4ClassRunner; | |
| 18 import org.chromium.base.test.util.Feature; | |
| 19 import org.chromium.chrome.test.util.ApplicationData; | |
| 20 import org.chromium.components.payments.JourneyLogger; | |
| 21 import org.chromium.content.browser.test.NativeLibraryTestRule; | |
| 22 | |
| 23 /** | |
| 24 * Tests for the PaymentRequestJourneyLogger class. | |
| 25 */ | |
| 26 @RunWith(BaseJUnit4ClassRunner.class) | |
| 27 public class PaymentRequestJourneyLoggerUnitTest { | |
| 28 @Rule | |
| 29 public NativeLibraryTestRule mNativeLibraryTestRule = new NativeLibraryTestR
ule(); | |
| 30 | |
| 31 @Before | |
| 32 public void setUp() throws Exception { | |
| 33 ApplicationData.clearAppData( | |
| 34 InstrumentationRegistry.getInstrumentation().getTargetContext())
; | |
| 35 mNativeLibraryTestRule.loadNativeLibraryAndInitBrowserProcess(); | |
| 36 } | |
| 37 | |
| 38 /** | |
| 39 * Tests the canMakePayment stats for the case where the merchant does not u
se it and does not | |
| 40 * show the PaymentRequest to the user. | |
| 41 */ | |
| 42 @Test | |
| 43 @SmallTest | |
| 44 @Feature({"Payments"}) | |
| 45 public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow(
) { | |
| 46 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 47 assertNoLogForCanMakePayment(); | |
| 48 | |
| 49 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 50 | |
| 51 // CanMakePayment was not used. | |
| 52 Assert.assertEquals(1, | |
| 53 RecordHistogram.getHistogramValueCountForTesting( | |
| 54 "PaymentRequest.CanMakePayment.Usage", | |
| 55 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); | |
| 56 | |
| 57 // There should be no completion stats since PR was not shown to the use
r | |
| 58 Assert.assertEquals(0, | |
| 59 RecordHistogram.getHistogramValueCountForTesting( | |
| 60 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 61 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 62 Assert.assertEquals(0, | |
| 63 RecordHistogram.getHistogramValueCountForTesting( | |
| 64 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 65 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 66 } | |
| 67 | |
| 68 /** | |
| 69 * Tests the canMakePayment stats for the case where the merchant does not u
se it and the | |
| 70 * transaction is aborted. | |
| 71 */ | |
| 72 @Test | |
| 73 @SmallTest | |
| 74 @Feature({"Payments"}) | |
| 75 public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAnd
UserAbort() { | |
| 76 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 77 assertNoLogForCanMakePayment(); | |
| 78 | |
| 79 // The merchant does not query CanMakePayment, show the PaymentRequest a
nd the user | |
| 80 // aborts it. | |
| 81 logger.setShowCalled(); | |
| 82 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 83 | |
| 84 // CanMakePayment was not used. | |
| 85 Assert.assertEquals(1, | |
| 86 RecordHistogram.getHistogramValueCountForTesting( | |
| 87 "PaymentRequest.CanMakePayment.Usage", | |
| 88 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); | |
| 89 | |
| 90 // There should be a record for an abort when CanMakePayment is not used
but the PR is shown | |
| 91 // to the user. | |
| 92 Assert.assertEquals(1, | |
| 93 RecordHistogram.getHistogramValueCountForTesting( | |
| 94 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 95 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 96 } | |
| 97 | |
| 98 /** | |
| 99 * Tests the canMakePayment stats for the case where the merchant does not u
se it and the | |
| 100 * transaction is aborted. | |
| 101 */ | |
| 102 @Test | |
| 103 @SmallTest | |
| 104 @Feature({"Payments"}) | |
| 105 public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAnd
OtherAbort() { | |
| 106 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 107 assertNoLogForCanMakePayment(); | |
| 108 | |
| 109 // The merchant does not query CanMakePayment, show the PaymentRequest a
nd the user | |
| 110 // aborts it. | |
| 111 logger.setShowCalled(); | |
| 112 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 113 | |
| 114 // CanMakePayment was not used. | |
| 115 Assert.assertEquals(1, | |
| 116 RecordHistogram.getHistogramValueCountForTesting( | |
| 117 "PaymentRequest.CanMakePayment.Usage", | |
| 118 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); | |
| 119 | |
| 120 // There should be a record for an abort when CanMakePayment is not used
but the PR is shown | |
| 121 // to the user. | |
| 122 Assert.assertEquals(1, | |
| 123 RecordHistogram.getHistogramValueCountForTesting( | |
| 124 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 125 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 126 } | |
| 127 | |
| 128 /** | |
| 129 * Tests the canMakePayment stats for the case where the merchant does not u
se it and the | |
| 130 * transaction is completed. | |
| 131 */ | |
| 132 @Test | |
| 133 @SmallTest | |
| 134 @Feature({"Payments"}) | |
| 135 public void testRecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAnd
Complete() { | |
| 136 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 137 assertNoLogForCanMakePayment(); | |
| 138 | |
| 139 // The merchant does not query CanMakePayment, show the PaymentRequest a
nd the user | |
| 140 // completes it. | |
| 141 logger.setShowCalled(); | |
| 142 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 143 | |
| 144 // CanMakePayment was not used. | |
| 145 Assert.assertEquals(1, | |
| 146 RecordHistogram.getHistogramValueCountForTesting( | |
| 147 "PaymentRequest.CanMakePayment.Usage", | |
| 148 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); | |
| 149 | |
| 150 // There should be a record for a completion when CanMakePayment is not
used but the PR is | |
| 151 // shown to the user. | |
| 152 Assert.assertEquals(1, | |
| 153 RecordHistogram.getHistogramValueCountForTesting( | |
| 154 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 155 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 156 } | |
| 157 | |
| 158 /** | |
| 159 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns false and | |
| 160 * show is not called. | |
| 161 */ | |
| 162 @Test | |
| 163 @SmallTest | |
| 164 @Feature({"Payments"}) | |
| 165 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNo
Show() { | |
| 166 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 167 assertNoLogForCanMakePayment(); | |
| 168 | |
| 169 // The user cannot make payment and the PaymentRequest is not shown. | |
| 170 logger.setCanMakePaymentValue(false); | |
| 171 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 172 | |
| 173 // CanMakePayment was used. | |
| 174 Assert.assertEquals(1, | |
| 175 RecordHistogram.getHistogramValueCountForTesting( | |
| 176 "PaymentRequest.CanMakePayment.Usage", | |
| 177 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 178 | |
| 179 // The CanMakePayment effect on show should be recorded as being false a
nd not shown. | |
| 180 Assert.assertEquals(1, | |
| 181 RecordHistogram.getHistogramValueCountForTesting( | |
| 182 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 183 JourneyLogger.CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NO
T_SHOW)); | |
| 184 | |
| 185 // There should be no completion stats since PR was not shown to the use
r. | |
| 186 Assert.assertEquals(0, | |
| 187 RecordHistogram.getHistogramValueCountForTesting( | |
| 188 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 189 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 190 Assert.assertEquals(0, | |
| 191 RecordHistogram.getHistogramValueCountForTesting( | |
| 192 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 193 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 194 } | |
| 195 | |
| 196 /** | |
| 197 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns true and | |
| 198 * show is not called. | |
| 199 */ | |
| 200 @Test | |
| 201 @SmallTest | |
| 202 @Feature({"Payments"}) | |
| 203 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoS
how() { | |
| 204 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 205 assertNoLogForCanMakePayment(); | |
| 206 | |
| 207 // The user can make a payment but the Payment Request is not shown. | |
| 208 logger.setCanMakePaymentValue(true); | |
| 209 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 210 | |
| 211 // CanMakePayment was used. | |
| 212 Assert.assertEquals(1, | |
| 213 RecordHistogram.getHistogramValueCountForTesting( | |
| 214 "PaymentRequest.CanMakePayment.Usage", | |
| 215 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 216 | |
| 217 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 218 Assert.assertEquals(1, | |
| 219 RecordHistogram.getHistogramValueCountForTesting( | |
| 220 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 221 JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); | |
| 222 | |
| 223 // There should be no completion stats since PR was not shown to the use
r. | |
| 224 Assert.assertEquals(0, | |
| 225 RecordHistogram.getHistogramValueCountForTesting( | |
| 226 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 227 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 228 Assert.assertEquals(0, | |
| 229 RecordHistogram.getHistogramValueCountForTesting( | |
| 230 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 231 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 232 } | |
| 233 | |
| 234 /** | |
| 235 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns false, show | |
| 236 * is called but the transaction is aborted by the user. | |
| 237 */ | |
| 238 @Test | |
| 239 @SmallTest | |
| 240 @Feature({"Payments"}) | |
| 241 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowA
ndUserAbort() { | |
| 242 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 243 assertNoLogForCanMakePayment(); | |
| 244 | |
| 245 // The user cannot make a payment. the payment request is shown but abor
ted. | |
| 246 logger.setShowCalled(); | |
| 247 logger.setCanMakePaymentValue(false); | |
| 248 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 249 | |
| 250 // CanMakePayment was used. | |
| 251 Assert.assertEquals(1, | |
| 252 RecordHistogram.getHistogramValueCountForTesting( | |
| 253 "PaymentRequest.CanMakePayment.Usage", | |
| 254 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 255 | |
| 256 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 257 Assert.assertEquals(1, | |
| 258 RecordHistogram.getHistogramValueCountForTesting( | |
| 259 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 260 JourneyLogger.CMP_SHOW_DID_SHOW)); | |
| 261 | |
| 262 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to | |
| 263 // the user. | |
| 264 Assert.assertEquals(1, | |
| 265 RecordHistogram.getHistogramValueCountForTesting( | |
| 266 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectO
nCompletion", | |
| 267 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 268 } | |
| 269 | |
| 270 /** | |
| 271 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns false, show | |
| 272 * is called but the transaction is aborted. | |
| 273 */ | |
| 274 @Test | |
| 275 @SmallTest | |
| 276 @Feature({"Payments"}) | |
| 277 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowA
ndOtherAbort() { | |
| 278 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 279 assertNoLogForCanMakePayment(); | |
| 280 | |
| 281 // The user cannot make a payment. the payment request is shown but abor
ted. | |
| 282 logger.setShowCalled(); | |
| 283 logger.setCanMakePaymentValue(false); | |
| 284 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 285 | |
| 286 // CanMakePayment was used. | |
| 287 Assert.assertEquals(1, | |
| 288 RecordHistogram.getHistogramValueCountForTesting( | |
| 289 "PaymentRequest.CanMakePayment.Usage", | |
| 290 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 291 | |
| 292 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 293 Assert.assertEquals(1, | |
| 294 RecordHistogram.getHistogramValueCountForTesting( | |
| 295 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 296 JourneyLogger.CMP_SHOW_DID_SHOW)); | |
| 297 | |
| 298 // There should be a record for an abort when CanMakePayment is false bu
t the PR is shown to | |
| 299 // the user. | |
| 300 Assert.assertEquals(1, | |
| 301 RecordHistogram.getHistogramValueCountForTesting( | |
| 302 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectO
nCompletion", | |
| 303 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 304 } | |
| 305 | |
| 306 /** | |
| 307 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns false, | |
| 308 * show is called and the transaction is completed. | |
| 309 */ | |
| 310 @Test | |
| 311 @SmallTest | |
| 312 @Feature({"Payments"}) | |
| 313 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowA
ndComplete() { | |
| 314 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 315 assertNoLogForCanMakePayment(); | |
| 316 | |
| 317 // The user cannot make a payment. the payment request is shown and comp
leted. | |
| 318 logger.setShowCalled(); | |
| 319 logger.setCanMakePaymentValue(false); | |
| 320 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 321 | |
| 322 // CanMakePayment was used. | |
| 323 Assert.assertEquals(1, | |
| 324 RecordHistogram.getHistogramValueCountForTesting( | |
| 325 "PaymentRequest.CanMakePayment.Usage", | |
| 326 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 327 | |
| 328 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 329 Assert.assertEquals(1, | |
| 330 RecordHistogram.getHistogramValueCountForTesting( | |
| 331 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 332 JourneyLogger.CMP_SHOW_DID_SHOW)); | |
| 333 | |
| 334 // There should be a record for a completion when CanMakePayment is fals
e and the PR is | |
| 335 // shown to the user. | |
| 336 Assert.assertEquals(1, | |
| 337 RecordHistogram.getHistogramValueCountForTesting( | |
| 338 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectO
nCompletion", | |
| 339 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 340 } | |
| 341 | |
| 342 /** | |
| 343 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns true, show | |
| 344 * is called but the transaction is aborted by the user. | |
| 345 */ | |
| 346 @Test | |
| 347 @SmallTest | |
| 348 @Feature({"Payments"}) | |
| 349 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAn
dUserAbort() { | |
| 350 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 351 assertNoLogForCanMakePayment(); | |
| 352 | |
| 353 // The user cannot make a payment. the payment request is shown and comp
leted. | |
| 354 logger.setShowCalled(); | |
| 355 logger.setCanMakePaymentValue(true); | |
| 356 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 357 | |
| 358 // CanMakePayment was used. | |
| 359 Assert.assertEquals(1, | |
| 360 RecordHistogram.getHistogramValueCountForTesting( | |
| 361 "PaymentRequest.CanMakePayment.Usage", | |
| 362 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 363 | |
| 364 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 365 Assert.assertEquals(1, | |
| 366 RecordHistogram.getHistogramValueCountForTesting( | |
| 367 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 368 JourneyLogger.CMP_SHOW_DID_SHOW | |
| 369 | JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); | |
| 370 | |
| 371 // There should be a record for an abort when CanMakePayment is true and
the PR is shown to | |
| 372 // the user. | |
| 373 Assert.assertEquals(1, | |
| 374 RecordHistogram.getHistogramValueCountForTesting( | |
| 375 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", | |
| 376 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 377 } | |
| 378 | |
| 379 /** | |
| 380 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns true, show | |
| 381 * is called but the transaction is aborted. | |
| 382 */ | |
| 383 @Test | |
| 384 @SmallTest | |
| 385 @Feature({"Payments"}) | |
| 386 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAn
dOtherAbort() { | |
| 387 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 388 assertNoLogForCanMakePayment(); | |
| 389 | |
| 390 // The user cannot make a payment. the payment request is shown and comp
leted. | |
| 391 logger.setShowCalled(); | |
| 392 logger.setCanMakePaymentValue(true); | |
| 393 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 394 | |
| 395 // CanMakePayment was used. | |
| 396 Assert.assertEquals(1, | |
| 397 RecordHistogram.getHistogramValueCountForTesting( | |
| 398 "PaymentRequest.CanMakePayment.Usage", | |
| 399 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 400 | |
| 401 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 402 Assert.assertEquals(1, | |
| 403 RecordHistogram.getHistogramValueCountForTesting( | |
| 404 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 405 JourneyLogger.CMP_SHOW_DID_SHOW | |
| 406 | JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); | |
| 407 | |
| 408 // There should be a record for an abort when CanMakePayment is true and
the PR is shown to | |
| 409 // the user. | |
| 410 Assert.assertEquals(1, | |
| 411 RecordHistogram.getHistogramValueCountForTesting( | |
| 412 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", | |
| 413 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 414 } | |
| 415 | |
| 416 /** | |
| 417 * Tests the canMakePayment stats for the case where the merchant uses it, r
eturns true, show | |
| 418 * is called and the transaction is completed. | |
| 419 */ | |
| 420 @Test | |
| 421 @SmallTest | |
| 422 @Feature({"Payments"}) | |
| 423 public void testRecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAn
dComplete() { | |
| 424 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 425 assertNoLogForCanMakePayment(); | |
| 426 | |
| 427 // The user cannot make a payment. the payment request is shown and comp
leted. | |
| 428 logger.setShowCalled(); | |
| 429 logger.setCanMakePaymentValue(true); | |
| 430 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 431 | |
| 432 // CanMakePayment was used. | |
| 433 Assert.assertEquals(1, | |
| 434 RecordHistogram.getHistogramValueCountForTesting( | |
| 435 "PaymentRequest.CanMakePayment.Usage", | |
| 436 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 437 | |
| 438 // The CanMakePayment effect on show should be recorded as being true an
d not shown. | |
| 439 Assert.assertEquals(1, | |
| 440 RecordHistogram.getHistogramValueCountForTesting( | |
| 441 "PaymentRequest.CanMakePayment.Used.EffectOnShow", | |
| 442 JourneyLogger.CMP_SHOW_DID_SHOW | |
| 443 | JourneyLogger.CMP_SHOW_COULD_MAKE_PAYMENT)); | |
| 444 | |
| 445 // There should be a record for a completion when CanMakePayment is true
and the PR is shown | |
| 446 // to the user. | |
| 447 Assert.assertEquals(1, | |
| 448 RecordHistogram.getHistogramValueCountForTesting( | |
| 449 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", | |
| 450 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 451 } | |
| 452 | |
| 453 /** | |
| 454 * Tests the canMakePayment metrics are not logged if the Payment Request wa
s done in an | |
| 455 * incognito tab. | |
| 456 */ | |
| 457 @Test | |
| 458 @SmallTest | |
| 459 @Feature({"Payments"}) | |
| 460 public void testRecordJourneyStatsHistograms_CanMakePayment_IncognitoTab() { | |
| 461 JourneyLogger logger = new JourneyLogger(true /* is_incognito */); | |
| 462 assertNoLogForCanMakePayment(); | |
| 463 | |
| 464 // The user is in an incognito tab so CanMakePayment is always true; | |
| 465 logger.setShowCalled(); | |
| 466 logger.setCanMakePaymentValue(true); | |
| 467 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 468 | |
| 469 // There should be no CanMakePayment metrics logged. | |
| 470 assertNoLogForCanMakePayment(); | |
| 471 } | |
| 472 | |
| 473 /** | |
| 474 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 475 * the requested sections are logged as correctly. | |
| 476 */ | |
| 477 @Test | |
| 478 @SmallTest | |
| 479 @Feature({"Payments"}) | |
| 480 public void testRecordJourneyStatsHistograms_SuggestionsForEverything_Comple
ted() { | |
| 481 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 482 | |
| 483 // Simulate that the user had suggestions for all the requested sections
. | |
| 484 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1
); | |
| 485 | |
| 486 // Simulate that the user completes the checkout. | |
| 487 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 488 | |
| 489 // Make sure the appropriate metric was logged. | |
| 490 Assert.assertEquals(1, | |
| 491 RecordHistogram.getHistogramValueCountForTesting( | |
| 492 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 493 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 494 | |
| 495 Assert.assertEquals(0, | |
| 496 RecordHistogram.getHistogramValueCountForTesting( | |
| 497 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 498 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 499 } | |
| 500 | |
| 501 /** | |
| 502 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 503 * the requested sections are logged as correctly. | |
| 504 */ | |
| 505 @Test | |
| 506 @SmallTest | |
| 507 @Feature({"Payments"}) | |
| 508 public void testRecordJourneyStatsHistograms_SuggestionsForEverything_UserAb
orted() { | |
| 509 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 510 | |
| 511 // Simulate that the user had suggestions for all the requested sections
. | |
| 512 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1
); | |
| 513 | |
| 514 // Simulate that the user aborts the checkout. | |
| 515 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 516 | |
| 517 // Make sure the appropriate metric was logged. | |
| 518 Assert.assertEquals(1, | |
| 519 RecordHistogram.getHistogramValueCountForTesting( | |
| 520 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 521 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 522 | |
| 523 Assert.assertEquals(0, | |
| 524 RecordHistogram.getHistogramValueCountForTesting( | |
| 525 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 526 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 527 } | |
| 528 | |
| 529 /** | |
| 530 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 531 * the requested sections are logged as correctly. | |
| 532 */ | |
| 533 @Test | |
| 534 @SmallTest | |
| 535 @Feature({"Payments"}) | |
| 536 public void testRecordJourneyStatsHistograms_SuggestionsForEverything_OtherA
borted() { | |
| 537 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 538 | |
| 539 // Simulate that the user had suggestions for all the requested sections
. | |
| 540 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 1
); | |
| 541 | |
| 542 // Simulate that the user aborts the checkout. | |
| 543 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 544 | |
| 545 // Make sure the appropriate metric was logged. | |
| 546 Assert.assertEquals(1, | |
| 547 RecordHistogram.getHistogramValueCountForTesting( | |
| 548 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 549 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 550 | |
| 551 Assert.assertEquals(0, | |
| 552 RecordHistogram.getHistogramValueCountForTesting( | |
| 553 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 554 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 555 } | |
| 556 | |
| 557 /** | |
| 558 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 559 * the requested sections are logged as correctly. | |
| 560 */ | |
| 561 @Test | |
| 562 @SmallTest | |
| 563 @Feature({"Payments"}) | |
| 564 public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_Comp
leted() { | |
| 565 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 566 | |
| 567 // Simulate that the user did not have suggestions for all the requested
sections. | |
| 568 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0
); | |
| 569 | |
| 570 // Simulate that the user completes the checkout. | |
| 571 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COMP
LETED); | |
| 572 | |
| 573 // Make sure the appropriate metric was logged. | |
| 574 Assert.assertEquals(1, | |
| 575 RecordHistogram.getHistogramValueCountForTesting( | |
| 576 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 577 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 578 | |
| 579 Assert.assertEquals(0, | |
| 580 RecordHistogram.getHistogramValueCountForTesting( | |
| 581 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 582 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 583 } | |
| 584 | |
| 585 /** | |
| 586 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 587 * the requested sections are logged as correctly. | |
| 588 */ | |
| 589 @Test | |
| 590 @SmallTest | |
| 591 @Feature({"Payments"}) | |
| 592 public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_User
Aborted() { | |
| 593 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 594 | |
| 595 // Simulate that the user did not have suggestions for all the requested
sections. | |
| 596 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0
); | |
| 597 | |
| 598 // Simulate that the user aborts the checkout. | |
| 599 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USER
_ABORTED); | |
| 600 | |
| 601 // Make sure the appropriate metric was logged. | |
| 602 Assert.assertEquals(1, | |
| 603 RecordHistogram.getHistogramValueCountForTesting( | |
| 604 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 605 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 606 | |
| 607 Assert.assertEquals(0, | |
| 608 RecordHistogram.getHistogramValueCountForTesting( | |
| 609 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 610 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 611 } | |
| 612 | |
| 613 /** | |
| 614 * Tests that the completion status metrics based on whether the user had su
ggestions for all | |
| 615 * the requested sections are logged as correctly. | |
| 616 */ | |
| 617 @Test | |
| 618 @SmallTest | |
| 619 @Feature({"Payments"}) | |
| 620 public void testRecordJourneyStatsHistograms_NoSuggestionsForEverything_Othe
rAborted() { | |
| 621 JourneyLogger logger = new JourneyLogger(false /* is_incognito */); | |
| 622 | |
| 623 // Simulate that the user did not have suggestions for all the requested
sections. | |
| 624 logger.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS, 0
); | |
| 625 | |
| 626 // Simulate that the user aborts the checkout. | |
| 627 logger.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_OTHE
R_ABORTED); | |
| 628 | |
| 629 // Make sure the appropriate metric was logged. | |
| 630 Assert.assertEquals(1, | |
| 631 RecordHistogram.getHistogramValueCountForTesting( | |
| 632 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 633 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 634 | |
| 635 Assert.assertEquals(0, | |
| 636 RecordHistogram.getHistogramValueCountForTesting( | |
| 637 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 638 JourneyLogger.COMPLETION_STATUS_OTHER_ABORTED)); | |
| 639 } | |
| 640 | |
| 641 /** | |
| 642 * Tests that the metrics are logged correctly for two simultaneous Payment
Requests. | |
| 643 */ | |
| 644 @Test | |
| 645 @SmallTest | |
| 646 @Feature({"Payments"}) | |
| 647 public void testRecordJourneyStatsHistograms_TwoPaymentRequests() { | |
| 648 JourneyLogger logger1 = new JourneyLogger(false /* is_incognito */); | |
| 649 JourneyLogger logger2 = new JourneyLogger(false /* is_incognito */); | |
| 650 | |
| 651 // Make the two loggers have different data. | |
| 652 logger1.setShowCalled(); | |
| 653 logger2.setShowCalled(); | |
| 654 | |
| 655 logger1.setCanMakePaymentValue(true); | |
| 656 | |
| 657 logger1.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS,
1); | |
| 658 logger2.setNumberOfSuggestionsShown(JourneyLogger.SECTION_CREDIT_CARDS,
0); | |
| 659 | |
| 660 // Simulate that the user completes one checkout and aborts the other. | |
| 661 logger1.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_COM
PLETED); | |
| 662 logger2.recordJourneyStatsHistograms(JourneyLogger.COMPLETION_STATUS_USE
R_ABORTED); | |
| 663 | |
| 664 // Make sure the appropriate metric was logged for logger1. | |
| 665 Assert.assertEquals(1, | |
| 666 RecordHistogram.getHistogramValueCountForTesting( | |
| 667 "PaymentRequest.UserHadSuggestionsForEverything.EffectOn
Completion", | |
| 668 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 669 Assert.assertEquals(1, | |
| 670 RecordHistogram.getHistogramValueCountForTesting( | |
| 671 "PaymentRequest.CanMakePayment.Usage", | |
| 672 JourneyLogger.CAN_MAKE_PAYMENT_USED)); | |
| 673 Assert.assertEquals(1, | |
| 674 RecordHistogram.getHistogramValueCountForTesting( | |
| 675 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOn
Completion", | |
| 676 JourneyLogger.COMPLETION_STATUS_COMPLETED)); | |
| 677 | |
| 678 // Make sure the appropriate metric was logged for logger2. | |
| 679 Assert.assertEquals(1, | |
| 680 RecordHistogram.getHistogramValueCountForTesting( | |
| 681 "PaymentRequest.UserDidNotHaveSuggestionsForEverything.E
ffectOnCompletion", | |
| 682 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 683 Assert.assertEquals(1, | |
| 684 RecordHistogram.getHistogramValueCountForTesting( | |
| 685 "PaymentRequest.CanMakePayment.Usage", | |
| 686 JourneyLogger.CAN_MAKE_PAYMENT_NOT_USED)); | |
| 687 Assert.assertEquals(1, | |
| 688 RecordHistogram.getHistogramValueCountForTesting( | |
| 689 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnC
ompletion", | |
| 690 JourneyLogger.COMPLETION_STATUS_USER_ABORTED)); | |
| 691 } | |
| 692 | |
| 693 /** | |
| 694 * Asserts that no histogram is logged. | |
| 695 */ | |
| 696 private void assertNoLogForCanMakePayment() { | |
| 697 // Use stats. | |
| 698 for (int i = 0; i < JourneyLogger.CAN_MAKE_PAYMENT_USE_MAX; ++i) { | |
| 699 Assert.assertEquals(0, | |
| 700 RecordHistogram.getHistogramValueCountForTesting( | |
| 701 "PaymentRequest.CanMakePayment.Usage", i)); | |
| 702 } | |
| 703 | |
| 704 // Effect on show stats. | |
| 705 for (int i = 0; i < JourneyLogger.CMP_SHOW_MAX; ++i) { | |
| 706 Assert.assertEquals(0, | |
| 707 RecordHistogram.getHistogramValueCountForTesting( | |
| 708 "PaymentRequest.CanMakePayment.Used.EffectOnShow", i
)); | |
| 709 } | |
| 710 | |
| 711 // Effect on completion stats. | |
| 712 for (int i = 0; i < JourneyLogger.COMPLETION_STATUS_MAX; ++i) { | |
| 713 Assert.assertEquals(0, | |
| 714 RecordHistogram.getHistogramValueCountForTesting( | |
| 715 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffec
tOnCompletion", i)); | |
| 716 Assert.assertEquals(0, | |
| 717 RecordHistogram.getHistogramValueCountForTesting( | |
| 718 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffe
ctOnCompletion", | |
| 719 i)); | |
| 720 Assert.assertEquals(0, | |
| 721 RecordHistogram.getHistogramValueCountForTesting( | |
| 722 "PaymentRequest.CanMakePayment.Used.FalseWithShowEff
ectOnCompletion", | |
| 723 i)); | |
| 724 } | |
| 725 } | |
| 726 } | |
| OLD | NEW |