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

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: Rebased. 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
« no previous file with comments | « components/ntp_tiles/metrics.cc ('k') | tools/metrics/rappor/rappor.xml » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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(
28 {{NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
29 {NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
30 {NTPTileSource::TOP_SITES, ICON_REAL, GURL()},
31 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()},
32 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL()},
33 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_REAL, GURL()},
34 {NTPTileSource::SUGGESTIONS_SERVICE, ICON_DEFAULT, GURL()},
35 {NTPTileSource::POPULAR, ICON_COLOR, GURL()}},
36 /*rappor_service=*/nullptr);
37 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
38 ElementsAre(base::Bucket(/*min=*/8, /*count=*/1)));
39 EXPECT_THAT(
40 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
41 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
42 base::Bucket(/*min=*/1, /*count=*/1),
43 base::Bucket(/*min=*/2, /*count=*/1),
44 base::Bucket(/*min=*/3, /*count=*/1),
45 base::Bucket(/*min=*/4, /*count=*/1),
46 base::Bucket(/*min=*/5, /*count=*/1),
47 base::Bucket(/*min=*/6, /*count=*/1),
48 base::Bucket(/*min=*/7, /*count=*/1)));
49 EXPECT_THAT(
50 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
51 ElementsAre(base::Bucket(/*min=*/5, /*count=*/1),
52 base::Bucket(/*min=*/6, /*count=*/1)));
53 EXPECT_THAT(
54 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
55 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
56 base::Bucket(/*min=*/1, /*count=*/1),
57 base::Bucket(/*min=*/2, /*count=*/1),
58 base::Bucket(/*min=*/3, /*count=*/1),
59 base::Bucket(/*min=*/4, /*count=*/1)));
60 EXPECT_THAT(histogram_tester.GetAllSamples(
61 "NewTabPage.SuggestionsImpression.popular"),
62 ElementsAre(base::Bucket(/*min=*/7, /*count=*/1)));
63 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"),
64 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/4),
65 base::Bucket(/*min=*/ICON_COLOR, /*count=*/3),
66 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1)));
67 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
68 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/1),
69 base::Bucket(/*min=*/ICON_DEFAULT, /*count=*/1)));
70 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
71 ElementsAre(base::Bucket(/*min=*/ICON_REAL, /*count=*/3),
72 base::Bucket(/*min=*/ICON_COLOR, /*count=*/2)));
73 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
74 ElementsAre(base::Bucket(/*min=*/ICON_COLOR, /*count=*/1)));
75 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
76 ElementsAre(base::Bucket(/*min=*/4, /*count=*/1)));
77 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
78 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
79 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
80 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
81 }
82
83 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) {
84 base::HistogramTester histogram_tester;
85 RecordPageImpression({{NTPTileSource::TOP_SITES, THUMBNAIL, GURL()},
86 {NTPTileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()},
87 {NTPTileSource::POPULAR, THUMBNAIL, GURL()}},
88 /*rappor_service=*/nullptr);
89 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"),
90 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1)));
91 EXPECT_THAT(
92 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"),
93 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1),
94 base::Bucket(/*min=*/1, /*count=*/1),
95 base::Bucket(/*min=*/2, /*count=*/1)));
96 EXPECT_THAT(
97 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"),
98 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1)));
99 EXPECT_THAT(
100 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"),
101 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1)));
102 EXPECT_THAT(histogram_tester.GetAllSamples(
103 "NewTabPage.SuggestionsImpression.popular"),
104 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1)));
105 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), IsEmpty());
106 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"),
107 IsEmpty());
108 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"),
109 IsEmpty());
110 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"),
111 IsEmpty());
112 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsReal"),
113 IsEmpty());
114 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsColor"),
115 IsEmpty());
116 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.IconsGray"),
117 IsEmpty());
118 }
119
120 TEST(RecordPageImpressionTest, ShouldRecordRappor) {
121 rappor::TestRapporServiceImpl rappor_service;
122
123 RecordPageImpression(
124 {{NTPTileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")},
125 {NTPTileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")},
126 {NTPTileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")},
127 {NTPTileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}},
128 &rappor_service);
129
130 // Thumbnail shouldn't get reported.
131 EXPECT_EQ(3, rappor_service.GetReportsCount());
132
133 {
134 std::string sample;
135 rappor::RapporType type;
136 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
137 "NTP.SuggestionsImpressions.IconsReal", &sample, &type));
138 EXPECT_EQ("site1.com", sample);
139 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
140 }
141
142 {
143 std::string sample;
144 rappor::RapporType type;
145 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
146 "NTP.SuggestionsImpressions.IconsColor", &sample, &type));
147 EXPECT_EQ("site2.com", sample);
148 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
149 }
150
151 {
152 std::string sample;
153 rappor::RapporType type;
154 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric(
155 "NTP.SuggestionsImpressions.IconsGray", &sample, &type));
156 EXPECT_EQ("site3.com", sample);
157 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type);
158 }
159 }
160
161 } // namespace
162 } // namespace metrics
163 } // namespace ntp_tiles
OLDNEW
« no previous file with comments | « components/ntp_tiles/metrics.cc ('k') | tools/metrics/rappor/rappor.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698