michael@0: const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}"); michael@0: const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; michael@0: michael@0: const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}"); michael@0: const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1"; michael@0: michael@0: var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager. michael@0: QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar); michael@0: michael@0: var mockAlertsService = { michael@0: showAlertNotification: function(imageUrl, title, text, textClickable, michael@0: cookie, alertListener, name, bidi, lang) { michael@0: // probably should do this async.... michael@0: SpecialPowers.wrap(alertListener).observe(null, "alertshow", cookie); michael@0: michael@0: if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) { michael@0: SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie); michael@0: } michael@0: michael@0: SpecialPowers.wrap(alertListener).observe(null, "alertfinished", cookie); michael@0: }, michael@0: michael@0: showAppNotification: function(imageUrl, title, text, alertListener, details) { michael@0: this.showAlertNotification(imageUrl, title, text, details.textClickable, "", michael@0: alertListener, details.name, details.dir, details.lang); michael@0: }, michael@0: michael@0: QueryInterface: function(aIID) { michael@0: if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || michael@0: SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService) || michael@0: SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAppNotificationService)) { michael@0: return this; michael@0: } michael@0: throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; michael@0: }, michael@0: michael@0: createInstance: function(aOuter, aIID) { michael@0: if (aOuter != null) { michael@0: throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION; michael@0: } michael@0: return this.QueryInterface(aIID); michael@0: } michael@0: }; michael@0: mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService); michael@0: michael@0: function setup_notifications(allowPrompt, forceClick, callback) { michael@0: SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true], michael@0: ["notification.prompt.testing.allow", allowPrompt], michael@0: ["notification.prompt.testing.click_on_notification", forceClick]]}, michael@0: callback); michael@0: michael@0: registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service", michael@0: SYSTEM_ALERTS_SERVICE_CONTRACT_ID, michael@0: mockAlertsService); michael@0: michael@0: registrar.registerFactory(MOCK_ALERTS_CID, "alerts service", michael@0: ALERTS_SERVICE_CONTRACT_ID, michael@0: mockAlertsService); michael@0: } michael@0: michael@0: function reset_notifications() { michael@0: registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService); michael@0: registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService); michael@0: } michael@0: michael@0: function is_feature_enabled() { michael@0: return navigator.mozNotification && SpecialPowers.getBoolPref("notification.feature.enabled"); michael@0: } michael@0: