on xenial help sign in
Moved lock_unity to testcase for pre-creation of uinput device
commit3557855219d93a8ffaca8adf70126a38f87f84f4 authorNick Dedekind <nick.dedekind@canonical.com> dateTue 31 Mar 2015, 12:11 (12 years ago) parent36a297f
3 files changed+18−21
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−2 tests/autopilot/unity8/process_helpers.py−19 tests/autopilot/unity8/shell/tests/__init__.py+16
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−2
@@ -90,7 +90,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
9090
9191 def test_greeter_hides_on_app_open(self):
9292 """Greeter should hide when an app is opened"""
93− process_helpers.lock_unity()
93+ self.lock_unity()
9494 greeter = self.main_window.get_greeter()
9595 self.assertThat(greeter.created, Eventually(Equals(True)))
9696
@@ -107,7 +107,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
107107 self.main_window.show_dash_swiping()
108108 self.assert_current_focused_application('unity8-dash')
109109
110− process_helpers.lock_unity()
110+ self.lock_unity()
111111 greeter = self.main_window.get_greeter()
112112 self.assertThat(greeter.created, Eventually(Equals(True)))
113113
tests/autopilot/unity8/process_helpers.py−19
@@ -87,25 +87,6 @@ def unlock_unity(unity_proxy_obj=None):
8787 greeter.created.wait_for(False)
8888 logger.info("Greeter unlocked, continuing.")
8989
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−
10990def restart_unity_with_testability(*args):
11091 """Restarts (or starts) unity with testability enabled.
11192
tests/autopilot/unity8/shell/tests/__init__.py+16
@@ -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)