on xenial help sign in
Moved lock_unity to testcase for pre-creation of uinput device
3557855Nick Dedekind
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−2
@@ -90,7 +90,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
90
90
91 def test_greeter_hides_on_app_open(self):
91 def test_greeter_hides_on_app_open(self):
92 """Greeter should hide when an app is opened"""
92 """Greeter should hide when an app is opened"""
93− process_helpers.lock_unity()
93+ self.lock_unity()
94 greeter = self.main_window.get_greeter()
94 greeter = self.main_window.get_greeter()
95 self.assertThat(greeter.created, Eventually(Equals(True)))
95 self.assertThat(greeter.created, Eventually(Equals(True)))
96
96
@@ -107,7 +107,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
107 self.main_window.show_dash_swiping()
107 self.main_window.show_dash_swiping()
108 self.assert_current_focused_application('unity8-dash')
108 self.assert_current_focused_application('unity8-dash')
109
109
110− process_helpers.lock_unity()
110+ self.lock_unity()
111 greeter = self.main_window.get_greeter()
111 greeter = self.main_window.get_greeter()
112 self.assertThat(greeter.created, Eventually(Equals(True)))
112 self.assertThat(greeter.created, Eventually(Equals(True)))
113
113
tests/autopilot/unity8/process_helpers.py−19
@@ -87,25 +87,6 @@ def unlock_unity(unity_proxy_obj=None):
87 greeter.created.wait_for(False)
87 greeter.created.wait_for(False)
88 logger.info("Greeter unlocked, continuing.")
88 logger.info("Greeter unlocked, continuing.")
89
89
90−
91−def lock_unity(unity_proxy_obj=None):
92− """Helper function that attempts to lock the unity greeter."""
93− import evdev
94− import time
95− uinput = evdev.UInput(name='unity8-autopilot-power-button',
96− devnode='/dev/autopilot-uinput')
97− time.sleep(1) # give it some time to appear for mir.
98− # One press and release to turn screen off (locking unity)
99− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
100− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
101− uinput.syn()
102− time.sleep(1)
103− # And another press and release to turn screen back on
104− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
105− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
106− uinput.syn()
107−
108−
109def restart_unity_with_testability(*args):
90def restart_unity_with_testability(*args):
110 """Restarts (or starts) unity with testability enabled.
91 """Restarts (or starts) unity with testability enabled.
111
92
tests/autopilot/unity8/shell/tests/__init__.py+16
@@ -34,6 +34,7 @@ import logging
34import os.path
34import os.path
35import subprocess
35import subprocess
36import sys
36import sys
37+import evdev
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)
165
166
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()
168
171
@@ -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
389
392
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+
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)