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

Side by Side Diff: components/ntp_tiles/metrics_unittest.cc

Issue 2557513007: ntp_tiles::metrics: Add rappor metrics for impression URLs per icon type. (Closed)
Patch Set: Fix build. Created 4 years 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 2016 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/ntp_tiles/metrics.h"
6
7 #include <stddef.h>
8
9 #include <string>
10 #include <vector>
11
12 #include "base/macros.h"
13 #include "base/test/histogram_tester.h"
14 #include "components/rappor/test_rappor_service.h"
15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h"
17
18 namespace ntp_tiles {
19 namespace metrics {
20 namespace {
21
22 using testing::ElementsAre;
23 using testing::IsEmpty;
24
25 TEST(RecordPageImpressionTest, ShouldRecordUmaForIcons) {
26 base::HistogramTester histogram_tester;
27 RecordPageImpression({{NTPTileSource::TOP_SITES, ICON_REAL},
28 {NTPTileSource::TOP_SITES, ICON_REAL},
29 {NTPTileSource::TOP_SITES, ICON_REAL},
30 {NTPTileSource::TOP_SITES, ICON_COLOR},
31 {NTPTileSource::TOP_SITES, ICON_COLOR},
32 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_REAL},
33 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_DEFAULT},
34 {NTPTileSource::POPULAR, ICON_COLOR}},
35 /*rappor_service=*/nullptr);
36 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
37 ElementsAre(base::Bucket(/*min=*/8, /*count=*/1)));
38 EXPECT_THAT(
39 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
40 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
41 base::Bucket(/*min=*/1, /*count=*/1),
42 base::Bucket(/*min=*/2, /*count=*/1),
43 base::Bucket(/*min=*/3, /*count=*/1),
44 base::Bucket(/*min=*/4, /*count=*/1),
45 base::Bucket(/*min=*/5, /*count=*/1),
46 base::Bucket(/*min=*/6, /*count=*/1),
47 base::Bucket(/*min=*/7, /*count=*/1)));
48 EXPECT_THAT(
49 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
50 ElementsAre(base::Bucket(/*min=*/5, /*count=*/1),
51 base::Bucket(/*min=*/6, /*count=*/1)));
52 EXPECT_THAT(
53 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
54 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
55 base::Bucket(/*min=*/1, /*count=*/1),
56 base::Bucket(/*min=*/2, /*count=*/1),
57 base::Bucket(/*min=*/3, /*count=*/1),
58 base::Bucket(/*min=*/4, /*count=*/1)));
59 EXPECT_THAT(histogram_tester.GetAllSamples(
60 "NewTabPage.SuggestionsImpression.popular"),
61 ElementsAre(base::Bucket(/*min=*/7, /*count=*/1)));
62 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"),
63 ElementsAre(base::Bucket(/*min=*/1, /*count=*/4),
Marc Treib 2016/12/08 12:58:22 Can we use the enum entries for "min" here, instea
mastiz 2016/12/08 13:47:07 Done.
64 base::Bucket(/*min=*/2, /*count=*/3),
65 base::Bucket(/*min=*/3, /*count=*/1)));
66 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
67 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1),
68 base::Bucket(/*min=*/3, /*count=*/1)));
69 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
70 ElementsAre(base::Bucket(/*min=*/1, /*count=*/3),
71 base::Bucket(/*min=*/2, /*count=*/2)));
72 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
73 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
74 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
75 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1)));
76 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
77 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
78 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
79 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
80 }
81
82 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) {
83 base::HistogramTester histogram_tester;
84 RecordPageImpression({{NTPTileSource::TOP_SITES, THUMBNAIL},
85 {NTPTileSource::SUGGESTIONS_SERVICE, THUMBNAIL},
86 {NTPTileSource::POPULAR, THUMBNAIL}},
87 /*rappor_service=*/nullptr);
88 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
89 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
90 EXPECT_THAT(
91 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
92 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
93 base::Bucket(/*min=*/1, /*count=*/1),
94 base::Bucket(/*min=*/2, /*count=*/1)));
95 EXPECT_THAT(
96 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
97 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
98 EXPECT_THAT(
99 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
100 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
101 EXPECT_THAT(histogram_tester.GetAllSamples(
102 "NewTabPage.SuggestionsImpression.popular"),
103 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
104 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), IsEmpty());
105 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
106 IsEmpty());
107 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
108 IsEmpty());
109 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
110 IsEmpty());
111 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
112 IsEmpty());
113 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
114 IsEmpty());
115 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
116 IsEmpty());
117 }
118
119 TEST(RecordPageImpressionTest, ShouldRecordRappor) {
120 rappor::TestRapporServiceImpl rappor_service;
121
122 RecordPageImpression(
123 {{NTPTileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")},
124 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")},
125 {NTPTileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")},
126 {NTPTileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}},
127 &rappor_service);
128
129 // Thumbnail shouldn't get reported.
130 EXPECT_EQ(3, rappor_service.GetReportsCount());
131
132 {
133 std::string sample;
134 rappor::RapporType type;
135 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
136 "NTP.SuggestionsImpressions.IconsReal", &sample, &type));
137 EXPECT_EQ("site1.com", sample);
138 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
139 }
140
141 {
142 std::string sample;
143 rappor::RapporType type;
144 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
145 "NTP.SuggestionsImpressions.IconsColor", &sample, &type));
146 EXPECT_EQ("site2.com", sample);
147 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
148 }
149
150 {
151 std::string sample;
152 rappor::RapporType type;
153 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
154 "NTP.SuggestionsImpressions.IconsGray", &sample, &type));
155 EXPECT_EQ("site3.com", sample);
156 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
157 }
158 }
159
160 } // namespace
161 } // namespace metrics
162 } // namespace ntp_tiles
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698