1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/tests/mochitest/notification/desktop-notification/test_system_principal.xul Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,81 @@ 1.4 +<?xml version="1.0"?> 1.5 +<?xml-stylesheet type="text/css" href="chrome://global/skin"?> 1.6 +<?xml-stylesheet type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"?> 1.7 +<!-- 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=874090 1.9 +--> 1.10 +<window title="Mozilla Bug 874090" onload="runTests()" 1.11 + xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> 1.12 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"/> 1.13 + <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"/> 1.14 + 1.15 + <!-- test results are displayed in the html:body --> 1.16 + <body xmlns="http://www.w3.org/1999/xhtml"> 1.17 + <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=874090" 1.18 + target="_blank">Mozilla Bug 874090</a> 1.19 + </body> 1.20 + 1.21 + <!-- test code goes here --> 1.22 + <script type="application/javascript"> 1.23 + <![CDATA[ 1.24 + /** Test for Bug 874090 **/ 1.25 + const MOCK_CID = Components.ID("{2a0f83c4-8818-4914-a184-f1172b4eaaa7}"); 1.26 + const ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; 1.27 + 1.28 + var mockAlertsService = { 1.29 + showAlertNotification: function(imageUrl, title, text, textClickable, 1.30 + cookie, alertListener, name, dir, lang) { 1.31 + ok(true, "System principal was granted permission and is able to call showAlertNotification."); 1.32 + unregisterMock(); 1.33 + SimpleTest.finish(); 1.34 + }, 1.35 + 1.36 + QueryInterface: function(aIID) { 1.37 + if (aIID.equals(Components.interfaces.nsISupports) || 1.38 + aIID.equals(Components.interfaces.nsIAlertsService)) { 1.39 + return this; 1.40 + } 1.41 + throw Components.results.NS_ERROR_NO_INTERFACE; 1.42 + }, 1.43 + 1.44 + createInstance: function(aOuter, aIID) { 1.45 + if (aOuter != null) { 1.46 + throw Components.results.NS_ERROR_NO_AGGREGATION; 1.47 + } 1.48 + return this.QueryInterface(aIID); 1.49 + } 1.50 + }; 1.51 + 1.52 + function registerMock() { 1.53 + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar). 1.54 + registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService); 1.55 + } 1.56 + 1.57 + function unregisterMock() { 1.58 + Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar). 1.59 + unregisterFactory(MOCK_CID, mockAlertsService); 1.60 + } 1.61 + 1.62 + function runTests() { 1.63 + registerMock(); 1.64 + 1.65 + is(Notification.permission, "granted", "System principal should be automatically granted permission."); 1.66 + 1.67 + Notification.requestPermission(function(permission) { 1.68 + is(permission, "granted", "System principal should be granted permission when calling requestPermission."); 1.69 + 1.70 + if (permission == "granted") { 1.71 + // Create a notification and make sure that it is able to call into 1.72 + // the mock alert service to show the notification. 1.73 + new Notification("Hello"); 1.74 + } else { 1.75 + unregisterMock(); 1.76 + SimpleTest.finish(); 1.77 + } 1.78 + }); 1.79 + } 1.80 + 1.81 + SimpleTest.waitForExplicitFinish(); 1.82 + ]]> 1.83 + </script> 1.84 +</window>