on xenial help sign in
Refactor greeter emulator to unlock the greeter via dbus

Approved by: Leo Arias

commitafa51cbf7ce7f427e72614f8e13c0f932ef50b8f authorJosh Arenson <joshua.arenson@canonical.com> dateThu 18 Jun 2015, 19:39 (11 years ago) parent2c033d457b5790
6 files changed+86−121
tests/autopilot/unity8/application_lifecycle/tests/__init__.py+2−2 tests/autopilot/unity8/greeter/__init__.py+52 tests/autopilot/unity8/indicators/tests/__init__.py+1−1 tests/autopilot/unity8/process_helpers.py+7−94 tests/autopilot/unity8/shell/tests/test_emulators.py+2−2 tests/autopilot/unity8/shell/tests/test_notifications.py+22−22
tests/autopilot/unity8/application_lifecycle/tests/__init__.py+2−2
@@ -31,8 +31,8 @@ class ApplicationLifeCycleTestCase(tests.UnityTestCase):
3131 super().setUp()
3232 self._qml_mock_enabled = False
3333 self._data_dirs_mock_enabled = False
34− unity_proxy = self.launch_unity()
35− process_helpers.unlock_unity(unity_proxy)
34+ self.launch_unity()
35+ process_helpers.unlock_unity()
3636
3737 def create_test_application(self):
3838 desktop_file_dict = fixture_setup.DEFAULT_DESKTOP_FILE_DICT
tests/autopilot/unity8/greeter/__init__.py+52
@@ -0,0 +1,52 @@
1+# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
2+#
3+# Unity Autopilot Test Suite
4+# Copyright (C) 2015 Canonical
5+#
6+# This program is free software: you can redistribute it and/or modify
7+# it under the terms of the GNU General Public License as published by
8+# the Free Software Foundation, either version 3 of the License, or
9+# (at your option) any later version.
10+#
11+# This program is distributed in the hope that it will be useful,
12+# but WITHOUT ANY WARRANTY; without even the implied warranty of
13+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14+# GNU General Public License for more details.
15+#
16+# You should have received a copy of the GNU General Public License
17+# along with this program. If not, see <http://www.gnu.org/licenses/>.
18+#
19+
20+import dbus
21+
22+from autopilot.matchers import Eventually
23+from testtools.matchers import Equals
24+
25+
26+def hide_greeter_with_dbus():
27+ dbus_proxy = _get_greeter_dbus_proxy()
28+ if _is_greeter_active():
29+ dbus_proxy.HideGreeter()
30+
31+
32+def show_greeter_with_dbus():
33+ dbus_proxy = _get_greeter_dbus_proxy()
34+ if not _is_greeter_active():
35+ dbus_proxy.ShowGreeter()
36+
37+
38+def wait_for_greeter():
39+ Eventually(Equals(True), timeout=300).match(_is_greeter_active)
40+
41+
42+def _get_greeter_dbus_proxy():
43+ bus = dbus.SessionBus()
44+ return bus.get_object('com.canonical.UnityGreeter', '/')
45+
46+
47+def _is_greeter_active():
48+ try:
49+ dbus_proxy = _get_greeter_dbus_proxy()
50+ return dbus_proxy.Get('com.canonical.UnityGreeter', 'IsActive')
51+ except:
52+ return False
tests/autopilot/unity8/indicators/tests/__init__.py+1−1
@@ -31,7 +31,7 @@ class IndicatorTestCase(tests.UnityTestCase):
3131 def setUp(self):
3232 super().setUp()
3333 self.unity_proxy = self.launch_unity()
34− process_helpers.unlock_unity(self.unity_proxy)
34+ process_helpers.unlock_unity()
3535
3636
3737class DeviceIndicatorTestCase(IndicatorTestCase):
tests/autopilot/unity8/process_helpers.py+7−94
@@ -19,14 +19,11 @@
1919
2020import logging
2121import subprocess
22−import dbus
2322
2423import ubuntuuitoolkit
25−from autopilot.exceptions import ProcessSearchError
2624from autopilot.introspection import get_proxy_object_for_existing_process
2725
28−from unity8.shell import emulators
29−from unity8.shell.emulators import main_window as main_window_emulator
26+from unity8 import greeter
3027
3128logger = logging.getLogger(__name__)
3229
@@ -39,104 +36,20 @@ class CannotAccessUnity(Exception):
3936 pass
4037
4138
42−def unlock_unity(unity_proxy_obj=None):
39+def unlock_unity():
4340 """Helper function that attempts to unlock the unity greeter.
4441
45− If unity_proxy_object is None create a proxy object by querying for the
46− running unity process.
47− Otherwise re-use the passed proxy object.
48−
49− :raises RuntimeError: if the greeter attempts and fails to be unlocked.
50−
51− :raises RuntimeWarning: when the greeter cannot be found because it is
52− already unlocked.
53− :raises CannotAccessUnity: if unity is not introspectable or cannot be
54− found on dbus.
55− :raises CannotAccessUnity: if unity's upstart status is not "start" or the
56− upstart job cannot be found at all.
57−
5842 """
59− if unity_proxy_obj is None:
60− try:
61− pid = get_unity_pid()
62− unity = _get_unity_proxy_object(pid)
63− main_window = unity.select_single(main_window_emulator.QQuickView)
64− except ProcessSearchError as e:
65− raise CannotAccessUnity(
66− "Cannot introspect unity, make sure that it has been started "
67− "with testability. Perhaps use the function "
68− "'restart_unity_with_testability' this module provides."
69− "(%s)"
70− % str(e)
71− )
72− else:
73− main_window = unity_proxy_obj.select_single(
74− main_window_emulator.QQuickView)
75−
76− greeter = main_window.get_greeter()
77− if greeter.created is False:
78− raise RuntimeWarning("Greeter appears to be already unlocked.")
79−
80− bus = dbus.SessionBus()
81− dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
82− try:
83− dbus_proxy.HideGreeter()
84− except dbus.DBusException:
85− logger.info("Failed to unlock greeter")
86− raise
87− else:
88− greeter.created.wait_for(False)
89− logger.info("Greeter unlocked, continuing.")
43+ greeter.wait_for_greeter()
44+ greeter.hide_greeter_with_dbus()
9045
9146
92−def lock_unity(unity_proxy_obj=None):
47+def lock_unity():
9348 """Helper function that attempts to lock unity greeter.
9449
95− If unity_proxy_object is None create a proxy object by querying for the
96− running unity process.
97− Otherwise re-use the passed proxy object.
98−
99− :raises RuntimeError: if the greeter attempts and fails to be locked.
100−
101− :raises RuntimeWarning: when the greeter is found because it is
102− already locked.
103− :raises CannotAccessUnity: if unity is not introspectable or cannot be
104− found on dbus.
105− :raises CannotAccessUnity: if unity's upstart status is not "start" or the
106− upstart job cannot be found at all.
107−
10850 """
109− if unity_proxy_obj is None:
110− try:
111− pid = get_unity_pid()
112− unity = _get_unity_proxy_object(pid)
113− main_window = unity.select_single(main_window_emulator.QQuickView)
114− except ProcessSearchError as e:
115− raise CannotAccessUnity(
116− "Cannot introspect unity, make sure that it has been started "
117− "with testability. Perhaps use the function "
118− "'restart_unity_with_testability' this module provides."
119− "(%s)"
120− % str(e)
121− )
122− else:
123− main_window = unity_proxy_obj.select_single(
124− main_window_emulator.QQuickView)
125−
126− greeter = main_window.get_greeter()
127− if greeter.created is True:
128− raise RuntimeWarning("Greeter appears to be already locked.")
129−
130− bus = dbus.SessionBus()
131− dbus_proxy = bus.get_object("com.canonical.UnityGreeter", "/")
132− try:
133− dbus_proxy.ShowGreeter()
134− except dbus.DBusException:
135− logger.info("Failed to lock greeter")
136− raise
137− else:
138− greeter.created.wait_for(True)
139− logger.info("Greeter locked, continuing.")
51+ greeter.show_greeter_with_dbus()
52+ greeter.wait_for_greeter()
14053
14154
14255def restart_unity_with_testability(*args):
tests/autopilot/unity8/shell/tests/test_emulators.py+2−2
@@ -41,8 +41,8 @@ class MainWindowTestCase(tests.UnityTestCase):
4141
4242 def setUp(self):
4343 super().setUp()
44− unity_proxy = self.launch_unity()
45− process_helpers.unlock_unity(unity_proxy)
44+ self.launch_unity()
45+ process_helpers.unlock_unity()
4646
4747
4848class DashEmulatorTestCase(tests.DashBaseTestCase):
tests/autopilot/unity8/shell/tests/test_notifications.py+22−22
@@ -119,8 +119,8 @@ class InteractiveNotificationBase(NotificationsBase):
119119
120120 def test_interactive(self):
121121 """Interactive notification must react upon click on itself."""
122− unity_proxy = self.launch_unity()
123− unlock_unity(unity_proxy)
122+ self.launch_unity()
123+ unlock_unity()
124124
125125 notify_list = self._get_notifications_list()
126126
@@ -156,8 +156,8 @@ class InteractiveNotificationBase(NotificationsBase):
156156 """Snap-decision with three actions should use
157157 one-over two button layout.
158158 """
159− unity_proxy = self.launch_unity()
160− unlock_unity(unity_proxy)
159+ self.launch_unity()
160+ unlock_unity()
161161
162162 summary = "Theatre at Ferria Stadium"
163163 body = "at Ferria Stadium in Bilbao, Spain\n07578545317"
@@ -197,8 +197,8 @@ class InteractiveNotificationBase(NotificationsBase):
197197 """Snap-decision should block input to shell
198198 without greeter/lockscreen.
199199 """
200− unity_proxy = self.launch_unity()
201− unlock_unity(unity_proxy)
200+ self.launch_unity()
201+ unlock_unity()
202202
203203 summary = "Incoming file"
204204 body = "Frank would like to send you the file: essay.pdf"
@@ -421,8 +421,8 @@ class EphemeralNotificationsTests(NotificationsBase):
421421
422422 def test_icon_summary_body(self):
423423 """Notification must display the expected summary and body text."""
424− unity_proxy = self.launch_unity()
425− unlock_unity(unity_proxy)
424+ self.launch_unity()
425+ unlock_unity()
426426
427427 notify_list = self._get_notifications_list()
428428
@@ -458,8 +458,8 @@ class EphemeralNotificationsTests(NotificationsBase):
458458 def test_icon_summary(self):
459459 """Notification must display the expected summary and secondary
460460 icon."""
461− unity_proxy = self.launch_unity()
462− unlock_unity(unity_proxy)
461+ self.launch_unity()
462+ unlock_unity()
463463
464464 notify_list = self._get_notifications_list()
465465
@@ -491,8 +491,8 @@ class EphemeralNotificationsTests(NotificationsBase):
491491 def test_urgency_order(self):
492492 """Notifications must be displayed in order according to their
493493 urgency."""
494− unity_proxy = self.launch_unity()
495− unlock_unity(unity_proxy)
494+ self.launch_unity()
495+ unlock_unity()
496496
497497 notify_list = self._get_notifications_list()
498498
@@ -578,8 +578,8 @@ class EphemeralNotificationsTests(NotificationsBase):
578578
579579 def test_summary_and_body(self):
580580 """Notification must display the expected summary- and body-text."""
581− unity_proxy = self.launch_unity()
582− unlock_unity(unity_proxy)
581+ self.launch_unity()
582+ unlock_unity()
583583
584584 notify_list = self._get_notifications_list()
585585
@@ -603,8 +603,8 @@ class EphemeralNotificationsTests(NotificationsBase):
603603
604604 def test_summary_only(self):
605605 """Notification must display only the expected summary-text."""
606− unity_proxy = self.launch_unity()
607− unlock_unity(unity_proxy)
606+ self.launch_unity()
607+ unlock_unity()
608608
609609 notify_list = self._get_notifications_list()
610610
@@ -621,8 +621,8 @@ class EphemeralNotificationsTests(NotificationsBase):
621621 def test_update_notification_same_layout(self):
622622 """Notification must allow updating its contents while being
623623 displayed."""
624− unity_proxy = self.launch_unity()
625− unlock_unity(unity_proxy)
624+ self.launch_unity()
625+ unlock_unity()
626626
627627 notify_list = self._get_notifications_list()
628628
@@ -660,8 +660,8 @@ class EphemeralNotificationsTests(NotificationsBase):
660660 def test_update_notification_layout_change(self):
661661 """Notification must allow updating its contents and layout while
662662 being displayed."""
663− unity_proxy = self.launch_unity()
664− unlock_unity(unity_proxy)
663+ self.launch_unity()
664+ unlock_unity()
665665
666666 notify_list = self._get_notifications_list()
667667
@@ -709,8 +709,8 @@ class EphemeralNotificationsTests(NotificationsBase):
709709 """ use the create notification script to get a notification dialog.
710710 Check that the arguments passed to the script match the fields. """
711711
712− unity_proxy = self.launch_unity()
713− unlock_unity(unity_proxy)
712+ self.launch_unity()
713+ unlock_unity()
714714
715715 summary = 'Helper summary'
716716 body = 'Helper body'