OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/test/power_monitor_test_base.h" | 5 #include "base/test/power_monitor_test_base.h" |
6 #include "content/browser/power_monitor_message_broadcaster.h" | 6 #include "content/browser/power_monitor_message_broadcaster.h" |
7 #include "content/common/power_monitor_messages.h" | 7 #include "content/common/power_monitor_messages.h" |
8 #include "ipc/ipc_sender.h" | 8 #include "ipc/ipc_sender.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
10 | 10 |
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
43 private: | 43 private: |
44 int power_state_changes_; // Count of OnPowerStateChange notifications. | 44 int power_state_changes_; // Count of OnPowerStateChange notifications. |
45 int suspends_; // Count of OnSuspend notifications. | 45 int suspends_; // Count of OnSuspend notifications. |
46 int resumes_; // Count of OnResume notifications. | 46 int resumes_; // Count of OnResume notifications. |
47 }; | 47 }; |
48 | 48 |
49 class PowerMonitorMessageBroadcasterTest : public testing::Test { | 49 class PowerMonitorMessageBroadcasterTest : public testing::Test { |
50 protected: | 50 protected: |
51 PowerMonitorMessageBroadcasterTest() { | 51 PowerMonitorMessageBroadcasterTest() { |
52 power_monitor_source_ = new base::PowerMonitorTestSource(); | 52 power_monitor_source_ = new base::PowerMonitorTestSource(); |
53 power_monitor_.reset(new base::PowerMonitor( | 53 base::PowerMonitor::Initialize( |
54 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_))); | 54 scoped_ptr<base::PowerMonitorSource>(power_monitor_source_)); |
55 } | 55 } |
56 virtual ~PowerMonitorMessageBroadcasterTest() {}; | 56 virtual ~PowerMonitorMessageBroadcasterTest() { |
| 57 base::PowerMonitor::ShutdownForTesting(); |
| 58 }; |
57 | 59 |
58 base::PowerMonitorTestSource* source() { return power_monitor_source_; } | 60 base::PowerMonitorTestSource* source() { return power_monitor_source_; } |
59 base::PowerMonitor* monitor() { return power_monitor_.get(); } | |
60 | 61 |
61 private: | 62 private: |
62 base::PowerMonitorTestSource* power_monitor_source_; | 63 base::PowerMonitorTestSource* power_monitor_source_; |
63 scoped_ptr<base::PowerMonitor> power_monitor_; | |
64 | 64 |
65 DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcasterTest); | 65 DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcasterTest); |
66 }; | 66 }; |
67 | 67 |
68 TEST_F(PowerMonitorMessageBroadcasterTest, PowerMessageBroadcast) { | 68 TEST_F(PowerMonitorMessageBroadcasterTest, PowerMessageBroadcast) { |
69 PowerMonitorMessageSender sender; | 69 PowerMonitorMessageSender sender; |
70 PowerMonitorMessageBroadcaster broadcaster(&sender); | 70 PowerMonitorMessageBroadcaster broadcaster(&sender); |
71 | 71 |
72 // Sending resume when not suspended should have no effect. | 72 // Sending resume when not suspended should have no effect. |
73 source()->GenerateResumeEvent(); | 73 source()->GenerateResumeEvent(); |
(...skipping 26 matching lines...) Expand all Loading... |
100 // Pretend the device has gone off battery power | 100 // Pretend the device has gone off battery power |
101 source()->GeneratePowerStateEvent(false); | 101 source()->GeneratePowerStateEvent(false); |
102 EXPECT_EQ(sender.power_state_changes(), 2); | 102 EXPECT_EQ(sender.power_state_changes(), 2); |
103 | 103 |
104 // Repeated indications the device is off battery power should be suppressed. | 104 // Repeated indications the device is off battery power should be suppressed. |
105 source()->GeneratePowerStateEvent(false); | 105 source()->GeneratePowerStateEvent(false); |
106 EXPECT_EQ(sender.power_state_changes(), 2); | 106 EXPECT_EQ(sender.power_state_changes(), 2); |
107 } | 107 } |
108 | 108 |
109 } // namespace base | 109 } // namespace base |
OLD | NEW |