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

Side by Side 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 unified diff | Download patch
OLDNEW
(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 "base/observer_list.h"
8 #include "testing/gtest/include/gtest/gtest.h"
9
10 namespace chromeos {
11
12 class FakePowerManagerClientTest : public testing::Test,
13 public FakePowerManagerClient::Observer {
oshima 2015/07/09 00:15:41 Please define a separate Observer class.
14 public:
15 FakePowerManagerClientTest() {}
16
17 void PowerChanged(
18 const power_manager::PowerSupplyProperties& proto) override {
19 props_ = proto;
20 }
21
22 protected:
23 FakePowerManagerClient client_;
oshima 2015/07/09 00:15:40 you can just create this on stack in the test body
24 power_manager::PowerSupplyProperties props_;
25
26 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest);
27 };
28
29 TEST_F(FakePowerManagerClientTest, UpdatePowerPropertiesTest) {
30 // Checking to verify when UpdatePowerProperties is called,
31 // |props_| values are updated.
32 client_.UpdatePowerProperties(
33 90, true, power_manager::PowerSupplyProperties_BatteryState_CHARGING,
34 power_manager::PowerSupplyProperties_ExternalPower_USB);
35
36 EXPECT_EQ(90, client_.props().battery_percent());
37 EXPECT_TRUE(client_.props().is_calculating_battery_time());
38 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_CHARGING,
39 client_.props().battery_state());
40 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
41 client_.props().external_power());
42 }
43
44 TEST_F(FakePowerManagerClientTest, NotifyObserversTest) {
45 // Test adding observer.
46 client_.AddObserver(this);
47 EXPECT_TRUE(client_.observers().HasObserver(this));
48
49 // Test if NotifyObservers sends the corrent values to |this.props_|.
50 client_.UpdatePowerProperties(
51 90, false, power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
52 power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED);
53
54 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.
55 EXPECT_EQ(this->props_.is_calculating_battery_time(),
56 client_.props().is_calculating_battery_time());
57 EXPECT_EQ(this->props_.battery_state(), client_.props().battery_state());
58 EXPECT_EQ(this->props_.external_power(), client_.props().external_power());
59
60 // Check number of times NotifyObservers is called.
61 EXPECT_EQ(1, client_.num_request_notify_observers());
62
63 // Test removing observer
64 client_.RemoveObserver(this);
65 EXPECT_FALSE(client_.observers().HasObserver(this));
66 }
67
68 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698