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 TestMetricsServiceObserver : public MetricsServiceObserver { |
| 139 public: |
| 140 TestMetricsServiceObserver(): observed_(0) {} |
| 141 virtual ~TestMetricsServiceObserver() {} |
| 142 |
| 143 virtual void OnDidCreateMetricsLog() OVERRIDE { |
| 144 ++observed_; |
| 145 } |
| 146 int observed() const { return observed_; } |
| 147 |
| 148 private: |
| 149 int observed_; |
| 150 |
| 151 DISALLOW_COPY_AND_ASSIGN(TestMetricsServiceObserver); |
| 152 }; |
| 153 |
138 } // namespace | 154 } // namespace |
139 | 155 |
140 TEST_F(MetricsServiceTest, IsPluginProcess) { | 156 TEST_F(MetricsServiceTest, IsPluginProcess) { |
141 EXPECT_TRUE( | 157 EXPECT_TRUE( |
142 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); | 158 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PLUGIN)); |
143 EXPECT_TRUE( | 159 EXPECT_TRUE( |
144 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); | 160 MetricsService::IsPluginProcess(content::PROCESS_TYPE_PPAPI_PLUGIN)); |
145 EXPECT_FALSE( | 161 EXPECT_FALSE( |
146 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); | 162 MetricsService::IsPluginProcess(content::PROCESS_TYPE_GPU)); |
147 } | 163 } |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
297 GetLocalState()->SetBoolean(crash_pref, true); | 313 GetLocalState()->SetBoolean(crash_pref, true); |
298 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); | 314 EXPECT_TRUE(MetricsServiceHelper::IsCrashReportingEnabled()); |
299 GetLocalState()->ClearPref(crash_pref); | 315 GetLocalState()->ClearPref(crash_pref); |
300 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 316 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
301 #endif // !defined(OS_CHROMEOS) | 317 #endif // !defined(OS_CHROMEOS) |
302 #else // defined(GOOGLE_CHROME_BUILD) | 318 #else // defined(GOOGLE_CHROME_BUILD) |
303 // Chromium branded browsers never have crash reporting enabled. | 319 // Chromium branded browsers never have crash reporting enabled. |
304 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); | 320 EXPECT_FALSE(MetricsServiceHelper::IsCrashReportingEnabled()); |
305 #endif // defined(GOOGLE_CHROME_BUILD) | 321 #endif // defined(GOOGLE_CHROME_BUILD) |
306 } | 322 } |
| 323 |
| 324 TEST_F(MetricsServiceTest, MetricsServiceObserver) { |
| 325 MetricsService service; |
| 326 TestMetricsServiceObserver observer1; |
| 327 TestMetricsServiceObserver observer2; |
| 328 |
| 329 service.AddObserver(&observer1); |
| 330 EXPECT_EQ(0, observer1.observed()); |
| 331 EXPECT_EQ(0, observer2.observed()); |
| 332 |
| 333 service.OpenNewLog(); |
| 334 EXPECT_EQ(1, observer1.observed()); |
| 335 EXPECT_EQ(0, observer2.observed()); |
| 336 service.log_manager_.FinishCurrentLog(); |
| 337 |
| 338 service.AddObserver(&observer2); |
| 339 |
| 340 service.OpenNewLog(); |
| 341 EXPECT_EQ(2, observer1.observed()); |
| 342 EXPECT_EQ(1, observer2.observed()); |
| 343 service.log_manager_.FinishCurrentLog(); |
| 344 |
| 345 service.RemoveObserver(&observer1); |
| 346 |
| 347 service.OpenNewLog(); |
| 348 EXPECT_EQ(2, observer1.observed()); |
| 349 EXPECT_EQ(2, observer2.observed()); |
| 350 service.log_manager_.FinishCurrentLog(); |
| 351 |
| 352 service.RemoveObserver(&observer2); |
| 353 } |
OLD | NEW |