1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/components/alerts/test/test_alerts.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,84 @@ 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, with observer "synchronous" case. 1.18 +<br> 1.19 +<br>Did a notification appear anywhere? 1.20 +<br>If so, the test will finish once the notification disappears. 1.21 + 1.22 +<pre id="test"> 1.23 +<script class="testbody" type="text/javascript"> 1.24 + 1.25 +var observer = { 1.26 + alertShow: false, 1.27 + observe: function (aSubject, aTopic, aData) { 1.28 + if (aTopic == "alertclickcallback") { 1.29 + todo(false, "Did someone click the notification while running mochitests? (Please don't.)"); 1.30 + } else if (aTopic == "alertshow") { 1.31 + ok(!this.alertShow, "Alert should not be shown more than once"); 1.32 + this.alertShow = true; 1.33 + } else { 1.34 + is(aTopic, "alertfinished", "Checking the topic for a finished notification"); 1.35 + SimpleTest.finish(); 1.36 + } 1.37 + is(aData, "foobarcookie", "Checking whether the alert cookie was passed correctly"); 1.38 + } 1.39 +}; 1.40 + 1.41 +function runTest() { 1.42 + const Cc = SpecialPowers.Cc; 1.43 + const Ci = SpecialPowers.Ci; 1.44 + 1.45 + if (!("@mozilla.org/alerts-service;1" in Cc)) { 1.46 + todo(false, "Alerts service does not exist in this application"); 1.47 + return; 1.48 + } 1.49 + 1.50 + ok(true, "Alerts service exists in this application"); 1.51 + 1.52 + var notifier; 1.53 + try { 1.54 + notifier = Cc["@mozilla.org/alerts-service;1"]. 1.55 + getService(Ci.nsIAlertsService); 1.56 + ok(true, "Alerts service is available"); 1.57 + } catch (ex) { 1.58 + todo(false, 1.59 + "Alerts service is not available.", ex); 1.60 + return; 1.61 + } 1.62 + 1.63 + try { 1.64 + var alertName = "fiorello"; 1.65 + SimpleTest.waitForExplicitFinish(); 1.66 + notifier.showAlertNotification(null, "Notification test", 1.67 + "Surprise! I'm here to test notifications!", 1.68 + false, "foobarcookie", observer, alertname); 1.69 + ok(true, "showAlertNotification() succeeded. Waiting for notification..."); 1.70 + if (MAC) { 1.71 + // Notifications are native on OS X 10.8 and later, and when they are they 1.72 + // persist in the Notification Center. We need to close explicitly to avoid a hang. 1.73 + // This also works for XUL notifications when running this test on OS X < 10.8. 1.74 + notifier.closeAlert(alertName); 1.75 + } 1.76 + } catch (ex) { 1.77 + todo(false, "showAlertNotification() failed.", ex); 1.78 + SimpleTest.finish(); 1.79 + } 1.80 +} 1.81 + 1.82 +runTest(); 1.83 + 1.84 +</script> 1.85 +</pre> 1.86 +</body> 1.87 +</html>