|
1 <?xml version="1.0"?> |
|
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
|
3 <?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?> |
|
4 <!-- |
|
5 XUL Widget Test for bug 457632 |
|
6 --> |
|
7 <window title="Bug 457632" width="500" height="600" |
|
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
9 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
10 |
|
11 <notificationbox id="nb"/> |
|
12 |
|
13 <!-- test results are displayed in the html:body --> |
|
14 <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;" |
|
15 onload="test()"/> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 var gNotificationBox; |
|
21 |
|
22 function completeAnimation(nextTest) { |
|
23 if (!gNotificationBox._animating) { |
|
24 nextTest(); |
|
25 return; |
|
26 } |
|
27 |
|
28 setTimeout(completeAnimation, 50, nextTest); |
|
29 } |
|
30 |
|
31 function test() { |
|
32 SimpleTest.waitForExplicitFinish(); |
|
33 gNotificationBox = document.getElementById("nb"); |
|
34 |
|
35 is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications"); |
|
36 gNotificationBox.appendNotification("Test notification", |
|
37 "notification1", null, |
|
38 gNotificationBox.PRIORITY_INFO_LOW, |
|
39 null); |
|
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"); |
|
43 |
|
44 // Wait for the notificaton to finish displaying |
|
45 completeAnimation(test1); |
|
46 } |
|
47 |
|
48 // Tests that a notification that is fully animated in gets removed immediately |
|
49 function test1() { |
|
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"); |
|
56 |
|
57 // Wait for the notificaton to finish hiding |
|
58 completeAnimation(test2); |
|
59 } |
|
60 |
|
61 // Tests that a notification that is animating in gets removed immediately |
|
62 function test2() { |
|
63 let notification = gNotificationBox.appendNotification("Test notification", |
|
64 "notification2", null, |
|
65 gNotificationBox.PRIORITY_INFO_LOW, |
|
66 null); |
|
67 gNotificationBox.removeNotification(notification); |
|
68 notification = gNotificationBox.getNotificationWithValue("notification2"); |
|
69 ok(!notification, "Test 2 showed notification was still present"); |
|
70 ok(!gNotificationBox.currentNotification, "Test 2 said there was still a current notification"); |
|
71 is(gNotificationBox.allNotifications.length, 0, "Test 2 should show no notifications present"); |
|
72 |
|
73 // Get rid of the hiding notifications |
|
74 gNotificationBox.removeAllNotifications(true); |
|
75 test3(); |
|
76 } |
|
77 |
|
78 // Tests that a background notification goes away immediately |
|
79 function test3() { |
|
80 let notification = gNotificationBox.appendNotification("Test notification", |
|
81 "notification3", null, |
|
82 gNotificationBox.PRIORITY_INFO_LOW, |
|
83 null); |
|
84 let notification2 = gNotificationBox.appendNotification("Test notification", |
|
85 "notification4", null, |
|
86 gNotificationBox.PRIORITY_INFO_LOW, |
|
87 null); |
|
88 is(gNotificationBox.allNotifications.length, 2, "Test 3 should show 2 notifications present"); |
|
89 gNotificationBox.removeNotification(notification); |
|
90 is(gNotificationBox.allNotifications.length, 1, "Test 3 should show 1 notifications present"); |
|
91 notification = gNotificationBox.getNotificationWithValue("notification3"); |
|
92 ok(!notification, "Test 3 showed notification was still present"); |
|
93 gNotificationBox.removeNotification(notification2); |
|
94 is(gNotificationBox.allNotifications.length, 0, "Test 3 should show 0 notifications present"); |
|
95 notification2 = gNotificationBox.getNotificationWithValue("notification4"); |
|
96 ok(!notification2, "Test 3 showed notification2 was still present"); |
|
97 ok(!gNotificationBox.currentNotification, "Test 3 said there was still a current notification"); |
|
98 |
|
99 // Get rid of the hiding notifications |
|
100 gNotificationBox.removeAllNotifications(true); |
|
101 test4(); |
|
102 } |
|
103 |
|
104 // Tests that a foreground notification hiding a background one goes away |
|
105 function test4() { |
|
106 let notification = gNotificationBox.appendNotification("Test notification", |
|
107 "notification5", null, |
|
108 gNotificationBox.PRIORITY_INFO_LOW, |
|
109 null); |
|
110 let notification2 = gNotificationBox.appendNotification("Test notification", |
|
111 "notification6", null, |
|
112 gNotificationBox.PRIORITY_INFO_LOW, |
|
113 null); |
|
114 gNotificationBox.removeNotification(notification2); |
|
115 notification2 = gNotificationBox.getNotificationWithValue("notification6"); |
|
116 ok(!notification2, "Test 4 showed notification2 was still present"); |
|
117 is(gNotificationBox.currentNotification, notification, "Test 4 said the current notification was wrong"); |
|
118 is(gNotificationBox.allNotifications.length, 1, "Test 4 should show 1 notifications present"); |
|
119 gNotificationBox.removeNotification(notification); |
|
120 notification = gNotificationBox.getNotificationWithValue("notification5"); |
|
121 ok(!notification, "Test 4 showed notification was still present"); |
|
122 ok(!gNotificationBox.currentNotification, "Test 4 said there was still a current notification"); |
|
123 is(gNotificationBox.allNotifications.length, 0, "Test 4 should show 0 notifications present"); |
|
124 |
|
125 // Get rid of the hiding notifications |
|
126 gNotificationBox.removeAllNotifications(true); |
|
127 test5(); |
|
128 } |
|
129 |
|
130 // Tests that removeAllNotifications gets rid of everything |
|
131 function test5() { |
|
132 let notification = gNotificationBox.appendNotification("Test notification", |
|
133 "notification7", null, |
|
134 gNotificationBox.PRIORITY_INFO_LOW, |
|
135 null); |
|
136 let notification2 = gNotificationBox.appendNotification("Test notification", |
|
137 "notification8", null, |
|
138 gNotificationBox.PRIORITY_INFO_LOW, |
|
139 null); |
|
140 gNotificationBox.removeAllNotifications(); |
|
141 notification = gNotificationBox.getNotificationWithValue("notification7"); |
|
142 notification2 = gNotificationBox.getNotificationWithValue("notification8"); |
|
143 ok(!notification, "Test 5 showed notification was still present"); |
|
144 ok(!notification2, "Test 5 showed notification2 was still present"); |
|
145 ok(!gNotificationBox.currentNotification, "Test 5 said there was still a current notification"); |
|
146 is(gNotificationBox.allNotifications.length, 0, "Test 5 should show 0 notifications present"); |
|
147 |
|
148 gNotificationBox.appendNotification("Test notification", |
|
149 "notification9", null, |
|
150 gNotificationBox.PRIORITY_INFO_LOW, |
|
151 null); |
|
152 |
|
153 // Wait for the notificaton to finish displaying |
|
154 completeAnimation(test6); |
|
155 } |
|
156 |
|
157 // Tests whether removing an already removed notification doesn't break things |
|
158 function test6() { |
|
159 let notification = gNotificationBox.getNotificationWithValue("notification9"); |
|
160 ok(notification, "Test 6 should have an initial notification"); |
|
161 gNotificationBox.removeNotification(notification); |
|
162 gNotificationBox.removeNotification(notification); |
|
163 |
|
164 ok(!gNotificationBox.currentNotification, "Test 6 shouldn't be any current notification"); |
|
165 is(gNotificationBox.allNotifications.length, 0, "Test 6 allNotifications.length should be 0"); |
|
166 notification = gNotificationBox.appendNotification("Test notification", |
|
167 "notification10", null, |
|
168 gNotificationBox.PRIORITY_INFO_LOW, |
|
169 null); |
|
170 is(notification, gNotificationBox.currentNotification, "Test 6 should have made the current notification"); |
|
171 gNotificationBox.removeNotification(notification); |
|
172 |
|
173 SimpleTest.finish(); |
|
174 } |
|
175 ]]> |
|
176 </script> |
|
177 |
|
178 </window> |