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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
|
<!DOCTYPE html>
<html>
<head>
<script src='/resources/testharness.js'></script>
<script src='/resources/testharnessreport.js'></script>
<script src="/common/get-host-info.sub.js"></script>
</head>
<body>
<script>
const SAMEORIGIN_BASE = get_host_info().HTTP_ORIGIN;
const CROSSORIGIN_BASE = get_host_info().HTTP_NOTSAMESITE_ORIGIN;
const TESTS = [
// HTMLImageElement
{
title: 'Test creating a VideoFrame with a same-origin HTMLImageElement',
factory: () => {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.src = SAMEORIGIN_BASE + '/webcodecs/four-colors.jpg';
});
},
should_throw: false,
},
{
title: 'Test creating a VideoFrame with a cross-origin HTMLImageElement',
factory: () => {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.src = CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg';
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin HTMLImageElement without setting crossorigin',
factory: () => {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.src = CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg?pipe=header(Access-Control-Allow-Origin,*)';
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin HTMLImageElement with crossorigin="anonymous"',
factory: () => {
return new Promise((resolve, reject) => {
const image = new Image();
image.onload = () => resolve(image);
image.onerror = reject;
image.crossOrigin = 'anonymous';
image.src = CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg?pipe=header(Access-Control-Allow-Origin,*)';
});
},
should_throw: false,
},
// SVGImageElement
{
title: 'Test creating a VideoFrame with a same-origin SVGImageElement',
factory: () => {
return new Promise((resolve, reject) => {
const image = document.createElementNS('http://www.w3.org/2000/svg','image');
image.onload = () => resolve(image);
image.onerror = reject;
image.setAttribute('href', SAMEORIGIN_BASE + '/webcodecs/four-colors.jpg');
});
},
should_throw: false,
},
{
title: 'Test creating a VideoFrame with a cross-origin SVGImageElement',
factory: () => {
return new Promise((resolve, reject) => {
const image = document.createElementNS('http://www.w3.org/2000/svg','image');
image.onload = () => resolve(image);
image.onerror = reject;
image.setAttribute('href', CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg');
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin SVGImageElement without setting crossorigin',
factory: () => {
return new Promise((resolve, reject) => {
const image = document.createElementNS('http://www.w3.org/2000/svg','image');
image.onload = () => resolve(image);
image.onerror = reject;
image.setAttribute('href', CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg?pipe=header(Access-Control-Allow-Origin,*)');
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin SVGImageElement with crossorigin="anonymous"',
factory: () => {
return new Promise((resolve, reject) => {
const image = document.createElementNS('http://www.w3.org/2000/svg','image');
image.onload = () => resolve(image);
image.onerror = reject;
image.crossOrigin = 'anonymous';
image.setAttribute('href', CROSSORIGIN_BASE + '/webcodecs/four-colors.jpg?pipe=header(Access-Control-Allow-Origin,*)');
});
},
should_throw: () => {
// SVGImageElement.crossOrigin is not standardized.
const image = document.createElementNS('http://www.w3.org/2000/svg','image');
return !('crossOrigin' in image);
},
},
// HTMLVideoElement
{
title: 'Test creating a VideoFrame with a same-origin HTMLVideoElement',
factory: () => {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
on_frame_available(video, () => resolve(video));
video.onerror = reject;
video.src = SAMEORIGIN_BASE + '/webcodecs/av1.mp4';
});
},
should_throw: false,
},
{
title: 'Test creating a VideoFrame with a cross-origin HTMLVideoElement',
factory: () => {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
on_frame_available(video, () => resolve(video));
video.onerror = reject;
video.src = CROSSORIGIN_BASE + '/webcodecs/av1.mp4';
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin HTMLVideoElement without setting crossorigin',
factory: () => {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
on_frame_available(video, () => resolve(video));
video.onerror = reject;
video.src = CROSSORIGIN_BASE + '/webcodecs/av1.mp4?pipe=header(Access-Control-Allow-Origin,*)';
});
},
should_throw: true,
},
{
title: 'Test creating a VideoFrame with a CORS enabled cross-origin HTMLVideoElement with crossorigin="anonymous"',
factory: () => {
return new Promise((resolve, reject) => {
const video = document.createElement('video');
on_frame_available(video, () => resolve(video));
video.onerror = reject;
video.crossOrigin = 'anonymous';
video.src = CROSSORIGIN_BASE + '/webcodecs/av1.mp4?pipe=header(Access-Control-Allow-Origin,*)';
});
},
should_throw: false,
},
];
TESTS.forEach(test => run_test(test));
function run_test(test) {
promise_test(async t => {
const source = await test.factory();
if (test.should_throw) {
assert_throws_dom('SecurityError', () => { create_frame(source); });
} else {
create_frame(source);
}
}, test.title);
}
function create_frame(img) {
let frame = new VideoFrame(img, {timestamp: 0});
frame.close();
}
function on_frame_available(video, callback) {
if ('requestVideoFrameCallback' in video)
video.requestVideoFrameCallback(callback);
else
video.onloadeddata = callback;
}
</script>
</body>
</html>
|