| 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
|
| index fbb1efd4cbde0f28e715ca757847ae645a39e51a..d44dc2bf2ee799a5f057a564a8fa2ac5d2f3e7fa 100644
|
| --- a/components/payments/core/journey_logger_unittest.cc
|
| +++ b/components/payments/core/journey_logger_unittest.cc
|
| @@ -8,9 +8,7 @@
|
| #include "base/test/histogram_tester.h"
|
| #include "base/test/scoped_feature_list.h"
|
| #include "components/autofill/core/browser/autofill_experiments.h"
|
| -#include "components/metrics/proto/ukm/entry.pb.h"
|
| -#include "components/ukm/test_ukm_service.h"
|
| -#include "components/ukm/ukm_entry.h"
|
| +#include "components/ukm/test_ukm_recorder.h"
|
| #include "components/ukm/ukm_source.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -19,26 +17,13 @@ using testing::ContainerEq;
|
|
|
| namespace payments {
|
|
|
| -namespace {
|
| -// Finds the specified UKM metric by |name| in the specified UKM |metrics|.
|
| -const ukm::Entry_Metric* FindMetric(
|
| - const char* name,
|
| - const google::protobuf::RepeatedPtrField<ukm::Entry_Metric>& metrics) {
|
| - for (const auto& metric : metrics) {
|
| - if (metric.metric_hash() == base::HashMetricName(name))
|
| - return &metric;
|
| - }
|
| - return nullptr;
|
| -}
|
| -} // namespace
|
| -
|
| // 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, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| logger.RecordJourneyStatsHistograms(
|
| JourneyLogger::COMPLETION_STATUS_COMPLETED);
|
| @@ -60,7 +45,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndUserAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -90,7 +75,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndOtherAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -120,7 +105,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentNotCalled_ShowAndComplete) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -150,7 +135,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseAndNoShow) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -184,7 +169,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueAndNoShow) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -218,7 +203,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndUserAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -252,7 +237,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndOtherAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -286,7 +271,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_FalseShowAndComplete) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -321,7 +306,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndUserAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -357,7 +342,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndOtherAbort) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -393,7 +378,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePaymentCalled_TrueShowAndComplete) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -429,7 +414,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_CanMakePayment_IncognitoTab) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Expect no log for CanMakePayment.
|
| EXPECT_THAT(
|
| @@ -454,7 +439,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_SuggestionsForEverything_Completed) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
|
| @@ -479,7 +464,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_SuggestionsForEverything_UserAborted) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
|
| @@ -504,7 +489,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_SuggestionsForEverything_OtherAborted) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
|
| @@ -530,7 +515,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_SuggestionsForEverything_Incognito) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 1);
|
| @@ -555,7 +540,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_NoSuggestionsForEverything_Completed) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
|
| @@ -581,7 +566,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_NoSuggestionsForEverything_UserAborted) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
|
| @@ -607,7 +592,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_NoSuggestionsForEverything_OtherAborted) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
|
| @@ -634,7 +619,7 @@ TEST(JourneyLoggerTest,
|
| RecordJourneyStatsHistograms_NoSuggestionsForEverything_Incognito) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Simulate that the user had suggestions for all the requested sections.
|
| logger.SetNumberOfSuggestionsShown(JourneyLogger::SECTION_CREDIT_CARDS, 0);
|
| @@ -659,9 +644,9 @@ TEST(JourneyLoggerTest,
|
| TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_TwoPaymentRequests) {
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger1(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
| JourneyLogger logger2(/*is_incognito=*/false, /*url=*/GURL(""),
|
| - /*ukm_service=*/nullptr);
|
| + /*ukm_recorder=*/nullptr);
|
|
|
| // Make the two loggers have different data.
|
| logger1.SetShowCalled();
|
| @@ -706,14 +691,12 @@ TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_CheckoutFunnelUkm) {
|
| base::test::ScopedFeatureList scoped_feature_list_;
|
| scoped_feature_list_.InitAndEnableFeature(autofill::kAutofillUkmLogging);
|
|
|
| - ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| - ukm::TestUkmService* ukm_service =
|
| - ukm_service_test_harness.test_ukm_service();
|
| + ukm::TestUkmRecorder ukm_recorder;
|
| char test_url[] = "http://www.google.com/";
|
|
|
| base::HistogramTester histogram_tester;
|
| JourneyLogger logger(/*is_incognito=*/true, /*url=*/GURL(test_url),
|
| - /*ukm_service=*/ukm_service);
|
| + /*ukm_recorder=*/&ukm_recorder);
|
|
|
| // Simulate that the user aborts after being shown the Payment Request and
|
| // clicking pay.
|
| @@ -723,31 +706,27 @@ TEST(JourneyLoggerTest, RecordJourneyStatsHistograms_CheckoutFunnelUkm) {
|
| JourneyLogger::COMPLETION_STATUS_USER_ABORTED);
|
|
|
| // Make sure the UKM was logged correctly.
|
| - ASSERT_EQ(1U, ukm_service->sources_count());
|
| - const ukm::UkmSource* source = ukm_service->GetSourceForUrl(test_url);
|
| + ASSERT_EQ(1U, ukm_recorder.sources_count());
|
| + const ukm::UkmSource* source = ukm_recorder.GetSourceForUrl(test_url);
|
| ASSERT_NE(nullptr, source);
|
|
|
| - ASSERT_EQ(1U, ukm_service->entries_count());
|
| - const ukm::UkmEntry* entry = ukm_service->GetEntry(0);
|
| - EXPECT_EQ(source->id(), entry->source_id());
|
| -
|
| - ukm::Entry entry_proto;
|
| - entry->PopulateProto(&entry_proto);
|
| - EXPECT_EQ(source->id(), entry_proto.source_id());
|
| + ASSERT_EQ(1U, ukm_recorder.entries_count());
|
| + const ukm::mojom::UkmEntry* entry = ukm_recorder.GetEntry(0);
|
| + EXPECT_EQ(source->id(), entry->source_id);
|
| EXPECT_EQ(base::HashMetricName(internal::kUKMCheckoutEventsEntryName),
|
| - entry_proto.event_hash());
|
| + entry->event_hash);
|
|
|
| - const ukm::Entry_Metric* status_metric = FindMetric(
|
| - internal::kUKMCompletionStatusMetricName, entry_proto.metrics());
|
| + const ukm::mojom::UkmMetric* status_metric = ukm::TestUkmRecorder::FindMetric(
|
| + entry, internal::kUKMCompletionStatusMetricName);
|
| ASSERT_NE(nullptr, status_metric);
|
| EXPECT_EQ(JourneyLogger::COMPLETION_STATUS_USER_ABORTED,
|
| - status_metric->value());
|
| + status_metric->value);
|
|
|
| - const ukm::Entry_Metric* step_metric =
|
| - FindMetric(internal::kUKMEventsMetricName, entry_proto.metrics());
|
| + const ukm::mojom::UkmMetric* step_metric =
|
| + ukm::TestUkmRecorder::FindMetric(entry, internal::kUKMEventsMetricName);
|
| ASSERT_NE(nullptr, step_metric);
|
| EXPECT_EQ(JourneyLogger::EVENT_SHOWN | JourneyLogger::EVENT_PAY_CLICKED,
|
| - step_metric->value());
|
| + step_metric->value);
|
| }
|
|
|
| -} // namespace payments
|
| +} // namespace payments
|
|
|