summaryrefslogtreecommitdiff
path: root/plugins/power/test.py
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2021-07-16 13:40:10 +0200
committerBastien Nocera <hadess@hadess.net>2021-07-22 22:02:30 +0200
commit3ff8b95c333689cbae4a0aa868cc214b118e0b3a (patch)
treebec420026a918373fa58e1e7f0121a98895315af /plugins/power/test.py
parent25374412a610ab473a937562e34c48ea0992c60a (diff)
downloadgnome-settings-daemon-3ff8b95c333689cbae4a0aa868cc214b118e0b3a.tar.gz
power: Enable power-saver profile when low on battery
When low on battery, and if the feature is enabled, hold the power profile to "power-saver" until the battery is sufficiently recharged.
Diffstat (limited to 'plugins/power/test.py')
-rwxr-xr-xplugins/power/test.py32
1 files changed, 32 insertions, 0 deletions
diff --git a/plugins/power/test.py b/plugins/power/test.py
index d98efc0a..e1d7d5e6 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -80,6 +80,13 @@ class PowerPluginBase(gsdtestcase.GSDTestCase):
'gnome_screensaver')
self.addCleanup(self.stop_process, self.screensaver)
+ # start mock power-profiles-daemon
+ try:
+ (self.ppd, self.obj_ppd) = self.spawn_server_template('power_profiles_daemon')
+ self.addCleanup(self.stop_process, self.ppd)
+ except ModuleNotFoundError:
+ self.ppd = None
+
self.start_session()
self.addCleanup(self.stop_session)
@@ -1235,5 +1242,30 @@ class PowerPluginTest8(PowerPluginBase):
self.assertEqual(exc.exception.get_dbus_message(), 'No usable backlight could be found!')
+ def test_power_saver_on_low_battery(self):
+ '''Check that the power-saver profile gets held when low on battery'''
+
+ if not self.ppd:
+ self.skipTest("power-profiles-daemon dbusmock support is not available")
+
+ obj_props = dbus.Interface(self.obj_ppd, dbus.PROPERTIES_IFACE)
+
+ self.set_composite_battery_discharging()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 0)
+
+ self.set_composite_battery_critical()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 1)
+ self.assertEqual(holds[0]['Profile'], 'power-saver')
+ self.assertEqual(holds[0]['ApplicationId'], 'org.gnome.SettingsDaemon.Power')
+
+ self.set_composite_battery_discharging()
+ time.sleep(0.5)
+ holds = obj_props.Get('net.hadess.PowerProfiles', 'ActiveProfileHolds')
+ self.assertEqual(len(holds), 0)
+
# avoid writing to stderr
unittest.main(testRunner=unittest.TextTestRunner(stream=sys.stdout, verbosity=2))