| OLD | NEW |
| 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 <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
| (...skipping 297 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 308 CheckForNonStabilityHistograms(uma_log); | 308 CheckForNonStabilityHistograms(uma_log); |
| 309 | 309 |
| 310 EXPECT_EQ(1, uma_log.system_profile().stability().crash_count()); | 310 EXPECT_EQ(1, uma_log.system_profile().stability().crash_count()); |
| 311 } | 311 } |
| 312 | 312 |
| 313 TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { | 313 TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { |
| 314 TestMetricsServiceClient client; | 314 TestMetricsServiceClient client; |
| 315 MetricsService service(GetMetricsStateManager(), &client, GetLocalState()); | 315 MetricsService service(GetMetricsStateManager(), &client, GetLocalState()); |
| 316 | 316 |
| 317 // Add two synthetic trials and confirm that they show up in the list. | 317 // Add two synthetic trials and confirm that they show up in the list. |
| 318 SyntheticTrialGroup trial1(HashName("TestTrial1"), HashName("Group1")); | 318 variations::SyntheticTrialGroup trial1(HashName("TestTrial1"), |
| 319 HashName("Group1")); |
| 319 service.RegisterSyntheticFieldTrial(trial1); | 320 service.RegisterSyntheticFieldTrial(trial1); |
| 320 | 321 |
| 321 SyntheticTrialGroup trial2(HashName("TestTrial2"), HashName("Group2")); | 322 variations::SyntheticTrialGroup trial2(HashName("TestTrial2"), |
| 323 HashName("Group2")); |
| 322 service.RegisterSyntheticFieldTrial(trial2); | 324 service.RegisterSyntheticFieldTrial(trial2); |
| 323 // Ensure that time has advanced by at least a tick before proceeding. | 325 // Ensure that time has advanced by at least a tick before proceeding. |
| 324 WaitUntilTimeChanges(base::TimeTicks::Now()); | 326 WaitUntilTimeChanges(base::TimeTicks::Now()); |
| 325 | 327 |
| 326 service.log_manager_.BeginLoggingWithLog(scoped_ptr<MetricsLog>( | 328 service.log_manager_.BeginLoggingWithLog(scoped_ptr<MetricsLog>( |
| 327 new MetricsLog("clientID", | 329 new MetricsLog("clientID", |
| 328 1, | 330 1, |
| 329 MetricsLog::INITIAL_STABILITY_LOG, | 331 MetricsLog::INITIAL_STABILITY_LOG, |
| 330 &client, | 332 &client, |
| 331 GetLocalState()))); | 333 GetLocalState()))); |
| 332 // Save the time when the log was started (it's okay for this to be greater | 334 // Save the time when the log was started (it's okay for this to be greater |
| 333 // than the time recorded by the above call since it's used to ensure the | 335 // than the time recorded by the above call since it's used to ensure the |
| 334 // value changes). | 336 // value changes). |
| 335 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); | 337 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); |
| 336 | 338 |
| 337 std::vector<variations::ActiveGroupId> synthetic_trials; | 339 std::vector<variations::ActiveGroupId> synthetic_trials; |
| 338 service.GetSyntheticFieldTrialsOlderThan(base::TimeTicks::Now(), | 340 service.GetSyntheticFieldTrialsOlderThan(base::TimeTicks::Now(), |
| 339 &synthetic_trials); | 341 &synthetic_trials); |
| 340 EXPECT_EQ(2U, synthetic_trials.size()); | 342 EXPECT_EQ(2U, synthetic_trials.size()); |
| 341 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group1")); | 343 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group1")); |
| 342 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 344 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 343 | 345 |
| 344 // Ensure that time has advanced by at least a tick before proceeding. | 346 // Ensure that time has advanced by at least a tick before proceeding. |
| 345 WaitUntilTimeChanges(begin_log_time); | 347 WaitUntilTimeChanges(begin_log_time); |
| 346 | 348 |
| 347 // Change the group for the first trial after the log started. | 349 // Change the group for the first trial after the log started. |
| 348 SyntheticTrialGroup trial3(HashName("TestTrial1"), HashName("Group2")); | 350 variations::SyntheticTrialGroup trial3(HashName("TestTrial1"), |
| 351 HashName("Group2")); |
| 349 service.RegisterSyntheticFieldTrial(trial3); | 352 service.RegisterSyntheticFieldTrial(trial3); |
| 350 service.GetSyntheticFieldTrialsOlderThan(begin_log_time, &synthetic_trials); | 353 service.GetSyntheticFieldTrialsOlderThan(begin_log_time, &synthetic_trials); |
| 351 EXPECT_EQ(1U, synthetic_trials.size()); | 354 EXPECT_EQ(1U, synthetic_trials.size()); |
| 352 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 355 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 353 | 356 |
| 354 // Add a new trial after the log started and confirm that it doesn't show up. | 357 // Add a new trial after the log started and confirm that it doesn't show up. |
| 355 SyntheticTrialGroup trial4(HashName("TestTrial3"), HashName("Group3")); | 358 variations::SyntheticTrialGroup trial4(HashName("TestTrial3"), |
| 359 HashName("Group3")); |
| 356 service.RegisterSyntheticFieldTrial(trial4); | 360 service.RegisterSyntheticFieldTrial(trial4); |
| 357 service.GetSyntheticFieldTrialsOlderThan(begin_log_time, &synthetic_trials); | 361 service.GetSyntheticFieldTrialsOlderThan(begin_log_time, &synthetic_trials); |
| 358 EXPECT_EQ(1U, synthetic_trials.size()); | 362 EXPECT_EQ(1U, synthetic_trials.size()); |
| 359 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 363 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 360 | 364 |
| 361 // Ensure that time has advanced by at least a tick before proceeding. | 365 // Ensure that time has advanced by at least a tick before proceeding. |
| 362 WaitUntilTimeChanges(base::TimeTicks::Now()); | 366 WaitUntilTimeChanges(base::TimeTicks::Now()); |
| 363 | 367 |
| 364 // Start a new log and ensure all three trials appear in it. | 368 // Start a new log and ensure all three trials appear in it. |
| 365 service.log_manager_.FinishCurrentLog(); | 369 service.log_manager_.FinishCurrentLog(); |
| (...skipping 18 matching lines...) Expand all Loading... |
| 384 TestMetricsProvider* test_provider = new TestMetricsProvider(); | 388 TestMetricsProvider* test_provider = new TestMetricsProvider(); |
| 385 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); | 389 service.RegisterMetricsProvider(scoped_ptr<MetricsProvider>(test_provider)); |
| 386 | 390 |
| 387 service.InitializeMetricsRecordingState(); | 391 service.InitializeMetricsRecordingState(); |
| 388 service.Stop(); | 392 service.Stop(); |
| 389 | 393 |
| 390 EXPECT_TRUE(test_provider->on_recording_disabled_called()); | 394 EXPECT_TRUE(test_provider->on_recording_disabled_called()); |
| 391 } | 395 } |
| 392 | 396 |
| 393 } // namespace metrics | 397 } // namespace metrics |
| OLD | NEW |