toolkit/content/tests/chrome/test_bug457632.xul

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/toolkit/content/tests/chrome/test_bug457632.xul	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,178 @@
     1.4 +<?xml version="1.0"?>
     1.5 +<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
     1.6 +<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
     1.7 +<!--
     1.8 +  XUL Widget Test for bug 457632
     1.9 +  -->
    1.10 +<window title="Bug 457632" width="500" height="600"
    1.11 +        xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
    1.12 +  <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>  
    1.13 +
    1.14 +  <notificationbox id="nb"/>
    1.15 +
    1.16 +  <!-- test results are displayed in the html:body -->
    1.17 +  <body xmlns="http://www.w3.org/1999/xhtml" style="height: 300px; overflow: auto;"
    1.18 +        onload="test()"/>
    1.19 +
    1.20 +  <!-- test code goes here -->
    1.21 +<script type="application/javascript">
    1.22 +<![CDATA[
    1.23 +var gNotificationBox;
    1.24 +
    1.25 +function completeAnimation(nextTest) {
    1.26 +  if (!gNotificationBox._animating) {
    1.27 +    nextTest();
    1.28 +    return;
    1.29 +  }
    1.30 +
    1.31 +  setTimeout(completeAnimation, 50, nextTest);
    1.32 +}
    1.33 +
    1.34 +function test() {
    1.35 +  SimpleTest.waitForExplicitFinish();
    1.36 +  gNotificationBox = document.getElementById("nb");
    1.37 +
    1.38 +  is(gNotificationBox.allNotifications.length, 0, "There should be no initial notifications");
    1.39 +  gNotificationBox.appendNotification("Test notification",
    1.40 +                                      "notification1", null,
    1.41 +                                      gNotificationBox.PRIORITY_INFO_LOW,
    1.42 +                                      null);
    1.43 +  is(gNotificationBox.allNotifications.length, 1, "Notification exists while animating in");
    1.44 +  let notification = gNotificationBox.getNotificationWithValue("notification1");
    1.45 +  ok(notification, "Notification should exist while animating in");
    1.46 +
    1.47 +  // Wait for the notificaton to finish displaying
    1.48 +  completeAnimation(test1);
    1.49 +}
    1.50 +
    1.51 +// Tests that a notification that is fully animated in gets removed immediately
    1.52 +function test1() {
    1.53 +  let notification = gNotificationBox.getNotificationWithValue("notification1");
    1.54 +  gNotificationBox.removeNotification(notification);
    1.55 +  notification = gNotificationBox.getNotificationWithValue("notification1");
    1.56 +  ok(!notification, "Test 1 showed notification was still present");
    1.57 +  ok(!gNotificationBox.currentNotification, "Test 1 said there was still a current notification");
    1.58 +  is(gNotificationBox.allNotifications.length, 0, "Test 1 should show no notifications present");
    1.59 +
    1.60 +  // Wait for the notificaton to finish hiding
    1.61 +  completeAnimation(test2);
    1.62 +}
    1.63 +
    1.64 +// Tests that a notification that is animating in gets removed immediately
    1.65 +function test2() {
    1.66 +  let notification = gNotificationBox.appendNotification("Test notification",
    1.67 +                                                         "notification2", null,
    1.68 +                                                         gNotificationBox.PRIORITY_INFO_LOW,
    1.69 +                                                         null);
    1.70 +  gNotificationBox.removeNotification(notification);
    1.71 +  notification = gNotificationBox.getNotificationWithValue("notification2");
    1.72 +  ok(!notification, "Test 2 showed notification was still present");
    1.73 +  ok(!gNotificationBox.currentNotification, "Test 2 said there was still a current notification");
    1.74 +  is(gNotificationBox.allNotifications.length, 0, "Test 2 should show no notifications present");
    1.75 +
    1.76 +  // Get rid of the hiding notifications
    1.77 +  gNotificationBox.removeAllNotifications(true);
    1.78 +  test3();
    1.79 +}
    1.80 +
    1.81 +// Tests that a background notification goes away immediately
    1.82 +function test3() {
    1.83 +  let notification = gNotificationBox.appendNotification("Test notification",
    1.84 +                                                         "notification3", null,
    1.85 +                                                         gNotificationBox.PRIORITY_INFO_LOW,
    1.86 +                                                         null);
    1.87 +  let notification2 = gNotificationBox.appendNotification("Test notification",
    1.88 +                                                          "notification4", null,
    1.89 +                                                          gNotificationBox.PRIORITY_INFO_LOW,
    1.90 +                                                          null);
    1.91 +  is(gNotificationBox.allNotifications.length, 2, "Test 3 should show 2 notifications present");
    1.92 +  gNotificationBox.removeNotification(notification);
    1.93 +  is(gNotificationBox.allNotifications.length, 1, "Test 3 should show 1 notifications present");
    1.94 +  notification = gNotificationBox.getNotificationWithValue("notification3");
    1.95 +  ok(!notification, "Test 3 showed notification was still present");
    1.96 +  gNotificationBox.removeNotification(notification2);
    1.97 +  is(gNotificationBox.allNotifications.length, 0, "Test 3 should show 0 notifications present");
    1.98 +  notification2 = gNotificationBox.getNotificationWithValue("notification4");
    1.99 +  ok(!notification2, "Test 3 showed notification2 was still present");
   1.100 +  ok(!gNotificationBox.currentNotification, "Test 3 said there was still a current notification");
   1.101 +
   1.102 +  // Get rid of the hiding notifications
   1.103 +  gNotificationBox.removeAllNotifications(true);
   1.104 +  test4();
   1.105 +}
   1.106 +
   1.107 +// Tests that a foreground notification hiding a background one goes away
   1.108 +function test4() {
   1.109 +  let notification = gNotificationBox.appendNotification("Test notification",
   1.110 +                                                         "notification5", null,
   1.111 +                                                         gNotificationBox.PRIORITY_INFO_LOW,
   1.112 +                                                         null);
   1.113 +  let notification2 = gNotificationBox.appendNotification("Test notification",
   1.114 +                                                          "notification6", null,
   1.115 +                                                          gNotificationBox.PRIORITY_INFO_LOW,
   1.116 +                                                          null);
   1.117 +  gNotificationBox.removeNotification(notification2);
   1.118 +  notification2 = gNotificationBox.getNotificationWithValue("notification6");
   1.119 +  ok(!notification2, "Test 4 showed notification2 was still present");
   1.120 +  is(gNotificationBox.currentNotification, notification, "Test 4 said the current notification was wrong");
   1.121 +  is(gNotificationBox.allNotifications.length, 1, "Test 4 should show 1 notifications present");
   1.122 +  gNotificationBox.removeNotification(notification);
   1.123 +  notification = gNotificationBox.getNotificationWithValue("notification5");
   1.124 +  ok(!notification, "Test 4 showed notification was still present");
   1.125 +  ok(!gNotificationBox.currentNotification, "Test 4 said there was still a current notification");
   1.126 +  is(gNotificationBox.allNotifications.length, 0, "Test 4 should show 0 notifications present");
   1.127 +
   1.128 +  // Get rid of the hiding notifications
   1.129 +  gNotificationBox.removeAllNotifications(true);
   1.130 +  test5();
   1.131 +}
   1.132 +
   1.133 +// Tests that removeAllNotifications gets rid of everything
   1.134 +function test5() {
   1.135 +  let notification = gNotificationBox.appendNotification("Test notification",
   1.136 +                                                         "notification7", null,
   1.137 +                                                         gNotificationBox.PRIORITY_INFO_LOW,
   1.138 +                                                         null);
   1.139 +  let notification2 = gNotificationBox.appendNotification("Test notification",
   1.140 +                                                          "notification8", null,
   1.141 +                                                          gNotificationBox.PRIORITY_INFO_LOW,
   1.142 +                                                          null);
   1.143 +  gNotificationBox.removeAllNotifications();
   1.144 +  notification = gNotificationBox.getNotificationWithValue("notification7");
   1.145 +  notification2 = gNotificationBox.getNotificationWithValue("notification8");
   1.146 +  ok(!notification, "Test 5 showed notification was still present");
   1.147 +  ok(!notification2, "Test 5 showed notification2 was still present");
   1.148 +  ok(!gNotificationBox.currentNotification, "Test 5 said there was still a current notification");
   1.149 +  is(gNotificationBox.allNotifications.length, 0, "Test 5 should show 0 notifications present");
   1.150 +
   1.151 +  gNotificationBox.appendNotification("Test notification",
   1.152 +                                      "notification9", null,
   1.153 +                                      gNotificationBox.PRIORITY_INFO_LOW,
   1.154 +                                      null);
   1.155 +
   1.156 +  // Wait for the notificaton to finish displaying
   1.157 +  completeAnimation(test6);
   1.158 +}
   1.159 +
   1.160 +// Tests whether removing an already removed notification doesn't break things
   1.161 +function test6() {
   1.162 +  let notification = gNotificationBox.getNotificationWithValue("notification9");
   1.163 +  ok(notification, "Test 6 should have an initial notification");
   1.164 +  gNotificationBox.removeNotification(notification);
   1.165 +  gNotificationBox.removeNotification(notification);
   1.166 +
   1.167 +  ok(!gNotificationBox.currentNotification, "Test 6 shouldn't be any current notification");
   1.168 +  is(gNotificationBox.allNotifications.length, 0, "Test 6 allNotifications.length should be 0");
   1.169 +  notification = gNotificationBox.appendNotification("Test notification",
   1.170 +                                                     "notification10", null,
   1.171 +                                                     gNotificationBox.PRIORITY_INFO_LOW,
   1.172 +                                                     null);
   1.173 +  is(notification, gNotificationBox.currentNotification, "Test 6 should have made the current notification");
   1.174 +  gNotificationBox.removeNotification(notification);
   1.175 +
   1.176 +  SimpleTest.finish();
   1.177 +}
   1.178 +]]>
   1.179 +</script>
   1.180 +
   1.181 +</window>

mercurial