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

Side by Side Diff: ash/common/system/chromeos/power/power_status_unittest.cc

Issue 2783503002: retry cd95e0083676d5e: Remove some pre-md code and assets. (Closed)
Patch Set: fix test Created 3 years, 8 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
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"
9 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
10 #include "base/run_loop.h" 11 #include "base/run_loop.h"
11 #include "chromeos/dbus/dbus_thread_manager.h" 12 #include "chromeos/dbus/dbus_thread_manager.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/cros_system_api/dbus/service_constants.h" 14 #include "third_party/cros_system_api/dbus/service_constants.h"
14 15
15 using power_manager::PowerSupplyProperties; 16 using power_manager::PowerSupplyProperties;
16 17
17 namespace ash { 18 namespace ash {
18 namespace { 19 namespace {
(...skipping 173 matching lines...) Expand 10 before | Expand all | Expand 10 after
192 power_status_->SetProtoForTesting(prop); 193 power_status_->SetProtoForTesting(prop);
193 EXPECT_NE(info_charging_98, 194 EXPECT_NE(info_charging_98,
194 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); 195 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT));
195 } 196 }
196 197
197 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly 198 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly
198 // with various power supply property values. 199 // with various power supply property values.
199 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) { 200 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) {
200 PowerSupplyProperties prop; 201 PowerSupplyProperties prop;
201 202
202 // A charging battery connected to AC power should have an ICON_BADGE_BOLT. 203 // A charging battery connected to AC power should have a bolt badge.
203 prop.set_external_power(PowerSupplyProperties::AC); 204 prop.set_external_power(PowerSupplyProperties::AC);
204 prop.set_battery_state(PowerSupplyProperties::CHARGING); 205 prop.set_battery_state(PowerSupplyProperties::CHARGING);
205 prop.set_battery_percent(98.0); 206 prop.set_battery_percent(98.0);
206 power_status_->SetProtoForTesting(prop); 207 power_status_->SetProtoForTesting(prop);
207 EXPECT_EQ( 208 const gfx::VectorIcon* bolt_icon =
208 PowerStatus::ICON_BADGE_BOLT, 209 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge;
209 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 210 EXPECT_TRUE(bolt_icon);
210 211
211 // A discharging battery connected to AC should also have an ICON_BADGE_BOLT. 212 // A discharging battery connected to AC should also have a bolt badge.
212 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); 213 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
213 power_status_->SetProtoForTesting(prop); 214 power_status_->SetProtoForTesting(prop);
214 EXPECT_EQ( 215 EXPECT_EQ(
215 PowerStatus::ICON_BADGE_BOLT, 216 bolt_icon,
216 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 217 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
217 218
218 // A charging battery connected to USB power should have an 219 // A charging battery connected to USB power should have an
219 // ICON_BADGE_UNRELIABLE. 220 // unreliable badge.
220 prop.set_external_power(PowerSupplyProperties::USB); 221 prop.set_external_power(PowerSupplyProperties::USB);
221 prop.set_battery_state(PowerSupplyProperties::CHARGING); 222 prop.set_battery_state(PowerSupplyProperties::CHARGING);
222 power_status_->SetProtoForTesting(prop); 223 power_status_->SetProtoForTesting(prop);
223 EXPECT_EQ( 224 const gfx::VectorIcon* unreliable_icon =
224 PowerStatus::ICON_BADGE_UNRELIABLE, 225 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge;
225 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 226 EXPECT_NE(unreliable_icon, bolt_icon);
227 EXPECT_TRUE(unreliable_icon);
226 228
227 // A discharging battery connected to USB power should also have an 229 // A discharging battery connected to USB power should also have an
228 // ICON_BADGE_UNRELIABLE. 230 // unreliable badge.
229 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); 231 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
230 power_status_->SetProtoForTesting(prop); 232 power_status_->SetProtoForTesting(prop);
231 EXPECT_EQ( 233 EXPECT_EQ(
232 PowerStatus::ICON_BADGE_UNRELIABLE, 234 unreliable_icon,
233 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 235 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
234 236
235 // Show an ICON_BADGE_X when no battery is present. 237 // Show the right icon when no battery is present.
236 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); 238 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
237 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); 239 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT);
238 power_status_->SetProtoForTesting(prop); 240 power_status_->SetProtoForTesting(prop);
239 EXPECT_EQ( 241 const gfx::VectorIcon* x_icon =
240 PowerStatus::ICON_BADGE_X, 242 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge;
241 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 243 EXPECT_TRUE(x_icon);
244 EXPECT_NE(bolt_icon, x_icon);
245 EXPECT_NE(unreliable_icon, x_icon);
242 246
243 // Do not show a badge when the battery is discharging. 247 // Do not show a badge when the battery is discharging.
244 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); 248 prop.set_battery_state(PowerSupplyProperties::DISCHARGING);
245 power_status_->SetProtoForTesting(prop); 249 power_status_->SetProtoForTesting(prop);
246 EXPECT_EQ( 250 EXPECT_FALSE(
247 PowerStatus::ICON_BADGE_NONE,
248 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 251 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
249 252
250 // Show ICON_BADGE_ALERT for a discharging battery when it falls below 253 // Show the right icon for a discharging battery when it falls below
251 // a charge level of PowerStatus::kCriticalBatteryChargePercentageMd. 254 // a charge level of PowerStatus::kCriticalBatteryChargePercentage.
252 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd); 255 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage);
253 power_status_->SetProtoForTesting(prop); 256 power_status_->SetProtoForTesting(prop);
254 EXPECT_EQ( 257 EXPECT_FALSE(
255 PowerStatus::ICON_BADGE_NONE,
256 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 258 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge);
257 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentageMd - 1); 259 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage - 1);
258 power_status_->SetProtoForTesting(prop); 260 power_status_->SetProtoForTesting(prop);
259 EXPECT_EQ( 261 const gfx::VectorIcon* alert_icon =
260 PowerStatus::ICON_BADGE_ALERT, 262 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge;
261 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); 263 EXPECT_TRUE(alert_icon);
264 EXPECT_NE(bolt_icon, alert_icon);
265 EXPECT_NE(unreliable_icon, alert_icon);
266 EXPECT_NE(x_icon, alert_icon);
262 } 267 }
263 268
264 // Tests that the |charge_level| member of BatteryImageInfo is set correctly 269 // Tests that the |charge_level| member of BatteryImageInfo is set correctly
265 // with various power supply property values. 270 // with various power supply property values.
266 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) { 271 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) {
267 PowerSupplyProperties prop; 272 PowerSupplyProperties prop;
268 273
269 // No charge level is drawn when the battery is not present. 274 // No charge level is drawn when the battery is not present.
270 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); 275 prop.set_external_power(PowerSupplyProperties::DISCONNECTED);
271 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); 276 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT);
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
310 11, 315 11,
311 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); 316 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level);
312 prop.set_battery_percent(100.0); 317 prop.set_battery_percent(100.0);
313 power_status_->SetProtoForTesting(prop); 318 power_status_->SetProtoForTesting(prop);
314 EXPECT_EQ( 319 EXPECT_EQ(
315 12, 320 12,
316 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); 321 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level);
317 } 322 }
318 323
319 } // namespace ash 324 } // namespace ash
OLDNEW
« no previous file with comments | « ash/common/system/chromeos/power/power_status.cc ('k') | ash/common/system/chromeos/session/tray_session_length_limit.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698