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

Side by Side Diff: chrome/browser/ui/webui/ntp/ntp_user_data_logger_unittest.cc

Issue 2696223004: Desktop NTP: Add a UMA metric NewTabPage.TilesReceivedTime (Closed)
Patch Set: histograms.xml Created 3 years, 10 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h" 5 #include "chrome/browser/ui/webui/ntp/ntp_user_data_logger.h"
6 6
7 #include <memory> 7 #include <memory>
8 #include <string> 8 #include <string>
9 #include <vector> 9 #include <vector>
10 10
11 #include "base/metrics/histogram.h" 11 #include "base/metrics/histogram.h"
12 #include "base/metrics/statistics_recorder.h" 12 #include "base/metrics/statistics_recorder.h"
13 #include "base/test/histogram_tester.h" 13 #include "base/test/histogram_tester.h"
14 #include "chrome/common/search/ntp_logging_events.h" 14 #include "chrome/common/search/ntp_logging_events.h"
15 #include "testing/gmock/include/gmock/gmock.h" 15 #include "testing/gmock/include/gmock/gmock.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using base::Bucket; 18 using base::Bucket;
19 using ntp_tiles::NTPTileSource; 19 using ntp_tiles::NTPTileSource;
20 using testing::ElementsAre; 20 using testing::ElementsAre;
21 using testing::IsEmpty; 21 using testing::IsEmpty;
22 using testing::SizeIs;
22 23
23 namespace { 24 namespace {
24 25
25 using Sample = base::HistogramBase::Sample; 26 using Sample = base::HistogramBase::Sample;
26 using Samples = std::vector<Sample>; 27 using Samples = std::vector<Sample>;
27 28
28 class TestNTPUserDataLogger : public NTPUserDataLogger { 29 class TestNTPUserDataLogger : public NTPUserDataLogger {
29 public: 30 public:
30 TestNTPUserDataLogger() : NTPUserDataLogger(nullptr) {} 31 TestNTPUserDataLogger() : NTPUserDataLogger(nullptr) {}
31 ~TestNTPUserDataLogger() override {} 32 ~TestNTPUserDataLogger() override {}
(...skipping 172 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 EXPECT_THAT( 205 EXPECT_THAT(
205 histogram_tester.GetAllSamples("NewTabPage.MostVisited"), 206 histogram_tester.GetAllSamples("NewTabPage.MostVisited"),
206 ElementsAre(Bucket(0, 2), Bucket(1, 2), Bucket(2, 2), Bucket(3, 2))); 207 ElementsAre(Bucket(0, 2), Bucket(1, 2), Bucket(2, 2), Bucket(3, 2)));
207 EXPECT_THAT( 208 EXPECT_THAT(
208 histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"), 209 histogram_tester.GetAllSamples("NewTabPage.MostVisited.server"),
209 ElementsAre(Bucket(0, 2), Bucket(1, 1), Bucket(2, 1))); 210 ElementsAre(Bucket(0, 2), Bucket(1, 1), Bucket(2, 1)));
210 EXPECT_THAT( 211 EXPECT_THAT(
211 histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"), 212 histogram_tester.GetAllSamples("NewTabPage.MostVisited.client"),
212 ElementsAre(Bucket(1, 1), Bucket(2, 1), Bucket(3, 2))); 213 ElementsAre(Bucket(1, 1), Bucket(2, 1), Bucket(3, 2)));
213 } 214 }
215
216 TEST(NTPUserDataLoggerTest, TestLoadTime) {
217 base::StatisticsRecorder::Initialize();
218
219 base::HistogramTester histogram_tester;
220
221 TestNTPUserDataLogger logger;
222 logger.ntp_url_ = GURL("chrome://newtab/");
223
224 base::TimeDelta delta_tiles_received = base::TimeDelta::FromMilliseconds(10);
225 base::TimeDelta delta_tiles_loaded = base::TimeDelta::FromMilliseconds(100);
226
227 // Send the ALL_TILES_RECEIVED event.
228 logger.LogEvent(NTP_ALL_TILES_RECEIVED, delta_tiles_received);
229
230 // The actual histograms are emitted only after the ALL_TILES_LOADED event, so
231 // at this point everything should still be empty.
sfiera 2017/02/16 14:35:33 Is this something we actually care about testing?
Marc Treib 2017/02/16 15:13:09 Good point. Removed.
232 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TilesReceivedTime"),
233 IsEmpty());
234 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime"), IsEmpty());
235
236 // Log a TOP_SITES impression (for the .MostVisited vs .MostLikely split in
237 // the LoadTime histogram).
238 logger.LogMostVisitedImpression(0, NTPTileSource::TOP_SITES);
239
240 // Send the ALL_TILES_LOADED event, this should trigger emitting histograms.
241 logger.LogEvent(NTP_ALL_TILES_LOADED, delta_tiles_loaded);
242
243 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TilesReceivedTime"),
244 SizeIs(1));
245 EXPECT_THAT(histogram_tester.GetAllSamples(
246 "NewTabPage.TilesReceivedTime.MostVisited"),
247 SizeIs(1));
248 EXPECT_THAT(
249 histogram_tester.GetAllSamples("NewTabPage.TilesReceivedTime.MostLikely"),
250 IsEmpty());
251 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime"), SizeIs(1));
252 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime.MostVisited"),
253 SizeIs(1));
254 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime.MostLikely"),
255 IsEmpty());
256
257 histogram_tester.ExpectTimeBucketCount("NewTabPage.TilesReceivedTime",
258 delta_tiles_received, 1);
259 histogram_tester.ExpectTimeBucketCount(
260 "NewTabPage.TilesReceivedTime.MostVisited", delta_tiles_received, 1);
261 histogram_tester.ExpectTimeBucketCount("NewTabPage.LoadTime",
262 delta_tiles_loaded, 1);
263 histogram_tester.ExpectTimeBucketCount("NewTabPage.LoadTime.MostVisited",
264 delta_tiles_loaded, 1);
265
266 // We should not log again for the same NTP.
267 logger.LogEvent(NTP_ALL_TILES_RECEIVED, delta_tiles_received);
268 logger.LogEvent(NTP_ALL_TILES_LOADED, delta_tiles_loaded);
269 histogram_tester.ExpectTimeBucketCount("NewTabPage.TilesReceivedTime",
270 delta_tiles_received, 1);
271 histogram_tester.ExpectTimeBucketCount("NewTabPage.LoadTime",
272 delta_tiles_loaded, 1);
273
274 // After navigating away from the NTP and back, we record again.
275 logger.NavigatedFromURLToURL(GURL("chrome://newtab/"),
276 GURL("http://chromium.org"));
277 logger.NavigatedFromURLToURL(GURL("http://chromium.org"),
278 GURL("chrome://newtab/"));
279
280 // This time, log a SUGGESTIONS_SERVICE impression, so the load time will end
281 // up in .MostLikely.
282 logger.LogMostVisitedImpression(0, NTPTileSource::SUGGESTIONS_SERVICE);
283
284 base::TimeDelta delta_tiles_received2 = base::TimeDelta::FromMilliseconds(50);
285 base::TimeDelta delta_tiles_loaded2 = base::TimeDelta::FromMilliseconds(500);
286 logger.LogEvent(NTP_ALL_TILES_RECEIVED, delta_tiles_received2);
287 logger.LogEvent(NTP_ALL_TILES_LOADED, delta_tiles_loaded2);
288
289 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.TilesReceivedTime"),
290 SizeIs(2));
291 EXPECT_THAT(histogram_tester.GetAllSamples(
292 "NewTabPage.TilesReceivedTime.MostVisited"),
293 SizeIs(1));
294 EXPECT_THAT(
295 histogram_tester.GetAllSamples("NewTabPage.TilesReceivedTime.MostLikely"),
296 SizeIs(1));
297 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime"), SizeIs(2));
298 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime.MostVisited"),
299 SizeIs(1));
300 EXPECT_THAT(histogram_tester.GetAllSamples("NewTabPage.LoadTime.MostLikely"),
301 SizeIs(1));
302
303 histogram_tester.ExpectTimeBucketCount("NewTabPage.TilesReceivedTime",
304 delta_tiles_received2, 1);
305 histogram_tester.ExpectTimeBucketCount(
306 "NewTabPage.TilesReceivedTime.MostLikely", delta_tiles_received2, 1);
307 histogram_tester.ExpectTimeBucketCount("NewTabPage.LoadTime",
308 delta_tiles_loaded2, 1);
309 histogram_tester.ExpectTimeBucketCount("NewTabPage.LoadTime.MostLikely",
310 delta_tiles_loaded2, 1);
311 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698