gecko/toolkit/components/alerts/test/test_alerts.html

78 lines
2.4 KiB
HTML

<!DOCTYPE HTML>
<!-- Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ -->
<html>
<head>
<title>Test for Alerts Service</title>
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<p id="display"></p>
<br>Alerts service, with observer "synchronous" case.
<br>
<br>Did a notification appear anywhere?
<br>If so, the test will finish once the notification disappears.
<pre id="test">
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
var observer = {
observe: function (aSubject, aTopic, aData) {
if (aTopic == "alertclickcallback")
todo(false, "Did someone click the notification while running mochitests? (Please don't.)");
else
is(aTopic, "alertfinished", "Checking the topic for a finished notification");
is(aData, "foobarcookie", "Checking whether the alert cookie was passed correctly");
// finish(), yet let the test actually end first, to be safe.
SimpleTest.executeSoon(SimpleTest.finish);
}
};
const Cc = Components.classes;
const Ci = Components.interfaces;
var gNotificationIsAvailable;
if (!("@mozilla.org/alerts-service;1" in Cc)) {
todo(false, "Alerts service does not exist in this application");
} else {
ok(true, "Alerts service exists in this application");
var notifier;
try {
notifier = Cc["@mozilla.org/alerts-service;1"].
getService(Ci.nsIAlertsService);
ok(true, "Alerts service is available");
} catch (ex) {
todo(false, "Alerts service is not available. (Mac OS X without Growl?)", ex);
}
if (notifier) {
try {
notifier.showAlertNotification(null, "Notification test",
"Surprise! I'm here to test notifications!",
false, "foobarcookie", observer);
ok(true, "showAlertNotification() succeeded");
gNotificationIsAvailable = true;
} catch (ex) {
todo(false, "showAlertNotification() failed. (Mac OS X without Growl?)", ex);
}
}
}
if (gNotificationIsAvailable) {
// Wait for the (asynchronous) notification callback.
SimpleTest.waitForExplicitFinish();
ok(true, "Waiting for notification callback to be triggered...");
}
</script>
</pre>
</body>
</html>