on xenial help sign in
Add Notification Helper.
commit90b43c01e2c001dd85e6ada222c6092e41a52026 authorYing-Chun Liu <paul.liu@canonical.com> dateWed 11 Feb 2015, 00:02 (12 years ago) parent958eebf
2 files changed+89
tests/autopilot/unity8/shell/__init__.py+67 tests/autopilot/unity8/shell/tests/test_notifications.py+22
tests/autopilot/unity8/shell/__init__.py+67
@@ -22,6 +22,10 @@
2222from time import sleep
2323from functools import wraps
2424from gi.repository import Notify
25+import ubuntuuitoolkit
26+from autopilot import introspection
27+from autopilot.introspection import dbus
28+from unity8.shell import emulators
2529
2630import logging
2731
@@ -105,3 +109,66 @@ def _get_urgency(urgency):
105109 'NORMAL': Notify.Urgency.NORMAL,
106110 'CRITICAL': Notify.Urgency.CRITICAL}
107111 return _urgency_enums.get(urgency.upper())
112+
113+def wait_for_notification_dialog(self, timeout):
114+ """Wait for a notification dialog to appear.
115+
116+ :param int timeout: Maximum amount of time to wait for the notification,
117+ in seconds.
118+ :return: An autopilot custom proxy object for the notification dialog.
119+ :raise StateNotFoundError: if the timeout expires when the
120+ notification has not appeared.
121+
122+ """
123+ notify_list = self.main_window.select_single('Notifications',
124+ objectName='notificationList')
125+ visible_notification = None
126+ for i in range(timeout):
127+ notification_list = notify_list.select_many('Notification')
128+ visible_notification = None
129+ for notification1 in notification_list:
130+ if (notification1.visible):
131+ visible_notification = notification1
132+
133+ if (not visible_notification):
134+ if i == timeout - 1:
135+ raise dbus.StateNotFoundError
136+ else:
137+ return visible_notification
138+ sleep(1)
139+ return visible_notification
140+ # Strategy to test the helper:
141+ # use the create notification script to verify that the method returns
142+ # when a notification is received.
143+
144+class Notification(emulators.UnityEmulatorBase):
145+
146+ """Custom proxy object for Notification dialogs."""
147+ @classmethod
148+ def validate_dbus_object(cls, path, state):
149+ name = introspection.get_classname_from_path(path)
150+ if name == b'Notification':
151+ return True
152+ return False
153+
154+ def __init__(self, state, path, backend):
155+ super(Notification, self).__init__(state, path, backend)
156+ # Backup data
157+ self._summary = self.summary
158+ self._body = self.body
159+ self._iconSource = self.iconSource
160+
161+
162+ def get_data(self):
163+ """Return the contents of a notification dialog.
164+
165+ :return: A data object that represents the contents of a notification
166+ dialog.
167+
168+ """
169+ return { 'summary': self._summary,
170+ 'body': self._body,
171+ 'iconSource': self._iconSource }
172+ # Strategy to test the helper:
173+ # use the create notification script to get a notification dialog.
174+ # Check that the arguments passed to the script match the fields
tests/autopilot/unity8/shell/tests/test_notifications.py+22
@@ -24,6 +24,7 @@ from __future__ import absolute_import
2424from unity8 import shell
2525from unity8.process_helpers import unlock_unity
2626from unity8.shell.tests import UnityTestCase, _get_device_emulation_scenarios
27+from unity8.shell import wait_for_notification_dialog
2728
2829from testtools.matchers import Equals, NotEquals
2930from autopilot.matchers import Eventually
@@ -701,3 +702,24 @@ class EphemeralNotificationsTests(NotificationsBase):
701702 self.assertThat(get_notification, Eventually(NotEquals(None)))
702703 self._assert_notification(
703704 get_notification(), summary, body, False, False, 1.0)
705+
706+ def test_notification_helper(self):
707+ unity_proxy = self.launch_unity()
708+ unlock_unity(unity_proxy)
709+
710+ summary = 'Helper summary'
711+ body = 'Helper body'
712+
713+ notification = shell.create_ephemeral_notification(summary, body)
714+ notification.show()
715+
716+ notification = wait_for_notification_dialog(self, 20)
717+
718+ self._assert_notification(
719+ notification,
720+ summary,
721+ body,
722+ False,
723+ False,
724+ 1.0
725+ )