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 29 matching lines...) Expand all Loading... |
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; |
50 // Initialize time() since it registers as a SystemMonitor observer. | |
51 base::Time now = base::Time::Now(); | |
52 | 50 |
53 SystemMonitor system_monitor; | 51 SystemMonitor system_monitor; |
54 PowerTest test[kObservers]; | 52 PowerTest test[kObservers]; |
55 for (int index = 0; index < kObservers; ++index) | 53 for (int index = 0; index < kObservers; ++index) |
56 system_monitor.AddObserver(&test[index]); | 54 system_monitor.AddObserver(&test[index]); |
57 | 55 |
58 // Send a bunch of power changes. Since the battery power hasn't | 56 // Send a bunch of power changes. Since the battery power hasn't |
59 // actually changed, we shouldn't get notifications. | 57 // actually changed, we shouldn't get notifications. |
60 for (int index = 0; index < 5; index++) { | 58 for (int index = 0; index < 5; index++) { |
61 system_monitor.ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); | 59 system_monitor.ProcessPowerMessage(SystemMonitor::POWER_STATE_EVENT); |
(...skipping 20 matching lines...) Expand all Loading... |
82 loop.RunAllPending(); | 80 loop.RunAllPending(); |
83 EXPECT_EQ(test[0].resumes(), 1); | 81 EXPECT_EQ(test[0].resumes(), 1); |
84 | 82 |
85 // Send a duplicate resume notification. This should be suppressed. | 83 // Send a duplicate resume notification. This should be suppressed. |
86 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); | 84 system_monitor.ProcessPowerMessage(SystemMonitor::RESUME_EVENT); |
87 loop.RunAllPending(); | 85 loop.RunAllPending(); |
88 EXPECT_EQ(test[0].resumes(), 1); | 86 EXPECT_EQ(test[0].resumes(), 1); |
89 } | 87 } |
90 | 88 |
91 } // namespace base | 89 } // namespace base |
OLD | NEW |