Chromium Code Reviews| 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 |