tor-browser

The Tor Browser
git clone https://git.dasho.dev/tor-browser.git
Log | Files | Refs | README | LICENSE

test_notification_system_principal.xhtml (2573B)


      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 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/>
     10  <script src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/>
     11 
     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>
     17 
     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 SYSTEM_CID = Components.ID("{a0ccaaf8-09da-44d8-b250-9ac3e93c8117}");
     24  const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1";
     25 
     26  var mockAlertsService = {
     27    showAlert() {
     28      ok(true, "System principal was granted permission and is able to call showAlert.");
     29      unregisterMock();
     30      SimpleTest.finish();
     31    },
     32 
     33    QueryInterface: ChromeUtils.generateQI(["nsIAlertsService"]),
     34 
     35    createInstance(aIID) {
     36      return this.QueryInterface(aIID);
     37    }
     38  };
     39 
     40  function registerMock() {
     41    Components.manager.QueryInterface(Ci.nsIComponentRegistrar).
     42      registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService);
     43  }
     44 
     45  function unregisterMock() {
     46    const registrar = Components.manager.QueryInterface(Ci.nsIComponentRegistrar);
     47    registrar.unregisterFactory(MOCK_CID, mockAlertsService);
     48    registrar.registerFactory(SYSTEM_CID, "", ALERTS_SERVICE_CONTRACT_ID, null);
     49  }
     50 
     51  function runTests() {
     52    registerMock();
     53 
     54    is(Notification.permission, "granted", "System principal should be automatically granted permission.");
     55 
     56    Notification.requestPermission(function(permission) {
     57      is(permission, "granted", "System principal should be granted permission when calling requestPermission.");
     58 
     59      if (permission == "granted") {
     60        // Create a notification and make sure that it is able to call into
     61        // the mock alert service to show the notification.
     62        new Notification("Hello");
     63      } else {
     64        unregisterMock();
     65        SimpleTest.finish();
     66      }
     67    });
     68  }
     69 
     70  SimpleTest.waitForExplicitFinish();
     71  ]]>
     72  </script>
     73 </window>