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