| 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" | 9 #include "ash/resources/vector_icons/vector_icons.h" |
| 10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 152 EXPECT_EQ(0, minutes); | 152 EXPECT_EQ(0, minutes); |
| 153 } | 153 } |
| 154 | 154 |
| 155 TEST_F(PowerStatusTest, GetBatteryImageInfo) { | 155 TEST_F(PowerStatusTest, GetBatteryImageInfo) { |
| 156 PowerSupplyProperties prop; | 156 PowerSupplyProperties prop; |
| 157 prop.set_external_power(PowerSupplyProperties::AC); | 157 prop.set_external_power(PowerSupplyProperties::AC); |
| 158 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 158 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
| 159 prop.set_battery_percent(98.0); | 159 prop.set_battery_percent(98.0); |
| 160 power_status_->SetProtoForTesting(prop); | 160 power_status_->SetProtoForTesting(prop); |
| 161 const PowerStatus::BatteryImageInfo info_charging_98 = | 161 const PowerStatus::BatteryImageInfo info_charging_98 = |
| 162 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT); | 162 power_status_->GetBatteryImageInfo(); |
| 163 | 163 |
| 164 // 99% should use the same icon as 98%. | 164 // 99% should use the same icon as 98%. |
| 165 prop.set_battery_percent(99.0); | 165 prop.set_battery_percent(99.0); |
| 166 power_status_->SetProtoForTesting(prop); | 166 power_status_->SetProtoForTesting(prop); |
| 167 EXPECT_EQ(info_charging_98, | 167 EXPECT_EQ(info_charging_98, power_status_->GetBatteryImageInfo()); |
| 168 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); | |
| 169 | 168 |
| 170 // The dark icon set should use a different image for non-MD, but the | 169 // A different icon should be used when the battery is full. |
| 171 // same image for MD. | |
| 172 prop.set_battery_percent(98.0); | |
| 173 EXPECT_EQ(info_charging_98, | |
| 174 power_status_->GetBatteryImageInfo(PowerStatus::ICON_DARK)); | |
| 175 | |
| 176 // A different icon should be used when the battery is full, too. | |
| 177 prop.set_battery_state(PowerSupplyProperties::FULL); | 170 prop.set_battery_state(PowerSupplyProperties::FULL); |
| 178 prop.set_battery_percent(100.0); | 171 prop.set_battery_percent(100.0); |
| 179 power_status_->SetProtoForTesting(prop); | 172 power_status_->SetProtoForTesting(prop); |
| 180 EXPECT_NE(info_charging_98, | 173 EXPECT_NE(info_charging_98, power_status_->GetBatteryImageInfo()); |
| 181 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); | |
| 182 | 174 |
| 183 // A much-lower battery level should use a different icon. | 175 // A much-lower battery level should use a different icon. |
| 184 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 176 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
| 185 prop.set_battery_percent(20.0); | 177 prop.set_battery_percent(20.0); |
| 186 power_status_->SetProtoForTesting(prop); | 178 power_status_->SetProtoForTesting(prop); |
| 187 EXPECT_NE(info_charging_98, | 179 EXPECT_NE(info_charging_98, power_status_->GetBatteryImageInfo()); |
| 188 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); | |
| 189 | 180 |
| 190 // Ditto for 98%, but on USB instead of AC. | 181 // Ditto for 98%, but on USB instead of AC. |
| 191 prop.set_external_power(PowerSupplyProperties::USB); | 182 prop.set_external_power(PowerSupplyProperties::USB); |
| 192 prop.set_battery_percent(98.0); | 183 prop.set_battery_percent(98.0); |
| 193 power_status_->SetProtoForTesting(prop); | 184 power_status_->SetProtoForTesting(prop); |
| 194 EXPECT_NE(info_charging_98, | 185 EXPECT_NE(info_charging_98, power_status_->GetBatteryImageInfo()); |
| 195 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT)); | |
| 196 } | 186 } |
| 197 | 187 |
| 198 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly | 188 // Tests that the |icon_badge| member of BatteryImageInfo is set correctly |
| 199 // with various power supply property values. | 189 // with various power supply property values. |
| 200 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) { | 190 TEST_F(PowerStatusTest, BatteryImageInfoIconBadge) { |
| 201 PowerSupplyProperties prop; | 191 PowerSupplyProperties prop; |
| 202 | 192 |
| 203 // A charging battery connected to AC power should have a bolt badge. | 193 // A charging battery connected to AC power should have a bolt badge. |
| 204 prop.set_external_power(PowerSupplyProperties::AC); | 194 prop.set_external_power(PowerSupplyProperties::AC); |
| 205 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 195 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
| 206 prop.set_battery_percent(98.0); | 196 prop.set_battery_percent(98.0); |
| 207 power_status_->SetProtoForTesting(prop); | 197 power_status_->SetProtoForTesting(prop); |
| 208 const gfx::VectorIcon* bolt_icon = | 198 const gfx::VectorIcon* bolt_icon = |
| 209 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge; | 199 power_status_->GetBatteryImageInfo().icon_badge; |
| 210 EXPECT_TRUE(bolt_icon); | 200 EXPECT_TRUE(bolt_icon); |
| 211 | 201 |
| 212 // A discharging battery connected to AC should also have a bolt badge. | 202 // A discharging battery connected to AC should also have a bolt badge. |
| 213 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 203 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
| 214 power_status_->SetProtoForTesting(prop); | 204 power_status_->SetProtoForTesting(prop); |
| 215 EXPECT_EQ( | 205 EXPECT_EQ(bolt_icon, power_status_->GetBatteryImageInfo().icon_badge); |
| 216 bolt_icon, | |
| 217 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | |
| 218 | 206 |
| 219 // A charging battery connected to USB power should have an | 207 // A charging battery connected to USB power should have an |
| 220 // unreliable badge. | 208 // unreliable badge. |
| 221 prop.set_external_power(PowerSupplyProperties::USB); | 209 prop.set_external_power(PowerSupplyProperties::USB); |
| 222 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 210 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
| 223 power_status_->SetProtoForTesting(prop); | 211 power_status_->SetProtoForTesting(prop); |
| 224 const gfx::VectorIcon* unreliable_icon = | 212 const gfx::VectorIcon* unreliable_icon = |
| 225 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge; | 213 power_status_->GetBatteryImageInfo().icon_badge; |
| 226 EXPECT_NE(unreliable_icon, bolt_icon); | 214 EXPECT_NE(unreliable_icon, bolt_icon); |
| 227 EXPECT_TRUE(unreliable_icon); | 215 EXPECT_TRUE(unreliable_icon); |
| 228 | 216 |
| 229 // A discharging battery connected to USB power should also have an | 217 // A discharging battery connected to USB power should also have an |
| 230 // unreliable badge. | 218 // unreliable badge. |
| 231 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 219 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
| 232 power_status_->SetProtoForTesting(prop); | 220 power_status_->SetProtoForTesting(prop); |
| 233 EXPECT_EQ( | 221 EXPECT_EQ(unreliable_icon, power_status_->GetBatteryImageInfo().icon_badge); |
| 234 unreliable_icon, | |
| 235 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | |
| 236 | 222 |
| 237 // Show the right icon when no battery is present. | 223 // Show the right icon when no battery is present. |
| 238 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); | 224 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); |
| 239 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); | 225 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); |
| 240 power_status_->SetProtoForTesting(prop); | 226 power_status_->SetProtoForTesting(prop); |
| 241 const gfx::VectorIcon* x_icon = | 227 const gfx::VectorIcon* x_icon = |
| 242 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge; | 228 power_status_->GetBatteryImageInfo().icon_badge; |
| 243 EXPECT_TRUE(x_icon); | 229 EXPECT_TRUE(x_icon); |
| 244 EXPECT_NE(bolt_icon, x_icon); | 230 EXPECT_NE(bolt_icon, x_icon); |
| 245 EXPECT_NE(unreliable_icon, x_icon); | 231 EXPECT_NE(unreliable_icon, x_icon); |
| 246 | 232 |
| 247 // Do not show a badge when the battery is discharging. | 233 // Do not show a badge when the battery is discharging. |
| 248 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); | 234 prop.set_battery_state(PowerSupplyProperties::DISCHARGING); |
| 249 power_status_->SetProtoForTesting(prop); | 235 power_status_->SetProtoForTesting(prop); |
| 250 EXPECT_FALSE( | 236 EXPECT_FALSE(power_status_->GetBatteryImageInfo().icon_badge); |
| 251 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | |
| 252 | 237 |
| 253 // Show the right icon for a discharging battery when it falls below | 238 // Show the right icon for a discharging battery when it falls below |
| 254 // a charge level of PowerStatus::kCriticalBatteryChargePercentage. | 239 // a charge level of PowerStatus::kCriticalBatteryChargePercentage. |
| 255 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage); | 240 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage); |
| 256 power_status_->SetProtoForTesting(prop); | 241 power_status_->SetProtoForTesting(prop); |
| 257 EXPECT_FALSE( | 242 EXPECT_FALSE(power_status_->GetBatteryImageInfo().icon_badge); |
| 258 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge); | |
| 259 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage - 1); | 243 prop.set_battery_percent(PowerStatus::kCriticalBatteryChargePercentage - 1); |
| 260 power_status_->SetProtoForTesting(prop); | 244 power_status_->SetProtoForTesting(prop); |
| 261 const gfx::VectorIcon* alert_icon = | 245 const gfx::VectorIcon* alert_icon = |
| 262 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).icon_badge; | 246 power_status_->GetBatteryImageInfo().icon_badge; |
| 263 EXPECT_TRUE(alert_icon); | 247 EXPECT_TRUE(alert_icon); |
| 264 EXPECT_NE(bolt_icon, alert_icon); | 248 EXPECT_NE(bolt_icon, alert_icon); |
| 265 EXPECT_NE(unreliable_icon, alert_icon); | 249 EXPECT_NE(unreliable_icon, alert_icon); |
| 266 EXPECT_NE(x_icon, alert_icon); | 250 EXPECT_NE(x_icon, alert_icon); |
| 267 } | 251 } |
| 268 | 252 |
| 269 // Tests that the |charge_level| member of BatteryImageInfo is set correctly | 253 // Tests that the |charge_level| member of BatteryImageInfo is set correctly |
| 270 // with various power supply property values. | 254 // with various power supply property values. |
| 271 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) { | 255 TEST_F(PowerStatusTest, BatteryImageInfoChargeLevel) { |
| 272 PowerSupplyProperties prop; | 256 PowerSupplyProperties prop; |
| 273 | 257 |
| 274 // No charge level is drawn when the battery is not present. | 258 // No charge level is drawn when the battery is not present. |
| 275 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); | 259 prop.set_external_power(PowerSupplyProperties::DISCONNECTED); |
| 276 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); | 260 prop.set_battery_state(PowerSupplyProperties::NOT_PRESENT); |
| 277 power_status_->SetProtoForTesting(prop); | 261 power_status_->SetProtoForTesting(prop); |
| 278 EXPECT_EQ( | 262 EXPECT_EQ(0, power_status_->GetBatteryImageInfo().charge_level); |
| 279 0, | |
| 280 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 281 | 263 |
| 282 // A charge level of 0 when the battery is 0% full. | 264 // A charge level of 0 when the battery is 0% full. |
| 283 prop.set_external_power(PowerSupplyProperties::AC); | 265 prop.set_external_power(PowerSupplyProperties::AC); |
| 284 prop.set_battery_state(PowerSupplyProperties::CHARGING); | 266 prop.set_battery_state(PowerSupplyProperties::CHARGING); |
| 285 prop.set_battery_percent(0.0); | 267 prop.set_battery_percent(0.0); |
| 286 EXPECT_EQ( | 268 EXPECT_EQ(0, power_status_->GetBatteryImageInfo().charge_level); |
| 287 0, | |
| 288 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 289 | 269 |
| 290 // A charge level of 1 when the battery is up to 16% full, and a level of 2 | 270 // A charge level of 1 when the battery is up to 16% full, and a level of 2 |
| 291 // for 17% full. | 271 // for 17% full. |
| 292 prop.set_battery_percent(16.0); | 272 prop.set_battery_percent(16.0); |
| 293 power_status_->SetProtoForTesting(prop); | 273 power_status_->SetProtoForTesting(prop); |
| 294 EXPECT_EQ( | 274 EXPECT_EQ(1, power_status_->GetBatteryImageInfo().charge_level); |
| 295 1, | |
| 296 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 297 prop.set_battery_percent(17.0); | 275 prop.set_battery_percent(17.0); |
| 298 power_status_->SetProtoForTesting(prop); | 276 power_status_->SetProtoForTesting(prop); |
| 299 EXPECT_EQ( | 277 EXPECT_EQ(2, power_status_->GetBatteryImageInfo().charge_level); |
| 300 2, | |
| 301 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 302 | 278 |
| 303 // A charge level of 6 when the battery is 50% full. | 279 // A charge level of 6 when the battery is 50% full. |
| 304 prop.set_battery_percent(50.0); | 280 prop.set_battery_percent(50.0); |
| 305 power_status_->SetProtoForTesting(prop); | 281 power_status_->SetProtoForTesting(prop); |
| 306 EXPECT_EQ( | 282 EXPECT_EQ(6, power_status_->GetBatteryImageInfo().charge_level); |
| 307 6, | |
| 308 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 309 | 283 |
| 310 // A charge level of 11 when the battery is 99% full, and a level of 12 when | 284 // A charge level of 11 when the battery is 99% full, and a level of 12 when |
| 311 // the battery is 100% full. | 285 // the battery is 100% full. |
| 312 prop.set_battery_percent(99.0); | 286 prop.set_battery_percent(99.0); |
| 313 power_status_->SetProtoForTesting(prop); | 287 power_status_->SetProtoForTesting(prop); |
| 314 EXPECT_EQ( | 288 EXPECT_EQ(11, power_status_->GetBatteryImageInfo().charge_level); |
| 315 11, | |
| 316 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 317 prop.set_battery_percent(100.0); | 289 prop.set_battery_percent(100.0); |
| 318 power_status_->SetProtoForTesting(prop); | 290 power_status_->SetProtoForTesting(prop); |
| 319 EXPECT_EQ( | 291 EXPECT_EQ(12, power_status_->GetBatteryImageInfo().charge_level); |
| 320 12, | |
| 321 power_status_->GetBatteryImageInfo(PowerStatus::ICON_LIGHT).charge_level); | |
| 322 } | 292 } |
| 323 | 293 |
| 324 } // namespace ash | 294 } // namespace ash |
| OLD | NEW |