OLD | NEW |
---|---|
(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 "components/autofill/core/browser/autofill_metrics.h" | |
8 #include "components/ukm/test_ukm_service.h" | |
9 #include "components/ukm/ukm_source.h" | |
10 #include "testing/gtest/include/gtest/gtest.h" | |
11 #include "url/gurl.h" | |
12 | |
13 namespace autofill { | |
14 | |
15 namespace { | |
16 | |
17 class AutofillUkmTest : public ::testing::Test { | |
18 protected: | |
19 AutofillUkmTest(){}; | |
20 | |
21 void SetUp() override; | |
22 | |
23 void TearDown() override; | |
24 | |
25 ukm::TestUkmService* GetTestUkmService() { | |
26 return ukm_service_test_harness_.test_ukm_service(); | |
27 } | |
28 | |
29 std::unique_ptr<AutofillUkm> autofill_ukm_; | |
30 | |
31 private: | |
32 ukm::UkmServiceTestingHarness ukm_service_test_harness_; | |
33 | |
34 DISALLOW_COPY_AND_ASSIGN(AutofillUkmTest); | |
35 }; | |
36 | |
37 void AutofillUkmTest::SetUp() { | |
38 autofill_ukm_.reset(new AutofillUkm(GetTestUkmService())); | |
Mathieu
2017/03/08 22:33:49
you can inline SetUp and TearDown above
| |
39 } | |
40 | |
41 void AutofillUkmTest::TearDown() { | |
42 autofill_ukm_.reset(); | |
43 } | |
44 | |
45 } // namespace | |
46 | |
47 // Tests that logging a card upload decision UKM works as expected. | |
48 TEST_F(AutofillUkmTest, RecordCardUploadDecisionMetric) { | |
49 GURL url("https://www.google.com"); | |
50 autofill_ukm_->SetCardUploadDecisionMetricUrl(url); | |
51 | |
52 ASSERT_EQ(0U, GetTestUkmService()->sources_count()); | |
53 | |
54 autofill_ukm_->LogCardUploadDecisionMetric( | |
55 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | |
56 | |
57 ASSERT_EQ(1U, GetTestUkmService()->sources_count()); | |
58 EXPECT_EQ(url.spec(), GetTestUkmService()->GetSource(0)->url().spec()); | |
59 } | |
60 | |
61 // Tests that only the most recent URL is used when logging the card upload | |
62 // decision UKM. | |
63 TEST_F(AutofillUkmTest, RecordCardUploadDecisionMetric_ChangeUrl) { | |
64 GURL url1("https://www.google.com"); | |
65 GURL url2("https://www.gmail.com"); | |
66 autofill_ukm_->SetCardUploadDecisionMetricUrl(url1); | |
67 autofill_ukm_->SetCardUploadDecisionMetricUrl(url2); | |
68 | |
69 autofill_ukm_->LogCardUploadDecisionMetric( | |
70 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | |
71 | |
72 ASSERT_EQ(1U, GetTestUkmService()->sources_count()); | |
73 EXPECT_EQ(url2.spec(), GetTestUkmService()->GetSource(0)->url().spec()); | |
74 } | |
75 | |
76 // Tests that no card upload decision UKM is logged when the URL is not set. | |
77 TEST_F(AutofillUkmTest, RecordCardUploadDecisionMetric_NoUrl) { | |
78 autofill_ukm_->LogCardUploadDecisionMetric( | |
79 AutofillMetrics::UPLOAD_NOT_OFFERED_NO_CVC); | |
80 | |
81 ASSERT_EQ(0U, GetTestUkmService()->sources_count()); | |
82 } | |
83 | |
84 // Tests that no card upload decision UKM is set if the decision is not valid. | |
85 TEST_F(AutofillUkmTest, RecordCardUploadDecisionMetric_InvalidDecision) { | |
86 GURL url("https://www.google.com"); | |
87 autofill_ukm_->SetCardUploadDecisionMetricUrl(url); | |
88 autofill_ukm_->LogCardUploadDecisionMetric( | |
89 AutofillMetrics::NUM_CARD_UPLOAD_DECISION_METRICS); | |
90 | |
91 ASSERT_EQ(0U, GetTestUkmService()->sources_count()); | |
92 } | |
93 | |
94 } // namespace autofill | |
OLD | NEW |