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 #include "components/payments/core/journey_logger.h" |
| 6 |
| 7 #include "base/test/histogram_tester.h" |
| 8 #include "testing/gmock/include/gmock/gmock.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 |
| 11 using testing::ContainerEq; |
| 12 |
| 13 namespace payments { |
| 14 |
| 15 // Tests the canMakePayment stats for the case where the merchant does not use |
| 16 // it and does not show the PaymentRequest to the user. |
| 17 TEST(JourneyLoggerTest, |
| 18 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) { |
| 19 base::HistogramTester histogram_tester; |
| 20 JourneyLogger logger(/*is_incognito=*/false); |
| 21 |
| 22 logger.RecordJourneyStatsHistograms( |
| 23 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 24 |
| 25 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 26 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
| 27 1); |
| 28 |
| 29 // There should be no completion stats since PR was not shown to the user |
| 30 EXPECT_THAT( |
| 31 histogram_tester.GetTotalCountsForPrefix( |
| 32 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
| 33 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 34 } |
| 35 |
| 36 // Tests the canMakePayment stats for the case where the merchant does not use |
| 37 // it and the transaction is aborted. |
| 38 TEST(JourneyLoggerTest, |
| 39 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) { |
| 40 base::HistogramTester histogram_tester; |
| 41 JourneyLogger logger(/*is_incognito=*/false); |
| 42 |
| 43 // Expect no log for CanMakePayment. |
| 44 EXPECT_THAT( |
| 45 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 46 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 47 |
| 48 // The merchant does not query CanMakePayment, show the PaymentRequest and the |
| 49 // user aborts it. |
| 50 logger.SetShowCalled(); |
| 51 logger.RecordJourneyStatsHistograms( |
| 52 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 53 |
| 54 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 55 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
| 56 1); |
| 57 |
| 58 // There should be a record for an abort when CanMakePayment is not used but |
| 59 // the PR is shown to the user. |
| 60 histogram_tester.ExpectBucketCount( |
| 61 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
| 62 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 63 } |
| 64 |
| 65 // Tests the canMakePayment stats for the case where the merchant does not use |
| 66 // it and the transaction is aborted. |
| 67 TEST(JourneyLoggerTest, |
| 68 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) { |
| 69 base::HistogramTester histogram_tester; |
| 70 JourneyLogger logger(/*is_incognito=*/false); |
| 71 |
| 72 // Expect no log for CanMakePayment. |
| 73 EXPECT_THAT( |
| 74 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 75 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 76 |
| 77 // The merchant does not query CanMakePayment, show the PaymentRequest and |
| 78 // there is an abort not initiated by the user. |
| 79 logger.SetShowCalled(); |
| 80 logger.RecordJourneyStatsHistograms( |
| 81 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 82 |
| 83 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 84 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
| 85 1); |
| 86 |
| 87 // There should be a record for an abort when CanMakePayment is not used but |
| 88 // the PR is shown to the user. |
| 89 histogram_tester.ExpectBucketCount( |
| 90 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
| 91 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 92 } |
| 93 |
| 94 // Tests the canMakePayment stats for the case where the merchant does not use |
| 95 // it and the transaction is completed. |
| 96 TEST(JourneyLoggerTest, |
| 97 RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) { |
| 98 base::HistogramTester histogram_tester; |
| 99 JourneyLogger logger(/*is_incognito=*/false); |
| 100 |
| 101 // Expect no log for CanMakePayment. |
| 102 EXPECT_THAT( |
| 103 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 104 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 105 |
| 106 // The merchant does not query CanMakePayment, show the PaymentRequest and the |
| 107 // user completes it. |
| 108 logger.SetShowCalled(); |
| 109 logger.RecordJourneyStatsHistograms( |
| 110 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 111 |
| 112 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 113 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
| 114 1); |
| 115 |
| 116 // There should be a record for an abort when CanMakePayment is not used but |
| 117 // the PR is shown to the user. |
| 118 histogram_tester.ExpectBucketCount( |
| 119 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
| 120 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 121 } |
| 122 |
| 123 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 124 // returns false and show is not called. |
| 125 TEST(JourneyLoggerTest, |
| 126 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) { |
| 127 base::HistogramTester histogram_tester; |
| 128 JourneyLogger logger(/*is_incognito=*/false); |
| 129 |
| 130 // Expect no log for CanMakePayment. |
| 131 EXPECT_THAT( |
| 132 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 133 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 134 |
| 135 // The user cannot make payment and the PaymentRequest is not shown. |
| 136 logger.SetCanMakePaymentValue(false); |
| 137 logger.RecordJourneyStatsHistograms( |
| 138 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 139 |
| 140 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 141 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 142 |
| 143 // The CanMakePayment effect on show should be recorded as being false and not |
| 144 // shown. |
| 145 histogram_tester.ExpectBucketCount( |
| 146 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 147 JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1); |
| 148 |
| 149 // There should be no completion stats since PR was not shown to the user. |
| 150 EXPECT_THAT( |
| 151 histogram_tester.GetTotalCountsForPrefix( |
| 152 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
| 153 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 154 } |
| 155 |
| 156 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 157 // returns true and show is not called. |
| 158 TEST(JourneyLoggerTest, |
| 159 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow) { |
| 160 base::HistogramTester histogram_tester; |
| 161 JourneyLogger logger(/*is_incognito=*/false); |
| 162 |
| 163 // Expect no log for CanMakePayment. |
| 164 EXPECT_THAT( |
| 165 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 166 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 167 |
| 168 // The user cannot make payment and the PaymentRequest is not shown. |
| 169 logger.SetCanMakePaymentValue(true); |
| 170 logger.RecordJourneyStatsHistograms( |
| 171 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 172 |
| 173 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 174 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 175 |
| 176 // The CanMakePayment effect on show should be recorded as being true and not |
| 177 // shown. |
| 178 histogram_tester.ExpectBucketCount( |
| 179 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 180 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1); |
| 181 |
| 182 // There should be no completion stats since PR was not shown to the user. |
| 183 EXPECT_THAT( |
| 184 histogram_tester.GetTotalCountsForPrefix( |
| 185 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
| 186 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 187 } |
| 188 |
| 189 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 190 // returns false, show is called but the transaction is aborted by the user. |
| 191 TEST(JourneyLoggerTest, |
| 192 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort) { |
| 193 base::HistogramTester histogram_tester; |
| 194 JourneyLogger logger(/*is_incognito=*/false); |
| 195 |
| 196 // Expect no log for CanMakePayment. |
| 197 EXPECT_THAT( |
| 198 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 199 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 200 |
| 201 // The user cannot make payment and the PaymentRequest is not shown. |
| 202 logger.SetShowCalled(); |
| 203 logger.SetCanMakePaymentValue(false); |
| 204 logger.RecordJourneyStatsHistograms( |
| 205 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 206 |
| 207 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 208 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 209 |
| 210 // The CanMakePayment effect on show should be recorded as being false and |
| 211 // shown. |
| 212 histogram_tester.ExpectBucketCount( |
| 213 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 214 JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
| 215 // There should be a record for an abort when CanMakePayment is false but the |
| 216 // PR is shown to the user. |
| 217 histogram_tester.ExpectBucketCount( |
| 218 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 219 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 220 } |
| 221 |
| 222 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 223 // returns false, show is called but the transaction is aborted. |
| 224 TEST(JourneyLoggerTest, |
| 225 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort) { |
| 226 base::HistogramTester histogram_tester; |
| 227 JourneyLogger logger(/*is_incognito=*/false); |
| 228 |
| 229 // Expect no log for CanMakePayment. |
| 230 EXPECT_THAT( |
| 231 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 232 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 233 |
| 234 // The user cannot make payment and the PaymentRequest is not shown. |
| 235 logger.SetShowCalled(); |
| 236 logger.SetCanMakePaymentValue(false); |
| 237 logger.RecordJourneyStatsHistograms( |
| 238 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 239 |
| 240 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 241 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 242 |
| 243 // The CanMakePayment effect on show should be recorded as being false and |
| 244 // shown. |
| 245 histogram_tester.ExpectBucketCount( |
| 246 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 247 JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
| 248 // There should be a record for an abort when CanMakePayment is false but the |
| 249 // PR is shown to the user. |
| 250 histogram_tester.ExpectBucketCount( |
| 251 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 252 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 253 } |
| 254 |
| 255 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 256 // returns false, show is called and the transaction is completed. |
| 257 TEST(JourneyLoggerTest, |
| 258 RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete) { |
| 259 base::HistogramTester histogram_tester; |
| 260 JourneyLogger logger(/*is_incognito=*/false); |
| 261 |
| 262 // Expect no log for CanMakePayment. |
| 263 EXPECT_THAT( |
| 264 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 265 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 266 |
| 267 // The user cannot make payment and the PaymentRequest is not shown. |
| 268 logger.SetShowCalled(); |
| 269 logger.SetCanMakePaymentValue(false); |
| 270 logger.RecordJourneyStatsHistograms( |
| 271 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 272 |
| 273 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 274 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 275 |
| 276 // The CanMakePayment effect on show should be recorded as being false and |
| 277 // shown. |
| 278 histogram_tester.ExpectBucketCount( |
| 279 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 280 JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
| 281 |
| 282 // There should be a record for an completion when CanMakePayment is false but |
| 283 // the PR is shown to the user. |
| 284 histogram_tester.ExpectBucketCount( |
| 285 "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
| 286 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 287 } |
| 288 |
| 289 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 290 // returns true, show is called but the transaction is aborted by the user. |
| 291 TEST(JourneyLoggerTest, |
| 292 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort) { |
| 293 base::HistogramTester histogram_tester; |
| 294 JourneyLogger logger(/*is_incognito=*/false); |
| 295 |
| 296 // Expect no log for CanMakePayment. |
| 297 EXPECT_THAT( |
| 298 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 299 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 300 |
| 301 // The user cannot make payment and the PaymentRequest is not shown. |
| 302 logger.SetShowCalled(); |
| 303 logger.SetCanMakePaymentValue(true); |
| 304 logger.RecordJourneyStatsHistograms( |
| 305 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 306 |
| 307 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 308 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 309 |
| 310 // The CanMakePayment effect on show should be recorded as being true and not |
| 311 // shown. |
| 312 histogram_tester.ExpectBucketCount( |
| 313 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 314 JourneyLogger::CMP_SHOW_DID_SHOW | |
| 315 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
| 316 1); |
| 317 // There should be a record for an abort when CanMakePayment is true and the |
| 318 // PR is shown to the user. |
| 319 histogram_tester.ExpectBucketCount( |
| 320 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 321 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 322 } |
| 323 |
| 324 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 325 // returns true, show is called but the transaction is aborted. |
| 326 TEST(JourneyLoggerTest, |
| 327 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort) { |
| 328 base::HistogramTester histogram_tester; |
| 329 JourneyLogger logger(/*is_incognito=*/false); |
| 330 |
| 331 // Expect no log for CanMakePayment. |
| 332 EXPECT_THAT( |
| 333 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 334 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 335 |
| 336 // The user cannot make payment and the PaymentRequest is not shown. |
| 337 logger.SetShowCalled(); |
| 338 logger.SetCanMakePaymentValue(true); |
| 339 logger.RecordJourneyStatsHistograms( |
| 340 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 341 |
| 342 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 343 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 344 |
| 345 // The CanMakePayment effect on show should be recorded as being true and not |
| 346 // shown. |
| 347 histogram_tester.ExpectBucketCount( |
| 348 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 349 JourneyLogger::CMP_SHOW_DID_SHOW | |
| 350 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
| 351 1); |
| 352 // There should be a record for an abort when CanMakePayment is true and the |
| 353 // PR is shown to the user. |
| 354 histogram_tester.ExpectBucketCount( |
| 355 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 356 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 357 } |
| 358 |
| 359 // Tests the canMakePayment stats for the case where the merchant uses it, |
| 360 // returns true, show is called and the transaction is completed. |
| 361 TEST(JourneyLoggerTest, |
| 362 RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete) { |
| 363 base::HistogramTester histogram_tester; |
| 364 JourneyLogger logger(/*is_incognito=*/false); |
| 365 |
| 366 // Expect no log for CanMakePayment. |
| 367 EXPECT_THAT( |
| 368 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 369 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 370 |
| 371 // The user cannot make payment and the PaymentRequest is not shown. |
| 372 logger.SetShowCalled(); |
| 373 logger.SetCanMakePaymentValue(true); |
| 374 logger.RecordJourneyStatsHistograms( |
| 375 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 376 |
| 377 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 378 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 379 |
| 380 // The CanMakePayment effect on show should be recorded as being true and not |
| 381 // shown. |
| 382 histogram_tester.ExpectBucketCount( |
| 383 "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
| 384 JourneyLogger::CMP_SHOW_DID_SHOW | |
| 385 JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
| 386 1); |
| 387 // There should be a record for a completion when CanMakePayment is true and |
| 388 // the PR is shown to the user. |
| 389 histogram_tester.ExpectBucketCount( |
| 390 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 391 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 392 } |
| 393 |
| 394 // Tests the canMakePayment metrics are not logged if the Payment Request was |
| 395 // done in an incognito tab. |
| 396 TEST(JourneyLoggerTest, |
| 397 RecordJourneyStatsHistograms_CanMakePayment_IncognitoTab) { |
| 398 base::HistogramTester histogram_tester; |
| 399 JourneyLogger logger(/*is_incognito=*/true); |
| 400 |
| 401 // Expect no log for CanMakePayment. |
| 402 EXPECT_THAT( |
| 403 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 404 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 405 |
| 406 // The user cannot make payment and the PaymentRequest is not shown. |
| 407 logger.SetShowCalled(); |
| 408 logger.SetCanMakePaymentValue(true); |
| 409 logger.RecordJourneyStatsHistograms( |
| 410 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 411 |
| 412 // Expect no log for CanMakePayment. |
| 413 EXPECT_THAT( |
| 414 histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
| 415 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 416 } |
| 417 |
| 418 // Tests that the completion status metrics based on whether the user had |
| 419 // suggestions for all the requested sections are logged as correctly. |
| 420 TEST(JourneyLoggerTest, |
| 421 RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) { |
| 422 base::HistogramTester histogram_tester; |
| 423 JourneyLogger logger(/*is_incognito=*/false); |
| 424 |
| 425 // Simulate that the user had suggestions for all the requested sections. |
| 426 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
| 427 |
| 428 // Simulate that the user completes the checkout. |
| 429 logger.RecordJourneyStatsHistograms( |
| 430 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 431 |
| 432 histogram_tester.ExpectBucketCount( |
| 433 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
| 434 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 435 |
| 436 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 437 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 438 "EffectOnCompletion"), |
| 439 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 440 } |
| 441 |
| 442 // Tests that the completion status metrics based on whether the user had |
| 443 // suggestions for all the requested sections are logged as correctly. |
| 444 TEST(JourneyLoggerTest, |
| 445 RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) { |
| 446 base::HistogramTester histogram_tester; |
| 447 JourneyLogger logger(/*is_incognito=*/false); |
| 448 |
| 449 // Simulate that the user had suggestions for all the requested sections. |
| 450 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
| 451 |
| 452 // Simulate that the user aborts the checkout. |
| 453 logger.RecordJourneyStatsHistograms( |
| 454 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 455 |
| 456 histogram_tester.ExpectBucketCount( |
| 457 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
| 458 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 459 |
| 460 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 461 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 462 "EffectOnCompletion"), |
| 463 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 464 } |
| 465 |
| 466 // Tests that the completion status metrics based on whether the user had |
| 467 // suggestions for all the requested sections are logged as correctly. |
| 468 TEST(JourneyLoggerTest, |
| 469 RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) { |
| 470 base::HistogramTester histogram_tester; |
| 471 JourneyLogger logger(/*is_incognito=*/false); |
| 472 |
| 473 // Simulate that the user had suggestions for all the requested sections. |
| 474 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
| 475 |
| 476 // Simulate that the checkout is aborted. |
| 477 logger.RecordJourneyStatsHistograms( |
| 478 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 479 |
| 480 histogram_tester.ExpectBucketCount( |
| 481 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
| 482 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 483 |
| 484 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 485 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 486 "EffectOnCompletion"), |
| 487 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 488 } |
| 489 |
| 490 // Tests that the completion status metrics based on whether the user had |
| 491 // suggestions for all the requested sections are logged as correctly, even in |
| 492 // incognito mode. |
| 493 TEST(JourneyLoggerTest, |
| 494 RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) { |
| 495 base::HistogramTester histogram_tester; |
| 496 JourneyLogger logger(/*is_incognito=*/true); |
| 497 |
| 498 // Simulate that the user had suggestions for all the requested sections. |
| 499 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
| 500 |
| 501 // Simulate that the user completes the checkout. |
| 502 logger.RecordJourneyStatsHistograms( |
| 503 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 504 |
| 505 histogram_tester.ExpectBucketCount( |
| 506 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
| 507 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 508 |
| 509 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 510 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 511 "EffectOnCompletion"), |
| 512 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 513 } |
| 514 |
| 515 // Tests that the completion status metrics based on whether the user had |
| 516 // suggestions for all the requested sections are logged as correctly. |
| 517 TEST(JourneyLoggerTest, |
| 518 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) { |
| 519 base::HistogramTester histogram_tester; |
| 520 JourneyLogger logger(/*is_incognito=*/false); |
| 521 |
| 522 // Simulate that the user had suggestions for all the requested sections. |
| 523 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
| 524 |
| 525 // Simulate that the user completes the checkout. |
| 526 logger.RecordJourneyStatsHistograms( |
| 527 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 528 |
| 529 histogram_tester.ExpectBucketCount( |
| 530 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 531 "EffectOnCompletion", |
| 532 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 533 |
| 534 EXPECT_THAT( |
| 535 histogram_tester.GetTotalCountsForPrefix( |
| 536 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"), |
| 537 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 538 } |
| 539 |
| 540 // Tests that the completion status metrics based on whether the user had |
| 541 // suggestions for all the requested sections are logged as correctly. |
| 542 TEST(JourneyLoggerTest, |
| 543 RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) { |
| 544 base::HistogramTester histogram_tester; |
| 545 JourneyLogger logger(/*is_incognito=*/false); |
| 546 |
| 547 // Simulate that the user had suggestions for all the requested sections. |
| 548 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
| 549 |
| 550 // Simulate that the user aborts the checkout. |
| 551 logger.RecordJourneyStatsHistograms( |
| 552 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 553 |
| 554 histogram_tester.ExpectBucketCount( |
| 555 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 556 "EffectOnCompletion", |
| 557 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 558 |
| 559 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 560 "PaymentRequest.UserHadSuggestionsForEverything." |
| 561 "EffectOnCompletion"), |
| 562 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 563 } |
| 564 |
| 565 // Tests that the completion status metrics based on whether the user had |
| 566 // suggestions for all the requested sections are logged as correctly. |
| 567 TEST(JourneyLoggerTest, |
| 568 RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) { |
| 569 base::HistogramTester histogram_tester; |
| 570 JourneyLogger logger(/*is_incognito=*/false); |
| 571 |
| 572 // Simulate that the user had suggestions for all the requested sections. |
| 573 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
| 574 |
| 575 // Simulate that the user aborts the checkout. |
| 576 logger.RecordJourneyStatsHistograms( |
| 577 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
| 578 |
| 579 histogram_tester.ExpectBucketCount( |
| 580 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 581 "EffectOnCompletion", |
| 582 JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
| 583 |
| 584 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 585 "PaymentRequest.UserHadSuggestionsForEverything." |
| 586 "EffectOnCompletion"), |
| 587 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 588 } |
| 589 |
| 590 // Tests that the completion status metrics based on whether the user had |
| 591 // suggestions for all the requested sections are logged as correctly, even in |
| 592 // incognito mode. |
| 593 TEST(JourneyLoggerTest, |
| 594 RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) { |
| 595 base::HistogramTester histogram_tester; |
| 596 JourneyLogger logger(/*is_incognito=*/true); |
| 597 |
| 598 // Simulate that the user had suggestions for all the requested sections. |
| 599 logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
| 600 |
| 601 // Simulate that the user aborts the checkout. |
| 602 logger.RecordJourneyStatsHistograms( |
| 603 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 604 |
| 605 histogram_tester.ExpectBucketCount( |
| 606 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 607 "EffectOnCompletion", |
| 608 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 609 |
| 610 EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
| 611 "PaymentRequest.UserHadSuggestionsForEverything." |
| 612 "EffectOnCompletion"), |
| 613 testing::ContainerEq(base::HistogramTester::CountsMap())); |
| 614 } |
| 615 |
| 616 // Tests that the metrics are logged correctly for two simultaneous Payment |
| 617 // Requests. |
| 618 TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) { |
| 619 base::HistogramTester histogram_tester; |
| 620 JourneyLogger logger1(/*is_incognito=*/false); |
| 621 JourneyLogger logger2(/*is_incognito=*/false); |
| 622 |
| 623 // Make the two loggers have different data. |
| 624 logger1.SetShowCalled(); |
| 625 logger2.SetShowCalled(); |
| 626 |
| 627 logger1.SetCanMakePaymentValue(true); |
| 628 |
| 629 logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
| 630 logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
| 631 |
| 632 // Simulate that the user completes one checkout and aborts the other. |
| 633 logger1.RecordJourneyStatsHistograms( |
| 634 JourneyLogger::COMPLETION_STATUS_COMPLETED); |
| 635 logger2.RecordJourneyStatsHistograms( |
| 636 JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
| 637 |
| 638 // Make sure the appropriate metrics were logged for logger1. |
| 639 histogram_tester.ExpectBucketCount( |
| 640 "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
| 641 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 642 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 643 JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
| 644 histogram_tester.ExpectBucketCount( |
| 645 "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
| 646 JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
| 647 |
| 648 // Make sure the appropriate metrics were logged for logger2. |
| 649 histogram_tester.ExpectBucketCount( |
| 650 "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
| 651 "EffectOnCompletion", |
| 652 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 653 histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
| 654 JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
| 655 1); |
| 656 histogram_tester.ExpectBucketCount( |
| 657 "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
| 658 JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
| 659 } |
| 660 |
| 661 } // namespace payments |
OLD | NEW |