Bug 516124. Add null checks to nsAlertsIconListener. r=roc

This commit is contained in:
Michael Ventnor 2009-11-17 15:16:59 -05:00
parent 3c349b25a6
commit e764036ed7
3 changed files with 41 additions and 2 deletions

View File

@ -44,8 +44,11 @@ relativesrcdir = toolkit/components/alerts/test
include $(DEPTH)/config/autoconf.mk
# Mochitest tests
# Synchronous tests like test_alerts.html must come before
# asynchronous tests like test_alerts_noobserve.html!
MOCHI_TESTS = \
test_alerts.html \
test_alerts_noobserve.html \
$(NULL)

View File

@ -0,0 +1,34 @@
<!DOCTYPE HTML>
<html>
<head>
<title>Test for Alerts Service</title>
<script type="text/javascript" src="/MochiKit/packed.js"></script>
<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>
Alerts service mochitest without observer<br/>
<pre id="test">
<script class="testbody" type="text/javascript">
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const Cc = Components.classes;
const Ci = Components.interfaces;
try {
var notifier = Cc["@mozilla.org/alerts-service;1"].
getService(Ci.nsIAlertsService);
notifier.showAlertNotification(null, "Notification test", "This notification has no observer",
false, "foobarcookie", null);
ok(true, "If we don't crash, we're good.");
} catch (ex) {
// Alerts service doesn't exist
}
</script>
</pre>
</body>
</html>

View File

@ -250,13 +250,15 @@ nsAlertsIconListener::StartRequest(const nsAString & aImageUrl)
void
nsAlertsIconListener::SendCallback()
{
mAlertListener->Observe(NULL, "alertclickcallback", mAlertCookie.get());
if (mAlertListener)
mAlertListener->Observe(NULL, "alertclickcallback", mAlertCookie.get());
}
void
nsAlertsIconListener::SendClosed()
{
mAlertListener->Observe(NULL, "alertfinished", mAlertCookie.get());
if (mAlertListener)
mAlertListener->Observe(NULL, "alertfinished", mAlertCookie.get());
}
nsresult