| Index: components/autofill/core/browser/autofill_ukm_unittest.cc
|
| diff --git a/components/autofill/core/browser/autofill_ukm_unittest.cc b/components/autofill/core/browser/autofill_ukm_unittest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..d044d570a8b279a8ebca4bbd5f00d2028eb22247
|
| --- /dev/null
|
| +++ b/components/autofill/core/browser/autofill_ukm_unittest.cc
|
| @@ -0,0 +1,68 @@
|
| +// 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/autofill/core/browser/autofill_ukm.h"
|
| +
|
| +#include <map>
|
| +
|
| +#include "components/autofill/core/browser/autofill_metrics.h"
|
| +#include "components/ukm/test_ukm_service.h"
|
| +#include "components/ukm/ukm_source.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "url/gurl.h"
|
| +
|
| +namespace autofill {
|
| +
|
| +// Tests that logging a UKM works as expected.
|
| +TEST(AutofillUkmTest, RecordCardUploadDecisionMetric) {
|
| + 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(AutofillUkm::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(AutofillUkmTest, RecordCardUploadDecisionMetric_InvalidUrl) {
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("");
|
| + std::map<std::string, int> metrics;
|
| + metrics.insert(std::make_pair("metric", 1));
|
| +
|
| + EXPECT_FALSE(AutofillUkm::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(AutofillUkmTest, RecordCardUploadDecisionMetric_NoMetrics) {
|
| + ukm::UkmServiceTestingHarness ukm_service_test_harness;
|
| + GURL url("https://www.google.com");
|
| + std::map<std::string, int> metrics;
|
| +
|
| + EXPECT_FALSE(AutofillUkm::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(AutofillUkmTest, RecordCardUploadDecisionMetric_NoUkmService) {
|
| + ;
|
| + 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(AutofillUkm::LogUkm(nullptr, url, "test_ukm", metrics));
|
| + ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
|
| +}
|
| +
|
| +} // namespace autofill
|
|
|