| <!DOCTYPE html> | |
| <html> | |
| <head> | |
| <script src='/resources/testharness.js'></script> | |
| <script src='/resources/testharnessreport.js'></script> | |
| </head> | |
| <body> | |
| <script> | |
| const SAMEORIGIN_BASE = '{{location[scheme]}}://{{location[host]}}'; | |
| const CROSSORIGIN_BASE = 'http://{{hosts[][www]}}:{{ports[http][0]}}'; | |
| const NO_CORS = undefined; | |
| 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: false, | |
| }, | |
| // HTMLVideoElement | |
| { | |
| title: 'Test creating a VideoFrame with a same-origin HTMLVideoElement', | |
| factory: () => { | |
| return new Promise((resolve, reject) => { | |
| const video = document.createElement('video'); | |
| video.onloadeddata = () => 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'); | |
| video.onloadeddata = () => 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'); | |
| video.onloadeddata = () => 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'); | |
| video.onloadeddata = () => 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(); | |
| } | |
| </script> | |
| </body> | |
| </html> |