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

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

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

Powered by Google App Engine
This is Rietveld 408576698