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

Side by Side Diff: ash/system/chromeos/power/tray_power_unittest.cc

Issue 32443004: ash: Improve low-battery notification thresholds. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: apply review feedback: update comment Created 7 years, 2 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 | Annotate | Revision Log
« no previous file with comments | « ash/system/chromeos/power/tray_power.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 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/system/chromeos/power/tray_power.h" 5 #include "ash/system/chromeos/power/tray_power.h"
6 6
7 #include "ash/ash_switches.h" 7 #include "ash/ash_switches.h"
8 #include "ash/test/ash_test_base.h" 8 #include "ash/test/ash_test_base.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 10 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after
154 154
155 // No notification when charging. 155 // No notification when charging.
156 PowerSupplyProperties charging = DefaultPowerSupplyProperties(); 156 PowerSupplyProperties charging = DefaultPowerSupplyProperties();
157 charging.set_external_power( 157 charging.set_external_power(
158 power_manager::PowerSupplyProperties_ExternalPower_AC); 158 power_manager::PowerSupplyProperties_ExternalPower_AC);
159 charging.set_battery_state( 159 charging.set_battery_state(
160 power_manager::PowerSupplyProperties_BatteryState_CHARGING); 160 power_manager::PowerSupplyProperties_BatteryState_CHARGING);
161 EXPECT_FALSE(UpdateNotificationState(charging)); 161 EXPECT_FALSE(UpdateNotificationState(charging));
162 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state()); 162 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state());
163 163
164 // Critical low battery notification. 164 // When the rounded minutes-to-empty are above the threshold, no notification
165 // should be shown.
166 PowerSupplyProperties low = DefaultPowerSupplyProperties();
167 low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 + 30);
168 EXPECT_FALSE(UpdateNotificationState(low));
169 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state());
170
171 // When the rounded value matches the threshold, the notification should
172 // appear.
173 low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 + 29);
174 EXPECT_TRUE(UpdateNotificationState(low));
175 EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state());
176
177 // It should persist at lower values.
178 low.set_battery_time_to_empty_sec(TrayPower::kLowPowerMinutes * 60 - 20);
179 EXPECT_FALSE(UpdateNotificationState(low));
180 EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state());
181
182 // The critical low battery notification should be shown when the rounded
183 // value is at the lower threshold.
165 PowerSupplyProperties critical = DefaultPowerSupplyProperties(); 184 PowerSupplyProperties critical = DefaultPowerSupplyProperties();
166 critical.set_battery_time_to_empty_sec(60); 185 critical.set_battery_time_to_empty_sec(TrayPower::kCriticalMinutes * 60 + 29);
167 critical.set_battery_percent(2.0);
168 EXPECT_TRUE(UpdateNotificationState(critical)); 186 EXPECT_TRUE(UpdateNotificationState(critical));
169 EXPECT_EQ(TrayPower::NOTIFICATION_CRITICAL, notification_state()); 187 EXPECT_EQ(TrayPower::NOTIFICATION_CRITICAL, notification_state());
188
189 // The notification should be dismissed when the no-warning threshold is
190 // reached.
191 PowerSupplyProperties safe = DefaultPowerSupplyProperties();
192 safe.set_battery_time_to_empty_sec(TrayPower::kNoWarningMinutes * 60 - 29);
193 EXPECT_FALSE(UpdateNotificationState(safe));
194 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state());
195
196 // Test that rounded percentages are used when a USB charger is connected.
197 PowerSupplyProperties low_usb = DefaultPowerSupplyProperties();
198 low_usb.set_external_power(
199 power_manager::PowerSupplyProperties_ExternalPower_USB);
200 low_usb.set_battery_percent(TrayPower::kLowPowerPercentage + 0.5);
201 EXPECT_FALSE(UpdateNotificationState(low_usb));
202 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state());
203
204 low_usb.set_battery_percent(TrayPower::kLowPowerPercentage + 0.49);
205 EXPECT_TRUE(UpdateNotificationState(low_usb));
206 EXPECT_EQ(TrayPower::NOTIFICATION_LOW_POWER, notification_state());
207
208 PowerSupplyProperties critical_usb = DefaultPowerSupplyProperties();
209 critical_usb.set_external_power(
210 power_manager::PowerSupplyProperties_ExternalPower_USB);
211 critical_usb.set_battery_percent(TrayPower::kCriticalPercentage + 0.2);
212 EXPECT_TRUE(UpdateNotificationState(critical_usb));
213 EXPECT_EQ(TrayPower::NOTIFICATION_CRITICAL, notification_state());
214
215 PowerSupplyProperties safe_usb = DefaultPowerSupplyProperties();
216 safe_usb.set_external_power(
217 power_manager::PowerSupplyProperties_ExternalPower_USB);
218 safe_usb.set_battery_percent(TrayPower::kNoWarningPercentage - 0.1);
219 EXPECT_FALSE(UpdateNotificationState(safe_usb));
220 EXPECT_EQ(TrayPower::NOTIFICATION_NONE, notification_state());
170 } 221 }
171 222
172 } // namespace internal 223 } // namespace internal
173 } // namespace ash 224 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/chromeos/power/tray_power.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698