| 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 62 base::PowerMonitorTestSource* power_monitor_source_; | 62 base::PowerMonitorTestSource* power_monitor_source_; |
| 63 scoped_ptr<base::PowerMonitor> power_monitor_; | 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 // Calling Init should invoke a power state change. |
| 73 broadcaster.Init(); |
| 74 EXPECT_EQ(sender.power_state_changes(), 1); |
| 75 |
| 72 // Sending resume when not suspended should have no effect. | 76 // Sending resume when not suspended should have no effect. |
| 73 source()->GenerateResumeEvent(); | 77 source()->GenerateResumeEvent(); |
| 74 EXPECT_EQ(sender.resumes(), 0); | 78 EXPECT_EQ(sender.resumes(), 0); |
| 75 | 79 |
| 76 // Pretend we suspended. | 80 // Pretend we suspended. |
| 77 source()->GenerateSuspendEvent(); | 81 source()->GenerateSuspendEvent(); |
| 78 EXPECT_EQ(sender.suspends(), 1); | 82 EXPECT_EQ(sender.suspends(), 1); |
| 79 | 83 |
| 80 // Send a second suspend notification. This should be suppressed. | 84 // Send a second suspend notification. This should be suppressed. |
| 81 source()->GenerateSuspendEvent(); | 85 source()->GenerateSuspendEvent(); |
| 82 EXPECT_EQ(sender.suspends(), 1); | 86 EXPECT_EQ(sender.suspends(), 1); |
| 83 | 87 |
| 84 // Pretend we were awakened. | 88 // Pretend we were awakened. |
| 85 source()->GenerateResumeEvent(); | 89 source()->GenerateResumeEvent(); |
| 86 EXPECT_EQ(sender.resumes(), 1); | 90 EXPECT_EQ(sender.resumes(), 1); |
| 87 | 91 |
| 88 // Send a duplicate resume notification. This should be suppressed. | 92 // Send a duplicate resume notification. This should be suppressed. |
| 89 source()->GenerateResumeEvent(); | 93 source()->GenerateResumeEvent(); |
| 90 EXPECT_EQ(sender.resumes(), 1); | 94 EXPECT_EQ(sender.resumes(), 1); |
| 91 | 95 |
| 92 // Pretend the device has gone on battery power | 96 // Pretend the device has gone on battery power |
| 93 source()->GeneratePowerStateEvent(true); | 97 source()->GeneratePowerStateEvent(true); |
| 94 EXPECT_EQ(sender.power_state_changes(), 1); | 98 EXPECT_EQ(sender.power_state_changes(), 2); |
| 95 | 99 |
| 96 // Repeated indications the device is on battery power should be suppressed. | 100 // Repeated indications the device is on battery power should be suppressed. |
| 97 source()->GeneratePowerStateEvent(true); | 101 source()->GeneratePowerStateEvent(true); |
| 98 EXPECT_EQ(sender.power_state_changes(), 1); | 102 EXPECT_EQ(sender.power_state_changes(), 2); |
| 99 | 103 |
| 100 // Pretend the device has gone off battery power | 104 // Pretend the device has gone off battery power |
| 101 source()->GeneratePowerStateEvent(false); | 105 source()->GeneratePowerStateEvent(false); |
| 102 EXPECT_EQ(sender.power_state_changes(), 2); | 106 EXPECT_EQ(sender.power_state_changes(), 3); |
| 103 | 107 |
| 104 // Repeated indications the device is off battery power should be suppressed. | 108 // Repeated indications the device is off battery power should be suppressed. |
| 105 source()->GeneratePowerStateEvent(false); | 109 source()->GeneratePowerStateEvent(false); |
| 106 EXPECT_EQ(sender.power_state_changes(), 2); | 110 EXPECT_EQ(sender.power_state_changes(), 3); |
| 107 } | 111 } |
| 108 | 112 |
| 109 } // namespace base | 113 } // namespace base |
| OLD | NEW |