toolkit/components/alerts/test/test_alerts_noobserve.html

Thu, 22 Jan 2015 13:21:57 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Thu, 22 Jan 2015 13:21:57 +0100
branch
TOR_BUG_9701
changeset 15
b8a032363ba2
permissions
-rw-r--r--

Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6

     1 <!DOCTYPE HTML>
     2 <!-- Any copyright is dedicated to the Public Domain.
     3      http://creativecommons.org/publicdomain/zero/1.0/ -->
     4 <html>
     5 <head>
     6   <title>Test for Alerts Service</title>
     7   <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 
     8   <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
     9 </head>
    11 <body>
    12 <p id="display"></p>
    14 <br>Alerts service, without observer "asynchronous" case.
    15 <br>
    16 <br>A notification should soon appear somewhere.
    17 <br>If there has been no crash when the notification (later) disappears, assume all is good.
    19 <pre id="test">
    20 <script class="testbody" type="text/javascript">
    22 const Cc = SpecialPowers.Cc;
    23 const Ci = SpecialPowers.Ci;
    25 const wm = Cc["@mozilla.org/appshell/window-mediator;1"]
    26              .getService(Ci.nsIWindowMediator);
    28 function anyXULAlertsVisible() {
    29   var windows = wm.getEnumerator('alert:alert');
    30   return windows.hasMoreElements();
    31 }
    33 function waitForAlertsThenFinish() {
    34   if (anyXULAlertsVisible()) {
    35     setTimeout(waitForAlertsThenFinish, 1000);
    36   } else {
    37     ok(true, "Alert disappeared.");
    38     SimpleTest.finish();
    39   }
    40 }
    42 function runTest() {
    43   if (!("@mozilla.org/alerts-service;1" in Cc)) {
    44     todo(false, "Alerts service does not exist in this application");
    45   } else {
    46     ok(true, "Alerts service exists in this application");
    48     var notifier;
    49     try {
    50       notifier = Cc["@mozilla.org/alerts-service;1"].
    51                  getService(Ci.nsIAlertsService);
    52       ok(true, "Alerts service is available");
    53     } catch (ex) {
    54       todo(false, "Alerts service is not available.", ex);
    55     }
    57     if (notifier) {
    58       try {
    59         notifier.showAlertNotification(null, "Notification test",
    60                                        "This notification has no observer");
    61         ok(true, "showAlertNotification() succeeded");
    62       } catch (ex) {
    63         todo(false, "showAlertNotification() failed.", ex);
    64       }
    65     }
    66   }
    67 }
    69 SimpleTest.waitForExplicitFinish();
    70 ok(!anyXULAlertsVisible(), "Alerts should not be present at the start of the test.");
    71 runTest();
    72 setTimeout(waitForAlertsThenFinish, 1000);
    73 </script>
    74 </pre>
    75 </body>
    76 </html>

mercurial