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 28 matching lines...) Expand all Loading... |
39 bool battery_; // Do we currently think we're on battery power. | 39 bool battery_; // Do we currently think we're on battery power. |
40 int power_state_changes_; // Count of OnPowerStateChange notifications. | 40 int power_state_changes_; // Count of OnPowerStateChange notifications. |
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("SystemMonitor"); |
50 | 50 |
51 #if defined(OS_MACOSX) | 51 #if defined(OS_MACOSX) |
52 SystemMonitor::AllocateSystemIOPorts(); | 52 SystemMonitor::AllocateSystemIOPorts(); |
53 #endif | 53 #endif |
54 | 54 |
55 SystemMonitor system_monitor; | 55 SystemMonitor system_monitor; |
56 PowerTest test[kObservers]; | 56 PowerTest test[kObservers]; |
57 for (int index = 0; index < kObservers; ++index) | 57 for (int index = 0; index < kObservers; ++index) |
58 system_monitor.AddObserver(&test[index]); | 58 system_monitor.AddObserver(&test[index]); |
59 | 59 |
(...skipping 24 matching lines...) Expand all Loading... |
84 loop.RunAllPending(); | 84 loop.RunAllPending(); |
85 EXPECT_EQ(test[0].resumes(), 1); | 85 EXPECT_EQ(test[0].resumes(), 1); |
86 | 86 |
87 // Send a duplicate resume notification. This should be suppressed. | 87 // Send a duplicate resume notification. This should be suppressed. |
88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); | 88 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); |
89 loop.RunAllPending(); | 89 loop.RunAllPending(); |
90 EXPECT_EQ(test[0].resumes(), 1); | 90 EXPECT_EQ(test[0].resumes(), 1); |
91 } | 91 } |
92 | 92 |
93 } // namespace base | 93 } // namespace base |
OLD | NEW |