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