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

Unified Diff: chrome/browser/metrics/metrics_log_unittest.cc

Issue 282093012: Remove dependencies of Metrics{Service,Log} on g_browser_process->local_state() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove cruft Created 6 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/metrics/metrics_log_unittest.cc
diff --git a/chrome/browser/metrics/metrics_log_unittest.cc b/chrome/browser/metrics/metrics_log_unittest.cc
index 8b69ccd927f7ae0dec6e0a2ee98e2526fc66cb2f..9058534ee3a21e89676d691b2b4fe1d92e47120b 100644
--- a/chrome/browser/metrics/metrics_log_unittest.cc
+++ b/chrome/browser/metrics/metrics_log_unittest.cc
@@ -129,24 +129,11 @@ class TestMetricsLogChromeOS : public MetricsLogChromeOS {
class TestMetricsLog : public MetricsLog {
public:
- TestMetricsLog(const std::string& client_id, int session_id, LogType log_type)
- : MetricsLog(client_id, session_id, log_type),
- prefs_(&scoped_prefs_),
- brand_for_testing_(kBrandForTesting) {
-#if defined(OS_CHROMEOS)
- metrics_log_chromeos_.reset(new TestMetricsLogChromeOS(
- MetricsLog::uma_proto()));
-#endif // OS_CHROMEOS
- chrome::RegisterLocalState(scoped_prefs_.registry());
- InitPrefs();
- }
- // Creates a TestMetricsLog that will use |prefs| as the fake local state.
- // Useful for tests that need to re-use the local state prefs between logs.
TestMetricsLog(const std::string& client_id,
int session_id,
LogType log_type,
TestingPrefServiceSimple* prefs)
- : MetricsLog(client_id, session_id, log_type),
+ : MetricsLog(client_id, session_id, log_type, prefs),
prefs_(prefs),
brand_for_testing_(kBrandForTesting) {
#if defined(OS_CHROMEOS)
@@ -157,10 +144,6 @@ class TestMetricsLog : public MetricsLog {
}
virtual ~TestMetricsLog() {}
- virtual PrefService* GetPrefService() OVERRIDE {
- return prefs_;
- }
-
const metrics::ChromeUserMetricsExtension& uma_proto() const {
return *MetricsLog::uma_proto();
}
@@ -222,6 +205,8 @@ class MetricsLogTest : public testing::Test {
protected:
virtual void SetUp() OVERRIDE {
+ chrome::RegisterLocalState(prefs_.registry());
+
#if defined(OS_CHROMEOS)
// Enable multi-profiles.
CommandLine::ForCurrentProcess()->AppendSwitch(switches::kMultiProfiles);
@@ -303,6 +288,7 @@ class MetricsLogTest : public testing::Test {
}
protected:
+ TestingPrefServiceSimple prefs_;
#if defined(OS_CHROMEOS)
FakeBluetoothAdapterClient* fake_bluetooth_adapter_client_;
FakeBluetoothDeviceClient* fake_bluetooth_device_client_;
@@ -315,7 +301,7 @@ class MetricsLogTest : public testing::Test {
};
TEST_F(MetricsLogTest, RecordEnvironment) {
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
std::vector<content::WebPluginInfo> plugins;
GoogleUpdateMetrics google_update_metrics;
@@ -329,9 +315,8 @@ TEST_F(MetricsLogTest, RecordEnvironment) {
CheckSystemProfile(log.system_profile());
// Check that the system profile has also been written to prefs.
- PrefService* local_state = log.GetPrefService();
const std::string base64_system_profile =
- local_state->GetString(prefs::kStabilitySavedSystemProfile);
+ prefs_.GetString(prefs::kStabilitySavedSystemProfile);
EXPECT_FALSE(base64_system_profile.empty());
std::string serialied_system_profile;
EXPECT_TRUE(base::Base64Decode(base64_system_profile,
@@ -345,39 +330,36 @@ TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
const char* kSystemProfilePref = prefs::kStabilitySavedSystemProfile;
const char* kSystemProfileHashPref = prefs::kStabilitySavedSystemProfileHash;
- TestingPrefServiceSimple prefs;
- chrome::RegisterLocalState(prefs.registry());
-
// The pref value is empty, so loading it from prefs should fail.
{
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
}
// Do a RecordEnvironment() call and check whether the pref is recorded.
{
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());
- EXPECT_FALSE(prefs.GetString(kSystemProfilePref).empty());
- EXPECT_FALSE(prefs.GetString(kSystemProfileHashPref).empty());
+ EXPECT_FALSE(prefs_.GetString(kSystemProfilePref).empty());
+ EXPECT_FALSE(prefs_.GetString(kSystemProfileHashPref).empty());
}
{
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_TRUE(log.LoadSavedEnvironmentFromPrefs());
// Check some values in the system profile.
EXPECT_EQ(kInstallDateExpected, log.system_profile().install_date());
EXPECT_EQ(kEnabledDateExpected, log.system_profile().uma_enabled_date());
// Ensure that the call cleared the prefs.
- EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
- EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
+ EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
+ EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
}
// Ensure that a non-matching hash results in the pref being invalid.
{
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
// Call RecordEnvironment() to record the pref again.
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
@@ -386,17 +368,18 @@ TEST_F(MetricsLogTest, LoadSavedEnvironmentFromPrefs) {
{
// Set the hash to a bad value.
- prefs.SetString(kSystemProfileHashPref, "deadbeef");
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs);
+ prefs_.SetString(kSystemProfileHashPref, "deadbeef");
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_FALSE(log.LoadSavedEnvironmentFromPrefs());
// Ensure that the prefs are cleared, even if the call failed.
- EXPECT_TRUE(prefs.GetString(kSystemProfilePref).empty());
- EXPECT_TRUE(prefs.GetString(kSystemProfileHashPref).empty());
+ EXPECT_TRUE(prefs_.GetString(kSystemProfilePref).empty());
+ EXPECT_TRUE(prefs_.GetString(kSystemProfileHashPref).empty());
}
}
TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG);
+ TestMetricsLog log(
+ kClientId, kSessionId, MetricsLog::INITIAL_STABILITY_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());
@@ -415,7 +398,7 @@ TEST_F(MetricsLogTest, InitialLogStabilityMetrics) {
}
TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());
@@ -435,7 +418,7 @@ TEST_F(MetricsLogTest, OngoingLogStabilityMetrics) {
#if defined(ENABLE_PLUGINS)
TEST_F(MetricsLogTest, Plugins) {
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
std::vector<content::WebPluginInfo> plugins;
plugins.push_back(CreateFakePluginInfo("p1", FILE_PATH_LITERAL("p1.plugin"),
@@ -464,7 +447,7 @@ TEST_F(MetricsLogTest, Plugins) {
plugin_dict->SetInteger(prefs::kStabilityPluginInstances, 3);
plugin_dict->SetInteger(prefs::kStabilityPluginLoadingErrors, 4);
{
- ListPrefUpdate update(log.GetPrefService(), prefs::kStabilityPluginStats);
+ ListPrefUpdate update(&prefs_, prefs::kStabilityPluginStats);
update.Get()->Append(plugin_dict.release());
}
@@ -491,7 +474,7 @@ TEST_F(MetricsLogTest, RecordProfilerData) {
EXPECT_EQ(GG_UINT64_C(1518842999910132863),
metrics::HashMetricName("birth_thread*"));
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_EQ(0, log.uma_proto().profiler_event_size());
{
@@ -652,7 +635,8 @@ TEST_F(MetricsLogTest, RecordProfilerData) {
}
TEST_F(MetricsLogTest, ChromeChannelWrittenToProtobuf) {
- TestMetricsLog log("user@test.com", kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(
+ "user@test.com", kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_TRUE(log.uma_proto().system_profile().has_channel());
}
@@ -672,7 +656,7 @@ TEST_F(MetricsLogTest, MultiProfileUserCount) {
user_manager->LoginUser(user1);
user_manager->LoginUser(user3);
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
std::vector<content::WebPluginInfo> plugins;
GoogleUpdateMetrics google_update_metrics;
std::vector<chrome_variations::ActiveGroupId> synthetic_trials;
@@ -694,7 +678,7 @@ TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
user_manager->LoginUser(user1);
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
EXPECT_EQ(1u, log.system_profile().multi_profile_user_count());
user_manager->LoginUser(user2);
@@ -705,7 +689,7 @@ TEST_F(MetricsLogTest, MultiProfileCountInvalidated) {
}
TEST_F(MetricsLogTest, BluetoothHardwareDisabled) {
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());
@@ -723,7 +707,7 @@ TEST_F(MetricsLogTest, BluetoothHardwareEnabled) {
dbus::ObjectPath(FakeBluetoothAdapterClient::kAdapterPath));
properties->powered.ReplaceValue(true);
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());
@@ -753,7 +737,7 @@ TEST_F(MetricsLogTest, BluetoothPairedDevices) {
dbus::ObjectPath(FakeBluetoothDeviceClient::kConfirmPasskeyPath));
properties->paired.ReplaceValue(true);
- TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG);
+ TestMetricsLog log(kClientId, kSessionId, MetricsLog::ONGOING_LOG, &prefs_);
log.RecordEnvironment(std::vector<content::WebPluginInfo>(),
GoogleUpdateMetrics(),
std::vector<chrome_variations::ActiveGroupId>());

Powered by Google App Engine
This is Rietveld 408576698