on xenial help sign in
use greeter dbus calls to lock unity
commit685165c6251e3f45a3dc85915b104e890b70fa23 authorNick Dedekind <nick.dedekind@canonical.com> dateWed 1 Apr 2015, 15:47 (12 years ago) parentb20b95f
3 files changed+51−26
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−6 tests/autopilot/unity8/process_helpers.py+49 tests/autopilot/unity8/shell/tests/__init__.py−20
tests/autopilot/unity8/application_lifecycle/tests/test_application_lifecycle.py+2−6
@@ -90,9 +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− self.lock_unity()
94− greeter = self.main_window.get_greeter()
95− self.assertThat(greeter.created, Eventually(Equals(True)))
93+ process_helpers.lock_unity()
9694
9795 application_name = self.launch_fake_app()
9896 greeter.wait_swiped_away()
@@ -107,9 +105,7 @@ class ApplicationLifecycleTests(tests.ApplicationLifeCycleTestCase):
107105 self.main_window.show_dash_swiping()
108106 self.assert_current_focused_application('unity8-dash')
109107
110− self.lock_unity()
111− greeter = self.main_window.get_greeter()
112− self.assertThat(greeter.created, Eventually(Equals(True)))
108+ process_helpers.lock_unity()
113109
114110 self.launch_upstart_application(application_name)
115111 greeter.wait_swiped_away()
tests/autopilot/unity8/process_helpers.py+49
@@ -87,6 +87,55 @@ def unlock_unity(unity_proxy_obj=None):
8787 greeter.created.wait_for(False)
8888 logger.info("Greeter unlocked, continuing.")
8989
90+def lock_unity(unity_proxy_obj=None):
91+ """Helper function that attempts to lock unity greeter.
92+
93+ If unity_proxy_object is None create a proxy object by querying for the
94+ running unity process.
95+ Otherwise re-use the passed proxy object.
96+
97+ :raises RuntimeError: if the greeter attempts and fails to be locked.
98+
99+ :raises RuntimeWarning: when the greeter is found because it is
100+ already locked.
101+ :raises CannotAccessUnity: if unity is not introspectable or cannot be
102+ found on dbus.
103+ :raises CannotAccessUnity: if unity's upstart status is not "start" or the
104+ upstart job cannot be found at all.
105+
106+ """
107+ if unity_proxy_obj is None:
108+ try:
109+ pid = _get_unity_pid()
110+ unity = _get_unity_proxy_object(pid)
111+ main_window = unity.select_single(main_window_emulator.QQuickView)
112+ except ProcessSearchError as e:
113+ raise CannotAccessUnity(
114+ "Cannot introspect unity, make sure that it has been started "
115+ "with testability. Perhaps use the function "
116+ "'restart_unity_with_testability' this module provides."
117+ "(%s)"
118+ % str(e)
119+ )
120+ else:
121+ main_window = unity_proxy_obj.select_single(
122+ main_window_emulator.QQuickView)
123+
124+ greeter = main_window.get_greeter()
125+ if greeter.created is True:
126+ raise RuntimeWarning("Greeter appears to be already locked.")
127+
128+ bus = dbus.SessionBus()
129+ dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
130+ try:
131+ dbus_proxy.ShowGreeter()
132+ except dbus.DBusException:
133+ logger.info("Failed to lock greeter")
134+ raise
135+ else:
136+ greeter.created.wait_for(True)
137+ logger.info("Greeter locked, continuing.")
138+
90139def restart_unity_with_testability(*args):
91140 """Restarts (or starts) unity with testability enabled.
92141
tests/autopilot/unity8/shell/tests/__init__.py−20
@@ -34,7 +34,6 @@ import logging
3434import os.path
3535import subprocess
3636import sys
37−import evdev
3837from testtools.matchers import Equals
3938from ubuntuuitoolkit import (
4039 fixture_setup as toolkit_fixtures,
@@ -164,8 +163,6 @@ class UnityTestCase(AutopilotTestCase):
164163 _uinput._touch_device = _uinput.create_touch_device()
165164 self.addCleanup(_uinput._touch_device.close)
166165
167− self.uinput = evdev.UInput(name='unity8-autopilot-power-button',
168− devnode='/dev/autopilot-uinput')
169166 self.touch = Touch.create()
170167 self._setup_display_details()
171168
@@ -390,23 +387,6 @@ class UnityTestCase(AutopilotTestCase):
390387 dash_app = dash_helpers.DashApp(dash_proxy)
391388 return dash_app.dash
392389
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−
406− greeter = self.main_window.wait_select_single(objectName='greeter')
407− print("Greeter status ", greeter.fullyShown, greeter.active, greeter.waiting, greeter.locked);
408− greeter.fullyShown.wait_for(True);
409−
410390 @property
411391 def main_window(self):
412392 return self._proxy.select_single(main_window_emulator.QQuickView)