2 <?xml-stylesheet href=
"chrome://global/skin" type=
"text/css"?>
3 <?xml-stylesheet href=
"chrome://mochikit/content/tests/SimpleTest/test.css" type=
"text/css"?>
5 XUL Widget Test for bug 457632
7 <window title=
"Bug 457632" width=
"500" height=
"600"
8 xmlns=
"http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
9 <script src=
"chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
13 <!-- test results are displayed in the html:body -->
14 <body xmlns=
"http://www.w3.org/1999/xhtml" style=
"height: 300px; overflow: auto;"
17 <!-- test code goes here -->
18 <script type=
"application/javascript">
22 function completeAnimation(nextTest) {
23 if (!gNotificationBox._animating) {
28 setTimeout(completeAnimation,
50, nextTest);
32 SimpleTest.waitForExplicitFinish();
33 gNotificationBox = new MozElements.NotificationBox(e =
> {
34 document.getElementById(
"nb").appendChild(e);
37 is(gNotificationBox.allNotifications.length,
0,
"There should be no initial notifications");
38 gNotificationBox.appendNotification(
"notification1",
39 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
40 is(gNotificationBox.allNotifications.length,
1,
"Notification exists while animating in");
41 let notification = gNotificationBox.getNotificationWithValue(
"notification1");
42 ok(notification,
"Notification should exist while animating in");
44 // Wait for the notificaton to finish displaying
45 completeAnimation(test1);
48 // Tests that a notification that is fully animated in gets removed immediately
50 let notification = gNotificationBox.getNotificationWithValue(
"notification1");
51 gNotificationBox.removeNotification(notification);
52 notification = gNotificationBox.getNotificationWithValue(
"notification1");
53 ok(!notification,
"Test 1 showed notification was still present");
54 ok(!gNotificationBox.currentNotification,
"Test 1 said there was still a current notification");
55 is(gNotificationBox.allNotifications.length,
0,
"Test 1 should show no notifications present");
57 // Wait for the notificaton to finish hiding
58 completeAnimation(test2);
61 // Tests that a notification that is animating in gets removed immediately
63 let notification = gNotificationBox.appendNotification(
"notification2",
64 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
65 gNotificationBox.removeNotification(notification);
66 notification = gNotificationBox.getNotificationWithValue(
"notification2");
67 ok(!notification,
"Test 2 showed notification was still present");
68 ok(!gNotificationBox.currentNotification,
"Test 2 said there was still a current notification");
69 is(gNotificationBox.allNotifications.length,
0,
"Test 2 should show no notifications present");
71 // Get rid of the hiding notifications
72 gNotificationBox.removeAllNotifications(true);
76 // Tests that a background notification goes away immediately
78 let notification = gNotificationBox.appendNotification(
"notification3",
79 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
80 let notification2 = gNotificationBox.appendNotification(
"notification4",
81 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
82 is(gNotificationBox.allNotifications.length,
2,
"Test 3 should show 2 notifications present");
83 gNotificationBox.removeNotification(notification);
84 is(gNotificationBox.allNotifications.length,
1,
"Test 3 should show 1 notifications present");
85 notification = gNotificationBox.getNotificationWithValue(
"notification3");
86 ok(!notification,
"Test 3 showed notification was still present");
87 gNotificationBox.removeNotification(notification2);
88 is(gNotificationBox.allNotifications.length,
0,
"Test 3 should show 0 notifications present");
89 notification2 = gNotificationBox.getNotificationWithValue(
"notification4");
90 ok(!notification2,
"Test 3 showed notification2 was still present");
91 ok(!gNotificationBox.currentNotification,
"Test 3 said there was still a current notification");
93 // Get rid of the hiding notifications
94 gNotificationBox.removeAllNotifications(true);
98 // Tests that a foreground notification hiding a background one goes away
100 let notification = gNotificationBox.appendNotification(
"notification5",
101 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
102 let notification2 = gNotificationBox.appendNotification(
"notification6",
103 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
104 gNotificationBox.removeNotification(notification2);
105 notification2 = gNotificationBox.getNotificationWithValue(
"notification6");
106 ok(!notification2,
"Test 4 showed notification2 was still present");
107 is(gNotificationBox.currentNotification, notification,
"Test 4 said the current notification was wrong");
108 is(gNotificationBox.allNotifications.length,
1,
"Test 4 should show 1 notifications present");
109 gNotificationBox.removeNotification(notification);
110 notification = gNotificationBox.getNotificationWithValue(
"notification5");
111 ok(!notification,
"Test 4 showed notification was still present");
112 ok(!gNotificationBox.currentNotification,
"Test 4 said there was still a current notification");
113 is(gNotificationBox.allNotifications.length,
0,
"Test 4 should show 0 notifications present");
115 // Get rid of the hiding notifications
116 gNotificationBox.removeAllNotifications(true);
120 // Tests that removeAllNotifications gets rid of everything
122 let notification = gNotificationBox.appendNotification(
"notification7",
123 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
124 let notification2 = gNotificationBox.appendNotification(
"notification8",
125 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
126 gNotificationBox.removeAllNotifications();
127 notification = gNotificationBox.getNotificationWithValue(
"notification7");
128 notification2 = gNotificationBox.getNotificationWithValue(
"notification8");
129 ok(!notification,
"Test 5 showed notification was still present");
130 ok(!notification2,
"Test 5 showed notification2 was still present");
131 ok(!gNotificationBox.currentNotification,
"Test 5 said there was still a current notification");
132 is(gNotificationBox.allNotifications.length,
0,
"Test 5 should show 0 notifications present");
134 gNotificationBox.appendNotification(
"notification9",
135 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
137 // Wait for the notificaton to finish displaying
138 completeAnimation(test6);
141 // Tests whether removing an already removed notification doesn't break things
143 let notification = gNotificationBox.getNotificationWithValue(
"notification9");
144 ok(notification,
"Test 6 should have an initial notification");
145 gNotificationBox.removeNotification(notification);
146 gNotificationBox.removeNotification(notification);
148 ok(!gNotificationBox.currentNotification,
"Test 6 shouldn't be any current notification");
149 is(gNotificationBox.allNotifications.length,
0,
"Test 6 allNotifications.length should be 0");
150 notification = gNotificationBox.appendNotification(
"notification10",
151 { label:
"Test notification", priority: gNotificationBox.PRIORITY_INFO_LOW });
152 is(notification, gNotificationBox.currentNotification,
"Test 6 should have made the current notification");
153 gNotificationBox.removeNotification(notification);