|
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> |
|
10 |
|
11 <body> |
|
12 <p id="display"></p> |
|
13 |
|
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. |
|
18 |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
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 }; |
|
37 |
|
38 function runTest() { |
|
39 const Cc = SpecialPowers.Cc; |
|
40 const Ci = SpecialPowers.Ci; |
|
41 |
|
42 if (!("@mozilla.org/alerts-service;1" in Cc)) { |
|
43 todo(false, "Alerts service does not exist in this application"); |
|
44 return; |
|
45 } |
|
46 |
|
47 ok(true, "Alerts service exists in this application"); |
|
48 |
|
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 } |
|
59 |
|
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 } |
|
78 |
|
79 runTest(); |
|
80 |
|
81 </script> |
|
82 </pre> |
|
83 </body> |
|
84 </html> |