gecko-dev/dom/security/test/csp/test_bug949549.html

68 строки
2.0 KiB
HTML

<!DOCTYPE HTML>
<html>
<head>
<title>Test for Bug 949549</title>
<script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
</head>
<body>
<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=949549">Mozilla Bug 949549</a>
<div id="content" style="display: none"></div>
<pre id="test">
<script type="application/javascript;version=1.8">
"use strict";
// Ensure that `setRequestContext` doesn't throw with app:// URLs
const csp = SpecialPowers.Cc["@mozilla.org/cspcontext;1"]
.createInstance(SpecialPowers.Ci.nsIContentSecurityPolicy);
const gManifestURL = "http://www.example.com/chrome/dom/apps/tests/apps/basic.webapp";
SimpleTest.waitForExplicitFinish();
var app;
var principal;
function setupTest() {
// We have to install an app in order for the app URL to be valid
// (otherwise we get a "DummyChannel" that throws NS_NOT_IMPLEMENTED)
SpecialPowers.addPermission("webapps-manage", true, document);
SpecialPowers.autoConfirmAppInstall(function () {
let req = navigator.mozApps.install(gManifestURL);
req.onsuccess = function () {
app = this.result;
runTest();
}
});
}
function runTest() {
try {
var secMan = SpecialPowers.Cc["@mozilla.org/scriptsecuritymanager;1"]
.getService(SpecialPowers.Ci.nsIScriptSecurityManager);
var manifestURI = SpecialPowers.Services.io.newURI(gManifestURL, null, null);
principal = secMan.getSimpleCodebasePrincipal(manifestURI);
csp.setRequestContext(null, principal);
ok(true, "setRequestContext hasn't thown");
} catch(e) {
ok(false, "setRequestContext throws");
}
cleanup()
}
function cleanup() {
SpecialPowers.autoConfirmAppUninstall(function () {
let req = navigator.mozApps.mgmt.uninstall(app);
req.onsuccess = function () {
SimpleTest.finish();
};
});
}
setupTest();
</script>
</pre>
</body>
</html>