|
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"/> |
|
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 ALERTS_SERVICE_CONTRACT_ID = "@mozilla.org/alerts-service;1"; |
|
24 |
|
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 }, |
|
32 |
|
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 }, |
|
40 |
|
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 }; |
|
48 |
|
49 function registerMock() { |
|
50 Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar). |
|
51 registerFactory(MOCK_CID, "alerts service", ALERTS_SERVICE_CONTRACT_ID, mockAlertsService); |
|
52 } |
|
53 |
|
54 function unregisterMock() { |
|
55 Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar). |
|
56 unregisterFactory(MOCK_CID, mockAlertsService); |
|
57 } |
|
58 |
|
59 function runTests() { |
|
60 registerMock(); |
|
61 |
|
62 is(Notification.permission, "granted", "System principal should be automatically granted permission."); |
|
63 |
|
64 Notification.requestPermission(function(permission) { |
|
65 is(permission, "granted", "System principal should be granted permission when calling requestPermission."); |
|
66 |
|
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 } |
|
77 |
|
78 SimpleTest.waitForExplicitFinish(); |
|
79 ]]> |
|
80 </script> |
|
81 </window> |