Chromium Code Reviews| 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 <ctype.h> | 5 #include <ctype.h> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
| 10 #include "chrome/browser/metrics/metrics_service.h" | 10 #include "chrome/browser/metrics/metrics_service.h" |
| 11 #include "chrome/common/chrome_switches.h" | 11 #include "chrome/common/chrome_switches.h" |
| 12 #include "chrome/common/pref_names.h" | 12 #include "chrome/common/pref_names.h" |
| 13 #include "chrome/test/base/scoped_testing_local_state.h" | 13 #include "chrome/test/base/scoped_testing_local_state.h" |
| 14 #include "chrome/test/base/testing_browser_process.h" | 14 #include "chrome/test/base/testing_browser_process.h" |
| 15 #include "components/variations/metrics_util.h" | 15 #include "components/variations/metrics_util.h" |
| 16 #include "content/public/common/process_type.h" | 16 #include "content/public/common/process_type.h" |
| 17 #include "content/public/common/webplugininfo.h" | |
| 17 #include "content/public/test/test_browser_thread.h" | 18 #include "content/public/test/test_browser_thread.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 | 20 |
| 20 namespace { | 21 namespace { |
| 21 | 22 |
| 23 class TestMetricsService : public MetricsService { | |
| 24 public: | |
| 25 TestMetricsService() {} | |
| 26 virtual ~TestMetricsService() {} | |
| 27 | |
| 28 const MetricsLogManager& log_manager() const { | |
| 29 return log_manager_; | |
| 30 } | |
| 31 | |
| 32 private: | |
| 33 DISALLOW_COPY_AND_ASSIGN(TestMetricsService); | |
| 34 }; | |
| 35 | |
| 22 class MetricsServiceTest : public testing::Test { | 36 class MetricsServiceTest : public testing::Test { |
| 23 public: | 37 public: |
| 24 MetricsServiceTest() | 38 MetricsServiceTest() |
| 25 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 39 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
| 26 testing_local_state_(TestingBrowserProcess::GetGlobal()) { | 40 testing_local_state_(TestingBrowserProcess::GetGlobal()) { |
| 27 } | 41 } |
| 28 | 42 |
| 43 virtual ~MetricsServiceTest() { | |
| 44 MetricsService::SetExecutionPhase(MetricsService::UNINITIALIZED_PHASE); | |
| 45 } | |
| 46 | |
| 29 PrefService* GetLocalState() { | 47 PrefService* GetLocalState() { |
| 30 return testing_local_state_.Get(); | 48 return testing_local_state_.Get(); |
| 31 } | 49 } |
| 32 | 50 |
| 33 // Returns true if there is a synthetic trial in the given vector that matches | 51 // Returns true if there is a synthetic trial in the given vector that matches |
| 34 // the given trial name and trial group; returns false otherwise. | 52 // the given trial name and trial group; returns false otherwise. |
| 35 bool HasSyntheticTrial( | 53 bool HasSyntheticTrial( |
| 36 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials, | 54 const std::vector<chrome_variations::ActiveGroupId>& synthetic_trials, |
| 37 const std::string& trial_name, | 55 const std::string& trial_name, |
| 38 const std::string& trial_group) { | 56 const std::string& trial_group) { |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 132 switches::kResetVariationState); | 150 switches::kResetVariationState); |
| 133 | 151 |
| 134 MetricsService::SetExecutionPhase(MetricsService::UNINITIALIZED_PHASE); | 152 MetricsService::SetExecutionPhase(MetricsService::UNINITIALIZED_PHASE); |
| 135 MetricsService service; | 153 MetricsService service; |
| 136 service.GetLowEntropySource(); | 154 service.GetLowEntropySource(); |
| 137 | 155 |
| 138 EXPECT_TRUE(GetLocalState()->GetString(kCachePrefName).empty()); | 156 EXPECT_TRUE(GetLocalState()->GetString(kCachePrefName).empty()); |
| 139 } | 157 } |
| 140 } | 158 } |
| 141 | 159 |
| 160 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { | |
| 161 base::FieldTrialList field_trial_list(NULL); | |
| 162 base::FieldTrialList::CreateFieldTrial("UMAStability", "SeparateLog"); | |
| 163 | |
| 164 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); | |
| 165 | |
| 166 TestMetricsService service; | |
| 167 service.InitializeMetricsRecordingState(MetricsService::REPORTING_ENABLED); | |
| 168 // No initial stability log should be generated. | |
| 169 EXPECT_FALSE(service.log_manager().has_unsent_logs()); | |
| 170 EXPECT_FALSE(service.log_manager().has_staged_log()); | |
| 171 } | |
| 172 | |
| 173 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { | |
| 174 base::FieldTrialList field_trial_list(NULL); | |
| 175 base::FieldTrialList::CreateFieldTrial("UMAStability", "SeparateLog"); | |
| 176 | |
| 177 GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly); | |
| 178 | |
| 179 // Set up prefs to simulate restarting after a crash. | |
| 180 | |
| 181 // Save an existing system profile to prefs, to correspond to what would be | |
| 182 // saved from a previous session. | |
| 183 MetricsLog log("client", 1); | |
| 184 log.RecordEnvironment(std::vector<content::WebPluginInfo>(), | |
| 185 GoogleUpdateMetrics(), | |
| 186 std::vector<chrome_variations::ActiveGroupId>()); | |
| 187 | |
| 188 // Record stability build time and version from previous session, so that | |
| 189 // stability metrics (including exited cleanly flag) won't be cleared. | |
| 190 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, | |
| 191 MetricsLog::GetBuildTime()); | |
| 192 GetLocalState()->SetString(prefs::kStabilityStatsVersion, | |
| 193 MetricsLog::GetVersionString()); | |
| 194 | |
| 195 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); | |
| 196 | |
| 197 TestMetricsService service; | |
| 198 service.InitializeMetricsRecordingState(MetricsService::REPORTING_ENABLED); | |
| 199 // The initial stability log should be generated and persisted in unsent logs. | |
| 200 EXPECT_TRUE(service.log_manager().has_unsent_logs()); | |
|
Ilya Sherman
2013/12/12 09:03:38
Can you check the contents of the unsent logs as w
Alexei Svitkine (slow)
2013/12/12 16:09:27
Done.
| |
| 201 EXPECT_FALSE(service.log_manager().has_staged_log()); | |
| 202 } | |
| 203 | |
| 142 // Crashes on at least Mac and Linux. http://crbug.com/320433 | 204 // Crashes on at least Mac and Linux. http://crbug.com/320433 |
| 143 TEST_F(MetricsServiceTest, DISABLED_RegisterSyntheticTrial) { | 205 TEST_F(MetricsServiceTest, DISABLED_RegisterSyntheticTrial) { |
| 144 MetricsService service; | 206 MetricsService service; |
| 145 | 207 |
| 146 // Add two synthetic trials and confirm that they show up in the list. | 208 // Add two synthetic trials and confirm that they show up in the list. |
| 147 SyntheticTrialGroup trial1(metrics::HashName("TestTrial1"), | 209 SyntheticTrialGroup trial1(metrics::HashName("TestTrial1"), |
| 148 metrics::HashName("Group1"), | 210 metrics::HashName("Group1"), |
| 149 base::TimeTicks::Now()); | 211 base::TimeTicks::Now()); |
| 150 service.RegisterSyntheticFieldTrial(trial1); | 212 service.RegisterSyntheticFieldTrial(trial1); |
| 151 | 213 |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 185 service.log_manager_.FinishCurrentLog(); | 247 service.log_manager_.FinishCurrentLog(); |
| 186 service.log_manager_.BeginLoggingWithLog(new MetricsLog("clientID", 1), | 248 service.log_manager_.BeginLoggingWithLog(new MetricsLog("clientID", 1), |
| 187 MetricsLog::ONGOING_LOG); | 249 MetricsLog::ONGOING_LOG); |
| 188 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); | 250 service.GetCurrentSyntheticFieldTrials(&synthetic_trials); |
| 189 EXPECT_EQ(3U, synthetic_trials.size()); | 251 EXPECT_EQ(3U, synthetic_trials.size()); |
| 190 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); | 252 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial1", "Group2")); |
| 191 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); | 253 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial2", "Group2")); |
| 192 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); | 254 EXPECT_TRUE(HasSyntheticTrial(synthetic_trials, "TestTrial3", "Group3")); |
| 193 service.log_manager_.FinishCurrentLog(); | 255 service.log_manager_.FinishCurrentLog(); |
| 194 } | 256 } |
| OLD | NEW |