1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/alerts/test/test_alerts_noobserve.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,76 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<!-- Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ --> 1.7 +<html> 1.8 +<head> 1.9 + <title>Test for Alerts Service</title> 1.10 + <script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.11 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.12 +</head> 1.13 + 1.14 +<body> 1.15 +<p id="display"></p> 1.16 + 1.17 +<br>Alerts service, without observer "asynchronous" case. 1.18 +<br> 1.19 +<br>A notification should soon appear somewhere. 1.20 +<br>If there has been no crash when the notification (later) disappears, assume all is good. 1.21 + 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +const Cc = SpecialPowers.Cc; 1.26 +const Ci = SpecialPowers.Ci; 1.27 + 1.28 +const wm = Cc["@mozilla.org/appshell/window-mediator;1"] 1.29 + .getService(Ci.nsIWindowMediator); 1.30 + 1.31 +function anyXULAlertsVisible() { 1.32 + var windows = wm.getEnumerator('alert:alert'); 1.33 + return windows.hasMoreElements(); 1.34 +} 1.35 + 1.36 +function waitForAlertsThenFinish() { 1.37 + if (anyXULAlertsVisible()) { 1.38 + setTimeout(waitForAlertsThenFinish, 1000); 1.39 + } else { 1.40 + ok(true, "Alert disappeared."); 1.41 + SimpleTest.finish(); 1.42 + } 1.43 +} 1.44 + 1.45 +function runTest() { 1.46 + if (!("@mozilla.org/alerts-service;1" in Cc)) { 1.47 + todo(false, "Alerts service does not exist in this application"); 1.48 + } else { 1.49 + ok(true, "Alerts service exists in this application"); 1.50 + 1.51 + var notifier; 1.52 + try { 1.53 + notifier = Cc["@mozilla.org/alerts-service;1"]. 1.54 + getService(Ci.nsIAlertsService); 1.55 + ok(true, "Alerts service is available"); 1.56 + } catch (ex) { 1.57 + todo(false, "Alerts service is not available.", ex); 1.58 + } 1.59 + 1.60 + if (notifier) { 1.61 + try { 1.62 + notifier.showAlertNotification(null, "Notification test", 1.63 + "This notification has no observer"); 1.64 + ok(true, "showAlertNotification() succeeded"); 1.65 + } catch (ex) { 1.66 + todo(false, "showAlertNotification() failed.", ex); 1.67 + } 1.68 + } 1.69 + } 1.70 +} 1.71 + 1.72 +SimpleTest.waitForExplicitFinish(); 1.73 +ok(!anyXULAlertsVisible(), "Alerts should not be present at the start of the test."); 1.74 +runTest(); 1.75 +setTimeout(waitForAlertsThenFinish, 1000); 1.76 +</script> 1.77 +</pre> 1.78 +</body> 1.79 +</html>