diff options
author | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
---|---|---|
committer | Matt A. Tobin <mattatobin@localhost.localdomain> | 2018-02-02 04:16:08 -0500 |
commit | 5f8de423f190bbb79a62f804151bc24824fa32d8 (patch) | |
tree | 10027f336435511475e392454359edea8e25895d /dom/tests/mochitest/notification/desktop-notification/notification_common.js | |
parent | 49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff) | |
download | UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip |
Add m-esr52 at 52.6.0
Diffstat (limited to 'dom/tests/mochitest/notification/desktop-notification/notification_common.js')
-rw-r--r-- | dom/tests/mochitest/notification/desktop-notification/notification_common.js | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/dom/tests/mochitest/notification/desktop-notification/notification_common.js b/dom/tests/mochitest/notification/desktop-notification/notification_common.js new file mode 100644 index 000000000..921b1e753 --- /dev/null +++ b/dom/tests/mochitest/notification/desktop-notification/notification_common.js @@ -0,0 +1,70 @@ +const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}"); +const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; + +const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}"); +const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1"; + +var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager. + QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar); + +var mockAlertsService = { + showAlert: function(alert, alertListener) { + // probably should do this async.... + SpecialPowers.wrap(alertListener).observe(null, "alertshow", alert.cookie); + + if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) { + SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", alert.cookie); + } + + SpecialPowers.wrap(alertListener).observe(null, "alertfinished", alert.cookie); + }, + + showAlertNotification: function(imageUrl, title, text, textClickable, + cookie, alertListener, name, bidi, + lang, data) { + return this.showAlert({ + cookie: cookie + }, alertListener); + }, + + QueryInterface: function(aIID) { + if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) || + SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService)) { + return this; + } + throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE; + }, + + createInstance: function(aOuter, aIID) { + if (aOuter != null) { + throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION; + } + return this.QueryInterface(aIID); + } +}; +mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService); + +function setup_notifications(allowPrompt, forceClick, callback) { + SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true], + ["notification.prompt.testing.allow", allowPrompt], + ["notification.prompt.testing.click_on_notification", forceClick]]}, + callback); + + registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service", + SYSTEM_ALERTS_SERVICE_CONTRACT_ID, + mockAlertsService); + + registrar.registerFactory(MOCK_ALERTS_CID, "alerts service", + ALERTS_SERVICE_CONTRACT_ID, + mockAlertsService); +} + +function reset_notifications() { + registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService); + registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService); +} + +function is_feature_enabled() { + return navigator.mozNotification && SpecialPowers.getBoolPref("notification.feature.enabled"); +} + |