|
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=995943 |
|
6 --> |
|
7 <window title="Mozilla Bug 995943" |
|
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 |
|
11 <!-- test results are displayed in the html:body --> |
|
12 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
13 <a href="https://bugzilla.mozilla.org/show_bug.cgi?id=995943" |
|
14 target="_blank">Mozilla Bug 995943</a> |
|
15 </body> |
|
16 |
|
17 <!-- test code goes here --> |
|
18 <script type="application/javascript"> |
|
19 <![CDATA[ |
|
20 const Cu = Components.utils; |
|
21 const Cc = Components.classes; |
|
22 const Ci = Components.interfaces; |
|
23 Cu.import("resource://gre/modules/Services.jsm"); |
|
24 function debug(msg) { info(msg); } |
|
25 |
|
26 /** Test for CAPS file:// URI prefs. **/ |
|
27 SimpleTest.waitForExplicitFinish(); |
|
28 SimpleTest.requestCompleteLog(); |
|
29 if (Services.appinfo.OS == "Darwin") // See bug 1067022 |
|
30 SimpleTest.expectAssertions(0, 1); |
|
31 |
|
32 var rootdir = Services.appinfo.OS == "WINNT" ? "file:///C:" : "file:///"; |
|
33 |
|
34 function checkLoadFileURI(domain, shouldLoad) { |
|
35 debug("Invoking checkLoadFileURI with domain: " + domain + ", shouldLoad: " + shouldLoad); |
|
36 return new Promise(function(resolve, reject) { |
|
37 $('ifr').addEventListener('load', function l1() { |
|
38 debug("Invoked l1 for " + domain); |
|
39 $('ifr').removeEventListener('load', l1); |
|
40 function l2() { |
|
41 debug("Invoked l2 for " + domain); |
|
42 $('ifr').removeEventListener('load', l2); |
|
43 ok(shouldLoad, "Successfully loaded file:// URI for domain: " + domain); |
|
44 resolve(); |
|
45 } |
|
46 $('ifr').addEventListener('load', l2); |
|
47 try { |
|
48 window[0].wrappedJSObject.location = rootdir; |
|
49 debug("Successfully navigated for " + domain); |
|
50 } catch (e) { |
|
51 ok(!shouldLoad && /denied|insecure/.test(e), |
|
52 "Prevented loading of file:// URI for domain: " + domain + " - " + e); |
|
53 $('ifr').removeEventListener('load', l2); |
|
54 resolve(); |
|
55 } |
|
56 }); |
|
57 let targetURI = domain + '/tests/js/xpconnect/tests/mochitest/file_empty.html'; |
|
58 debug("Navigating iframe to " + targetURI); |
|
59 $('ifr').contentWindow.location = targetURI; |
|
60 }); |
|
61 } |
|
62 |
|
63 function pushPrefs(prefs) { |
|
64 return new Promise(function(resolve) { SpecialPowers.pushPrefEnv({ set: prefs }, resolve); }); |
|
65 } |
|
66 |
|
67 function popPrefs() { |
|
68 return new Promise(function(resolve) { SpecialPowers.popPrefEnv(resolve); }); |
|
69 } |
|
70 |
|
71 var gGoCount = 0; |
|
72 function go() { |
|
73 debug("Invoking go for window with id: " + window.getInterface(Ci.nsIDOMWindowUtils).currentInnerWindowID); |
|
74 is(++gGoCount, 1, "Should only call go once!"); |
|
75 checkLoadFileURI('http://example.com', false).then( |
|
76 pushPrefs.bind(null, [['capability.policy.policynames', ' somepolicy '], |
|
77 ['capability.policy.somepolicy.checkloaduri.enabled', 'AlLAcCeSs'], |
|
78 ['capability.policy.somepolicy.sites', 'http://example.com']])) |
|
79 .then(checkLoadFileURI.bind(null, 'http://example.com', true)) |
|
80 .then(popPrefs) |
|
81 .then(checkLoadFileURI.bind(null, 'http://example.com', false)) |
|
82 .then( |
|
83 pushPrefs.bind(null, [['capability.policy.policynames', ',somepolicy, someotherpolicy, '], |
|
84 ['capability.policy.somepolicy.checkloaduri.enabled', 'allaccess'], |
|
85 ['capability.policy.someotherpolicy.checkloaduri.enabled', 'nope'], |
|
86 ['capability.policy.somepolicy.sites', ' http://example.org test1.example.com https://test2.example.com '], |
|
87 ['capability.policy.someotherpolicy.sites', 'http://example.net ']])) |
|
88 .then(checkLoadFileURI.bind(null, 'http://example.org', true)) |
|
89 .then(checkLoadFileURI.bind(null, 'http://test2.example.com', false)) |
|
90 .then(checkLoadFileURI.bind(null, 'https://test2.example.com', true)) |
|
91 .then(checkLoadFileURI.bind(null, 'http://sub1.test2.example.com', false)) |
|
92 .then(checkLoadFileURI.bind(null, 'https://sub1.test2.example.com', true)) |
|
93 .then(checkLoadFileURI.bind(null, 'http://example.net', false)) |
|
94 .then(checkLoadFileURI.bind(null, 'http://test1.example.com', true)) |
|
95 .then(checkLoadFileURI.bind(null, 'https://test1.example.com', true)) |
|
96 .then(checkLoadFileURI.bind(null, 'http://sub1.test1.example.com', true)) |
|
97 .then(checkLoadFileURI.bind(null, 'https://sub1.test1.example.com', true)) |
|
98 .then(pushPrefs.bind(null, [['capability.policy.someotherpolicy.checkloaduri.enabled', 'allAccess']])) |
|
99 .then(checkLoadFileURI.bind(null, 'http://example.net', true)) |
|
100 .then(popPrefs) |
|
101 .then(popPrefs) |
|
102 .then(checkLoadFileURI.bind(null, 'http://example.net', false)) |
|
103 .then(SimpleTest.finish.bind(SimpleTest)); |
|
104 |
|
105 } |
|
106 addLoadEvent(go); |
|
107 |
|
108 ]]> |
|
109 </script> |
|
110 <iframe id="ifr" type="content" /> |
|
111 </window> |