OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "chromeos/dbus/fake_power_manager_client.h" | |
6 | |
7 #include "testing/gtest/include/gtest/gtest.h" | |
8 | |
9 namespace chromeos { | |
10 | |
11 class FakePowerManagerClientTest : public testing::Test { | |
12 public: | |
13 FakePowerManagerClientTest() {} | |
14 | |
15 void UpdatePowerProperties( | |
16 int percentage, | |
17 power_manager::PowerSupplyProperties_BatteryState state, | |
18 power_manager::PowerSupplyProperties_ExternalPower power) { | |
19 client_.UpdatePowerProperties(percentage, false, state, power); | |
20 } | |
21 | |
22 protected: | |
23 FakePowerManagerClient client_; | |
24 | |
25 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest); | |
26 }; | |
27 | |
28 TEST_F(FakePowerManagerClientTest, InitializationTest) { | |
29 // Test the default values that are assigned when the | |
30 // FakePowerManagerClient::Init() is called. | |
31 client_.Init(nullptr); | |
32 | |
33 EXPECT_EQ(50, client_.props().battery_percent()); | |
Daniel Erat
2015/07/07 21:30:56
as mentioned in the last round of comments, i don'
mozartalouis
2015/07/08 23:13:02
Done.
| |
34 EXPECT_FALSE(client_.props().is_calculating_battery_time()); | |
35 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
36 client_.props().battery_state()); | |
37 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, | |
38 client_.props().external_power()); | |
39 } | |
40 | |
41 TEST_F(FakePowerManagerClientTest, BatteryStateTest) { | |
42 // Test if setting battery_percent to 100 and battery_state to | |
43 // CHARGING will reset the battery_state to FULL. | |
44 UpdatePowerProperties( | |
45 100, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
46 power_manager::PowerSupplyProperties_ExternalPower_AC); | |
47 EXPECT_EQ(100, client_.props().battery_percent()); | |
48 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_FULL, | |
49 client_.props().battery_state()); | |
50 | |
51 // Test if setting battery_percent less than 100 and | |
52 // battery_state to FULL will reset battery_state to | |
53 // DISCHARGING. | |
54 UpdatePowerProperties( | |
55 80, power_manager::PowerSupplyProperties_BatteryState_FULL, | |
56 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); | |
57 EXPECT_EQ(80, client_.props().battery_percent()); | |
58 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
59 client_.props().battery_state()); | |
60 } | |
61 | |
62 TEST_F(FakePowerManagerClientTest, ExternalPowerTest) { | |
63 // Test if setting battery_percent less than 100 and | |
64 // battery_state to CHARGING while external_power is set to | |
65 // USB will set external_power to USB. | |
66 UpdatePowerProperties( | |
67 80, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
68 power_manager::PowerSupplyProperties_ExternalPower_USB); | |
69 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, | |
70 client_.props().external_power()); | |
71 | |
72 // Test if setting battery_percent less than 100 and | |
73 // battery_state to DISCHARGING while external_power is set to | |
74 // USB will set external_power to USB. | |
75 UpdatePowerProperties( | |
76 80, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
77 power_manager::PowerSupplyProperties_ExternalPower_USB); | |
78 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, | |
79 client_.props().external_power()); | |
80 | |
81 // Test if setting battery_percent less than 100 and | |
82 // battery_state to CHARGING while external_power is set to | |
83 // DISCONNECTED will set external_power to AC. | |
84 UpdatePowerProperties( | |
85 80, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
86 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); | |
87 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_AC, | |
88 client_.props().external_power()); | |
89 | |
90 // Test if setting battery_percent less than 100 and | |
91 // battery_state to CHARGING while external_power is set to | |
92 // AC will set external_power to DISCONNECTED. | |
93 UpdatePowerProperties( | |
94 80, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
95 power_manager::PowerSupplyProperties_ExternalPower_AC); | |
96 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, | |
97 client_.props().external_power()); | |
98 } | |
99 | |
100 } // namespace chromeos | |
OLD | NEW |