OLD | NEW |
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 "base/metrics/histogram.h" | 7 #include "base/metrics/histogram.h" |
8 #include "base/metrics/statistics_recorder.h" | 8 #include "base/metrics/statistics_recorder.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/search/ntp_logging_events.h" | 10 #include "chrome/common/search/ntp_logging_events.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 | 45 |
46 // Enusure non-zero statistics. | 46 // Enusure non-zero statistics. |
47 TestNTPUserDataLogger logger; | 47 TestNTPUserDataLogger logger; |
48 | 48 |
49 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(0); | 49 base::TimeDelta delta = base::TimeDelta::FromMilliseconds(0); |
50 | 50 |
51 for (int i = 0; i < 8; ++i) | 51 for (int i = 0; i < 8; ++i) |
52 logger.LogEvent(NTP_TILE, delta); | 52 logger.LogEvent(NTP_TILE, delta); |
53 logger.LogEvent(NTP_SERVER_SIDE_SUGGESTION, delta); | 53 logger.LogEvent(NTP_SERVER_SIDE_SUGGESTION, delta); |
54 | 54 |
55 logger.EmitNtpStatistics(NTPUserDataLogger::EmitReason::NAVIGATED_AWAY); | 55 logger.LogEvent(NTP_ALL_TILES_LOADED, delta); |
56 | 56 |
57 EXPECT_EQ(1, GetTotalCount("NewTabPage.NumberOfTiles")); | 57 EXPECT_EQ(1, GetTotalCount("NewTabPage.NumberOfTiles")); |
58 EXPECT_EQ(1, GetBinCount("NewTabPage.NumberOfTiles", 8)); | 58 EXPECT_EQ(1, GetBinCount("NewTabPage.NumberOfTiles", 8)); |
59 | 59 |
60 // Statistics should be reset to 0, so we should not log anything else. | 60 // Statistics should be reset to 0, so we should not log anything else. |
61 logger.EmitNtpStatistics(NTPUserDataLogger::EmitReason::NAVIGATED_AWAY); | 61 logger.LogEvent(NTP_ALL_TILES_LOADED, delta); |
62 EXPECT_EQ(1, GetTotalCount("NewTabPage.NumberOfTiles")); | 62 EXPECT_EQ(1, GetTotalCount("NewTabPage.NumberOfTiles")); |
63 } | 63 } |
64 | 64 |
65 TEST_F(NTPUserDataLoggerTest, TestLogMostVisitedImpression) { | 65 TEST_F(NTPUserDataLoggerTest, TestLogMostVisitedImpression) { |
66 base::StatisticsRecorder::Initialize(); | 66 base::StatisticsRecorder::Initialize(); |
67 | 67 |
68 EXPECT_EQ(0, GetTotalCount("NewTabPage.SuggestionsImpression")); | 68 EXPECT_EQ(0, GetTotalCount("NewTabPage.SuggestionsImpression")); |
69 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.server", 1)); | 69 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.server", 1)); |
70 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.server", 5)); | 70 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.server", 5)); |
71 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.client", 1)); | 71 EXPECT_EQ(0, GetBinCount("NewTabPage.SuggestionsImpression.client", 1)); |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 1)); | 134 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 1)); |
135 EXPECT_EQ(0, GetBinCount("NewTabPage.MostVisited.client", 5)); | 135 EXPECT_EQ(0, GetBinCount("NewTabPage.MostVisited.client", 5)); |
136 | 136 |
137 logger.LogMostVisitedNavigation(5, NTPLoggingTileSource::CLIENT); | 137 logger.LogMostVisitedNavigation(5, NTPLoggingTileSource::CLIENT); |
138 EXPECT_EQ(4, GetTotalCount("NewTabPage.MostVisited")); | 138 EXPECT_EQ(4, GetTotalCount("NewTabPage.MostVisited")); |
139 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.server", 1)); | 139 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.server", 1)); |
140 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.server", 5)); | 140 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.server", 5)); |
141 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 1)); | 141 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 1)); |
142 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 5)); | 142 EXPECT_EQ(1, GetBinCount("NewTabPage.MostVisited.client", 5)); |
143 } | 143 } |
OLD | NEW |