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

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

Issue 1859213002: Move the thread hop for UMA user actions from content:: to base::. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing Chromecast (I hope!) Created 4 years, 8 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 <string> 9 #include <string>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/macros.h" 12 #include "base/macros.h"
13 #include "base/memory/scoped_ptr.h" 13 #include "base/memory/scoped_ptr.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/user_metrics.h"
16 #include "base/metrics/statistics_recorder.h" 17 #include "base/metrics/statistics_recorder.h"
17 #include "base/threading/platform_thread.h" 18 #include "base/threading/platform_thread.h"
18 #include "components/metrics/client_info.h" 19 #include "components/metrics/client_info.h"
19 #include "components/metrics/metrics_log.h" 20 #include "components/metrics/metrics_log.h"
20 #include "components/metrics/metrics_pref_names.h" 21 #include "components/metrics/metrics_pref_names.h"
21 #include "components/metrics/metrics_state_manager.h" 22 #include "components/metrics/metrics_state_manager.h"
22 #include "components/metrics/test_metrics_provider.h" 23 #include "components/metrics/test_metrics_provider.h"
23 #include "components/metrics/test_metrics_service_client.h" 24 #include "components/metrics/test_metrics_service_client.h"
24 #include "components/prefs/testing_pref_service.h" 25 #include "components/prefs/testing_pref_service.h"
25 #include "components/variations/metrics_util.h" 26 #include "components/variations/metrics_util.h"
(...skipping 136 matching lines...) Expand 10 before | Expand all | Expand 10 after
162 DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest); 163 DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest);
163 }; 164 };
164 165
165 } // namespace 166 } // namespace
166 167
167 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { 168 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) {
168 EnableMetricsReporting(); 169 EnableMetricsReporting();
169 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); 170 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true);
170 171
171 TestMetricsServiceClient client; 172 TestMetricsServiceClient client;
173 base::ResetRecordActionTaskRunnerForTesting();
172 TestMetricsService service( 174 TestMetricsService service(
173 GetMetricsStateManager(), &client, GetLocalState()); 175 GetMetricsStateManager(), &client, GetLocalState());
174 176
175 TestMetricsProvider* test_provider = new TestMetricsProvider(); 177 TestMetricsProvider* test_provider = new TestMetricsProvider();
176 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 178 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
177 179
178 service.InitializeMetricsRecordingState(); 180 service.InitializeMetricsRecordingState();
179 // No initial stability log should be generated. 181 // No initial stability log should be generated.
180 EXPECT_FALSE(service.log_manager()->has_unsent_logs()); 182 EXPECT_FALSE(service.log_manager()->has_unsent_logs());
181 EXPECT_FALSE(service.log_manager()->has_staged_log()); 183 EXPECT_FALSE(service.log_manager()->has_staged_log());
(...skipping 18 matching lines...) Expand all
200 // stability metrics (including exited cleanly flag) won't be cleared. 202 // stability metrics (including exited cleanly flag) won't be cleared.
201 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 203 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime,
202 MetricsLog::GetBuildTime()); 204 MetricsLog::GetBuildTime());
203 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 205 GetLocalState()->SetString(prefs::kStabilityStatsVersion,
204 client.GetVersionString()); 206 client.GetVersionString());
205 207
206 // Set the clean exit flag, as that will otherwise cause a stabilty 208 // Set the clean exit flag, as that will otherwise cause a stabilty
207 // log to be produced, irrespective provider requests. 209 // log to be produced, irrespective provider requests.
208 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); 210 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true);
209 211
212 base::ResetRecordActionTaskRunnerForTesting();
210 TestMetricsService service( 213 TestMetricsService service(
211 GetMetricsStateManager(), &client, GetLocalState()); 214 GetMetricsStateManager(), &client, GetLocalState());
212 // Add a metrics provider that requests a stability log. 215 // Add a metrics provider that requests a stability log.
213 TestMetricsProvider* test_provider = new TestMetricsProvider(); 216 TestMetricsProvider* test_provider = new TestMetricsProvider();
214 test_provider->set_has_initial_stability_metrics(true); 217 test_provider->set_has_initial_stability_metrics(true);
215 service.RegisterMetricsProvider( 218 service.RegisterMetricsProvider(
216 scoped_ptr<MetricsProvider>(test_provider)); 219 scoped_ptr<MetricsProvider>(test_provider));
217 220
218 service.InitializeMetricsRecordingState(); 221 service.InitializeMetricsRecordingState();
219 222
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after
266 269
267 // Record stability build time and version from previous session, so that 270 // Record stability build time and version from previous session, so that
268 // stability metrics (including exited cleanly flag) won't be cleared. 271 // stability metrics (including exited cleanly flag) won't be cleared.
269 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, 272 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime,
270 MetricsLog::GetBuildTime()); 273 MetricsLog::GetBuildTime());
271 GetLocalState()->SetString(prefs::kStabilityStatsVersion, 274 GetLocalState()->SetString(prefs::kStabilityStatsVersion,
272 client.GetVersionString()); 275 client.GetVersionString());
273 276
274 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); 277 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false);
275 278
279 base::ResetRecordActionTaskRunnerForTesting();
276 TestMetricsService service( 280 TestMetricsService service(
277 GetMetricsStateManager(), &client, GetLocalState()); 281 GetMetricsStateManager(), &client, GetLocalState());
278 // Add a provider. 282 // Add a provider.
279 TestMetricsProvider* test_provider = new TestMetricsProvider(); 283 TestMetricsProvider* test_provider = new TestMetricsProvider();
280 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 284 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
281 service.InitializeMetricsRecordingState(); 285 service.InitializeMetricsRecordingState();
282 286
283 // The initial stability log should be generated and persisted in unsent logs. 287 // The initial stability log should be generated and persisted in unsent logs.
284 MetricsLogManager* log_manager = service.log_manager(); 288 MetricsLogManager* log_manager = service.log_manager();
285 EXPECT_TRUE(log_manager->has_unsent_logs()); 289 EXPECT_TRUE(log_manager->has_unsent_logs());
(...skipping 22 matching lines...) Expand all
308 EXPECT_EQ(0, uma_log.omnibox_event_size()); 312 EXPECT_EQ(0, uma_log.omnibox_event_size());
309 EXPECT_EQ(0, uma_log.profiler_event_size()); 313 EXPECT_EQ(0, uma_log.profiler_event_size());
310 EXPECT_EQ(0, uma_log.perf_data_size()); 314 EXPECT_EQ(0, uma_log.perf_data_size());
311 CheckForNonStabilityHistograms(uma_log); 315 CheckForNonStabilityHistograms(uma_log);
312 316
313 EXPECT_EQ(1, uma_log.system_profile().stability().crash_count()); 317 EXPECT_EQ(1, uma_log.system_profile().stability().crash_count());
314 } 318 }
315 319
316 TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { 320 TEST_F(MetricsServiceTest, RegisterSyntheticTrial) {
317 TestMetricsServiceClient client; 321 TestMetricsServiceClient client;
322 base::ResetRecordActionTaskRunnerForTesting();
318 MetricsService service(GetMetricsStateManager(), &client, GetLocalState()); 323 MetricsService service(GetMetricsStateManager(), &client, GetLocalState());
319 324
320 // Add two synthetic trials and confirm that they show up in the list. 325 // Add two synthetic trials and confirm that they show up in the list.
321 variations::SyntheticTrialGroup trial1(HashName("TestTrial1"), 326 variations::SyntheticTrialGroup trial1(HashName("TestTrial1"),
322 HashName("Group1")); 327 HashName("Group1"));
323 service.RegisterSyntheticFieldTrial(trial1); 328 service.RegisterSyntheticFieldTrial(trial1);
324 329
325 variations::SyntheticTrialGroup trial2(HashName("TestTrial2"), 330 variations::SyntheticTrialGroup trial2(HashName("TestTrial2"),
326 HashName("Group2")); 331 HashName("Group2"));
327 service.RegisterSyntheticFieldTrial(trial2); 332 service.RegisterSyntheticFieldTrial(trial2);
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
378 EXPECT_EQ(3U, synthetic_trials.size()); 383 EXPECT_EQ(3U, synthetic_trials.size());
379 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); 384 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2"));
380 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); 385 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2"));
381 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); 386 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3"));
382 service.log_manager_.FinishCurrentLog(); 387 service.log_manager_.FinishCurrentLog();
383 } 388 }
384 389
385 TEST_F(MetricsServiceTest, 390 TEST_F(MetricsServiceTest,
386 MetricsProviderOnRecordingDisabledCalledOnInitialStop) { 391 MetricsProviderOnRecordingDisabledCalledOnInitialStop) {
387 TestMetricsServiceClient client; 392 TestMetricsServiceClient client;
393 base::ResetRecordActionTaskRunnerForTesting();
388 TestMetricsService service( 394 TestMetricsService service(
389 GetMetricsStateManager(), &client, GetLocalState()); 395 GetMetricsStateManager(), &client, GetLocalState());
390 396
391 TestMetricsProvider* test_provider = new TestMetricsProvider(); 397 TestMetricsProvider* test_provider = new TestMetricsProvider();
392 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 398 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
393 399
394 service.InitializeMetricsRecordingState(); 400 service.InitializeMetricsRecordingState();
395 service.Stop(); 401 service.Stop();
396 402
397 EXPECT_TRUE(test_provider->on_recording_disabled_called()); 403 EXPECT_TRUE(test_provider->on_recording_disabled_called());
398 } 404 }
399 405
400 TEST_F(MetricsServiceTest, MetricsProvidersInitialized) { 406 TEST_F(MetricsServiceTest, MetricsProvidersInitialized) {
401 TestMetricsServiceClient client; 407 TestMetricsServiceClient client;
408 base::ResetRecordActionTaskRunnerForTesting();
402 TestMetricsService service( 409 TestMetricsService service(
403 GetMetricsStateManager(), &client, GetLocalState()); 410 GetMetricsStateManager(), &client, GetLocalState());
404 411
405 TestMetricsProvider* test_provider = new TestMetricsProvider(); 412 TestMetricsProvider* test_provider = new TestMetricsProvider();
406 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); 413 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider));
407 414
408 service.InitializeMetricsRecordingState(); 415 service.InitializeMetricsRecordingState();
409 416
410 EXPECT_TRUE(test_provider->init_called()); 417 EXPECT_TRUE(test_provider->init_called());
411 } 418 }
412 419
413 } // namespace metrics 420 } // namespace metrics
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698