| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 "chrome/browser/metrics/metrics_service.h" | 5 #include "chrome/browser/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/prefs/testing_pref_service.h" | 10 #include "base/prefs/testing_pref_service.h" |
| 11 #include "base/threading/platform_thread.h" | 11 #include "base/threading/platform_thread.h" |
| 12 #include "chrome/browser/google/google_util.h" | 12 #include "chrome/browser/google/google_util.h" |
| 13 #include "chrome/common/pref_names.h" | 13 #include "chrome/common/pref_names.h" |
| 14 #include "chrome/test/base/scoped_testing_local_state.h" | 14 #include "chrome/test/base/scoped_testing_local_state.h" |
| 15 #include "chrome/test/base/testing_browser_process.h" | 15 #include "chrome/test/base/testing_browser_process.h" |
| 16 #include "components/metrics/metrics_log_base.h" | 16 #include "components/metrics/metrics_log.h" |
| 17 #include "components/metrics/metrics_service_observer.h" | 17 #include "components/metrics/metrics_service_observer.h" |
| 18 #include "components/metrics/metrics_state_manager.h" | 18 #include "components/metrics/metrics_state_manager.h" |
| 19 #include "components/metrics/test_metrics_service_client.h" | 19 #include "components/metrics/test_metrics_service_client.h" |
| 20 #include "components/variations/metrics_util.h" | 20 #include "components/variations/metrics_util.h" |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 23 |
| 24 #if defined(OS_CHROMEOS) | 24 #if defined(OS_CHROMEOS) |
| 25 #include "chromeos/login/login_state.h" | 25 #include "chromeos/login/login_state.h" |
| 26 #endif // defined(OS_CHROMEOS) | 26 #endif // defined(OS_CHROMEOS) |
| (...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 232 SyntheticTrialGroup trial1(metrics::HashName("TestTrial1"), | 232 SyntheticTrialGroup trial1(metrics::HashName("TestTrial1"), |
| 233 metrics::HashName("Group1")); | 233 metrics::HashName("Group1")); |
| 234 service.RegisterSyntheticFieldTrial(trial1); | 234 service.RegisterSyntheticFieldTrial(trial1); |
| 235 | 235 |
| 236 SyntheticTrialGroup trial2(metrics::HashName("TestTrial2"), | 236 SyntheticTrialGroup trial2(metrics::HashName("TestTrial2"), |
| 237 metrics::HashName("Group2")); | 237 metrics::HashName("Group2")); |
| 238 service.RegisterSyntheticFieldTrial(trial2); | 238 service.RegisterSyntheticFieldTrial(trial2); |
| 239 // Ensure that time has advanced by at least a tick before proceeding. | 239 // Ensure that time has advanced by at least a tick before proceeding. |
| 240 WaitUntilTimeChanges(base::TimeTicks::Now()); | 240 WaitUntilTimeChanges(base::TimeTicks::Now()); |
| 241 | 241 |
| 242 service.log_manager_.BeginLoggingWithLog(scoped_ptr<metrics::MetricsLogBase>( | 242 service.log_manager_.BeginLoggingWithLog(scoped_ptr<MetricsLog>( |
| 243 new MetricsLog("clientID", | 243 new MetricsLog("clientID", |
| 244 1, | 244 1, |
| 245 MetricsLog::INITIAL_STABILITY_LOG, | 245 MetricsLog::INITIAL_STABILITY_LOG, |
| 246 &client, | 246 &client, |
| 247 GetLocalState()))); | 247 GetLocalState()))); |
| 248 // Save the time when the log was started (it's okay for this to be greater | 248 // Save the time when the log was started (it's okay for this to be greater |
| 249 // than the time recorded by the above call since it's used to ensure the | 249 // than the time recorded by the above call since it's used to ensure the |
| 250 // value changes). | 250 // value changes). |
| 251 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); | 251 const base::TimeTicks begin_log_time = base::TimeTicks::Now(); |
| 252 | 252 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 274 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); | 274 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
| 275 EXPECT_EQ(1U, synthetic_trials.size()); | 275 EXPECT_EQ(1U, synthetic_trials.size()); |
| 276 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 276 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 277 | 277 |
| 278 // Ensure that time has advanced by at least a tick before proceeding. | 278 // Ensure that time has advanced by at least a tick before proceeding. |
| 279 WaitUntilTimeChanges(base::TimeTicks::Now()); | 279 WaitUntilTimeChanges(base::TimeTicks::Now()); |
| 280 | 280 |
| 281 // Start a new log and ensure all three trials appear in it. | 281 // Start a new log and ensure all three trials appear in it. |
| 282 service.log_manager_.FinishCurrentLog(); | 282 service.log_manager_.FinishCurrentLog(); |
| 283 service.log_manager_.BeginLoggingWithLog( | 283 service.log_manager_.BeginLoggingWithLog( |
| 284 scoped_ptr<metrics::MetricsLogBase>(new MetricsLog( | 284 scoped_ptr<MetricsLog>(new MetricsLog( |
| 285 "clientID", 1, MetricsLog::ONGOING_LOG, &client, GetLocalState()))); | 285 "clientID", 1, MetricsLog::ONGOING_LOG, &client, GetLocalState()))); |
| 286 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); | 286 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
| 287 EXPECT_EQ(3U, synthetic_trials.size()); | 287 EXPECT_EQ(3U, synthetic_trials.size()); |
| 288 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); | 288 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); |
| 289 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 289 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 290 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); | 290 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); |
| 291 service.log_manager_.FinishCurrentLog(); | 291 service.log_manager_.FinishCurrentLog(); |
| 292 } | 292 } |
| 293 | 293 |
| 294 TEST_F(MetricsServiceTest, MetricsServiceObserver) { | 294 TEST_F(MetricsServiceTest, MetricsServiceObserver) { |
| (...skipping 20 matching lines...) Expand all Loading... |
| 315 | 315 |
| 316 service.RemoveObserver(&observer1); | 316 service.RemoveObserver(&observer1); |
| 317 | 317 |
| 318 service.OpenNewLog(); | 318 service.OpenNewLog(); |
| 319 EXPECT_EQ(2, observer1.observed()); | 319 EXPECT_EQ(2, observer1.observed()); |
| 320 EXPECT_EQ(2, observer2.observed()); | 320 EXPECT_EQ(2, observer2.observed()); |
| 321 service.log_manager_.FinishCurrentLog(); | 321 service.log_manager_.FinishCurrentLog(); |
| 322 | 322 |
| 323 service.RemoveObserver(&observer2); | 323 service.RemoveObserver(&observer2); |
| 324 } | 324 } |
| OLD | NEW |