20 """Tests for Notifications"""
22 from __future__
import absolute_import
24 from unity8
import shell
28 from testtools.matchers
import Equals, NotEquals
29 from autopilot.matchers
import Eventually
31 from gi.repository
import Notify
39 logger = logging.getLogger(__name__)
43 if sys.version_info < (3,):
48 """Base class for all notification tests that provides helper methods."""
50 scenarios = _get_device_emulation_scenarios(
'Nexus4')
52 def _get_icon_path(self, icon_name):
53 """Given an icons file name returns the full path (either system or
56 Consider the graphics directory as root so for example (running tests
57 from installed unity8-autopilot package):
58 >>> self.get_icon_path('clock.png')
59 /usr/share/unity8/graphics/clock.png
61 >>> self.get_icon_path('applicationIcons/facebook.png')
62 /usr/share/unity8/graphics/applicationIcons/facebook.png
65 if os.path.abspath(__file__).startswith(
'/usr/'):
66 return '/usr/share/unity8/graphics/' + icon_name
68 return os.path.dirname(__file__) + (
69 "/../../../../../qml/graphics/" + icon_name)
71 def _get_notifications_list(self):
72 return self.main_window.select_single(
74 objectName=
'notificationList'
77 def _assert_notification(
86 """Assert that the expected qualities of a notification are as
91 if summary
is not None:
92 self.assertThat(notification.summary, Eventually(Equals(summary)))
95 self.assertThat(notification.body, Eventually(Equals(body)))
98 self.assertThat(notification.iconSource, Eventually(NotEquals(
"")))
100 self.assertThat(notification.iconSource, Eventually(Equals(
"")))
104 notification.secondaryIconSource,
105 Eventually(NotEquals(
""))
109 notification.secondaryIconSource,
110 Eventually(Equals(
""))
113 if opacity
is not None:
114 self.assertThat(notification.opacity, Eventually(Equals(opacity)))
118 """Collection of test for Interactive tests including snap decisions."""
121 super(InteractiveNotificationBase, self).setUp()
126 """Interactive notification must react upon click on itself."""
128 unlock_unity(unity_proxy)
132 summary =
"Interactive notification"
133 body =
"This notification can be clicked on to trigger an action."
135 actions = [(
"action_id",
"dummy")]
137 (
"x-canonical-switch-to-application",
"true"),
138 (
"x-canonical-secondary-icon",
"dialer")
150 get_notification =
lambda: notify_list.wait_select_single(
151 'Notification', objectName=
'notification1')
152 notification = get_notification()
154 notification.pointing_device.click_object(
155 notification.select_single(objectName=
"interactiveArea")
161 """Rejecting a call should make notification expand and
162 offer more options."""
164 unlock_unity(unity_proxy)
166 summary =
"Incoming call"
167 body =
"Frank Zappa\n+44 (0)7736 027340"
170 (
"x-canonical-secondary-icon",
"incoming-call"),
171 (
"x-canonical-snap-decisions",
"true"),
172 (
"x-canonical-private-affirmative-tint",
"true"),
173 (
"x-canonical-private-rejection-tint",
"true"),
177 (
'action_accept',
'Hold + Answer'),
178 (
'action_decline_1',
'End + Answer'),
179 (
'action_decline_2',
'Decline'),
180 (
'action_decline_3',
'message:I missed your call - can you call me now?'),
181 (
'action_decline_4',
'message:I\'m running late. I\'m on my way.'),
182 (
'action_decline_5',
'message:I\'m busy at the moment. I\'ll call later.'),
183 (
'action_decline_6',
'edit:Custom'),
196 get_notification =
lambda: notify_list.wait_select_single(
197 'Notification', objectName=
'notification1')
198 notification = get_notification()
200 notification.pointing_device.click_object(
201 notification.select_single(objectName=
"combobutton_dropdown"))
203 notification.select_single(objectName=
"notify_button2").expanded,
204 Eventually(Equals(
True)))
206 notification.pointing_device.click_object(
207 notification.select_single(objectName=
"notify_button4"))
212 """Snap-decision with three actions should use one-over two button layout."""
214 unlock_unity(unity_proxy)
216 summary =
"Theatre at Ferria Stadium"
217 body =
"at Ferria Stadium in Bilbao, Spain\n07578545317"
219 (
"x-canonical-snap-decisions",
"true"),
220 (
"x-canonical-non-shaped-icon",
"true"),
221 (
"x-canonical-private-affirmative-tint",
"true")
225 (
'action_accept',
'Ok'),
226 (
'action_decline_1',
'Snooze'),
227 (
'action_decline_2',
'View'),
241 get_notification =
lambda: notify_list.wait_select_single(
242 'Notification', objectName=
'notification1')
243 notification = get_notification()
245 notification, summary, body,
False,
False, 1.0)
246 notification.pointing_device.click_object(
247 notification.select_single(objectName=
"notify_oot_button0"))
251 """Snap-decision should block input to shell without greeter."""
253 unlock_unity(unity_proxy)
255 summary =
"Incoming file"
256 body =
"Frank would like to send you the file: essay.pdf"
257 icon_path =
"sync-idle"
259 (
"x-canonical-snap-decisions",
"true"),
260 (
"x-canonical-non-shaped-icon",
"true"),
261 (
"x-canonical-private-affirmative-tint",
"true"),
262 (
"x-canonical-private-rejection-tint",
"true"),
266 (
'action_accept',
'Accept'),
267 (
'action_decline_1',
'Decline'),
282 self.main_window.show_dash_swiping()
284 self.main_window.is_launcher_open, Eventually(Equals(
False)))
288 get_notification =
lambda: notify_list.wait_select_single(
289 'Notification', objectName=
'notification1')
290 notification = get_notification()
292 notification, summary, body,
True,
False, 1.0)
293 notification.pointing_device.click_object(
294 notification.select_single(objectName=
"notify_button0"))
298 """A snap-decision should not block input to the greeter beneath it."""
301 summary =
"Incoming file"
302 body =
"Frank would like to send you the file: essay.pdf"
303 icon_path =
"sync-idle"
305 (
"x-canonical-snap-decisions",
"true"),
306 (
"x-canonical-non-shaped-icon",
"true"),
307 (
"x-canonical-private-affirmative-tint",
"true"),
308 (
"x-canonical-private-rejection-tint",
"true"),
312 (
'action_accept',
'Accept'),
313 (
'action_decline_1',
'Decline'),
327 self.main_window.show_dash_swiping()
328 greeter = self.main_window.get_greeter()
329 self.assertThat(greeter.shown, Eventually(Equals(
False)))
333 get_notification =
lambda: notify_list.wait_select_single(
334 'Notification', objectName=
'notification1')
335 notification = get_notification()
337 notification, summary, body,
True,
False, 1.0)
338 notification.pointing_device.click_object(
339 notification.select_single(objectName=
"notify_button0"))
342 def _create_interactive_notification(
351 """Create a interactive notification command.
353 :param summary: Summary text for the notification
354 :param body: Body text to display in the notification
355 :param icon: Path string to the icon to use
356 :param urgency: Urgency string for the noticiation, either: 'LOW',
358 :param actions: List of tuples containing the 'id' and 'label' for all
360 :param hint_strings: List of tuples containing the 'name' and value for
361 setting the hint strings for the notification
366 "Creating snap-decision notification with summary(%s), body(%s) "
374 '--summary', summary,
380 script_args.extend([
'--icon', icon])
384 script_args.extend([
'--hint',
"%s,%s" % (key, value)])
386 for action
in actions:
387 action_id, action_label = action
388 action_string =
"%s,%s" % (action_id, action_label)
389 script_args.extend([
'--action', action_string])
391 python_bin = subprocess.check_output([
'which',
'python']).strip()
393 logger.info(
"Launching snap-decision notification as: %s", command)
396 stdin=subprocess.PIPE,
397 stdout=subprocess.PIPE,
398 stderr=subprocess.PIPE,
400 universal_newlines=
True,
405 poll_result = self._notify_proc.poll()
406 if poll_result
is not None and self._notify_proc.returncode != 0:
407 error_output = self._notify_proc.communicate()[1]
408 raise RuntimeError(
"Call to script failed with: %s" % error_output)
410 def _get_notify_script(self):
411 """Returns the path to the interactive notification creation script."""
412 file_path =
"../../emulators/create_interactive_notification.py"
414 the_path = os.path.abspath(
415 os.path.join(__file__, file_path))
419 def _tidy_up_script_process(self):
420 if self.
_notify_proc is not None and self._notify_proc.poll()
is None:
421 logger.error(
"Notification process wasn't killed, killing now.")
422 os.killpg(self._notify_proc.pid, signal.SIGTERM)
425 """Assert that the interactive notification callback of id *action_id*
428 :raises AssertionError: If no interactive notification has actually
430 :raises AssertionError: When *action_id* does not match the actual
432 :raises AssertionError: If no callback was called at all.
436 raise AssertionError(
"No interactive notification was created.")
438 for i
in range(timeout):
439 self._notify_proc.poll()
440 if self._notify_proc.returncode
is not None:
441 output = self._notify_proc.communicate()
442 actual_action_id = output[0].strip(
"\n")
443 if actual_action_id != action_id:
444 raise AssertionError(
445 "action id '%s' does not match actual returned '%s'"
446 % (action_id, actual_action_id)
452 os.killpg(self._notify_proc.pid, signal.SIGTERM)
454 raise AssertionError(
455 "No callback was called, killing interactivenotification script"
460 """Collection of tests for Emphemeral notifications (non-interactive.)"""
463 super(EphemeralNotificationsTests, self).setUp()
466 Notify.init(
"Autopilot Ephemeral Notification Tests")
467 self.addCleanup(Notify.uninit)
470 """Notification must display the expected summary and body text."""
472 unlock_unity(unity_proxy)
476 summary =
"Icon-Summary-Body"
477 body =
"Hey pal, what's up with the party next weekend? Will you " \
481 (
"x-canonical-secondary-icon",
"message")
484 notification = shell.create_ephemeral_notification(
494 notification =
lambda: notify_list.wait_select_single(
495 'Notification', objectName=
'notification1')
506 """Notification must display the expected summary and secondary
509 unlock_unity(unity_proxy)
513 summary =
"Upload of image completed"
517 notification = shell.create_ephemeral_notification(
527 notification =
lambda: notify_list.wait_select_single(
528 'Notification', objectName=
'notification1')
539 """Notifications must be displayed in order according to their
542 unlock_unity(unity_proxy)
546 summary_low =
'Low Urgency'
547 body_low =
"No, I'd rather see paint dry, pal *yawn*"
550 summary_normal =
'Normal Urgency'
551 body_normal =
"Hey pal, what's up with the party next weekend? Will " \
552 "you join me and Anna?"
555 summary_critical =
'Critical Urgency'
556 body_critical =
'Dude, this is so urgent you have no idea :)'
557 icon_path_critical = self.
_get_icon_path(
'avatars/anna_olsson.png')
559 notification_normal = shell.create_ephemeral_notification(
565 notification_normal.show()
567 notification_low = shell.create_ephemeral_notification(
573 notification_low.show()
575 notification_critical = shell.create_ephemeral_notification(
581 notification_critical.show()
583 get_notification =
lambda: notify_list.wait_select_single(
585 summary=summary_critical
588 notification = get_notification()
598 get_normal_notification =
lambda: notify_list.wait_select_single(
600 summary=summary_normal
602 notification = get_normal_notification()
612 get_low_notification =
lambda: notify_list.wait_select_single(
616 notification = get_low_notification()
627 """Notification must display the expected summary- and body-text."""
629 unlock_unity(unity_proxy)
633 summary =
'Summary-Body'
634 body =
'This is a superfluous notification'
636 notification = shell.create_ephemeral_notification(summary, body)
639 notification = notify_list.wait_select_single(
640 'Notification', objectName=
'notification1')
652 """Notification must display only the expected summary-text."""
654 unlock_unity(unity_proxy)
658 summary =
'Summary-Only'
660 notification = shell.create_ephemeral_notification(summary)
663 notification = notify_list.wait_select_single(
664 'Notification', objectName=
'notification1')
669 """Notification must allow updating its contents while being
672 unlock_unity(unity_proxy)
676 summary =
'Initial notification'
677 body =
'This is the original content of this notification-bubble.'
680 notification = shell.create_ephemeral_notification(
687 get_notification =
lambda: notify_list.wait_select_single(
688 'Notification', summary=summary)
698 summary =
'Updated notification'
699 body =
'Here the same bubble with new title- and body-text, even ' \
700 'the icon can be changed on the update.'
702 notification.update(summary, body, icon_path)
705 get_notification(), summary, body,
True,
False, 1.0)
708 """Notification must allow updating its contents and layout while
711 unlock_unity(unity_proxy)
715 summary =
'Initial layout'
716 body =
'This bubble uses the icon-title-body layout with a ' \
721 notification = shell.create_ephemeral_notification(
726 notification.set_hint_string(
727 'x-canonical-secondary-icon',
732 get_notification =
lambda: notify_list.wait_select_single(
733 'Notification', objectName=
'notification1')
744 notification.clear_hints()
745 summary =
'Updated layout'
746 body =
'After the update we now have a bubble using the title-body ' \
748 notification.update(summary, body,
None)
751 self.assertThat(get_notification, Eventually(NotEquals(
None)))
753 get_notification(), summary, body,
False,
False, 1.0)
def test_update_notification_same_layout
def test_sd_one_over_two_layout
def _get_notifications_list
def test_modal_sd_without_greeter
def assert_notification_action_id_was_called
def _tidy_up_script_process
def _create_interactive_notification
def test_summary_and_body
def test_sd_incoming_call
def test_icon_summary_body
def test_update_notification_layout_change
def test_modal_sd_with_greeter