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() { 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) { | |
bengr
2014/05/07 16:03:58
You should also test with multiple observers.
bolian
2014/05/07 18:11:44
Done.
| |
325 MetricsService service; | |
326 TestMetricsServiceObserver observer; | |
327 | |
328 service.AddObserver(&observer); | |
329 EXPECT_EQ(0, observer.observed()); | |
330 | |
331 service.OpenNewLog(); | |
332 EXPECT_EQ(1, observer.observed()); | |
333 service.log_manager_.FinishCurrentLog(); | |
334 | |
335 service.OpenNewLog(); | |
336 EXPECT_EQ(2, observer.observed()); | |
337 service.log_manager_.FinishCurrentLog(); | |
338 | |
339 service.RemoveObserver(&observer); | |
340 | |
341 service.OpenNewLog(); | |
342 EXPECT_EQ(2, observer.observed()); | |
343 service.log_manager_.FinishCurrentLog(); | |
344 } | |
OLD | NEW |