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

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 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 "testing/gtest/include/gtest/gtest.h"
8
9 namespace chromeos {
10
11 class FakePowerManagerClientTest : public testing::Test {
12 public:
13 // These are based on the PowerSupplyProperties enums for BatteryState
14 // and ExternalPower.
15 enum BatteryState { FULL, CHARGING, DISCHARGING };
Daniel Erat 2015/07/06 14:28:15 this will break; someone will update the proto's e
mozartalouis 2015/07/06 20:49:42 Done.
16 enum ExternalPower { AC, USB, DISCONNECTED };
17
18 FakePowerManagerClientTest() {
19 // Test the default values that are assigned when the
20 // FakePowerManagerClient::Init() is called.
21 client_.Init(nullptr);
22
23 EXPECT_EQ(50, client_.props().battery_percent());
Daniel Erat 2015/07/06 14:28:14 putting expectations in the base class doesn't mak
mozartalouis 2015/07/06 20:49:42 Done.
24 EXPECT_FALSE(client_.props().is_calculating_battery_time());
25 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
26 client_.props().battery_state());
27 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED,
28 client_.props().external_power());
29 }
30
31 void UpdatePowerProperties(int percentage,
32 BatteryState state,
33 ExternalPower power) {
34 client_.UpdatePowerProperties(
35 percentage, false,
36 static_cast<power_manager::PowerSupplyProperties_BatteryState>(state),
37 static_cast<power_manager::PowerSupplyProperties_ExternalPower>(power));
38 }
39
40 FakePowerManagerClient& client() { return client_; }
Daniel Erat 2015/07/06 14:28:15 we don't use non-const references (but see below;
mozartalouis 2015/07/06 20:49:42 Done.
41
42 private:
43 FakePowerManagerClient client_;
Daniel Erat 2015/07/06 14:28:15 put this in a "protected:" section; then derived c
mozartalouis 2015/07/06 20:49:42 Done.
44
45 DISALLOW_COPY_AND_ASSIGN(FakePowerManagerClientTest);
46 };
47
48 TEST_F(FakePowerManagerClientTest, BatteryStateTest) {
49 // Test if setting battery_percent to 100 and battery_state to
50 // CHARGING will reset the battery_state to FULL.
51 UpdatePowerProperties(100, BatteryState::CHARGING, ExternalPower::AC);
52 EXPECT_EQ(100, client().props().battery_percent());
53 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_FULL,
54 client().props().battery_state());
55
56 // Test if setting battery_percent less than 100 and
57 // battery_state to FULL will reset battery_state to
58 // DISCHARGING.
59 UpdatePowerProperties(80, BatteryState::FULL, ExternalPower::DISCONNECTED);
60 EXPECT_EQ(80, client().props().battery_percent());
61 EXPECT_EQ(power_manager::PowerSupplyProperties_BatteryState_DISCHARGING,
62 client().props().battery_state());
63 }
64
65 TEST_F(FakePowerManagerClientTest, ExternalPowerTest) {
66 // Test if setting battery_percent less than 100 and
67 // battery_state to CHARGING while external_power is set to
68 // USB will set external_power to USB.
69 UpdatePowerProperties(80, BatteryState::CHARGING, ExternalPower::USB);
70 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
71 client().props().external_power());
72
73 // Test if setting battery_percent less than 100 and
74 // battery_state to DISCHARGING while external_power is set to
75 // USB will set external_power to USB.
76 UpdatePowerProperties(80, BatteryState::DISCHARGING, ExternalPower::USB);
77 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_USB,
78 client().props().external_power());
79
80 // Test if setting battery_percent less than 100 and
81 // battery_state to CHARGING while external_power is set to
82 // DISCONNECTED will set external_power to AC.
83 UpdatePowerProperties(80, BatteryState::CHARGING,
84 ExternalPower::DISCONNECTED);
85 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_AC,
86 client().props().external_power());
87
88 // Test if setting battery_percent less than 100 and
89 // battery_state to CHARGING while external_power is set to
90 // AC will set external_power to DISCONNECTED.
91 UpdatePowerProperties(80, BatteryState::DISCHARGING, ExternalPower::AC);
92 EXPECT_EQ(power_manager::PowerSupplyProperties_ExternalPower_DISCONNECTED,
93 client().props().external_power());
94 }
95
96 } // namespace chromeos
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698