@@ -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