Chromium Code Reviews| 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 namespace { | |
| 11 class TestObserver : public PowerManagerClient::Observer { | |
| 12 public: | |
| 13 TestObserver() : num_request_notify_observers_(0) {} | |
|
Daniel Erat
2015/07/09 15:41:48
add an empty virtual d'tor: https://google-stylegu
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 14 | |
| 15 power_manager::PowerSupplyProperties& props() { return props_; } | |
|
Daniel Erat
2015/07/09 15:41:48
both the return value and this method itself shoul
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 16 const int num_request_notify_observers() { | |
|
Daniel Erat
2015/07/09 15:41:48
this method should be const. the copy-by-value ret
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 17 return num_request_notify_observers_; | |
| 18 } | |
| 19 | |
| 20 void PowerChanged( | |
| 21 const power_manager::PowerSupplyProperties& proto) override { | |
| 22 props_ = proto; | |
| 23 ++num_request_notify_observers_; | |
| 24 } | |
| 25 | |
| 26 private: | |
| 27 int num_request_notify_observers_; | |
|
Daniel Erat
2015/07/09 15:41:47
this should probably be num_power_changed_ instead
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 28 power_manager::PowerSupplyProperties props_; | |
| 29 | |
| 30 DISALLOW_COPY_AND_ASSIGN(TestObserver); | |
| 31 }; | |
| 32 | |
| 33 } // namespace | |
| 34 | |
| 35 TEST(FakePowerManagerClientTest, UpdatePowerPropertiesTest) { | |
| 36 // Checking to verify when UpdatePowerProperties is called, | |
| 37 // |props_| values are updated. | |
| 38 FakePowerManagerClient client_; | |
| 39 | |
| 40 client_.UpdatePowerProperties( | |
| 41 90, false, power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
| 42 power_manager::PowerSupplyProperties_ExternalPower_USB); | |
| 43 | |
| 44 EXPECT_EQ(90, client_.props().battery_percent()); | |
| 45 EXPECT_FALSE(client_.props().is_calculating_battery_time()); | |
| 46 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_CHARGING, | |
| 47 client_.props().battery_state()); | |
| 48 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB, | |
| 49 client_.props().external_power()); | |
| 50 }; | |
| 51 | |
|
oshima
2015/07/09 17:10:16
can you also test if RequestStatusUpdate() works c
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 52 TEST(FakePowerManagerClientTest, NotifyObserversTest) { | |
| 53 TestObserver test_obeserver; | |
|
Daniel Erat
2015/07/09 15:41:47
this variable is misspelled throughout the functio
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 54 FakePowerManagerClient client_; | |
|
Daniel Erat
2015/07/09 15:41:48
no trailing underscore here; those are just to den
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 55 | |
| 56 // Test adding observer. | |
| 57 client_.AddObserver(&test_obeserver); | |
| 58 EXPECT_TRUE(client_.observers().HasObserver(&test_obeserver)); | |
|
Daniel Erat
2015/07/09 15:41:48
just call client.HasObserver()
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 59 | |
| 60 // Test if NotifyObservers sends the corrent values to ||. | |
|
Daniel Erat
2015/07/09 15:41:47
sp: correct
did you mean |observer| instead of ||
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 61 client_.UpdatePowerProperties( | |
| 62 90, true, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
| 63 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED); | |
| 64 | |
| 65 EXPECT_EQ(90, test_obeserver.props().battery_percent()); | |
| 66 EXPECT_TRUE(test_obeserver.props().is_calculating_battery_time()); | |
| 67 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING, | |
| 68 test_obeserver.props().battery_state()); | |
| 69 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED, | |
| 70 test_obeserver.props().external_power()); | |
| 71 | |
| 72 // Check number of times NotifyObservers is called. | |
| 73 EXPECT_EQ(1, test_obeserver.num_request_notify_observers()); | |
| 74 | |
| 75 // Test removing observer | |
| 76 client_.RemoveObserver(&test_obeserver); | |
| 77 EXPECT_FALSE(client_.observers().HasObserver(&test_obeserver)); | |
|
Daniel Erat
2015/07/09 15:41:47
client.HasObserver()
mozartalouis
2015/07/14 20:01:28
Done.
| |
| 78 }; | |
| 79 | |
| 80 } // namespace chromeos | |
| OLD | NEW |