Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(275)

Side by Side Diff: components/autofill/core/browser/autofill_ukm_unittest.cc

Issue 2740633002: [Autofill] Add upstreaming UKM (Closed)
Patch Set: Re-do Created 3 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2017 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "components/autofill/core/browser/autofill_ukm.h"
6
7 #include <map>
8
9 #include "components/autofill/core/browser/autofill_metrics.h"
10 #include "components/ukm/test_ukm_service.h"
11 #include "components/ukm/ukm_source.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "url/gurl.h"
14
15 namespace autofill {
16
17 // Tests that logging a UKM works as expected.
18 TEST(AutofillUkmTest, RecordCardUploadDecisionMetric) {
19 ukm::UkmServiceTestingHarness ukm_service_test_harness;
20 GURL url("https://www.google.com");
21 std::map<std::string, int> metrics;
22 metrics.insert(std::make_pair("metric", 1));
23
24 EXPECT_TRUE(AutofillUkm::LogUkm(ukm_service_test_harness.test_ukm_service(),
25 url, "test_ukm", metrics));
26
27 ASSERT_EQ(1U, ukm_service_test_harness.test_ukm_service()->sources_count());
28 EXPECT_EQ(
29 url.spec(),
30 ukm_service_test_harness.test_ukm_service()->GetSource(0)->url().spec());
31 }
32
33 // Tests that no UKM is logged when the URL is not valid.
34 TEST(AutofillUkmTest, RecordCardUploadDecisionMetric_InvalidUrl) {
35 ukm::UkmServiceTestingHarness ukm_service_test_harness;
36 GURL url("");
37 std::map<std::string, int> metrics;
38 metrics.insert(std::make_pair("metric", 1));
39
40 EXPECT_FALSE(AutofillUkm::LogUkm(ukm_service_test_harness.test_ukm_service(),
41 url, "test_ukm", metrics));
42 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
43 }
44
45 // Tests that no UKM is logged when the metrics map is empty.
46 TEST(AutofillUkmTest, RecordCardUploadDecisionMetric_NoMetrics) {
47 ukm::UkmServiceTestingHarness ukm_service_test_harness;
48 GURL url("https://www.google.com");
49 std::map<std::string, int> metrics;
50
51 EXPECT_FALSE(AutofillUkm::LogUkm(ukm_service_test_harness.test_ukm_service(),
52 url, "test_ukm", metrics));
53 EXPECT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
54 }
55
56 // Tests that no UKM is logged when the ukm service is null.
57 TEST(AutofillUkmTest, RecordCardUploadDecisionMetric_NoUkmService) {
58 ;
59 ukm::UkmServiceTestingHarness ukm_service_test_harness;
60 GURL url("https://www.google.com");
61 std::map<std::string, int> metrics;
62 metrics.insert(std::make_pair("metric", 1));
63
64 EXPECT_FALSE(AutofillUkm::LogUkm(nullptr, url, "test_ukm", metrics));
65 ASSERT_EQ(0U, ukm_service_test_harness.test_ukm_service()->sources_count());
66 }
67
68 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698