Thu, 22 Jan 2015 13:21:57 +0100
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, with observer "synchronous" case.
15 <br>
16 <br>Did a notification appear anywhere?
17 <br>If so, the test will finish once the notification disappears.
19 <pre id="test">
20 <script class="testbody" type="text/javascript">
22 var observer = {
23 alertShow: false,
24 observe: function (aSubject, aTopic, aData) {
25 if (aTopic == "alertclickcallback") {
26 todo(false, "Did someone click the notification while running mochitests? (Please don't.)");
27 } else if (aTopic == "alertshow") {
28 ok(!this.alertShow, "Alert should not be shown more than once");
29 this.alertShow = true;
30 } else {
31 is(aTopic, "alertfinished", "Checking the topic for a finished notification");
32 SimpleTest.finish();
33 }
34 is(aData, "foobarcookie", "Checking whether the alert cookie was passed correctly");
35 }
36 };
38 function runTest() {
39 const Cc = SpecialPowers.Cc;
40 const Ci = SpecialPowers.Ci;
42 if (!("@mozilla.org/alerts-service;1" in Cc)) {
43 todo(false, "Alerts service does not exist in this application");
44 return;
45 }
47 ok(true, "Alerts service exists in this application");
49 var notifier;
50 try {
51 notifier = Cc["@mozilla.org/alerts-service;1"].
52 getService(Ci.nsIAlertsService);
53 ok(true, "Alerts service is available");
54 } catch (ex) {
55 todo(false,
56 "Alerts service is not available.", ex);
57 return;
58 }
60 try {
61 var alertName = "fiorello";
62 SimpleTest.waitForExplicitFinish();
63 notifier.showAlertNotification(null, "Notification test",
64 "Surprise! I'm here to test notifications!",
65 false, "foobarcookie", observer, alertname);
66 ok(true, "showAlertNotification() succeeded. Waiting for notification...");
67 if (MAC) {
68 // Notifications are native on OS X 10.8 and later, and when they are they
69 // persist in the Notification Center. We need to close explicitly to avoid a hang.
70 // This also works for XUL notifications when running this test on OS X < 10.8.
71 notifier.closeAlert(alertName);
72 }
73 } catch (ex) {
74 todo(false, "showAlertNotification() failed.", ex);
75 SimpleTest.finish();
76 }
77 }
79 runTest();
81 </script>
82 </pre>
83 </body>
84 </html>