| Index: components/autofill/core/browser/autofill_metrics_unittest.cc
|
| diff --git a/components/autofill/core/browser/autofill_metrics_unittest.cc b/components/autofill/core/browser/autofill_metrics_unittest.cc
|
| index b0928c076534b6967dbb3851fa0d20400c9c6814..eb269ed2846ba7171358a5c04c59c884e7196759 100644
|
| --- a/components/autofill/core/browser/autofill_metrics_unittest.cc
|
| +++ b/components/autofill/core/browser/autofill_metrics_unittest.cc
|
| @@ -6,17 +6,21 @@
|
|
|
| #include <stddef.h>
|
|
|
| +#include <map>
|
| #include <memory>
|
| #include <vector>
|
|
|
| +#include "base/feature_list.h"
|
| #include "base/macros.h"
|
| #include "base/memory/ptr_util.h"
|
| #include "base/run_loop.h"
|
| #include "base/strings/string16.h"
|
| #include "base/strings/utf_string_conversions.h"
|
| #include "base/test/histogram_tester.h"
|
| +#include "base/test/scoped_feature_list.h"
|
| #include "base/test/user_action_tester.h"
|
| #include "base/time/time.h"
|
| +#include "components/autofill/core/browser/autofill_experiments.h"
|
| #include "components/autofill/core/browser/autofill_external_delegate.h"
|
| #include "components/autofill/core/browser/autofill_manager.h"
|
| #include "components/autofill/core/browser/autofill_test_utils.h"
|
| @@ -34,6 +38,8 @@
|
| #include "components/signin/core/browser/fake_signin_manager.h"
|
| #include "components/signin/core/browser/test_signin_client.h"
|
| #include "components/signin/core/common/signin_pref_names.h"
|
| +#include "components/ukm/test_ukm_service.h"
|
| +#include "components/ukm/ukm_source.h"
|
| #include "components/webdata/common/web_data_results.h"
|
| #include "testing/gmock/include/gmock/gmock.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| @@ -311,6 +317,7 @@ class AutofillMetricsTest : public testing::Test {
|
|
|
| protected:
|
| void EnableWalletSync();
|
| + void EnableUkmLogging();
|
|
|
| base::MessageLoop message_loop_;
|
| TestAutofillClient autofill_client_;
|
| @@ -321,6 +328,7 @@ class AutofillMetricsTest : public testing::Test {
|
| std::unique_ptr<TestAutofillManager> autofill_manager_;
|
| std::unique_ptr<TestPersonalDataManager> personal_data_;
|
| std::unique_ptr<AutofillExternalDelegate> external_delegate_;
|
| + base::test::ScopedFeatureList scoped_feature_list_;
|
| };
|
|
|
| AutofillMetricsTest::~AutofillMetricsTest() {
|
| @@ -377,6 +385,10 @@ void AutofillMetricsTest::EnableWalletSync() {
|
| signin_manager_->SetAuthenticatedAccountInfo("12345", "syncuser@example.com");
|
| }
|
|
|
| +void AutofillMetricsTest::EnableUkmLogging() {
|
| + scoped_feature_list_.InitAndEnableFeature(kAutofillUkmLogging);
|
| +}
|
| +
|
| // Test that we log quality metrics appropriately.
|
| TEST_F(AutofillMetricsTest, QualityMetrics) {
|
| // Set up our form data.
|
| @@ -4340,4 +4352,70 @@ TEST_F(AutofillMetricsTest,
|
| }
|
| }
|
|
|
| +// Tests that logging a UKM works as expected.
|
| +TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric) {
|
| + EnableUkmLogging();
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("https://www.google.com");
|
| + std::map<std::string, int> metrics;
|
| + metrics.insert(std::make_pair("metric", 1));
|
| +
|
| + EXPECT_TRUE(AutofillMetrics::LogUkm(
|
| + ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| +
|
| + ASSERT_EQ(1U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| + EXPECT_EQ(
|
| + url.spec(),
|
| + ukm_service_test_harness.test_ukm_service()->GetSource(0)->url().spec());
|
| +}
|
| +
|
| +// Tests that no UKM is logged when the URL is not valid.
|
| +TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_InvalidUrl) {
|
| + EnableUkmLogging();
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("");
|
| + std::map<std::string, int> metrics;
|
| + metrics.insert(std::make_pair("metric", 1));
|
| +
|
| + EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| + ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| + EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| +}
|
| +
|
| +// Tests that no UKM is logged when the metrics map is empty.
|
| +TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoMetrics) {
|
| + EnableUkmLogging();
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("https://www.google.com");
|
| + std::map<std::string, int> metrics;
|
| +
|
| + EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| + ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| + EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| +}
|
| +
|
| +// Tests that no UKM is logged when the ukm service is null.
|
| +TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_NoUkmService) {
|
| + EnableUkmLogging();
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("https://www.google.com");
|
| + std::map<std::string, int> metrics;
|
| + metrics.insert(std::make_pair("metric", 1));
|
| +
|
| + EXPECT_FALSE(AutofillMetrics::LogUkm(nullptr, url, "test_ukm", metrics));
|
| + ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| +}
|
| +
|
| +// Tests that no UKM is logged when the ukm logging feature is disabled.
|
| +TEST_F(AutofillMetricsTest, RecordCardUploadDecisionMetric_FeatureDisabled) {
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("https://www.google.com");
|
| + std::map<std::string, int> metrics;
|
| + metrics.insert(std::make_pair("metric", 1));
|
| +
|
| + EXPECT_FALSE(AutofillMetrics::LogUkm(
|
| + ukm_service_test_harness.test_ukm_service(), url, "test_ukm", metrics));
|
| + EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| +}
|
| +
|
| } // namespace autofill
|
|
|