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
|
<!DOCTYPE html>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<meta http-equiv="Content-Security-Policy" content="img-src 'self'">
<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, "load");
frame.remove();
test.done();
}));
}
async_test(t => {
var i = document.createElement('iframe');
document.body.appendChild(i);
var img = document.createElement('img');
img.onload = t.step_func_done(_ => i.remove());
img.onerror = t.unreached_func();
i.contentDocument.body.appendChild(img);
img.src = "{{location[server]}}/images/red-16x16.png";
}, "<iframe>'s about:blank inherits policy.");
async_test(t => {
var i = document.createElement('iframe');
i.srcdoc = `
<img src='{{location[server]}}/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='{{location[server]}}/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='{{location[server]}}/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='{{location[server]}}/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.");
async_test(t => {
var i = document.createElement('iframe');
var b = new Blob(
[`
<img src='{{location[server]}}/images/red-16x16.png'
onload='window.top.postMessage("load", "*");'
onerror='window.top.postMessage("error", "*");'
>
`], {type:"text/html"});
i.src = URL.createObjectURL(b);
i.sandbox = 'allow-scripts';
wait_for_error_from_frame(i, t);
document.body.appendChild(i);
}, "<iframe sandbox src='blob:...'>'s inherits policy. (opaque origin sandbox)");
</script>
|