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/macros.h" | 5 #include "base/macros.h" |
6 #include "base/message_loop/message_loop.h" | 6 #include "base/message_loop/message_loop.h" |
7 #include "base/run_loop.h" | 7 #include "base/run_loop.h" |
8 #include "base/test/power_monitor_test_base.h" | 8 #include "base/test/power_monitor_test_base.h" |
9 #include "content/browser/power_monitor_message_broadcaster.h" | 9 #include "device/power_monitor/power_monitor_message_broadcaster.h" |
10 #include "mojo/public/cpp/bindings/binding.h" | 10 #include "mojo/public/cpp/bindings/binding.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 namespace content { | 13 namespace device { |
14 | 14 |
15 class FakePowerMonitorClient : public device::mojom::PowerMonitorClient { | 15 class FakePowerMonitorClient : public device::mojom::PowerMonitorClient { |
16 public: | 16 public: |
17 FakePowerMonitorClient(device::mojom::PowerMonitorClientRequest request) | 17 FakePowerMonitorClient(device::mojom::PowerMonitorClientRequest request) |
18 : binding_(this, std::move(request)), | 18 : binding_(this, std::move(request)), |
19 power_state_changes_(0), | 19 power_state_changes_(0), |
20 suspends_(0), | 20 suspends_(0), |
21 resumes_(0) {} | 21 resumes_(0) {} |
22 ~FakePowerMonitorClient() override {} | 22 ~FakePowerMonitorClient() override {} |
23 | 23 |
24 // Implement device::mojom::PowerMonitorClient | 24 // Implement device::mojom::PowerMonitorClient |
25 void PowerStateChange(bool on_battery_power) override { | 25 void PowerStateChange(bool on_battery_power) override { |
26 power_state_changes_++; | 26 power_state_changes_++; |
27 } | 27 } |
28 void Suspend() override { suspends_++; } | 28 void Suspend() override { suspends_++; } |
29 void Resume() override { resumes_++; } | 29 void Resume() override { resumes_++; } |
30 | 30 |
31 // Test status counts. | 31 // Test status counts. |
32 int power_state_changes() { return power_state_changes_; } | 32 int power_state_changes() { return power_state_changes_; } |
33 int suspends() { return suspends_; } | 33 int suspends() { return suspends_; } |
34 int resumes() { return resumes_; } | 34 int resumes() { return resumes_; } |
35 | 35 |
36 private: | 36 private: |
37 mojo::Binding<device::mojom::PowerMonitorClient> binding_; | 37 mojo::Binding<device::mojom::PowerMonitorClient> binding_; |
38 int power_state_changes_; // Count of OnPowerStateChange notifications. | 38 int power_state_changes_; // Count of OnPowerStateChange notifications. |
39 int suspends_; // Count of OnSuspend notifications. | 39 int suspends_; // Count of OnSuspend notifications. |
40 int resumes_; // Count of OnResume notifications. | 40 int resumes_; // Count of OnResume notifications. |
41 }; | 41 }; |
42 | 42 |
43 class PowerMonitorMessageBroadcasterTest : public testing::Test { | 43 class PowerMonitorMessageBroadcasterTest : public testing::Test { |
44 protected: | 44 protected: |
45 PowerMonitorMessageBroadcasterTest() { | 45 PowerMonitorMessageBroadcasterTest() { |
46 power_monitor_source_ = new base::PowerMonitorTestSource(); | 46 power_monitor_source_ = new base::PowerMonitorTestSource(); |
47 power_monitor_.reset(new base::PowerMonitor( | 47 power_monitor_.reset(new base::PowerMonitor( |
48 std::unique_ptr<base::PowerMonitorSource>(power_monitor_source_))); | 48 std::unique_ptr<base::PowerMonitorSource>(power_monitor_source_))); |
49 } | 49 } |
50 ~PowerMonitorMessageBroadcasterTest() override {} | 50 ~PowerMonitorMessageBroadcasterTest() override {} |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
101 | 101 |
102 // Pretend the device has gone off battery power | 102 // Pretend the device has gone off battery power |
103 source()->GeneratePowerStateEvent(false); | 103 source()->GeneratePowerStateEvent(false); |
104 EXPECT_EQ(client.power_state_changes(), 3); | 104 EXPECT_EQ(client.power_state_changes(), 3); |
105 | 105 |
106 // Repeated indications the device is off battery power should be suppressed. | 106 // Repeated indications the device is off battery power should be suppressed. |
107 source()->GeneratePowerStateEvent(false); | 107 source()->GeneratePowerStateEvent(false); |
108 EXPECT_EQ(client.power_state_changes(), 3); | 108 EXPECT_EQ(client.power_state_changes(), 3); |
109 } | 109 } |
110 | 110 |
111 } // namespace base | 111 } // namespace device |
OLD | NEW |