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

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

Issue 2687393004: Gather stability prefs into managing objects. (Closed)
Patch Set: Remove unused method 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 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_service.h" 5 #include "components/metrics/metrics_service.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
11 11
12 #include "base/bind.h" 12 #include "base/bind.h"
13 #include "base/macros.h" 13 #include "base/macros.h"
14 #include "base/message_loop/message_loop.h" 14 #include "base/message_loop/message_loop.h"
15 #include "base/metrics/metrics_hashes.h" 15 #include "base/metrics/metrics_hashes.h"
16 #include "base/metrics/statistics_recorder.h" 16 #include "base/metrics/statistics_recorder.h"
17 #include "base/metrics/user_metrics.h" 17 #include "base/metrics/user_metrics.h"
18 #include "base/test/scoped_feature_list.h" 18 #include "base/test/scoped_feature_list.h"
19 #include "base/test/test_simple_task_runner.h" 19 #include "base/test/test_simple_task_runner.h"
20 #include "base/threading/platform_thread.h" 20 #include "base/threading/platform_thread.h"
21 #include "base/threading/thread_task_runner_handle.h" 21 #include "base/threading/thread_task_runner_handle.h"
22 #include "components/metrics/client_info.h" 22 #include "components/metrics/client_info.h"
23 #include "components/metrics/environment_recorder.h"
23 #include "components/metrics/metrics_log.h" 24 #include "components/metrics/metrics_log.h"
24 #include "components/metrics/metrics_pref_names.h" 25 #include "components/metrics/metrics_pref_names.h"
25 #include "components/metrics/metrics_state_manager.h" 26 #include "components/metrics/metrics_state_manager.h"
27 #include "components/metrics/stability_pref_names.h"
26 #include "components/metrics/test_enabled_state_provider.h" 28 #include "components/metrics/test_enabled_state_provider.h"
27 #include "components/metrics/test_metrics_provider.h" 29 #include "components/metrics/test_metrics_provider.h"
28 #include "components/metrics/test_metrics_service_client.h" 30 #include "components/metrics/test_metrics_service_client.h"
29 #include "components/prefs/testing_pref_service.h" 31 #include "components/prefs/testing_pref_service.h"
30 #include "components/variations/metrics_util.h" 32 #include "components/variations/metrics_util.h"
31 #include "testing/gtest/include/gtest/gtest.h" 33 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/zlib/google/compression_utils.h" 34 #include "third_party/zlib/google/compression_utils.h"
33 35
34 namespace metrics { 36 namespace metrics {
35 37
(...skipping 168 matching lines...) Expand 10 before | Expand all | Expand 10 after
204 206
205 // Save an existing system profile to prefs, to correspond to what would be 207 // Save an existing system profile to prefs, to correspond to what would be
206 // saved from a previous session. 208 // saved from a previous session.
207 TestMetricsServiceClient client; 209 TestMetricsServiceClient client;
208 TestMetricsLog log("client", 1, &client, GetLocalState()); 210 TestMetricsLog log("client", 1, &client, GetLocalState());
209 log.RecordEnvironment(std::vector<MetricsProvider*>(), 211 log.RecordEnvironment(std::vector<MetricsProvider*>(),
210 std::vector<variations::ActiveGroupId>(), 0, 0); 212 std::vector<variations::ActiveGroupId>(), 0, 0);
211 213
212 // Record stability build time and version from previous session, so that 214 // Record stability build time and version from previous session, so that
213 // stability metrics (including exited cleanly flag) won't be cleared. 215 // stability metrics (including exited cleanly flag) won't be cleared.
214 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 216 EnvironmentRecorder(GetLocalState())
215 MetricsLog::GetBuildTime()); 217 .SetBuildtimeAndVersion(MetricsLog::GetBuildTime(),
216 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 218 client.GetVersionString());
217 client.GetVersionString());
218 219
219 // Set the clean exit flag, as that will otherwise cause a stabilty 220 // Set the clean exit flag, as that will otherwise cause a stabilty
220 // log to be produced, irrespective provider requests. 221 // log to be produced, irrespective provider requests.
221 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); 222 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true);
222 223
223 TestMetricsService service( 224 TestMetricsService service(
224 GetMetricsStateManager(), &client, GetLocalState()); 225 GetMetricsStateManager(), &client, GetLocalState());
225 // Add a metrics provider that requests a stability log. 226 // Add a metrics provider that requests a stability log.
226 TestMetricsProvider* test_provider = new TestMetricsProvider(); 227 TestMetricsProvider* test_provider = new TestMetricsProvider();
227 test_provider->set_has_initial_stability_metrics(true); 228 test_provider->set_has_initial_stability_metrics(true);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 277
277 // Save an existing system profile to prefs, to correspond to what would be 278 // Save an existing system profile to prefs, to correspond to what would be
278 // saved from a previous session. 279 // saved from a previous session.
279 TestMetricsServiceClient client; 280 TestMetricsServiceClient client;
280 TestMetricsLog log("client", 1, &client, GetLocalState()); 281 TestMetricsLog log("client", 1, &client, GetLocalState());
281 log.RecordEnvironment(std::vector<MetricsProvider*>(), 282 log.RecordEnvironment(std::vector<MetricsProvider*>(),
282 std::vector<variations::ActiveGroupId>(), 0, 0); 283 std::vector<variations::ActiveGroupId>(), 0, 0);
283 284
284 // Record stability build time and version from previous session, so that 285 // Record stability build time and version from previous session, so that
285 // stability metrics (including exited cleanly flag) won't be cleared. 286 // stability metrics (including exited cleanly flag) won't be cleared.
286 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 287 EnvironmentRecorder(GetLocalState())
287 MetricsLog::GetBuildTime()); 288 .SetBuildtimeAndVersion(MetricsLog::GetBuildTime(),
288 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 289 client.GetVersionString());
289 client.GetVersionString());
290 290
291 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); 291 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false);
292 292
293 TestMetricsService service( 293 TestMetricsService service(
294 GetMetricsStateManager(), &client, GetLocalState()); 294 GetMetricsStateManager(), &client, GetLocalState());
295 // Add a provider. 295 // Add a provider.
296 TestMetricsProvider* test_provider = new TestMetricsProvider(); 296 TestMetricsProvider* test_provider = new TestMetricsProvider();
297 service.RegisterMetricsProvider( 297 service.RegisterMetricsProvider(
298 std::unique_ptr<MetricsProvider>(test_provider)); 298 std::unique_ptr<MetricsProvider>(test_provider));
299 service.InitializeMetricsRecordingState(); 299 service.InitializeMetricsRecordingState();
(...skipping 247 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 client.uploader()->CompleteUpload(200); 547 client.uploader()->CompleteUpload(200);
548 EXPECT_FALSE(client.uploader()->is_uploading()); 548 EXPECT_FALSE(client.uploader()->is_uploading());
549 EXPECT_EQ(1U, task_runner_->NumPendingTasks()); 549 EXPECT_EQ(1U, task_runner_->NumPendingTasks());
550 // Upload should start. 550 // Upload should start.
551 task_runner_->RunPendingTasks(); 551 task_runner_->RunPendingTasks();
552 EXPECT_TRUE(client.uploader()->is_uploading()); 552 EXPECT_TRUE(client.uploader()->is_uploading());
553 EXPECT_EQ(0U, task_runner_->NumPendingTasks()); 553 EXPECT_EQ(0U, task_runner_->NumPendingTasks());
554 } 554 }
555 555
556 } // namespace metrics 556 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698