Index: chrome/browser/metrics/metrics_service_unittest.cc |
diff --git a/chrome/browser/metrics/metrics_service_unittest.cc b/chrome/browser/metrics/metrics_service_unittest.cc |
index c3bef76eed3854798e608008c47fe3b8c6cdf02d..f9e213bd985b747ed12829ed0f502676bd415cf7 100644 |
--- a/chrome/browser/metrics/metrics_service_unittest.cc |
+++ b/chrome/browser/metrics/metrics_service_unittest.cc |
@@ -7,12 +7,13 @@ |
#include <string> |
#include "base/command_line.h" |
+#include "base/prefs/testing_pref_service.h" |
#include "base/threading/platform_thread.h" |
#include "chrome/browser/metrics/metrics_service_observer.h" |
#include "chrome/browser/metrics/metrics_state_manager.h" |
+#include "chrome/browser/prefs/browser_prefs.h" |
#include "chrome/common/chrome_switches.h" |
#include "chrome/common/pref_names.h" |
-#include "chrome/test/base/scoped_testing_local_state.h" |
#include "chrome/test/base/testing_browser_process.h" |
#include "components/variations/metrics_util.h" |
#include "content/public/common/process_type.h" |
@@ -31,9 +32,9 @@ using metrics::MetricsLogManager; |
class TestMetricsService : public MetricsService { |
public: |
- explicit TestMetricsService(metrics::MetricsStateManager* state_manager) |
- : MetricsService(state_manager) { |
- } |
+ explicit TestMetricsService(metrics::MetricsStateManager* state_manager, |
+ PrefService* local_state) |
+ : MetricsService(state_manager, local_state) {} |
virtual ~TestMetricsService() {} |
MetricsLogManager* log_manager() { |
@@ -61,8 +62,13 @@ class TestMetricsLogChromeOS : public MetricsLogChromeOS { |
class TestMetricsLog : public MetricsLog { |
public: |
- TestMetricsLog(const std::string& client_id, int session_id) |
- : MetricsLog(client_id, session_id, MetricsLog::ONGOING_LOG) { |
+ TestMetricsLog(const std::string& client_id, |
+ int session_id, |
+ PrefService* local_state) |
+ : MetricsLog(client_id, |
+ session_id, |
+ MetricsLog::ONGOING_LOG, |
+ local_state) { |
#if defined(OS_CHROMEOS) |
metrics_log_chromeos_.reset(new TestMetricsLogChromeOS( |
MetricsLog::uma_proto())); |
@@ -88,23 +94,22 @@ class TestMetricsLog : public MetricsLog { |
class MetricsServiceTest : public testing::Test { |
public: |
- MetricsServiceTest() |
- : testing_local_state_(TestingBrowserProcess::GetGlobal()), |
- metrics_state_manager_(metrics::MetricsStateManager::Create( |
- GetLocalState())) { |
+ MetricsServiceTest() { |
+ chrome::RegisterLocalState(testing_local_state_.registry()); |
Alexei Svitkine (slow)
2014/05/19 13:13:54
Instead of calling this, could this call MetricsSe
|
+ metrics_state_manager_ = |
+ metrics::MetricsStateManager::Create(GetLocalState()); |
} |
virtual ~MetricsServiceTest() { |
- MetricsService::SetExecutionPhase(MetricsService::UNINITIALIZED_PHASE); |
+ MetricsService::SetExecutionPhase(MetricsService::UNINITIALIZED_PHASE, |
+ GetLocalState()); |
} |
metrics::MetricsStateManager* GetMetricsStateManager() { |
return metrics_state_manager_.get(); |
} |
- PrefService* GetLocalState() { |
- return testing_local_state_.Get(); |
- } |
+ PrefService* GetLocalState() { return &testing_local_state_; } |
// Sets metrics reporting as enabled for testing. |
void EnableMetricsReporting() { |
@@ -140,7 +145,7 @@ class MetricsServiceTest : public testing::Test { |
private: |
content::TestBrowserThreadBundle thread_bundle_; |
- ScopedTestingLocalState testing_local_state_; |
+ TestingPrefServiceSimple testing_local_state_; |
scoped_ptr<metrics::MetricsStateManager> metrics_state_manager_; |
DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest); |
@@ -177,7 +182,7 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { |
EnableMetricsReporting(); |
GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); |
- TestMetricsService service(GetMetricsStateManager()); |
+ TestMetricsService service(GetMetricsStateManager(), GetLocalState()); |
service.InitializeMetricsRecordingState(); |
// No initial stability log should be generated. |
EXPECT_FALSE(service.log_manager()->has_unsent_logs()); |
@@ -192,7 +197,7 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { |
// Save an existing system profile to prefs, to correspond to what would be |
// saved from a previous session. |
- TestMetricsLog log("client", 1); |
+ TestMetricsLog log("client", 1, GetLocalState()); |
log.RecordEnvironment(std::vector<content::WebPluginInfo>(), |
GoogleUpdateMetrics(), |
std::vector<chrome_variations::ActiveGroupId>()); |
@@ -206,7 +211,7 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { |
GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); |
- TestMetricsService service(GetMetricsStateManager()); |
+ TestMetricsService service(GetMetricsStateManager(), GetLocalState()); |
service.InitializeMetricsRecordingState(); |
// The initial stability log should be generated and persisted in unsent logs. |
@@ -234,7 +239,7 @@ TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { |
} |
TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { |
- MetricsService service(GetMetricsStateManager()); |
+ MetricsService service(GetMetricsStateManager(), GetLocalState()); |
// Add two synthetic trials and confirm that they show up in the list. |
SyntheticTrialGroup trial1(metrics::HashName("TestTrial1"), |
@@ -247,8 +252,8 @@ TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { |
// Ensure that time has advanced by at least a tick before proceeding. |
WaitUntilTimeChanges(base::TimeTicks::Now()); |
- service.log_manager_.BeginLoggingWithLog( |
- new MetricsLog("clientID", 1, MetricsLog::INITIAL_STABILITY_LOG)); |
+ service.log_manager_.BeginLoggingWithLog(new MetricsLog( |
+ "clientID", 1, MetricsLog::INITIAL_STABILITY_LOG, GetLocalState())); |
// Save the time when the log was started (it's okay for this to be greater |
// than the time recorded by the above call since it's used to ensure the |
// value changes). |
@@ -285,7 +290,7 @@ TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { |
// Start a new log and ensure all three trials appear in it. |
service.log_manager_.FinishCurrentLog(); |
service.log_manager_.BeginLoggingWithLog( |
- new MetricsLog("clientID", 1, MetricsLog::ONGOING_LOG)); |
+ new MetricsLog("clientID", 1, MetricsLog::ONGOING_LOG, GetLocalState())); |
service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
EXPECT_EQ(3U, synthetic_trials.size()); |
EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); |
@@ -297,15 +302,18 @@ TEST_F(MetricsServiceTest, RegisterSyntheticTrial) { |
TEST_F(MetricsServiceTest, MetricsReportingEnabled) { |
#if !defined(OS_CHROMEOS) |
GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled, false); |
- EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); |
+ EXPECT_FALSE( |
+ MetricsServiceHelper::IsMetricsReportingEnabled(GetLocalState())); |
GetLocalState()->SetBoolean(prefs::kMetricsReportingEnabled, true); |
- EXPECT_TRUE(MetricsServiceHelper::IsMetricsReportingEnabled()); |
+ EXPECT_TRUE(MetricsServiceHelper::IsMetricsReportingEnabled(GetLocalState())); |
GetLocalState()->ClearPref(prefs::kMetricsReportingEnabled); |
- EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); |
+ EXPECT_FALSE( |
+ MetricsServiceHelper::IsMetricsReportingEnabled(GetLocalState())); |
#else |
// ChromeOS does not register prefs::kMetricsReportingEnabled and uses |
// device settings for metrics reporting. |
- EXPECT_FALSE(MetricsServiceHelper::IsMetricsReportingEnabled()); |
+ EXPECT_FALSE( |
+ MetricsServiceHelper::IsMetricsReportingEnabled(GetLocalState())); |
#endif |
} |
@@ -319,20 +327,20 @@ TEST_F(MetricsServiceTest, CrashReportingEnabled) { |
const char* crash_pref = prefs::kMetricsReportingEnabled; |
#endif |
GetLocalState()->SetBoolean(crash_pref, false); |
- EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
+ EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled(GetLocalState())); |
GetLocalState()->SetBoolean(crash_pref, true); |
- EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); |
+ EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled(GetLocalState())); |
GetLocalState()->ClearPref(crash_pref); |
- EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
+ EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled(GetLocalState())); |
#endif // !defined(OS_CHROMEOS) |
#else // defined(GOOGLE_CHROME_BUILD) |
// Chromium branded browsers never have crash reporting enabled. |
- EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
+ EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled(GetLocalState())); |
#endif // defined(GOOGLE_CHROME_BUILD) |
} |
TEST_F(MetricsServiceTest, MetricsServiceObserver) { |
- MetricsService service(GetMetricsStateManager()); |
+ MetricsService service(GetMetricsStateManager(), GetLocalState()); |
TestMetricsServiceObserver observer1; |
TestMetricsServiceObserver observer2; |