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

Side by Side Diff: components/metrics/metrics_log_manager_unittest.cc

Issue 2588873002: Delegate PersistedLogs metrics recording (Closed)
Patch Set: Fix tests Created 3 years, 11 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
« no previous file with comments | « components/metrics/metrics_log_manager.cc ('k') | components/metrics/persisted_logs.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/metrics/metrics_log_manager.h" 5 #include "components/metrics/metrics_log_manager.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 8
9 #include <string> 9 #include <string>
10 #include <utility> 10 #include <utility>
11 #include <vector> 11 #include <vector>
12 12
13 #include "base/memory/ptr_util.h" 13 #include "base/memory/ptr_util.h"
14 #include "components/metrics/metrics_log.h" 14 #include "components/metrics/metrics_log.h"
15 #include "components/metrics/metrics_pref_names.h" 15 #include "components/metrics/metrics_pref_names.h"
16 #include "components/metrics/persisted_logs_metrics_impl.h"
16 #include "components/metrics/test_metrics_service_client.h" 17 #include "components/metrics/test_metrics_service_client.h"
17 #include "components/prefs/pref_registry_simple.h" 18 #include "components/prefs/pref_registry_simple.h"
18 #include "components/prefs/testing_pref_service.h" 19 #include "components/prefs/testing_pref_service.h"
19 #include "testing/gtest/include/gtest/gtest.h" 20 #include "testing/gtest/include/gtest/gtest.h"
20 21
21 namespace metrics { 22 namespace metrics {
22 23
23 namespace { 24 namespace {
24 25
25 // Dummy serializer that just stores logs in memory. 26 // Dummy serializer that just stores logs in memory.
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
156 TestLogPrefService pref_service; 157 TestLogPrefService pref_service;
157 // Set up some in-progress logging in a scoped log manager simulating the 158 // Set up some in-progress logging in a scoped log manager simulating the
158 // leadup to quitting, then persist as would be done on quit. 159 // leadup to quitting, then persist as would be done on quit.
159 { 160 {
160 MetricsLogManager log_manager(&pref_service, 0); 161 MetricsLogManager log_manager(&pref_service, 0);
161 log_manager.LoadPersistedUnsentLogs(); 162 log_manager.LoadPersistedUnsentLogs();
162 163
163 // Simulate a log having already been unsent from a previous session. 164 // Simulate a log having already been unsent from a previous session.
164 { 165 {
165 std::string log("proto"); 166 std::string log("proto");
166 PersistedLogs ongoing_logs(&pref_service, prefs::kMetricsOngoingLogs, 167 PersistedLogs ongoing_logs(std::unique_ptr<PersistedLogsMetricsImpl>(
168 new PersistedLogsMetricsImpl()),
169 &pref_service, prefs::kMetricsOngoingLogs,
167 prefs::kDeprecatedMetricsOngoingLogs, 1, 1, 0); 170 prefs::kDeprecatedMetricsOngoingLogs, 1, 1, 0);
168 ongoing_logs.StoreLog(log); 171 ongoing_logs.StoreLog(log);
169 ongoing_logs.SerializeLogs(); 172 ongoing_logs.SerializeLogs();
170 } 173 }
171 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); 174 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG));
172 EXPECT_FALSE(log_manager.has_unsent_logs()); 175 EXPECT_FALSE(log_manager.has_unsent_logs());
173 log_manager.LoadPersistedUnsentLogs(); 176 log_manager.LoadPersistedUnsentLogs();
174 EXPECT_TRUE(log_manager.has_unsent_logs()); 177 EXPECT_TRUE(log_manager.has_unsent_logs());
175 178
176 log_manager.BeginLoggingWithLog(base::MakeUnique<MetricsLog>( 179 log_manager.BeginLoggingWithLog(base::MakeUnique<MetricsLog>(
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
298 log_manager.FinishCurrentLog(); 301 log_manager.FinishCurrentLog();
299 log_manager.DiscardStagedLog(); 302 log_manager.DiscardStagedLog();
300 303
301 log_manager.PersistUnsentLogs(); 304 log_manager.PersistUnsentLogs();
302 EXPECT_EQ(0U, pref_service.TypeCount(MetricsLog::INITIAL_STABILITY_LOG)); 305 EXPECT_EQ(0U, pref_service.TypeCount(MetricsLog::INITIAL_STABILITY_LOG));
303 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG)); 306 EXPECT_EQ(1U, pref_service.TypeCount(MetricsLog::ONGOING_LOG));
304 } 307 }
305 } 308 }
306 309
307 } // namespace metrics 310 } // namespace metrics
OLDNEW
« no previous file with comments | « components/metrics/metrics_log_manager.cc ('k') | components/metrics/persisted_logs.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698