Backed out 7 changesets (bug 1845150) for causing dt failures on browser_screenshot_b...
[gecko.git] / toolkit / content / tests / chrome / test_bug457632.xhtml
blob7f94eaef09a0ed2dbc81d7d5b513786877a4d8f2
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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
11 <vbox id="nb"/>
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()"/>
17 <!-- test code goes here -->
18 <script type="application/javascript">
19 <![CDATA[
20 var gNotificationBox;
22 function completeAnimation(nextTest) {
23 if (!gNotificationBox._animating) {
24 nextTest();
25 return;
28 setTimeout(completeAnimation, 50, nextTest);
31 function test() {
32 SimpleTest.waitForExplicitFinish();
33 gNotificationBox = new MozElements.NotificationBox(e => {
34 document.getElementById("nb").appendChild(e);
35 });
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
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");
57 // Wait for the notificaton to finish hiding
58 completeAnimation(test2);
61 // Tests that a notification that is animating in gets removed immediately
62 function test2() {
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);
73 test3();
76 // Tests that a background notification goes away immediately
77 function test3() {
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);
95 test4();
98 // Tests that a foreground notification hiding a background one goes away
99 function test4() {
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);
117 test5();
120 // Tests that removeAllNotifications gets rid of everything
121 function test5() {
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
142 function test6() {
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);
155 SimpleTest.finish();
158 </script>
160 </window>