[gnome-settings-daemon] power tests: Check idle/suspend inhibition



commit 62f76177d498fb5caf6159df235050a3835cc182
Author: Martin Pitt <martinpitt gnome org>
Date:   Mon Jan 14 16:45:38 2013 +0100

    power tests: Check idle/suspend inhibition

 plugins/power/test.py |   30 ++++++++++++++++++++++++++++++
 tests/gsdtestcase.py  |    7 +++++++
 2 files changed, 37 insertions(+), 0 deletions(-)
---
diff --git a/plugins/power/test.py b/plugins/power/test.py
index 79d4ffb..c836906 100755
--- a/plugins/power/test.py
+++ b/plugins/power/test.py
@@ -136,6 +136,36 @@ class PowerPluginTest(gsdtestcase.GSDTestCase):
         # 1 s notification delay + 1 s error margin
         self.check_for_suspend(16)
 
+    def test_sleep_inhibition(self):
+        '''Does not sleep under idle inhibition'''
+
+        self.settings_session['idle-delay'] = 2
+        # disable screen blanking
+        self.settings_gsd_power['sleep-display-battery'] = 0
+        self.settings_gsd_power['sleep-inactive-battery-timeout'] = 5
+        self.settings_gsd_power['sleep-inactive-battery-type'] = 'suspend'
+
+        # flush notification log
+        try:
+            self.p_notify.stdout.read()
+        except IOError:
+            pass
+
+        # create inhibitor
+        inhibit_id = self.obj_session_mgr.Inhibit(
+            'testsuite', dbus.UInt32(0), 'for testing',
+            dbus.UInt32(gsdtestcase.GSM_INHIBITOR_FLAG_IDLE | gsdtestcase.GSM_INHIBITOR_FLAG_SUSPEND))
+        try:
+            # wait long enough to ensure it didn't do anything
+            time.sleep(7)
+            # check that it did not suspend or hibernate
+            log = self.logind.stdout.read()
+            if log:
+                self.assertFalse(b' Suspend' in log, 'unexpected Suspend request')
+                self.assertFalse(b' Hibernate' in log, 'unexpected Hibernate request')
+        finally:
+            self.obj_session_mgr.Uninhibit(dbus.UInt32(inhibit_id))
+
     def test_action_critical_battery(self):
         '''action on critical battery'''
 
diff --git a/tests/gsdtestcase.py b/tests/gsdtestcase.py
index 3d2485f..5b93365 100644
--- a/tests/gsdtestcase.py
+++ b/tests/gsdtestcase.py
@@ -34,6 +34,13 @@ if subprocess.call(['which', 'gnome-session'], stdout=subprocess.PIPE) != 0:
 top_builddir = os.environ.get('TOP_BUILDDIR',
                               os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
 
+# from gnome-session/gsm-inhibitor.h
+GSM_INHIBITOR_FLAG_LOGOUT      = 1 << 0
+GSM_INHIBITOR_FLAG_SWITCH_USER = 1 << 1
+GSM_INHIBITOR_FLAG_SUSPEND     = 1 << 2
+GSM_INHIBITOR_FLAG_IDLE        = 1 << 3
+GSM_INHIBITOR_FLAG_AUTOMOUNT   = 1 << 4
+
 
 def set_nonblock(fd):
     '''Set a file object to non-blocking'''



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]