@@ -34,6 +34,7 @@ import logging
3434import os.path
3535import subprocess
3636import sys
37+import evdev
3738from testtools.matchers import Equals
3839from ubuntuuitoolkit import (
3940 fixture_setup as toolkit_fixtures,
@@ -163,6 +164,8 @@ class UnityTestCase(AutopilotTestCase):
163164 _uinput._touch_device = _uinput.create_touch_device()
164165 self.addCleanup(_uinput._touch_device.close)
165166
167+ self.uinput = evdev.UInput(name='unity8-autopilot-power-button',
168+ devnode='/dev/autopilot-uinput')
166169 self.touch = Touch.create()
167170 self._setup_display_details()
168171
@@ -387,6 +390,19 @@ class UnityTestCase(AutopilotTestCase):
387390 dash_app = dash_helpers.DashApp(dash_proxy)
388391 return dash_app.dash
389392
393+ def lock_unity(self):
394+ """Helper function that attempts to lock the unity greeter."""
395+ import time
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)
399+ self.uinput.syn()
400+ time.sleep(1)
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)
404+ self.uinput.syn()
405+
390406 @property
391407 def main_window(self):
392408 return self._proxy.select_single(main_window_emulator.QQuickView)