dom/tests/mochitest/notification/desktop-notification/test_system_principal.xul

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 <?xml version="1.0"?>
     2 <?xml-stylesheet type="text/css" href="chrome://global/skin"?>
     3 <?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?>
     4 <!--
     5 https://bugzilla.mozilla.org/show_bug.cgi?id=874090
     6 -->
     7 <window title="Mozilla Bug 874090" onload="runTests()"
     8         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
     9   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
    10   <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
    12   <!-- test results are displayed in the html:body -->
    13   <body xmlns="http://www.w3.org/1999/xhtml">
    14   <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=874090"
    15      target="_blank">Mozilla Bug 874090</a>
    16   </body>
    18   <!-- test code goes here -->
    19   <script type="application/javascript">
    20   <![CDATA[
    21   /** Test for Bug 874090 **/
    22   const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}");
    23   const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
    25   var mockAlertsService = {
    26     showAlertNotification: function(imageUrl, title, text, textClickable,
    27                                     cookie, alertListener, name, dir, lang) {
    28       ok(true, "System principal was granted permission and is able to call showAlertNotification.");
    29       unregisterMock();
    30       SimpleTest.finish();
    31     },
    33     QueryInterface: function(aIID) {
    34       if (aIID.equals(Components.interfaces.nsISupports) ||
    35           aIID.equals(Components.interfaces.nsIAlertsService)) {
    36         return this;
    37       }
    38       throw Components.results.NS_ERROR_NO_INTERFACE;
    39     },
    41     createInstance: function(aOuter, aIID) {
    42       if (aOuter != null) {
    43         throw Components.results.NS_ERROR_NO_AGGREGATION;
    44       }
    45       return this.QueryInterface(aIID);
    46     }
    47   };
    49   function registerMock() {
    50     Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
    51       registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
    52   }
    54   function unregisterMock() {
    55     Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
    56       unregisterFactory(MOCK_CID, mockAlertsService);
    57   }
    59   function runTests() {
    60     registerMock();
    62     is(Notification.permission, "granted", "System principal should be automatically granted permission.");
    64     Notification.requestPermission(function(permission) {
    65       is(permission, "granted", "System principal should be granted permission when calling requestPermission.");
    67       if (permission == "granted") {
    68         // Create a notification and make sure that it is able to call into
    69         // the mock alert service to show the notification.
    70         new Notification("Hello");
    71       } else {
    72         unregisterMock();
    73         SimpleTest.finish();
    74       }
    75     });
    76   }
    78   SimpleTest.waitForExplicitFinish();
    79   ]]>
    80   </script>
    81 </window>

mercurial