Index: chromeos/dbus/fake_power_manager_client_unittest.cc |
diff --git a/chromeos/dbus/fake_power_manager_client_unittest.cc b/chromeos/dbus/fake_power_manager_client_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..d3561d5b31e49bb438752ee01794e83a32fb37a5 |
--- /dev/null |
+++ b/chromeos/dbus/fake_power_manager_client_unittest.cc |
@@ -0,0 +1,100 @@ |
+// Copyright 2015 The Chromium Authors. All rights reserved. |
+// Use of this source code is governed by a BSD-style license that can be |
+// found in the LICENSE file. |
+ |
+#include "chromeos/dbus/fake_power_manager_client.h" |
+ |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace chromeos { |
+ |
+class FakePowerManagerClientTest : public testing::Test { |
+ public: |
+ FakePowerManagerClientTest() {} |
+ |
+ void UpdatePowerProperties( |
+ int percentage, |
+ power_manager::PowerSupplyProperties_BatteryState state, |
+ power_manager::PowerSupplyProperties_ExternalPower power) { |
+ client_.UpdatePowerProperties(percentage, false, state, power); |
+ } |
+ |
+ protected: |
+ FakePowerManagerClient client_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest); |
+}; |
+ |
+TEST_F(FakePowerManagerClientTest, InitializationTest) { |
+ // Test the default values that are assigned when the |
+ // FakePowerManagerClient::Init() is called. |
+ client_.Init(nullptr); |
+ |
+ 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.
|
+ EXPECT_FALSE(client_.props().is_calculating_battery_time()); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, |
+ client_.props().battery_state()); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, |
+ client_.props().external_power()); |
+} |
+ |
+TEST_F(FakePowerManagerClientTest, BatteryStateTest) { |
+ // Test if setting battery_percent to 100 and battery_state to |
+ // CHARGING will reset the battery_state to FULL. |
+ UpdatePowerProperties( |
+ 100, power_manager::PowerSupplyProperties_BatteryState_CHARGING, |
+ power_manager::PowerSupplyProperties_ExternalPower_AC); |
+ EXPECT_EQ(100, client_.props().battery_percent()); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_FULL, |
+ client_.props().battery_state()); |
+ |
+ // Test if setting battery_percent less than 100 and |
+ // battery_state to FULL will reset battery_state to |
+ // DISCHARGING. |
+ UpdatePowerProperties( |
+ 80, power_manager::PowerSupplyProperties_BatteryState_FULL, |
+ power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); |
+ EXPECT_EQ(80, client_.props().battery_percent()); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, |
+ client_.props().battery_state()); |
+} |
+ |
+TEST_F(FakePowerManagerClientTest, ExternalPowerTest) { |
+ // Test if setting battery_percent less than 100 and |
+ // battery_state to CHARGING while external_power is set to |
+ // USB will set external_power to USB. |
+ UpdatePowerProperties( |
+ 80, power_manager::PowerSupplyProperties_BatteryState_CHARGING, |
+ power_manager::PowerSupplyProperties_ExternalPower_USB); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, |
+ client_.props().external_power()); |
+ |
+ // Test if setting battery_percent less than 100 and |
+ // battery_state to DISCHARGING while external_power is set to |
+ // USB will set external_power to USB. |
+ UpdatePowerProperties( |
+ 80, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, |
+ power_manager::PowerSupplyProperties_ExternalPower_USB); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, |
+ client_.props().external_power()); |
+ |
+ // Test if setting battery_percent less than 100 and |
+ // battery_state to CHARGING while external_power is set to |
+ // DISCONNECTED will set external_power to AC. |
+ UpdatePowerProperties( |
+ 80, power_manager::PowerSupplyProperties_BatteryState_CHARGING, |
+ power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_AC, |
+ client_.props().external_power()); |
+ |
+ // Test if setting battery_percent less than 100 and |
+ // battery_state to CHARGING while external_power is set to |
+ // AC will set external_power to DISCONNECTED. |
+ UpdatePowerProperties( |
+ 80, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, |
+ power_manager::PowerSupplyProperties_ExternalPower_AC); |
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, |
+ client_.props().external_power()); |
+} |
+ |
+} // namespace chromeos |