OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 #include "testing/gtest/include/gtest/gtest.h" | 6 #include "testing/gtest/include/gtest/gtest.h" |
7 | 7 |
8 namespace base { | 8 namespace base { |
9 | 9 |
10 class PowerTest : public SystemMonitor::PowerObserver { | 10 class PowerTest : public SystemMonitor::PowerObserver { |
(...skipping 30 matching lines...) Expand all Loading... |
41 int suspends_; // Count of OnSuspend notifications. | 41 int suspends_; // Count of OnSuspend notifications. |
42 int resumes_; // Count of OnResume notifications. | 42 int resumes_; // Count of OnResume notifications. |
43 }; | 43 }; |
44 | 44 |
45 TEST(SystemMonitor, PowerNotifications) { | 45 TEST(SystemMonitor, PowerNotifications) { |
46 const int kObservers = 5; | 46 const int kObservers = 5; |
47 | 47 |
48 // Initialize a message loop for this to run on. | 48 // Initialize a message loop for this to run on. |
49 MessageLoop loop; | 49 MessageLoop loop; |
50 | 50 |
| 51 #if defined(OS_MACOSX) |
| 52 SystemMonitor::AllocateSystemIOPorts(); |
| 53 #endif |
| 54 |
51 SystemMonitor system_monitor; | 55 SystemMonitor system_monitor; |
52 PowerTest test[kObservers]; | 56 PowerTest test[kObservers]; |
53 for (int index = 0; index < kObservers; ++index) | 57 for (int index = 0; index < kObservers; ++index) |
54 system_monitor.AddObserver(&test[index]); | 58 system_monitor.AddObserver(&test[index]); |
55 | 59 |
56 // Send a bunch of power changes. Since the battery power hasn't | 60 // Send a bunch of power changes. Since the battery power hasn't |
57 // actually changed, we shouldn't get notifications. | 61 // actually changed, we shouldn't get notifications. |
58 for (int index = 0; index < 5; index++) { | 62 for (int index = 0; index < 5; index++) { |
59 system_monitor.ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 63 system_monitor.ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
60 EXPECT_EQ(test[0].power_state_changes(), 0); | 64 EXPECT_EQ(test[0].power_state_changes(), 0); |
(...skipping 19 matching lines...) Expand all Loading... |
80 loop.RunAllPending(); | 84 loop.RunAllPending(); |
81 EXPECT_EQ(test[0].resumes(), 1); | 85 EXPECT_EQ(test[0].resumes(), 1); |
82 | 86 |
83 // Send a duplicate resume notification. This should be suppressed. | 87 // Send a duplicate resume notification. This should be suppressed. |
84 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); | 88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); |
85 loop.RunAllPending(); | 89 loop.RunAllPending(); |
86 EXPECT_EQ(test[0].resumes(), 1); | 90 EXPECT_EQ(test[0].resumes(), 1); |
87 } | 91 } |
88 | 92 |
89 } // namespace base | 93 } // namespace base |
OLD | NEW |