Source code
Revision control
Copy as Markdown
Other Tools
Test Info:
- Manifest: dom/notification/test/chrome/chrome.toml
<?xml version="1.0"?>
<!--
-->
<!-- test results are displayed in the html:body -->
</body>
<!-- test code goes here -->
<script type="application/javascript">
<![CDATA[
const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
const SYSTEM_CID = Components.ID("{a0ccaaf8-09da-44d8-b250-9ac3e93c8117}");
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
var mockAlertsService = {
showAlert() {
ok(true, "System principal was granted permission and is able to call showAlert.");
unregisterMock();
SimpleTest.finish();
},
showAlertNotification() {
this.showAlert();
},
QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
createInstance(aIID) {
return this.QueryInterface(aIID);
}
};
function registerMock() {
Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
}
function unregisterMock() {
const registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
registrar.unregisterFactory(MOCK_CID, mockAlertsService);
registrar.registerFactory(SYSTEM_CID, "", ALERTS_SERVICE_CONTRACT_ID, null);
}
function runTests() {
registerMock();
is(Notification.permission, "granted", "System principal should be automatically granted permission.");
Notification.requestPermission(function(permission) {
is(permission, "granted", "System principal should be granted permission when calling requestPermission.");
if (permission == "granted") {
// Create a notification and make sure that it is able to call into
// the mock alert service to show the notification.
new Notification("Hello");
} else {
unregisterMock();
SimpleTest.finish();
}
});
}
SimpleTest.waitForExplicitFinish();
]]>
</script>
</window>