gecko-dev/testing/web-platform/tests/content-security-policy/inheritance/iframe.html

85 строки
2.4 KiB
HTML

<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta http-equiv="Content-Security-Policy" content="img-src 'none'">
<body>
<script>
function wait_for_error_from_frame(frame, test) {
window.addEventListener('message', test.step_func(e => {
if (e.source != frame.contentWindow)
return;
assert_equals(e.data, "error");
frame.remove();
test.done();
}));
}
async_test(t => {
var i = document.createElement('iframe');
document.body.appendChild(i);
var img = document.createElement('img');
img.onerror = t.step_func_done(_ => i.remove());
img.onload = t.unreached_func();
i.contentDocument.body.appendChild(img);
img.src = "/images/red-16x16.png";
}, "<iframe>'s about:blank inherits policy.");
async_test(t => {
var i = document.createElement('iframe');
i.srcdoc = `
<img src='/images/red-16x16.png'
onload='window.top.postMessage("load", "*");'
onerror='window.top.postMessage("error", "*");'
>
`;
wait_for_error_from_frame(i, t);
document.body.appendChild(i);
}, "<iframe srcdoc>'s inherits policy.");
async_test(t => {
var i = document.createElement('iframe');
var b = new Blob(
[`
<img src='${window.origin}/images/red-16x16.png'
onload='window.top.postMessage("load", "*");'
onerror='window.top.postMessage("error", "*");'
>
`], {type:"text/html"});
i.src = URL.createObjectURL(b);
wait_for_error_from_frame(i, t);
document.body.appendChild(i);
}, "<iframe src='blob:...'>'s inherits policy.");
async_test(t => {
var i = document.createElement('iframe');
i.src = `data:text/html,<img src='${window.origin}/images/red-16x16.png'
onload='window.top.postMessage("load", "*");'
onerror='window.top.postMessage("error", "*");'
>`;
wait_for_error_from_frame(i, t);
document.body.appendChild(i);
}, "<iframe src='data:...'>'s inherits policy.");
async_test(t => {
var i = document.createElement('iframe');
i.src = `javascript:"<img src='${window.origin}/images/red-16x16.png'
onload='window.top.postMessage(\\"load\\", \\"*\\");'
onerror='window.top.postMessage(\\"error\\", \\"*\\");'
>"`;
wait_for_error_from_frame(i, t);
document.body.appendChild(i);
}, "<iframe src='javascript:...'>'s inherits policy.");
</script>