dom/tests/mochitest/notification/desktop-notification/notification_common.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 const MOCK_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{48068bc2-40ab-4904-8afd-4cdfb3a385f3}");
     2 const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
     4 const MOCK_SYSTEM_ALERTS_CID = SpecialPowers.wrap(SpecialPowers.Components).ID("{e86d888c-e41b-4b78-9104-2f2742a532de}");
     5 const SYSTEM_ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/system-alerts-service;1";
     7 var registrar = SpecialPowers.wrap(SpecialPowers.Components).manager.
     8   QueryInterface(SpecialPowers.Ci.nsIComponentRegistrar);
    10 var mockAlertsService = {
    11   showAlertNotification: function(imageUrl, title, text, textClickable,
    12                                   cookie, alertListener, name, bidi, lang) {
    13     // probably should do this async....
    14     SpecialPowers.wrap(alertListener).observe(null, "alertshow", cookie);
    16     if (SpecialPowers.getBoolPref("notification.prompt.testing.click_on_notification") == true) {
    17        SpecialPowers.wrap(alertListener).observe(null, "alertclickcallback", cookie);
    18     }
    20     SpecialPowers.wrap(alertListener).observe(null, "alertfinished", cookie);
    21   },
    23   showAppNotification: function(imageUrl, title, text, alertListener, details) {
    24     this.showAlertNotification(imageUrl, title, text, details.textClickable, "",
    25                                alertListener, details.name, details.dir, details.lang);
    26   },
    28   QueryInterface: function(aIID) {
    29     if (SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsISupports) ||
    30         SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAlertsService) ||
    31         SpecialPowers.wrap(aIID).equals(SpecialPowers.Ci.nsIAppNotificationService)) {
    32       return this;
    33     }
    34     throw SpecialPowers.Components.results.NS_ERROR_NO_INTERFACE;
    35   },
    37   createInstance: function(aOuter, aIID) {
    38     if (aOuter != null) {
    39       throw SpecialPowers.Components.results.NS_ERROR_NO_AGGREGATION;
    40     }
    41     return this.QueryInterface(aIID);
    42   }
    43 };
    44 mockAlertsService = SpecialPowers.wrapCallbackObject(mockAlertsService);
    46 function setup_notifications(allowPrompt, forceClick, callback) {
    47   SpecialPowers.pushPrefEnv({'set': [["notification.prompt.testing", true],
    48                                      ["notification.prompt.testing.allow", allowPrompt],
    49                                      ["notification.prompt.testing.click_on_notification", forceClick]]},
    50                             callback);
    52   registrar.registerFactory(MOCK_SYSTEM_ALERTS_CID, "system alerts service",
    53                             SYSTEM_ALERTS_SERVICE_CONTRACT_ID,
    54                             mockAlertsService);
    56   registrar.registerFactory(MOCK_ALERTS_CID, "alerts service",
    57                             ALERTS_SERVICE_CONTRACT_ID,
    58                             mockAlertsService);
    59 }
    61 function reset_notifications() {
    62   registrar.unregisterFactory(MOCK_SYSTEM_ALERTS_CID, mockAlertsService);
    63   registrar.unregisterFactory(MOCK_ALERTS_CID, mockAlertsService);
    64 }
    66 function is_feature_enabled() {
    67   return navigator.mozNotification && SpecialPowers.getBoolPref("notification.feature.enabled");
    68 }

mercurial