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.

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

mercurial