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 "base/system_monitor/system_monitor.h" | 5 #include "base/system_monitor/system_monitor.h" |
6 | 6 |
7 #include "base/file_path.h" | 7 #include "base/file_path.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/test/mock_devices_changed_observer.h" | 9 #include "base/test/mock_devices_changed_observer.h" |
10 #include "base/utf_string_conversions.h" | 10 #include "base/utf_string_conversions.h" |
11 #include "testing/gmock/include/gmock/gmock.h" | 11 #include "testing/gmock/include/gmock/gmock.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
13 | 13 |
14 namespace base { | 14 namespace base { |
15 | 15 |
16 namespace { | 16 namespace { |
17 | 17 |
18 class PowerTest : public SystemMonitor::PowerObserver { | 18 class PowerTest : public SystemMonitor::PowerObserver { |
19 public: | 19 public: |
20 PowerTest() | 20 PowerTest() |
21 : battery_(false), | 21 : power_state_changes_(0), |
22 power_state_changes_(0), | |
23 suspends_(0), | 22 suspends_(0), |
24 resumes_(0) { | 23 resumes_(0) { |
25 } | 24 } |
26 | 25 |
27 // PowerObserver callbacks. | 26 // PowerObserver callbacks. |
28 virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE { | 27 virtual void OnPowerStateChange(bool on_battery_power) OVERRIDE { |
29 power_state_changes_++; | 28 power_state_changes_++; |
30 } | 29 } |
31 | 30 |
32 virtual void OnSuspend() OVERRIDE { | 31 virtual void OnSuspend() OVERRIDE { |
33 suspends_++; | 32 suspends_++; |
34 } | 33 } |
35 | 34 |
36 virtual void OnResume() OVERRIDE { | 35 virtual void OnResume() OVERRIDE { |
37 resumes_++; | 36 resumes_++; |
38 } | 37 } |
39 | 38 |
40 // Test status counts. | 39 // Test status counts. |
41 bool battery() { return battery_; } | |
42 int power_state_changes() { return power_state_changes_; } | 40 int power_state_changes() { return power_state_changes_; } |
43 int suspends() { return suspends_; } | 41 int suspends() { return suspends_; } |
44 int resumes() { return resumes_; } | 42 int resumes() { return resumes_; } |
45 | 43 |
46 private: | 44 private: |
47 bool battery_; // Do we currently think we're on battery power. | |
48 int power_state_changes_; // Count of OnPowerStateChange notifications. | 45 int power_state_changes_; // Count of OnPowerStateChange notifications. |
49 int suspends_; // Count of OnSuspend notifications. | 46 int suspends_; // Count of OnSuspend notifications. |
50 int resumes_; // Count of OnResume notifications. | 47 int resumes_; // Count of OnResume notifications. |
51 }; | 48 }; |
52 | 49 |
53 class SystemMonitorTest : public testing::Test { | 50 class SystemMonitorTest : public testing::Test { |
54 protected: | 51 protected: |
55 SystemMonitorTest() { | 52 SystemMonitorTest() { |
56 #if defined(OS_MACOSX) | 53 #if defined(OS_MACOSX) |
57 // This needs to happen before SystemMonitor's ctor. | 54 // This needs to happen before SystemMonitor's ctor. |
(...skipping 148 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
206 | 203 |
207 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); | 204 system_monitor_->ProcessMediaDeviceDetached(kDeviceId2); |
208 message_loop_.RunAllPending(); | 205 message_loop_.RunAllPending(); |
209 devices = system_monitor_->GetAttachedMediaDevices(); | 206 devices = system_monitor_->GetAttachedMediaDevices(); |
210 EXPECT_EQ(0U, devices.size()); | 207 EXPECT_EQ(0U, devices.size()); |
211 } | 208 } |
212 | 209 |
213 } // namespace | 210 } // namespace |
214 | 211 |
215 } // namespace base | 212 } // namespace base |
OLD | NEW |