@@ -34,6 +34,7 @@ import logging
34import os.path
34import os.path
35import subprocess
35import subprocess
37from testtools.matchers import Equals
38from testtools.matchers import Equals
38from ubuntuuitoolkit import (
39from ubuntuuitoolkit import (
39 fixture_setup as toolkit_fixtures,
40 fixture_setup as toolkit_fixtures,
@@ -163,6 +164,8 @@ class UnityTestCase(AutopilotTestCase):
163 _uinput._touch_device = _uinput.create_touch_device()
164 _uinput._touch_device = _uinput.create_touch_device()
164 self.addCleanup(_uinput._touch_device.close)
165 self.addCleanup(_uinput._touch_device.close)
167+ self.uinput = evdev.UInput(name='unity8-autopilot-power-button',
168+ devnode='/dev/autopilot-uinput')
166 self.touch = Touch.create()
169 self.touch = Touch.create()
167 self._setup_display_details()
170 self._setup_display_details()
@@ -387,6 +390,19 @@ class UnityTestCase(AutopilotTestCase):
387 dash_app = dash_helpers.DashApp(dash_proxy)
390 dash_app = dash_helpers.DashApp(dash_proxy)
388 return dash_app.dash
391 return dash_app.dash
393+ def lock_unity(self):
394+ """Helper function that attempts to lock the unity greeter."""
396+ # One press and release to turn screen off (locking unity)
397+ self.uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
398+ self.uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
401+ # And another press and release to turn screen back on
402+ self.uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
403+ self.uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
390 @property
406 @property
391 def main_window(self):
407 def main_window(self):
392 return self._proxy.select_single(main_window_emulator.QQuickView)
408 return self._proxy.select_single(main_window_emulator.QQuickView)