gecko/dom/tests/mochitest/notification/notification_common.js
Doug Turner 28279da9a1 Bug 573588 - Implement Desktop Notifications - Tests r=olli, a=beltzner
--HG--
extra : rebase_source : 0d6f956bbc4cb35986e4bc01ef6f06d26feff3d3
2010-09-09 22:00:20 -07:00

75 lines
3.1 KiB
JavaScript

netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
const FAKE_CID = Components.classes["@mozilla.org/uuid-generator;1"].
getService(Components.interfaces.nsIUUIDGenerator).generateUUID();
const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
const ALERTS_SERVICE_CID = Components.ID(Components.classes[ALERTS_SERVICE_CONTRACT_ID].number);
function MockAlertsService() {}
MockAlertsService.prototype = {
showAlertNotification: function(imageUrl, title, text, textClickable,
cookie, alertListener, name) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
// probably should do this async....
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
if (prefs.getBoolPref("notification.prompt.testing.click_on_notification") == true) {
alertListener.observe(null, "alertclickcallback", cookie);
}
alertListener.observe(null, "alertfinished", cookie);
},
QueryInterface: function(aIID) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (aIID.equals(Components.interfaces.nsISupports) ||
aIID.equals(Components.interfaces.nsIAlertsService))
return this;
throw Components.results.NS_ERROR_NO_INTERFACE;
}
};
var factory = {
createInstance: function(aOuter, aIID) {
netscape.security.PrivilegeManager.enablePrivilege('UniversalXPConnect');
if (aOuter != null)
throw Components.results.NS_ERROR_NO_AGGREGATION;
return new MockAlertsService().QueryInterface(aIID);
}
};
function force_prompt(allow) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("notification.prompt.testing", true);
prefs.setBoolPref("notification.prompt.testing.allow", allow);
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
.registerFactory(FAKE_CID, "",
ALERTS_SERVICE_CONTRACT_ID,
factory)
}
function reset_prompt() {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("notification.prompt.testing", false);
prefs.setBoolPref("notification.prompt.testing.allow", false);
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar)
.registerFactory(ALERTS_SERVICE_CID, "",
ALERTS_SERVICE_CONTRACT_ID,
null);
}
function force_click_on_notification(val) {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
var prefs = Components.classes["@mozilla.org/preferences-service;1"].getService(Components.interfaces.nsIPrefBranch);
prefs.setBoolPref("notification.prompt.testing.click_on_notification", val);
}