| 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/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| 11 #include "chrome/browser/metrics/metrics_state_manager.h" | 11 #include "chrome/browser/metrics/metrics_state_manager.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/metrics/metrics_log_base.h" | 15 #include "components/metrics/metrics_log_base.h" |
| 16 #include "components/metrics/metrics_service_observer.h" | 16 #include "components/metrics/metrics_service_observer.h" |
| 17 #include "components/metrics/test_metrics_service_client.h" | 17 #include "components/metrics/test_metrics_service_client.h" |
| 18 #include "components/variations/metrics_util.h" | 18 #include "components/variations/metrics_util.h" |
| 19 #include "content/public/common/process_type.h" | |
| 20 #include "content/public/common/webplugininfo.h" | |
| 21 #include "content/public/test/test_browser_thread_bundle.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/gfx/size.h" | 21 #include "ui/gfx/size.h" |
| 24 | 22 |
| 25 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 26 #include "chrome/browser/metrics/metrics_log_chromeos.h" | 24 #include "chrome/browser/metrics/metrics_log_chromeos.h" |
| 27 #endif // OS_CHROMEOS | 25 #endif // OS_CHROMEOS |
| 28 | 26 |
| 29 namespace { | 27 namespace { |
| 30 | 28 |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 165 int observed() const { return observed_; } | 163 int observed() const { return observed_; } |
| 166 | 164 |
| 167 private: | 165 private: |
| 168 int observed_; | 166 int observed_; |
| 169 | 167 |
| 170 DISALLOW_COPY_AND_ASSIGN(TestMetricsServiceObserver); | 168 DISALLOW_COPY_AND_ASSIGN(TestMetricsServiceObserver); |
| 171 }; | 169 }; |
| 172 | 170 |
| 173 } // namespace | 171 } // namespace |
| 174 | 172 |
| 175 TEST_F(MetricsServiceTest, IsPluginProcess) { | |
| 176 EXPECT_TRUE( | |
| 177 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); | |
| 178 EXPECT_TRUE( | |
| 179 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); | |
| 180 EXPECT_FALSE( | |
| 181 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); | |
| 182 } | |
| 183 | |
| 184 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { | 173 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCleanShutDown) { |
| 185 EnableMetricsReporting(); | 174 EnableMetricsReporting(); |
| 186 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); | 175 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, true); |
| 187 | 176 |
| 188 metrics::TestMetricsServiceClient client; | 177 metrics::TestMetricsServiceClient client; |
| 189 TestMetricsService service(GetMetricsStateManager(), &client); | 178 TestMetricsService service(GetMetricsStateManager(), &client); |
| 190 service.InitializeMetricsRecordingState(); | 179 service.InitializeMetricsRecordingState(); |
| 191 // No initial stability log should be generated. | 180 // No initial stability log should be generated. |
| 192 EXPECT_FALSE(service.log_manager()->has_unsent_logs()); | 181 EXPECT_FALSE(service.log_manager()->has_unsent_logs()); |
| 193 EXPECT_FALSE(service.log_manager()->has_staged_log()); | 182 EXPECT_FALSE(service.log_manager()->has_staged_log()); |
| 194 } | 183 } |
| 195 | 184 |
| 196 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { | 185 TEST_F(MetricsServiceTest, InitialStabilityLogAfterCrash) { |
| 197 EnableMetricsReporting(); | 186 EnableMetricsReporting(); |
| 198 GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly); | 187 GetLocalState()->ClearPref(prefs::kStabilityExitedCleanly); |
| 199 | 188 |
| 200 // Set up prefs to simulate restarting after a crash. | 189 // Set up prefs to simulate restarting after a crash. |
| 201 | 190 |
| 202 // Save an existing system profile to prefs, to correspond to what would be | 191 // Save an existing system profile to prefs, to correspond to what would be |
| 203 // saved from a previous session. | 192 // saved from a previous session. |
| 204 metrics::TestMetricsServiceClient client; | 193 metrics::TestMetricsServiceClient client; |
| 205 TestMetricsLog log("client", 1, &client); | 194 TestMetricsLog log("client", 1, &client); |
| 206 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), | 195 log.RecordEnvironment(std::vector<metrics::MetricsProvider*>(), |
| 207 std::vector<content::WebPluginInfo>(), | |
| 208 std::vector<variations::ActiveGroupId>()); | 196 std::vector<variations::ActiveGroupId>()); |
| 209 | 197 |
| 210 // Record stability build time and version from previous session, so that | 198 // Record stability build time and version from previous session, so that |
| 211 // stability metrics (including exited cleanly flag) won't be cleared. | 199 // stability metrics (including exited cleanly flag) won't be cleared. |
| 212 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, | 200 GetLocalState()->SetInt64(prefs::kStabilityStatsBuildTime, |
| 213 MetricsLog::GetBuildTime()); | 201 MetricsLog::GetBuildTime()); |
| 214 GetLocalState()->SetString(prefs::kStabilityStatsVersion, | 202 GetLocalState()->SetString(prefs::kStabilityStatsVersion, |
| 215 client.GetVersionString()); | 203 client.GetVersionString()); |
| 216 | 204 |
| 217 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); | 205 GetLocalState()->SetBoolean(prefs::kStabilityExitedCleanly, false); |
| (...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 330 | 318 |
| 331 service.RemoveObserver(&observer1); | 319 service.RemoveObserver(&observer1); |
| 332 | 320 |
| 333 service.OpenNewLog(); | 321 service.OpenNewLog(); |
| 334 EXPECT_EQ(2, observer1.observed()); | 322 EXPECT_EQ(2, observer1.observed()); |
| 335 EXPECT_EQ(2, observer2.observed()); | 323 EXPECT_EQ(2, observer2.observed()); |
| 336 service.log_manager_.FinishCurrentLog(); | 324 service.log_manager_.FinishCurrentLog(); |
| 337 | 325 |
| 338 service.RemoveObserver(&observer2); | 326 service.RemoveObserver(&observer2); |
| 339 } | 327 } |
| OLD | NEW |