Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(98)

Unified Diff: chromeos/dbus/fake_power_manager_client_unittest.cc

Issue 1206733002: ChromeOs Power Emulation Impl (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Updated test and logic Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chromeos/dbus/fake_power_manager_client.cc ('k') | chromeos/dbus/power_manager_client.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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..81dcf1c35e2709a8bc20f5dda9acd808143cae10
--- /dev/null
+++ b/chromeos/dbus/fake_power_manager_client_unittest.cc
@@ -0,0 +1,98 @@
+// 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:
+ FakePowerManagerClientTest() {
+ // Test the default values that are assign when the
+ // FakePowerManagerClient::Init() function is created.
afakhry 2015/07/01 16:47:48 Nits: - "assign" --> "assigned" - "created" --> "c
mozartalouis 2015/07/01 20:05:23 Done.
+ client().Init(NULL);
afakhry 2015/07/01 16:47:48 NULL --> nullptr
mozartalouis 2015/07/01 20:05:23 Done.
+
+ EXPECT_EQ(50, client().props().battery_percent());
afakhry 2015/07/01 16:47:48 Nit: You don't have to use client() here, you're i
mozartalouis 2015/07/01 20:05:23 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());
+ }
+
+ FakePowerManagerClient& client() { return client_; }
+
+ private:
+ FakePowerManagerClient client_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest);
+};
+
+TEST_F(FakePowerManagerClientTest, BatteryStateTest) {
+ // Test if setting props_.battery_percent to 100 and props_.battery_state to
+ // _CHARGING will set props_.battery_state to _FULL.
+ client().UpdatePowerProperties(
afakhry 2015/07/01 16:47:48 I would make things more readable here by wrapping
mozartalouis 2015/07/01 20:05:23 Done.
+ 100, false, 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 props_.battery_percent less than 100 and
+ // props_.battery_state to _FULL will set props_.battery_state to
+ // _DISCHARGING.
+ client().UpdatePowerProperties(
+ 80, false, 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 props_.battery_percent less than 100 and
+ // props_.battery_state to _CHARGING while props_.external_power is set to
+ // _USB will set props_.external_power to _USB
+ client().UpdatePowerProperties(
+ 80, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_USB);
+
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
+ client().props().external_power());
+
+ // Test if setting props_.battery_percent less than 100 and
+ // props_.battery_state to _DISCHARGING while props_.external_power is set to
+ // _USB will set props_.external_power to _USB
+ client().UpdatePowerProperties(
+ 80, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_USB);
+
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
+ client().props().external_power());
+
+ // Test if setting props_.battery_percent less than 100 and
+ // props_.battery_state to _CHARGING while props_.external_power is set to
+ // _DISCONNECTED will set props_.external_power to _AC
+ client().UpdatePowerProperties(
+ 80, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED);
+
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_AC,
+ client().props().external_power());
+
+ // Test if setting props_.battery_percent less than 100 and
+ // props_.battery_state to _CHARGING while props_.external_power is set to
+ // _AC will set props_.external_power to _DISCONNECTED
+ client().UpdatePowerProperties(
+ 80, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_AC);
+
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED,
+ client().props().external_power());
+}
+
+} // namespace chromeos
« no previous file with comments | « chromeos/dbus/fake_power_manager_client.cc ('k') | chromeos/dbus/power_manager_client.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698