Commit e386d878 authored by Thomas Guilbert's avatar Thomas Guilbert Committed by Commit Bot

Add VideoFrame serialization tests

This CL adds tests which verify that VideoFrames are properly serialized
when posted as messages, and that they can be cloned and destructoyed.

Change-Id: I4aedcde443a8f8f0b1884a106cebd013a4d482d5
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2358349Reviewed-by: default avatarChrome Cunningham <chcunningham@chromium.org>
Commit-Queue: Chrome Cunningham <chcunningham@chromium.org>
Auto-Submit: Thomas Guilbert <tguilbert@chromium.org>
Cr-Commit-Position: refs/heads/master@{#799261}
parent e80da6ed
<!DOCTYPE html>
<html>
<title>Test posting VideoFrames.</title>
<body></body>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<script src="/common/media.js"></script>
<script>
function makeImageBitmap(width, height) {
let canvas = document.createElement('canvas');
canvas.width = width;
canvas.height = height;
let ctx = canvas.getContext('2d');
ctx.fillStyle = 'rgba(50, 100, 150, 255)';
ctx.fillRect(0, 0, width, height);
return createImageBitmap(canvas);
}
var defaultInit = {
timestamp : 100,
duration : 33,
}
async function createDefaultVideoFrame() {
let image = await makeImageBitmap(32,16);
return new VideoFrame(image, defaultInit);
}
async_test(async function(t) {
let frame = await createDefaultVideoFrame();
let clone = frame.clone();
assert_equals(frame.timestamp, clone.timestamp);
assert_equals(frame.duration, clone.duration);
assert_equals(frame.cropWidth, clone.cropWidth);
assert_equals(frame.cropHeight, clone.cropHeight);
assert_equals(frame.cropWidth, clone.cropWidth);
assert_equals(frame.cropHeight, clone.cropHeight);
frame.destroy();
clone.destroy();
t.done();
}, 'Test we can clone a VideoFrame.');
async_test(async function(t) {
let frame = await createDefaultVideoFrame();
let copy = frame;
let clone = frame.clone();
frame.destroy();
assert_not_equals(copy.timestamp, defaultInit.timestamp);
assert_equals(clone.timestamp, defaultInit.timestamp);
clone.destroy();
t.done();
}, 'Verify destroying a frame doesn\'t affect its clones.');
async_test(async function(t) {
let frame = await createDefaultVideoFrame();
frame.destroy();
assert_throws_dom("InvalidStateError", () => {
let clone = frame.clone();
});
t.done();
}, 'Verify cloning a destroyed frame throws.');
async_test(async function(t) {
let localFrame = await createDefaultVideoFrame();
let channel = new MessageChannel();
let localPort = channel.port1;
let externalPort = channel.port2;
externalPort.onmessage = t.step_func((e) => {
let externalFrame = e.data;
externalFrame.destroy();
externalPort.postMessage("Done");
})
localPort.onmessage = t.step_func_done((e) => {
assert_not_equals(localFrame.timestamp, defaultInit.timestamp);
})
localPort.postMessage(localFrame);
}, 'Verify destroying frames propagates accross contexts.');
async_test(async function(t) {
let localFrame = await createDefaultVideoFrame();
let channel = new MessageChannel();
let localPort = channel.port1;
let externalPort = channel.port2;
externalPort.onmessage = t.step_func((e) => {
let externalFrame = e.data;
externalFrame.destroy();
externalPort.postMessage("Done");
})
localPort.onmessage = t.step_func_done((e) => {
assert_equals(localFrame.timestamp, defaultInit.timestamp);
localFrame.destroy();
})
localPort.postMessage(localFrame.clone());
}, 'Verify destroying cloned frames doesn\'t propagate accross contexts.');
async_test(async function(t) {
let localFrame = await createDefaultVideoFrame();
let channel = new MessageChannel();
let localPort = channel.port1;
localPort.onmessage = t.unreached_func();
localFrame.destroy();
assert_throws_dom("DataCloneError", () => {
localPort.postMessage(localFrame);
});
t.done();
}, 'Verify posting destroyed frames throws.');
</script>
</html>
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment