|
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, 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. |
|
18 |
|
19 <pre id="test"> |
|
20 <script class="testbody" type="text/javascript"> |
|
21 |
|
22 const Cc = SpecialPowers.Cc; |
|
23 const Ci = SpecialPowers.Ci; |
|
24 |
|
25 const wm = Cc["@mozilla.org/appshell/window-mediator;1"] |
|
26 .getService(Ci.nsIWindowMediator); |
|
27 |
|
28 function anyXULAlertsVisible() { |
|
29 var windows = wm.getEnumerator('alert:alert'); |
|
30 return windows.hasMoreElements(); |
|
31 } |
|
32 |
|
33 function waitForAlertsThenFinish() { |
|
34 if (anyXULAlertsVisible()) { |
|
35 setTimeout(waitForAlertsThenFinish, 1000); |
|
36 } else { |
|
37 ok(true, "Alert disappeared."); |
|
38 SimpleTest.finish(); |
|
39 } |
|
40 } |
|
41 |
|
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"); |
|
47 |
|
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 } |
|
56 |
|
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 } |
|
68 |
|
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> |