on xenial help sign in
Fixed autopilot test failures related to udev input failure for power button.
fb2598eNick Dedekind
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−4
@@ -91,10 +91,9 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
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 process_helpers.lock_unity()
94− greeter = self.main_window.get_greeter()
95− self.assertThat(greeter.created, Eventually(Equals(True)))
96
94
97 application_name = self.launch_fake_app()
95 application_name = self.launch_fake_app()
96+ greeter = self.main_window.get_greeter()
98 greeter.wait_swiped_away()
97 greeter.wait_swiped_away()
99 process_helpers.unlock_unity()
98 process_helpers.unlock_unity()
100 self.assert_current_focused_application(application_name)
99 self.assert_current_focused_application(application_name)
@@ -108,10 +107,9 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
108 self.assert_current_focused_application('unity8-dash')
107 self.assert_current_focused_application('unity8-dash')
109
108
110 process_helpers.lock_unity()
109 process_helpers.lock_unity()
111− greeter = self.main_window.get_greeter()
112− self.assertThat(greeter.created, Eventually(Equals(True)))
113
110
114 self.launch_upstart_application(application_name)
111 self.launch_upstart_application(application_name)
112+ greeter = self.main_window.get_greeter()
115 greeter.wait_swiped_away()
113 greeter.wait_swiped_away()
116 process_helpers.unlock_unity()
114 process_helpers.unlock_unity()
117 self.assert_current_focused_application(application_name)
115 self.assert_current_focused_application(application_name)
tests/autopilot/unity8/process_helpers.py+47−14
@@ -89,20 +89,53 @@ def unlock_unity(unity_proxy_obj=None):
89
89
90
90
91def lock_unity(unity_proxy_obj=None):
91def lock_unity(unity_proxy_obj=None):
92− """Helper function that attempts to lock the unity greeter."""
92+ """Helper function that attempts to lock unity greeter.
93− import evdev
93+
94− import time
94+ If unity_proxy_object is None create a proxy object by querying for the
95− uinput = evdev.UInput(name='unity8-autopilot-power-button',
95+ running unity process.
96− devnode='/dev/autopilot-uinput')
96+ Otherwise re-use the passed proxy object.
97− # One press and release to turn screen off (locking unity)
97+
98− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
98+ :raises RuntimeError: if the greeter attempts and fails to be locked.
99− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
99+
100− uinput.syn()
100+ :raises RuntimeWarning: when the greeter is found because it is
101− time.sleep(1)
101+ already locked.
102− # And another press and release to turn screen back on
102+ :raises CannotAccessUnity: if unity is not introspectable or cannot be
103− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
103+ found on dbus.
104− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
104+ :raises CannotAccessUnity: if unity's upstart status is not "start" or the
105− uinput.syn()
105+ upstart job cannot be found at all.
106+
107+ """
108+ if unity_proxy_obj is None:
109+ try:
110+ pid = _get_unity_pid()
111+ unity = _get_unity_proxy_object(pid)
112+ main_window = unity.select_single(main_window_emulator.QQuickView)
113+ except ProcessSearchError as e:
114+ raise CannotAccessUnity(
115+ "Cannot introspect unity, make sure that it has been started "
116+ "with testability. Perhaps use the function "
117+ "'restart_unity_with_testability' this module provides."
118+ "(%s)"
119+ % str(e)
120+ )
121+ else:
122+ main_window = unity_proxy_obj.select_single(
123+ main_window_emulator.QQuickView)
124+
125+ greeter = main_window.get_greeter()
126+ if greeter.created is True:
127+ raise RuntimeWarning("Greeter appears to be already locked.")
128+
129+ bus = dbus.SessionBus()
130+ dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
131+ try:
132+ dbus_proxy.ShowGreeter()
133+ except dbus.DBusException:
134+ logger.info("Failed to lock greeter")
135+ raise
136+ else:
137+ greeter.created.wait_for(True)
138+ logger.info("Greeter locked, continuing.")
106
139
107
140
108def restart_unity_with_testability(*args):
141def restart_unity_with_testability(*args):