@@ -36,23 +36,11 @@ import subprocess
3636logger = logging.getLogger(__name__)
3737
3838
39−class NotificationsTests(UnityTestCase):
40− """Notification tests base class that takes care of starting a custom dbus
41− session if required.
42−
43− """
39+class NotificationsBase(UnityTestCase):
40+ """Base class for all notification tests that provides helper methods."""
4441
4542 scenarios = _get_device_emulation_scenarios()
4643
47− def setUp(self):
48− super(NotificationsTests, self).setUp()
49−
50− self._notify_proc = None
51− # Because we are using the Notify library we need to init and un-init
52− # otherwise we get crashes.
53− Notify.init("Autopilot Ephemeral Notification Tests")
54− self.addCleanup(Notify.uninit)
55−
5644 def _get_icon_path(self, icon_name):
5745 """Given an icons file name returns the full path (either system or
5846 source tree.
@@ -113,6 +101,103 @@ class NotificationsTests(UnityTestCase):
113101 if opacity is not None:
114102 self.assertThat(notification.opacity, Eventually(Equals(opacity)))
115103
104+
105+class InteractiveNotificationBase(NotificationsBase):
106+ """Collection of test for Interactive tests including snap decisions."""
107+
108+ def setUp(self):
109+ super(InteractiveNotificationBase, self).setUp()
110+ # Need to keep track when we launch the notification script.
111+ self._notify_proc = None
112+
113+ def test_interactive(self):
114+ self.launch_unity()
115+ greeter = self.main_window.get_greeter()
116+ greeter.unlock()
117+
118+ notify_list = self._get_notifications_list()
119+
120+ summary = "Summary"
121+ body = "Body"
122+ icon_path = self._get_icon_path('avatars/anna_olsson@12.png')
123+ actions = [("action_id", "dummy")]
124+ hints = [
125+ ("x-canonical-switch-to-application", "true"),
126+ (
127+ "x-canonical-secondary-icon",
128+ self._get_icon_path('applicationIcons/phone-app@18.png')
129+ )
130+ ]
131+
132+ self._create_interactive_notification(
133+ summary,
134+ body,
135+ icon_path,
136+ "NORMAL",
137+ actions,
138+ hints,
139+ )
140+
141+ get_notification = lambda: notify_list.select_single('Notification')
142+ self.assertThat(get_notification, Eventually(NotEquals(None)))
143+ notification = get_notification()
144+
145+ self.touch.tap_object(
146+ notification.select_single(objectName="interactiveArea")
147+ )
148+
149+ self.assert_notification_action_id_was_called('action_id')
150+
151+ def test_sd_incoming_call(self):
152+ """Snap-decision simulating incoming call."""
153+ self.launch_unity()
154+ greeter = self.main_window.get_greeter()
155+ greeter.unlock()
156+
157+ notify_list = self._get_notifications_list()
158+
159+ summary = "Incoming call"
160+ body = "Frank Zappa\n+44 (0)7736 027340"
161+ icon_path = self._get_icon_path('avatars/anna_olsson@12.png')
162+ hints = [
163+ (
164+ "x-canonical-secondary-icon",
165+ self._get_icon_path('applicationIcons/phone-app@18.png')
166+ ),
167+ ("x-canonical-snap-decisions", "true"),
168+ ]
169+
170+ actions = [
171+ ('action_accept', 'Accept'),
172+ ('action_decline_1', 'Decline'),
173+ ('action_decline_2', '"Can\'t talk now, what\'s up?"'),
174+ ('action_decline_3', '"I call you back."'),
175+ ('action_decline_4', 'Send custom message...'),
176+ ]
177+
178+ self._create_interactive_notification(
179+ summary,
180+ body,
181+ icon_path,
182+ "NORMAL",
183+ actions,
184+ hints
185+ )
186+
187+ get_notification = lambda: notify_list.select_single('Notification')
188+ self.assertThat(get_notification, Eventually(NotEquals(None)))
189+ notification = get_notification()
190+ #self._assert_notification(notification, None, None, True, True, 1.0)
191+ self.touch.tap_object(notification.select_single(objectName="button1"))
192+ # Veebers: this needs a better check as it's happening to quick.
193+ self.assertThat(
194+ notification.select_single(objectName="buttonRow").expanded,
195+ Eventually(Equals(True))
196+ )
197+ time.sleep(2)
198+ self.touch.tap_object(notification.select_single(objectName="button4"))
199+ self.assert_notification_action_id_was_called("action_decline_4")
200+
116201 def _create_interactive_notification(
117202 self,
118203 summary="",
@@ -228,93 +313,16 @@ class NotificationsTests(UnityTestCase):
228313 "No callback was called, killing interactivenotification script"
229314 )
230315
231− def test_interactive(self):
232− self.launch_unity()
233− greeter = self.main_window.get_greeter()
234− greeter.unlock()
235−
236− notify_list = self._get_notifications_list()
237−
238− summary = "Summary"
239− body = "Body"
240− icon_path = self._get_icon_path('avatars/anna_olsson@12.png')
241− actions = [("action_id", "dummy")]
242− hints = [
243− ("x-canonical-switch-to-application", "true"),
244− (
245− "x-canonical-secondary-icon",
246− self._get_icon_path('applicationIcons/phone-app@18.png')
247− )
248− ]
249−
250− self._create_interactive_notification(
251− summary,
252− body,
253− icon_path,
254− "NORMAL",
255− actions,
256− hints,
257− )
258−
259− get_notification = lambda: notify_list.select_single('Notification')
260− self.assertThat(get_notification, Eventually(NotEquals(None)))
261− notification = get_notification()
262−
263− self.touch.tap_object(
264− notification.select_single(objectName="interactiveArea")
265− )
266−
267− self.assert_notification_action_id_was_called('action_id')
268−
269− def test_sd_incoming_call(self):
270− """Snap-decision simulating incoming call."""
271− self.launch_unity()
272− greeter = self.main_window.get_greeter()
273− greeter.unlock()
274−
275− notify_list = self._get_notifications_list()
276−
277− summary = "Incoming call"
278− body = "Frank Zappa\n+44 (0)7736 027340"
279− icon_path = self._get_icon_path('avatars/anna_olsson@12.png')
280− hints = [
281− (
282− "x-canonical-secondary-icon",
283− self._get_icon_path('applicationIcons/phone-app@18.png')
284− ),
285− ("x-canonical-snap-decisions", "true"),
286− ]
287−
288− actions = [
289− ('action_accept', 'Accept'),
290− ('action_decline_1', 'Decline'),
291− ('action_decline_2', '"Can\'t talk now, what\'s up?"'),
292− ('action_decline_3', '"I call you back."'),
293− ('action_decline_4', 'Send custom message...'),
294− ]
295316
296− self._create_interactive_notification(
297− summary,
298− body,
299− icon_path,
300− "NORMAL",
301− actions,
302− hints
303− )
317+class EphemeralNotificationsTests(NotificationsBase):
318+ """Collection of tests for Emphemeral notifications (non-interactive.)"""
304319
305− get_notification = lambda: notify_list.select_single('Notification')
306− self.assertThat(get_notification, Eventually(NotEquals(None)))
307− notification = get_notification()
308− #self._assert_notification(notification, None, None, True, True, 1.0)
309− self.touch.tap_object(notification.select_single(objectName="button1"))
310− # Veebers: this needs a better check as it's happening to quick.
311− self.assertThat(
312− notification.select_single(objectName="buttonRow").expanded,
313− Eventually(Equals(True))
314− )
315− time.sleep(2)
316− self.touch.tap_object(notification.select_single(objectName="button4"))
317− self.assert_notification_action_id_was_called("action_decline_4")
320+ def setUp(self):
321+ super(EphemeralNotificationsTests, self).setUp()
322+ # Because we are using the Notify library we need to init and un-init
323+ # otherwise we get crashes.
324+ Notify.init("Autopilot Ephemeral Notification Tests")
325+ self.addCleanup(Notify.uninit)
318326
319327 def test_icon_summary_body(self):
320328 """Notification must display the expected summary and body text."""