on xenial help sign in
Fixed autopilot test failures related to udev input failure for power button.

Approved by: Albert Astals Cid

commitfb2598e03bfc2df1ca6471f70b4f72a71be7a08d authorNick Dedekind <nick.dedekind@canonical.com> dateThu 9 Apr 2015, 14:00 (12 years ago) parent19c28525ecd0d3
2 files changed+49−18
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−4 tests/autopilot/unity8/process_helpers.py+47−14
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−4
@@ -91,10 +91,9 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
9191 def test_greeter_hides_on_app_open(self):
9292 """Greeter should hide when an app is opened"""
9393 process_helpers.lock_unity()
94− greeter = self.main_window.get_greeter()
95− self.assertThat(greeter.created, Eventually(Equals(True)))
9694
9795 application_name = self.launch_fake_app()
96+ greeter = self.main_window.get_greeter()
9897 greeter.wait_swiped_away()
9998 process_helpers.unlock_unity()
10099 self.assert_current_focused_application(application_name)
@@ -108,10 +107,9 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
108107 self.assert_current_focused_application('unity8-dash')
109108
110109 process_helpers.lock_unity()
111− greeter = self.main_window.get_greeter()
112− self.assertThat(greeter.created, Eventually(Equals(True)))
113110
114111 self.launch_upstart_application(application_name)
112+ greeter = self.main_window.get_greeter()
115113 greeter.wait_swiped_away()
116114 process_helpers.unlock_unity()
117115 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):
8989
9090
9191def 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− # One press and release to turn screen off (locking unity)
98− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
99− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
100− uinput.syn()
101− time.sleep(1)
102− # And another press and release to turn screen back on
103− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 1)
104− uinput.write(evdev.ecodes.EV_KEY, evdev.ecodes.KEY_POWER, 0)
105− uinput.syn()
92+ """Helper function that attempts to lock unity greeter.
93+
94+ If unity_proxy_object is None create a proxy object by querying for the
95+ running unity process.
96+ Otherwise re-use the passed proxy object.
97+
98+ :raises RuntimeError: if the greeter attempts and fails to be locked.
99+
100+ :raises RuntimeWarning: when the greeter is found because it is
101+ already locked.
102+ :raises CannotAccessUnity: if unity is not introspectable or cannot be
103+ found on dbus.
104+ :raises CannotAccessUnity: if unity's upstart status is not "start" or the
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.")
106139
107140
108141def restart_unity_with_testability(*args):