| 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 "services/device/power_monitor/power_monitor_message_broadcaster.h" | 5 #include "services/device/power_monitor/power_monitor_message_broadcaster.h" |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/message_loop/message_loop.h" | 8 #include "base/message_loop/message_loop.h" |
| 9 #include "base/run_loop.h" | 9 #include "base/run_loop.h" |
| 10 #include "base/test/power_monitor_test_base.h" | 10 #include "base/test/power_monitor_test_base.h" |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 std::unique_ptr<base::PowerMonitor> power_monitor_; | 59 std::unique_ptr<base::PowerMonitor> power_monitor_; |
| 60 | 60 |
| 61 DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcasterTest); | 61 DISALLOW_COPY_AND_ASSIGN(PowerMonitorMessageBroadcasterTest); |
| 62 }; | 62 }; |
| 63 | 63 |
| 64 TEST_F(PowerMonitorMessageBroadcasterTest, PowerMessageBroadcast) { | 64 TEST_F(PowerMonitorMessageBroadcasterTest, PowerMessageBroadcast) { |
| 65 device::mojom::PowerMonitorClientPtr proxy; | 65 device::mojom::PowerMonitorClientPtr proxy; |
| 66 FakePowerMonitorClient client(mojo::MakeRequest(&proxy)); | 66 FakePowerMonitorClient client(mojo::MakeRequest(&proxy)); |
| 67 PowerMonitorMessageBroadcaster broadcaster; | 67 PowerMonitorMessageBroadcaster broadcaster; |
| 68 | 68 |
| 69 // Calling SetClient should invoke a power state change. | 69 // Calling AddClient should invoke a power state change. |
| 70 broadcaster.SetClient(std::move(proxy)); | 70 broadcaster.AddClient(std::move(proxy)); |
| 71 | 71 |
| 72 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
| 73 EXPECT_EQ(client.power_state_changes(), 1); | 73 EXPECT_EQ(client.power_state_changes(), 1); |
| 74 | 74 |
| 75 // Sending resume when not suspended should have no effect. | 75 // Sending resume when not suspended should have no effect. |
| 76 source()->GenerateResumeEvent(); | 76 source()->GenerateResumeEvent(); |
| 77 EXPECT_EQ(client.resumes(), 0); | 77 EXPECT_EQ(client.resumes(), 0); |
| 78 | 78 |
| 79 // Pretend we suspended. | 79 // Pretend we suspended. |
| 80 source()->GenerateSuspendEvent(); | 80 source()->GenerateSuspendEvent(); |
| (...skipping 22 matching lines...) Expand all Loading... |
| 103 // Pretend the device has gone off battery power | 103 // Pretend the device has gone off battery power |
| 104 source()->GeneratePowerStateEvent(false); | 104 source()->GeneratePowerStateEvent(false); |
| 105 EXPECT_EQ(client.power_state_changes(), 3); | 105 EXPECT_EQ(client.power_state_changes(), 3); |
| 106 | 106 |
| 107 // Repeated indications the device is off battery power should be suppressed. | 107 // Repeated indications the device is off battery power should be suppressed. |
| 108 source()->GeneratePowerStateEvent(false); | 108 source()->GeneratePowerStateEvent(false); |
| 109 EXPECT_EQ(client.power_state_changes(), 3); | 109 EXPECT_EQ(client.power_state_changes(), 3); |
| 110 } | 110 } |
| 111 | 111 |
| 112 } // namespace device | 112 } // namespace device |
| OLD | NEW |