OLD | NEW |
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/common/system/chromeos/power/power_status.h" | 5 #include "ash/common/system/chromeos/power/power_status.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/resources/vector_icons/vector_icons.h" | |
10 #include "base/message_loop/message_loop.h" | 9 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
12 #include "chromeos/dbus/dbus_thread_manager.h" | 11 #include "chromeos/dbus/dbus_thread_manager.h" |
13 #include "testing/gtest/include/gtest/gtest.h" | 12 #include "testing/gtest/include/gtest/gtest.h" |
14 #include "third_party/cros_system_api/dbus/service_constants.h" | 13 #include "third_party/cros_system_api/dbus/service_constants.h" |
15 | 14 |
16 using power_manager::PowerSupplyProperties; | 15 using power_manager::PowerSupplyProperties; |
17 | 16 |
18 namespace ash { | 17 namespace ash { |
19 namespace { | 18 namespace { |
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 power_status_->SetProtoForTesting(prop); | 192 power_status_->SetProtoForTesting(prop); |
194 EXPECT_NE(info_charging_98, | 193 EXPECT_NE(info_charging_98, |
195 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); | 194 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); |
196 } | 195 } |
197 | 196 |
198 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly | 197 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly |
199 // with various power supply property values. | 198 // with various power supply property values. |
200 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) { | 199 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) { |
201 PowerSupplyProperties prop; | 200 PowerSupplyProperties prop; |
202 | 201 |
203 // A charging battery connected to AC power should have a bolt badge. | 202 // A charging battery connected to AC power should have an ICON_BADGE_BOLT. |
204 prop.set_external_power(PowerSupplyProperties::AC); | 203 prop.set_external_power(PowerSupplyProperties::AC); |
205 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 204 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
206 prop.set_battery_percent(98.0); | 205 prop.set_battery_percent(98.0); |
207 power_status_->SetProtoForTesting(prop); | 206 power_status_->SetProtoForTesting(prop); |
208 EXPECT_EQ( | 207 EXPECT_EQ( |
209 &kSystemTrayBatteryBoltIcon, | 208 PowerStatus::ICON_BADGE_BOLT, |
210 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 209 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
211 | 210 |
212 // A discharging battery connected to AC should also have a bolt badge. | 211 // A discharging battery connected to AC should also have an ICON_BADGE_BOLT. |
213 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 212 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
214 power_status_->SetProtoForTesting(prop); | 213 power_status_->SetProtoForTesting(prop); |
215 EXPECT_EQ( | 214 EXPECT_EQ( |
216 &kSystemTrayBatteryBoltIcon, | 215 PowerStatus::ICON_BADGE_BOLT, |
217 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 216 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
218 | 217 |
219 // A charging battery connected to USB power should have an | 218 // A charging battery connected to USB power should have an |
220 // unreliable badge. | 219 // ICON_BADGE_UNRELIABLE. |
221 prop.set_external_power(PowerSupplyProperties::USB); | 220 prop.set_external_power(PowerSupplyProperties::USB); |
222 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 221 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
223 power_status_->SetProtoForTesting(prop); | 222 power_status_->SetProtoForTesting(prop); |
224 EXPECT_EQ( | 223 EXPECT_EQ( |
225 &kSystemTrayBatteryUnreliableIcon, | 224 PowerStatus::ICON_BADGE_UNRELIABLE, |
226 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 225 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
227 | 226 |
228 // A discharging battery connected to USB power should also have an | 227 // A discharging battery connected to USB power should also have an |
229 // unreliable badge. | 228 // ICON_BADGE_UNRELIABLE. |
230 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 229 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
231 power_status_->SetProtoForTesting(prop); | 230 power_status_->SetProtoForTesting(prop); |
232 EXPECT_EQ( | 231 EXPECT_EQ( |
233 &kSystemTrayBatteryUnreliableIcon, | 232 PowerStatus::ICON_BADGE_UNRELIABLE, |
234 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 233 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
235 | 234 |
236 // Show the right icon when no battery is present. | 235 // Show an ICON_BADGE_X when no battery is present. |
237 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); | 236 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); |
238 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); | 237 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); |
239 power_status_->SetProtoForTesting(prop); | 238 power_status_->SetProtoForTesting(prop); |
240 EXPECT_EQ( | 239 EXPECT_EQ( |
241 &kSystemTrayBatteryXIcon, | 240 PowerStatus::ICON_BADGE_X, |
242 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 241 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
243 | 242 |
244 // Do not show a badge when the battery is discharging. | 243 // Do not show a badge when the battery is discharging. |
245 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 244 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
246 power_status_->SetProtoForTesting(prop); | 245 power_status_->SetProtoForTesting(prop); |
247 EXPECT_EQ( | 246 EXPECT_EQ( |
248 nullptr, | 247 PowerStatus::ICON_BADGE_NONE, |
249 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 248 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
250 | 249 |
251 // Show the right icon for a discharging battery when it falls below | 250 // Show ICON_BADGE_ALERT for a discharging battery when it falls below |
252 // a charge level of PowerStatus::kCriticalBatteryChargePercentage. | 251 // a charge level of PowerStatus::kCriticalBatteryChargePercentageMd. |
253 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage); | 252 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd); |
254 power_status_->SetProtoForTesting(prop); | 253 power_status_->SetProtoForTesting(prop); |
255 EXPECT_EQ( | 254 EXPECT_EQ( |
256 nullptr, | 255 PowerStatus::ICON_BADGE_NONE, |
257 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 256 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
258 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage - 1); | 257 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd - 1); |
259 power_status_->SetProtoForTesting(prop); | 258 power_status_->SetProtoForTesting(prop); |
260 EXPECT_EQ( | 259 EXPECT_EQ( |
261 &kSystemTrayBatteryAlertIcon, | 260 PowerStatus::ICON_BADGE_ALERT, |
262 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | 261 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); |
263 } | 262 } |
264 | 263 |
265 // Tests that the |charge_level| member of BatteryImageInfo is set correctly | 264 // Tests that the |charge_level| member of BatteryImageInfo is set correctly |
266 // with various power supply property values. | 265 // with various power supply property values. |
267 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) { | 266 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) { |
268 PowerSupplyProperties prop; | 267 PowerSupplyProperties prop; |
269 | 268 |
270 // No charge level is drawn when the battery is not present. | 269 // No charge level is drawn when the battery is not present. |
271 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); | 270 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
311 11, | 310 11, |
312 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | 311 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); |
313 prop.set_battery_percent(100.0); | 312 prop.set_battery_percent(100.0); |
314 power_status_->SetProtoForTesting(prop); | 313 power_status_->SetProtoForTesting(prop); |
315 EXPECT_EQ( | 314 EXPECT_EQ( |
316 12, | 315 12, |
317 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | 316 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); |
318 } | 317 } |
319 | 318 |
320 } // namespace ash | 319 } // namespace ash |
OLD | NEW |