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

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 Unittest and removed power manager restrictions Created 5 years, 5 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
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..f706aa22116e4182bdb6ab018b4e294a3eb7e301
--- /dev/null
+++ b/chromeos/dbus/fake_power_manager_client_unittest.cc
@@ -0,0 +1,68 @@
+// 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 "base/observer_list.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace chromeos {
+
+class FakePowerManagerClientTest : public testing::Test,
+ public FakePowerManagerClient::Observer {
oshima 2015/07/09 00:15:41 Please define a separate Observer class.
+ public:
+ FakePowerManagerClientTest() {}
+
+ void PowerChanged(
+ const power_manager::PowerSupplyProperties& proto) override {
+ props_ = proto;
+ }
+
+ protected:
+ FakePowerManagerClient client_;
oshima 2015/07/09 00:15:40 you can just create this on stack in the test body
+ power_manager::PowerSupplyProperties props_;
+
+ DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest);
+};
+
+TEST_F(FakePowerManagerClientTest, UpdatePowerPropertiesTest) {
+ // Checking to verify when UpdatePowerProperties is called,
+ // |props_| values are updated.
+ client_.UpdatePowerProperties(
+ 90, true, power_manager::PowerSupplyProperties_BatteryState_CHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_USB);
+
+ EXPECT_EQ(90, client_.props().battery_percent());
+ EXPECT_TRUE(client_.props().is_calculating_battery_time());
+ EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_CHARGING,
+ client_.props().battery_state());
+ EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
+ client_.props().external_power());
+}
+
+TEST_F(FakePowerManagerClientTest, NotifyObserversTest) {
+ // Test adding observer.
+ client_.AddObserver(this);
+ EXPECT_TRUE(client_.observers().HasObserver(this));
+
+ // Test if NotifyObservers sends the corrent values to |this.props_|.
+ client_.UpdatePowerProperties(
+ 90, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
+ power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED);
+
+ EXPECT_EQ(this->props_.battery_percent(), client_.props().battery_percent());
oshima 2015/07/09 00:15:40 please test against the actual value set instead.
+ EXPECT_EQ(this->props_.is_calculating_battery_time(),
+ client_.props().is_calculating_battery_time());
+ EXPECT_EQ(this->props_.battery_state(), client_.props().battery_state());
+ EXPECT_EQ(this->props_.external_power(), client_.props().external_power());
+
+ // Check number of times NotifyObservers is called.
+ EXPECT_EQ(1, client_.num_request_notify_observers());
+
+ // Test removing observer
+ client_.RemoveObserver(this);
+ EXPECT_FALSE(client_.observers().HasObserver(this));
+}
+
+} // namespace chromeos

Powered by Google App Engine
This is Rietveld 408576698