Index: components/payments/core/journey_logger_unittest.cc |
diff --git a/components/payments/core/journey_logger_unittest.cc b/components/payments/core/journey_logger_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..75372e98c4cf4f5e6e4e5900b8f90a946dc60da3 |
--- /dev/null |
+++ b/components/payments/core/journey_logger_unittest.cc |
@@ -0,0 +1,661 @@ |
+// Copyright 2017 The Chromium Authors. All rights reserved. |
+// 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/test/histogram_tester.h" |
+#include "testing/gmock/include/gmock/gmock.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+using testing::ContainerEq; |
+ |
+namespace payments { |
+ |
+// Tests the canMakePayment stats for the case where the merchant does not use |
+// it and does not show the PaymentRequest to the user. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentNotCalled_NoShow) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
+ 1); |
+ |
+ // There should be no completion stats since PR was not shown to the user |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant does not use |
+// it and the transaction is aborted. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The merchant does not query CanMakePayment, show the PaymentRequest and the |
+ // user aborts it. |
+ logger.SetShowCalled(); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
+ 1); |
+ |
+ // There should be a record for an abort when CanMakePayment is not used but |
+ // the PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant does not use |
+// it and the transaction is aborted. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The merchant does not query CanMakePayment, show the PaymentRequest and |
+ // there is an abort not initiated by the user. |
+ logger.SetShowCalled(); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
+ 1); |
+ |
+ // There should be a record for an abort when CanMakePayment is not used but |
+ // the PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant does not use |
+// it and the transaction is completed. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The merchant does not query CanMakePayment, show the PaymentRequest and the |
+ // user completes it. |
+ logger.SetShowCalled(); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
+ 1); |
+ |
+ // There should be a record for an abort when CanMakePayment is not used but |
+ // the PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns false and show is not called. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetCanMakePaymentValue(false); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being false and not |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_COULD_NOT_MAKE_PAYMENT_AND_DID_NOT_SHOW, 1); |
+ |
+ // There should be no completion stats since PR was not shown to the user. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns true and show is not called. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetCanMakePaymentValue(true); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being true and not |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, 1); |
+ |
+ // There should be no completion stats since PR was not shown to the user. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns false, show is called but the transaction is aborted by the user. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(false); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being false and |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
+ // There should be a record for an abort when CanMakePayment is false but the |
+ // PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns false, show is called but the transaction is aborted. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(false); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being false and |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
+ // There should be a record for an abort when CanMakePayment is false but the |
+ // PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns false, show is called and the transaction is completed. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(false); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being false and |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW, 1); |
+ |
+ // There should be a record for an completion when CanMakePayment is false but |
+ // the PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.FalseWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns true, show is called but the transaction is aborted by the user. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(true); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being true and not |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW | |
+ JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
+ 1); |
+ // There should be a record for an abort when CanMakePayment is true and the |
+ // PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns true, show is called but the transaction is aborted. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(true); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being true and not |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW | |
+ JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
+ 1); |
+ // There should be a record for an abort when CanMakePayment is true and the |
+ // PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
+} |
+ |
+// Tests the canMakePayment stats for the case where the merchant uses it, |
+// returns true, show is called and the transaction is completed. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/false); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(true); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ |
+ // The CanMakePayment effect on show should be recorded as being true and not |
+ // shown. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.EffectOnShow", |
+ JourneyLogger::CMP_SHOW_DID_SHOW | |
+ JourneyLogger::CMP_SHOW_COULD_MAKE_PAYMENT, |
+ 1); |
+ // There should be a record for a completion when CanMakePayment is true and |
+ // the PR is shown to the user. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+} |
+ |
+// Tests the canMakePayment metrics are not logged if the Payment Request was |
+// done in an incognito tab. |
+TEST(JourneyLoggerTest, |
+ RecordJourneyStatsHistograms_CanMakePayment_IncognitoTab) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger(/*is_incognito=*/true); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+ |
+ // The user cannot make payment and the PaymentRequest is not shown. |
+ logger.SetShowCalled(); |
+ logger.SetCanMakePaymentValue(true); |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ // Expect no log for CanMakePayment. |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix("PaymentRequest.CanMakePayment"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
+ |
+ // Simulate that the user completes the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
+ |
+ // Simulate that the user aborts the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
+ |
+ // Simulate that the checkout is aborted. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/true); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
+ |
+ // Simulate that the user completes the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
+ |
+ // Simulate that the user completes the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+ |
+ EXPECT_THAT( |
+ histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
+ |
+ // Simulate that the user aborts the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserHadSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/false); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
+ |
+ // Simulate that the user aborts the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_OTHER_ABORTED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserHadSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// 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(/*is_incognito=*/true); |
+ |
+ // Simulate that the user had suggestions for all the requested sections. |
+ logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
+ |
+ // Simulate that the user aborts the checkout. |
+ logger.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+ |
+ EXPECT_THAT(histogram_tester.GetTotalCountsForPrefix( |
+ "PaymentRequest.UserHadSuggestionsForEverything." |
+ "EffectOnCompletion"), |
+ testing::ContainerEq(base::HistogramTester::CountsMap())); |
+} |
+ |
+// Tests that the metrics are logged correctly for two simultaneous Payment |
+// Requests. |
+TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) { |
+ base::HistogramTester histogram_tester; |
+ JourneyLogger logger1(/*is_incognito=*/false); |
+ JourneyLogger logger2(/*is_incognito=*/false); |
+ |
+ // Make the two loggers have different data. |
+ logger1.SetShowCalled(); |
+ logger2.SetShowCalled(); |
+ |
+ logger1.SetCanMakePaymentValue(true); |
+ |
+ logger1.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1); |
+ logger2.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0); |
+ |
+ // Simulate that the user completes one checkout and aborts the other. |
+ logger1.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED); |
+ logger2.RecordJourneyStatsHistograms( |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED); |
+ |
+ // Make sure the appropriate metrics were logged for logger1. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserHadSuggestionsForEverything.EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_USED, 1); |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.Used.TrueWithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_COMPLETED, 1); |
+ |
+ // Make sure the appropriate metrics were logged for logger2. |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.UserDidNotHaveSuggestionsForEverything." |
+ "EffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+ histogram_tester.ExpectBucketCount("PaymentRequest.CanMakePayment.Usage", |
+ JourneyLogger::CAN_MAKE_PAYMENT_NOT_USED, |
+ 1); |
+ histogram_tester.ExpectBucketCount( |
+ "PaymentRequest.CanMakePayment.NotUsed.WithShowEffectOnCompletion", |
+ JourneyLogger::COMPLETION_STATUS_USER_ABORTED, 1); |
+} |
+ |
+} // namespace payments |