Source code
Revision control
Copy as Markdown
Other Tools
Test Info: Warnings
- This test gets skipped with pattern: http3 OR http2
- Manifest: dom/security/test/csp/mochitest.toml
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<!-- Including SimpleTest.js so we can use waitForExplicitFinish !-->
<script src="/tests/SimpleTest/SimpleTest.js"></script>
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" />
</head>
<body>
<iframe style="width:100%;" id="testframe"></iframe>
<script class="testbody" type="text/javascript">
/* Description of the test:
* We load a page serving two XHR requests (including being redirected);
* one that should not require CORS and one that should require cors, in particular:
*
* Test 1:
* Description: Upgrade insecure should upgrade from http to https and also
* surpress CORS for that case.
*
* Test 2:
* Description: Upgrade insecure should upgrade from http to https and also
* prevent CORS for that case.
* Note: If redirecting to a different port, then CORS *should* be enforced (unless
* it's port 443). Unfortunately we can't test that because of the setup of our
* *.sjs files; they only are able to listen to port 443, see:
*
* Test 3:
* Description: Upgrade insecure should *not* prevent CORS since
* the page performs a cross origin xhr.
*
*/
const CSP_POLICY = "upgrade-insecure-requests; script-src 'unsafe-inline'";
var tests = 3;
function loadTest() {
// append the file that should be served
src += escape("tests/dom/security/test/csp/file_upgrade_insecure_cors.html")
// append the CSP that should be used to serve the file
src += "&csp=" + escape(CSP_POLICY);
document.getElementById("testframe").src = src;
}
function checkResult(result) {
if (result === "test1-no-cors-ok" ||
result === "test2-no-cors-diffport-ok" ||
result === "test3-cors-ok") {
ok(true, "'upgrade-insecure-requests' acknowledges CORS (" + result + ")");
}
else {
ok(false, "'upgrade-insecure-requests' acknowledges CORS (" + result + ")");
}
if (--tests > 0) {
return;
}
window.removeEventListener("message", receiveMessage);
SimpleTest.finish();
}
// a postMessage handler that is used to bubble up results from
// within the iframe.
window.addEventListener("message", receiveMessage);
function receiveMessage(event) {
checkResult(event.data);
}
SimpleTest.waitForExplicitFinish();
loadTest();
</script>
</body>
</html>