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 "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/command_line.h" | 9 #include "base/command_line.h" |
| 10 #include "base/threading/platform_thread.h" | 10 #include "base/threading/platform_thread.h" |
| (...skipping 117 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 128 return false; | 128 return false; |
| 129 } | 129 } |
| 130 | 130 |
| 131 private: | 131 private: |
| 132 content::TestBrowserThreadBundle thread_bundle_; | 132 content::TestBrowserThreadBundle thread_bundle_; |
| 133 ScopedTestingLocalState testing_local_state_; | 133 ScopedTestingLocalState testing_local_state_; |
| 134 | 134 |
| 135 DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest); | 135 DISALLOW_COPY_AND_ASSIGN(MetricsServiceTest); |
| 136 }; | 136 }; |
| 137 | 137 |
| 138 class TestMetricsLogObserver : public MetricsLogObserver { | |
| 139 public: | |
| 140 TestMetricsLogObserver(): observed_(0) {} | |
| 141 virtual ~TestMetricsLogObserver() {} | |
| 142 | |
| 143 virtual void OnNewMetricsLog() OVERRIDE { | |
| 144 observed_++; | |
|
Ilya Sherman
2014/05/07 01:03:16
nit: Pre-increment.
bolian
2014/05/07 02:20:26
Done.
| |
| 145 } | |
| 146 | |
| 147 int observed_; | |
|
Ilya Sherman
2014/05/07 01:03:16
nit: Please leave a space after this.
Ilya Sherman
2014/05/07 01:03:16
nit: Please make the variable private, and add a g
bolian
2014/05/07 02:20:26
Done.
bolian
2014/05/07 02:20:26
Done.
| |
| 148 private: | |
| 149 DISALLOW_COPY_AND_ASSIGN(TestMetricsLogObserver); | |
| 150 }; | |
| 151 | |
| 138 } // namespace | 152 } // namespace |
| 139 | 153 |
| 140 TEST_F(MetricsServiceTest, IsPluginProcess) { | 154 TEST_F(MetricsServiceTest, IsPluginProcess) { |
| 141 EXPECT_TRUE( | 155 EXPECT_TRUE( |
| 142 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); | 156 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); |
| 143 EXPECT_TRUE( | 157 EXPECT_TRUE( |
| 144 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); | 158 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); |
| 145 EXPECT_FALSE( | 159 EXPECT_FALSE( |
| 146 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); | 160 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); |
| 147 } | 161 } |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 297 GetLocalState()->SetBoolean(crash_pref, true); | 311 GetLocalState()->SetBoolean(crash_pref, true); |
| 298 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); | 312 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); |
| 299 GetLocalState()->ClearPref(crash_pref); | 313 GetLocalState()->ClearPref(crash_pref); |
| 300 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 314 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
| 301 #endif // !defined(OS_CHROMEOS) | 315 #endif // !defined(OS_CHROMEOS) |
| 302 #else // defined(GOOGLE_CHROME_BUILD) | 316 #else // defined(GOOGLE_CHROME_BUILD) |
| 303 // Chromium branded browsers never have crash reporting enabled. | 317 // Chromium branded browsers never have crash reporting enabled. |
| 304 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 318 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
| 305 #endif // defined(GOOGLE_CHROME_BUILD) | 319 #endif // defined(GOOGLE_CHROME_BUILD) |
| 306 } | 320 } |
| 321 | |
| 322 TEST_F(MetricsServiceTest, MetricsLogObserver) { | |
| 323 MetricsService service; | |
| 324 TestMetricsLogObserver observer; | |
| 325 | |
| 326 service.AddMetricsLogObserver(&observer); | |
| 327 EXPECT_EQ(0, observer.observed_); | |
| 328 | |
| 329 service.OpenNewLog(); | |
| 330 EXPECT_EQ(1, observer.observed_); | |
| 331 service.log_manager_.FinishCurrentLog(); | |
| 332 | |
| 333 service.OpenNewLog(); | |
| 334 EXPECT_EQ(2, observer.observed_); | |
| 335 service.log_manager_.FinishCurrentLog(); | |
| 336 | |
| 337 service.RemoveMetricsLogObserver(&observer); | |
| 338 | |
| 339 service.OpenNewLog(); | |
| 340 EXPECT_EQ(2, observer.observed_); | |
| 341 service.log_manager_.FinishCurrentLog(); | |
| 342 } | |
|
Ilya Sherman
2014/05/07 01:03:16
Could you please also add test coverage for the ot
bolian
2014/05/07 02:20:26
The other two places require non-trivial amount of
| |
| OLD | NEW |