OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 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 | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/ntp_tiles/metrics.h" | 5 #include "components/ntp_tiles/metrics.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <string> | 9 #include <string> |
10 #include <vector> | 10 #include <vector> |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1), | 83 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1), |
84 base::Bucket(/*min=*/4, /*count=*/1), | 84 base::Bucket(/*min=*/4, /*count=*/1), |
85 base::Bucket(/*min=*/7, /*count=*/1))); | 85 base::Bucket(/*min=*/7, /*count=*/1))); |
86 EXPECT_THAT(histogram_tester.GetAllSamples( | 86 EXPECT_THAT(histogram_tester.GetAllSamples( |
87 "NewTabPage.SuggestionsImpression.IconsGray"), | 87 "NewTabPage.SuggestionsImpression.IconsGray"), |
88 ElementsAre(base::Bucket(/*min=*/6, /*count=*/1))); | 88 ElementsAre(base::Bucket(/*min=*/6, /*count=*/1))); |
89 } | 89 } |
90 | 90 |
91 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) { | 91 TEST(RecordPageImpressionTest, ShouldRecordUmaForThumbnails) { |
92 base::HistogramTester histogram_tester; | 92 base::HistogramTester histogram_tester; |
93 RecordPageImpression({{TileSource::TOP_SITES, THUMBNAIL, GURL()}, | 93 RecordPageImpression({{TileSource::TOP_SITES, THUMBNAIL_FAILED, GURL()}, |
94 {TileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, | 94 {TileSource::SUGGESTIONS_SERVICE, THUMBNAIL, GURL()}, |
95 {TileSource::POPULAR, THUMBNAIL, GURL()}}, | 95 {TileSource::POPULAR, THUMBNAIL, GURL()}}, |
96 /*rappor_service=*/nullptr); | 96 /*rappor_service=*/nullptr); |
97 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), | 97 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.NumberOfTiles"), |
98 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 98 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
99 EXPECT_THAT( | 99 EXPECT_THAT( |
100 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), | 100 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression"), |
101 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), | 101 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1), |
102 base::Bucket(/*min=*/1, /*count=*/1), | 102 base::Bucket(/*min=*/1, /*count=*/1), |
103 base::Bucket(/*min=*/2, /*count=*/1))); | 103 base::Bucket(/*min=*/2, /*count=*/1))); |
104 EXPECT_THAT( | 104 EXPECT_THAT( |
105 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"), | 105 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.server"), |
106 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); | 106 ElementsAre(base::Bucket(/*min=*/1, /*count=*/1))); |
107 EXPECT_THAT( | 107 EXPECT_THAT( |
108 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"), | 108 histogram_tester.GetAllSamples("NewTabPage.SuggestionsImpression.client"), |
109 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); | 109 ElementsAre(base::Bucket(/*min=*/0, /*count=*/1))); |
110 EXPECT_THAT(histogram_tester.GetAllSamples( | 110 EXPECT_THAT(histogram_tester.GetAllSamples( |
111 "NewTabPage.SuggestionsImpression.popular"), | 111 "NewTabPage.SuggestionsImpression.popular"), |
112 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1))); | 112 ElementsAre(base::Bucket(/*min=*/2, /*count=*/1))); |
113 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), IsEmpty()); | 113 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType"), |
| 114 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/2), |
| 115 base::Bucket(/*min=*/THUMBNAIL_FAILED, /*count=*/1))); |
114 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), | 116 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.server"), |
115 IsEmpty()); | 117 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/1))); |
116 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), | 118 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.client"), |
117 IsEmpty()); | 119 ElementsAre(base::Bucket(/*min=*/THUMBNAIL_FAILED, /*count=*/1))); |
118 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), | 120 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TileType.popular"), |
119 IsEmpty()); | 121 ElementsAre(base::Bucket(/*min=*/THUMBNAIL, /*count=*/1))); |
120 EXPECT_THAT(histogram_tester.GetAllSamples( | 122 EXPECT_THAT(histogram_tester.GetAllSamples( |
121 "NewTabPage.SuggestionsImpression.IconsReal"), | 123 "NewTabPage.SuggestionsImpression.IconsReal"), |
122 IsEmpty()); | 124 IsEmpty()); |
123 EXPECT_THAT(histogram_tester.GetAllSamples( | 125 EXPECT_THAT(histogram_tester.GetAllSamples( |
124 "NewTabPage.SuggestionsImpression.IconsColor"), | 126 "NewTabPage.SuggestionsImpression.IconsColor"), |
125 IsEmpty()); | 127 IsEmpty()); |
126 EXPECT_THAT(histogram_tester.GetAllSamples( | 128 EXPECT_THAT(histogram_tester.GetAllSamples( |
127 "NewTabPage.SuggestionsImpression.IconsGray"), | 129 "NewTabPage.SuggestionsImpression.IconsGray"), |
128 IsEmpty()); | 130 IsEmpty()); |
129 } | 131 } |
130 | 132 |
131 TEST(RecordTileClickTest, ShouldRecordUma) { | 133 TEST(RecordTileClickTest, ShouldRecordUmaForIcon) { |
132 base::HistogramTester histogram_tester; | 134 base::HistogramTester histogram_tester; |
133 RecordTileClick(3, TileSource::TOP_SITES, ICON_REAL); | 135 RecordTileClick(3, TileSource::TOP_SITES, ICON_REAL); |
| 136 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited"), |
| 137 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
134 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), | 138 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), |
135 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 139 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
136 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), | 140 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), |
137 IsEmpty()); | 141 IsEmpty()); |
138 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), | 142 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), |
139 IsEmpty()); | 143 IsEmpty()); |
140 EXPECT_THAT( | 144 EXPECT_THAT( |
141 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), | 145 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), |
142 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); | 146 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
143 EXPECT_THAT( | 147 EXPECT_THAT( |
144 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), | 148 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), |
145 IsEmpty()); | 149 IsEmpty()); |
146 EXPECT_THAT( | 150 EXPECT_THAT( |
147 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), | 151 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), |
148 IsEmpty()); | 152 IsEmpty()); |
| 153 EXPECT_THAT( |
| 154 histogram_tester.GetAllSamples("NewTabPage.MostVisited.Thumbnail"), |
| 155 IsEmpty()); |
| 156 EXPECT_THAT( |
| 157 histogram_tester.GetAllSamples("NewTabPage.MostVisited.ThumbnailFailed"), |
| 158 IsEmpty()); |
149 } | 159 } |
150 | 160 |
151 TEST(RecordTileClickTest, ShouldIgnoreThumbnails) { | 161 TEST(RecordTileClickTest, ShouldRecordUmaForThumbnail) { |
152 base::HistogramTester histogram_tester; | 162 base::HistogramTester histogram_tester; |
153 RecordTileClick(3, TileSource::TOP_SITES, THUMBNAIL); | 163 RecordTileClick(3, TileSource::TOP_SITES, THUMBNAIL); |
| 164 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited"), |
| 165 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 166 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), |
| 167 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 168 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), |
| 169 IsEmpty()); |
| 170 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), |
| 171 IsEmpty()); |
154 EXPECT_THAT( | 172 EXPECT_THAT( |
155 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), | 173 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), |
156 IsEmpty()); | 174 IsEmpty()); |
| 175 EXPECT_THAT( |
| 176 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), |
| 177 IsEmpty()); |
| 178 EXPECT_THAT( |
| 179 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), |
| 180 IsEmpty()); |
| 181 EXPECT_THAT( |
| 182 histogram_tester.GetAllSamples("NewTabPage.MostVisited.Thumbnail"), |
| 183 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 184 EXPECT_THAT( |
| 185 histogram_tester.GetAllSamples("NewTabPage.MostVisited.ThumbnailFailed"), |
| 186 IsEmpty()); |
| 187 } |
| 188 |
| 189 TEST(RecordTileClickTest, ShouldNotRecordUnknownTileType) { |
| 190 base::HistogramTester histogram_tester; |
| 191 RecordTileClick(3, TileSource::TOP_SITES, UNKNOWN_TILE_TYPE); |
| 192 // The click should still get recorded. |
| 193 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited"), |
| 194 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 195 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), |
| 196 ElementsAre(base::Bucket(/*min=*/3, /*count=*/1))); |
| 197 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), |
| 198 IsEmpty()); |
| 199 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.MostVisited.popular"), |
| 200 IsEmpty()); |
| 201 // But all of the tile type histograms should be empty. |
| 202 EXPECT_THAT( |
| 203 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsReal"), |
| 204 IsEmpty()); |
157 EXPECT_THAT( | 205 EXPECT_THAT( |
158 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), | 206 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsColor"), |
159 IsEmpty()); | 207 IsEmpty()); |
160 EXPECT_THAT( | 208 EXPECT_THAT( |
161 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), | 209 histogram_tester.GetAllSamples("NewTabPage.MostVisited.IconsGray"), |
162 IsEmpty()); | 210 IsEmpty()); |
| 211 EXPECT_THAT( |
| 212 histogram_tester.GetAllSamples("NewTabPage.MostVisited.Thumbnail"), |
| 213 IsEmpty()); |
| 214 EXPECT_THAT( |
| 215 histogram_tester.GetAllSamples("NewTabPage.MostVisited.ThumbnailFailed"), |
| 216 IsEmpty()); |
163 } | 217 } |
164 | 218 |
165 TEST(RecordPageImpressionTest, ShouldRecordRappor) { | 219 TEST(RecordPageImpressionTest, ShouldRecordRappor) { |
166 rappor::TestRapporServiceImpl rappor_service; | 220 rappor::TestRapporServiceImpl rappor_service; |
167 | 221 |
168 RecordPageImpression( | 222 RecordPageImpression( |
169 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, | 223 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.site1.com/")}, |
170 {TileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, | 224 {TileSource::TOP_SITES, ICON_COLOR, GURL("http://www.site2.com/")}, |
171 {TileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}, | 225 {TileSource::TOP_SITES, ICON_DEFAULT, GURL("http://www.site3.com/")}}, |
172 {TileSource::TOP_SITES, THUMBNAIL, GURL("http://www.site4.com/")}}, | |
173 &rappor_service); | 226 &rappor_service); |
174 | 227 |
175 // Thumbnail shouldn't get reported. | |
176 EXPECT_EQ(3, rappor_service.GetReportsCount()); | 228 EXPECT_EQ(3, rappor_service.GetReportsCount()); |
177 | 229 |
178 { | 230 { |
179 std::string sample; | 231 std::string sample; |
180 rappor::RapporType type; | 232 rappor::RapporType type; |
181 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 233 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
182 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); | 234 "NTP.SuggestionsImpressions.IconsReal", &sample, &type)); |
183 EXPECT_EQ("site1.com", sample); | 235 EXPECT_EQ("site1.com", sample); |
184 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 236 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
185 } | 237 } |
(...skipping 10 matching lines...) Expand all Loading... |
196 { | 248 { |
197 std::string sample; | 249 std::string sample; |
198 rappor::RapporType type; | 250 rappor::RapporType type; |
199 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( | 251 EXPECT_TRUE(rappor_service.GetRecordedSampleForMetric( |
200 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); | 252 "NTP.SuggestionsImpressions.IconsGray", &sample, &type)); |
201 EXPECT_EQ("site3.com", sample); | 253 EXPECT_EQ("site3.com", sample); |
202 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); | 254 EXPECT_EQ(rappor::ETLD_PLUS_ONE_RAPPOR_TYPE, type); |
203 } | 255 } |
204 } | 256 } |
205 | 257 |
| 258 TEST(RecordPageImpressionTest, ShouldNotRecordRapporForUnknownTileType) { |
| 259 rappor::TestRapporServiceImpl rappor_service; |
| 260 |
| 261 RecordPageImpression( |
| 262 {{TileSource::TOP_SITES, ICON_REAL, GURL("http://www.s1.com/")}, |
| 263 {TileSource::TOP_SITES, UNKNOWN_TILE_TYPE, GURL("http://www.s2.com/")}}, |
| 264 &rappor_service); |
| 265 |
| 266 // Unknown tile type shouldn't get reported. |
| 267 EXPECT_EQ(1, rappor_service.GetReportsCount()); |
| 268 } |
| 269 |
206 } // namespace | 270 } // namespace |
207 } // namespace metrics | 271 } // namespace metrics |
208 } // namespace ntp_tiles | 272 } // namespace ntp_tiles |
OLD | NEW |