1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735
|
// Copyright 2017 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "components/payments/core/journey_logger.h"
#include "base/metrics/metrics_hashes.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/task_environment.h"
#include "components/ukm/test_ukm_recorder.h"
#include "services/metrics/public/cpp/ukm_builders.h"
#include "services/metrics/public/cpp/ukm_source.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
using testing::ContainerEq;
using PaymentMethodCategory = payments::JourneyLogger::PaymentMethodCategory;
using Event2 = payments::JourneyLogger::Event2;
namespace payments {
int toInt(Event2 event) {
return static_cast<int>(event);
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user completes the checkout.
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kBasicCard);
logger.SetCompleted();
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user aborts the checkout.
logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the checkout is aborted.
logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly, even in
// incognito mode.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for all the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user completes the checkout.
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kBasicCard);
logger.SetCompleted();
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for none of the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 0,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user completes the checkout.
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kBasicCard);
logger.SetCompleted();
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_FALSE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for none of the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 0,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user aborts the checkout.
logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_FALSE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for none of the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 0,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the the checkout is aborted.
logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_FALSE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly, even in
// incognito mode.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had suggestions for none of the requested sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 0,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the user aborts the checkout.
logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_FALSE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(
JourneyLoggerTest,
RecordJourneyStatsHistograms_NoCompleteSuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/false, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had incomplete suggestions for the requested
// sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 2,
/*has_complete_suggestion=*/false);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the the checkout is aborted.
logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(
JourneyLoggerTest,
RecordJourneyStatsHistograms_NoCompleteSuggestionsForEverything_SomeComplete_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had incomplete suggestions for one of the requested
// sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 2,
/*has_complete_suggestion=*/false);
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_SHIPPING_ADDRESS, 1,
/*has_complete_suggestion=*/true);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the the checkout is aborted.
logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the completion status metrics based on whether the user had
// suggestions for all the requested sections are logged as correctly.
TEST(
JourneyLoggerTest,
RecordJourneyStatsHistograms_CompleteSuggestionsForEverything_OtherAborted) {
base::HistogramTester histogram_tester;
JourneyLogger logger(ukm::kInvalidSourceId);
// The merchant only requests payment information.
logger.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user had incomplete suggestions for one of the requested
// sections.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 2,
/*has_complete_suggestion=*/true);
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_SHIPPING_ADDRESS, 1,
/*has_complete_suggestion=*/true);
// Simulate that the Payment Request was shown to the user.
logger.SetShown();
// Simulate that the the checkout is aborted.
logger.SetAborted(JourneyLogger::ABORT_REASON_OTHER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(1U, buckets.size());
EXPECT_TRUE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the metrics are logged correctly for two simultaneous Payment
// Requests.
TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) {
base::HistogramTester histogram_tester;
JourneyLogger logger1(ukm::kInvalidSourceId);
JourneyLogger logger2(ukm::kInvalidSourceId);
// Make the two loggers have different data.
logger1.SetShown();
logger1.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/true,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard,
PaymentMethodCategory::kGoogle,
PaymentMethodCategory::kOther};
logger1.SetRequestedPaymentMethods(methods);
logger2.SetShown();
logger2.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/false,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods2{PaymentMethodCategory::kOther};
logger2.SetRequestedPaymentMethods(methods2);
logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/false);
logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 0,
/*has_complete_suggestion=*/false);
// Simulate that the user completes one checkout and aborts the other.
logger1.SetPayClicked();
logger1.SetSelectedMethod(PaymentMethodCategory::kBasicCard);
logger1.SetCompleted();
logger2.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
// Make sure the correct events were logged.
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
ASSERT_EQ(2U, buckets.size());
// logger2
EXPECT_TRUE(buckets[0].min & toInt(Event2::kShown));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kOtherAborted));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kCompleted));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kUserAborted));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestShipping));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestPayerData));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodOther));
// logger1
EXPECT_TRUE(buckets[1].min & toInt(Event2::kShown));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kHadInitialFormOfPayment));
EXPECT_FALSE(buckets[1].min & toInt(Event2::kOtherAborted));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kCompleted));
EXPECT_FALSE(buckets[1].min & toInt(Event2::kUserAborted));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kRequestShipping));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kRequestPayerData));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_TRUE(buckets[1].min & toInt(Event2::kRequestMethodOther));
}
// Tests that the Payment Request UKMs are logged correctly when the user aborts
// the Payment Request.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CheckoutFunnelUkm_UserAborted) {
base::test::TaskEnvironment task_environment_;
using UkmEntry = ukm::builders::PaymentRequest_CheckoutEvents;
ukm::TestAutoSetUkmRecorder ukm_recorder;
char test_url[] = "http://www.google.com/";
base::HistogramTester histogram_tester;
ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(source_id, GURL(test_url));
JourneyLogger logger(source_id);
logger.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/true,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user aborts after being shown the Payment Request and
// clicking pay.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/true);
logger.SetShown();
logger.SetPayClicked();
logger.SetAborted(JourneyLogger::ABORT_REASON_ABORTED_BY_USER);
int64_t expected_step_metric =
toInt(Event2::kShown) | toInt(Event2::kPayClicked) |
toInt(Event2::kRequestShipping) | toInt(Event2::kRequestPayerData) |
toInt(Event2::kRequestMethodBasicCard) | toInt(Event2::kUserAborted) |
toInt(Event2::kHadInitialFormOfPayment);
// Make sure the UKM was logged correctly.
auto entries = ukm_recorder.GetEntriesByName(UkmEntry::kEntryName);
EXPECT_EQ(1u, entries.size());
for (const ukm::mojom::UkmEntry* const entry : entries) {
ukm_recorder.ExpectEntrySourceHasUrl(entry, GURL(test_url));
EXPECT_EQ(2U, entry->metrics.size());
ukm_recorder.ExpectEntryMetric(
entry, UkmEntry::kCompletionStatusName,
JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kEvents2Name,
expected_step_metric);
}
}
// Tests that the Payment Request UKMs are logged correctly when the user
// completes the Payment Request.
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_CheckoutFunnelUkm_Completed) {
base::test::TaskEnvironment task_environment_;
using UkmEntry = ukm::builders::PaymentRequest_CheckoutEvents;
ukm::TestAutoSetUkmRecorder ukm_recorder;
char test_url[] = "http://www.google.com/";
base::HistogramTester histogram_tester;
ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(source_id, GURL(test_url));
JourneyLogger logger(source_id);
logger.SetRequestedInformation(
/*requested_shipping=*/true, /*requested_email=*/true,
/*requested_phone=*/false, /*requested_name=*/false);
std::vector<PaymentMethodCategory> methods{PaymentMethodCategory::kBasicCard};
logger.SetRequestedPaymentMethods(methods);
// Simulate that the user aborts after being shown the Payment Request.
logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_PAYMENT_METHOD, 1,
/*has_complete_suggestion=*/true);
logger.SetShown();
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kBasicCard);
logger.SetCompleted();
int64_t expected_step_metric =
toInt(Event2::kShown) | toInt(Event2::kRequestShipping) |
toInt(Event2::kRequestPayerData) |
toInt(Event2::kRequestMethodBasicCard) | toInt(Event2::kCompleted) |
toInt(Event2::kHadInitialFormOfPayment) | toInt(Event2::kPayClicked) |
toInt(Event2::kSelectedCreditCard);
// Make sure the UKM was logged correctly.
auto entries = ukm_recorder.GetEntriesByName(UkmEntry::kEntryName);
EXPECT_EQ(1u, entries.size());
for (const ukm::mojom::UkmEntry* const entry : entries) {
ukm_recorder.ExpectEntrySourceHasUrl(entry, GURL(test_url));
EXPECT_EQ(2U, entry->metrics.size());
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kCompletionStatusName,
JourneyLogger::COMPLETION_STATUS_COMPLETED);
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kEvents2Name,
expected_step_metric);
}
}
// Tests that the Payment Request UKMs and UMAs are logged correctly when the
// user selects the play billing method.
TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_SelectedPlayBilling) {
base::test::TaskEnvironment task_environment_;
using UkmEntry = ukm::builders::PaymentRequest_CheckoutEvents;
ukm::TestAutoSetUkmRecorder ukm_recorder;
char test_url[] = "http://www.google.com/";
base::HistogramTester histogram_tester;
ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(source_id, GURL(test_url));
JourneyLogger logger(source_id);
std::vector<PaymentMethodCategory> methods{
PaymentMethodCategory::kPlayBilling};
logger.SetRequestedPaymentMethods(methods);
logger.SetSkippedShow();
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kPlayBilling);
logger.SetCompleted();
int64_t expected_events =
toInt(Event2::kSkippedShow) | toInt(Event2::kCompleted) |
toInt(Event2::kPayClicked) | toInt(Event2::kRequestMethodPlayBilling) |
toInt(Event2::kSelectedPlayBilling);
// Make sure the UKM was logged correctly.
auto entries = ukm_recorder.GetEntriesByName(UkmEntry::kEntryName);
EXPECT_EQ(1u, entries.size());
for (const ukm::mojom::UkmEntry* const entry : entries) {
ukm_recorder.ExpectEntrySourceHasUrl(entry, GURL(test_url));
EXPECT_EQ(2U, entry->metrics.size());
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kCompletionStatusName,
JourneyLogger::COMPLETION_STATUS_COMPLETED);
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kEvents2Name,
expected_events);
}
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodBasicCard));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodGoogle));
EXPECT_FALSE(buckets[0].min &
toInt(Event2::kRequestMethodGooglePayAuthentication));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kRequestMethodPlayBilling));
EXPECT_FALSE(buckets[0].min &
toInt(Event2::kRequestMethodSecurePaymentConfirmation));
EXPECT_FALSE(buckets[0].min & toInt(Event2::kRequestMethodOther));
}
TEST(JourneyLoggerTest,
RecordJourneyStatsHistograms_MethodGooglePayAuthentication) {
base::test::TaskEnvironment task_environment_;
using UkmEntry = ukm::builders::PaymentRequest_CheckoutEvents;
ukm::TestAutoSetUkmRecorder ukm_recorder;
char test_url[] = "http://www.google.com";
base::HistogramTester histogram_tester;
ukm::SourceId source_id = ukm::UkmRecorder::GetNewSourceID();
ukm_recorder.UpdateSourceURL(source_id, GURL(test_url));
JourneyLogger logger(source_id);
std::vector<PaymentMethodCategory> methods{
PaymentMethodCategory::kGooglePayAuthentication};
logger.SetRequestedPaymentMethods(methods);
logger.SetSkippedShow();
logger.SetPayClicked();
logger.SetSelectedMethod(PaymentMethodCategory::kGooglePayAuthentication);
logger.SetCompleted();
int64_t expected_events =
toInt(Event2::kSkippedShow) | toInt(Event2::kCompleted) |
toInt(Event2::kPayClicked) |
toInt(Event2::kRequestMethodGooglePayAuthentication) |
toInt(Event2::kSelectedOther);
// Make sure the UKM was logged correctly.
auto entries = ukm_recorder.GetEntriesByName(UkmEntry::kEntryName);
EXPECT_EQ(1u, entries.size());
for (const ukm::mojom::UkmEntry* const entry : entries) {
ukm_recorder.ExpectEntrySourceHasUrl(entry, GURL(test_url));
EXPECT_EQ(2U, entry->metrics.size());
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kCompletionStatusName,
JourneyLogger::COMPLETION_STATUS_COMPLETED);
ukm_recorder.ExpectEntryMetric(entry, UkmEntry::kEvents2Name,
expected_events);
}
std::vector<base::Bucket> buckets =
histogram_tester.GetAllSamples("PaymentRequest.Events2");
EXPECT_TRUE(buckets[0].min &
toInt(Event2::kRequestMethodGooglePayAuthentication));
EXPECT_TRUE(buckets[0].min & toInt(Event2::kSelectedOther));
}
} // namespace payments
|