From 6bf0a5cb5034a7e684dcc3500e841785237ce2dd Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 19:32:43 +0200 Subject: Adding upstream version 1:115.7.0. Signed-off-by: Daniel Baumann --- .../tests/webcodecs/videoFrame-construction.any.js | 757 +++++++++++++++++++++ 1 file changed, 757 insertions(+) create mode 100644 testing/web-platform/tests/webcodecs/videoFrame-construction.any.js (limited to 'testing/web-platform/tests/webcodecs/videoFrame-construction.any.js') diff --git a/testing/web-platform/tests/webcodecs/videoFrame-construction.any.js b/testing/web-platform/tests/webcodecs/videoFrame-construction.any.js new file mode 100644 index 0000000000..d6374c11d1 --- /dev/null +++ b/testing/web-platform/tests/webcodecs/videoFrame-construction.any.js @@ -0,0 +1,757 @@ +// META: global=window,dedicatedworker +// META: script=/webcodecs/utils.js +// META: script=/webcodecs/videoFrame-utils.js + +test(t => { + let image = makeImageBitmap(32, 16); + let frame = new VideoFrame(image, {timestamp: 10}); + + assert_equals(frame.timestamp, 10, 'timestamp'); + assert_equals(frame.duration, null, 'duration'); + assert_equals(frame.visibleRect.width, 32, 'visibleRect.width'); + assert_equals(frame.visibleRect.height, 16, 'visibleRect.height'); + assert_equals(frame.displayWidth, 32, 'displayWidth'); + assert_equals(frame.displayHeight, 16, 'displayHeight'); + + frame.close(); +}, 'Test we can construct a VideoFrame.'); + +test(t => { + let image = makeImageBitmap(32, 16); + let frame = new VideoFrame(image, {timestamp: 10, duration: 15}); + frame.close(); + + assert_equals(frame.format, null, 'format') + assert_equals(frame.timestamp, 10, 'timestamp'); + assert_equals(frame.duration, 15, 'duration'); + assert_equals(frame.codedWidth, 0, 'codedWidth'); + assert_equals(frame.codedHeight, 0, 'codedHeight'); + assert_equals(frame.visibleRect, null, 'visibleRect'); + assert_equals(frame.displayWidth, 0, 'displayWidth'); + assert_equals(frame.displayHeight, 0, 'displayHeight'); + assert_equals(frame.colorSpace.primaries, null, 'colorSpace.primaries'); + assert_equals(frame.colorSpace.transfer, null, 'colorSpace.transfer'); + assert_equals(frame.colorSpace.matrix, null, 'colorSpace.matrix'); + assert_equals(frame.colorSpace.fullRange, null, 'colorSpace.fullRange'); + assert_true(isFrameClosed(frame)); + + assert_throws_dom('InvalidStateError', () => frame.clone()); +}, 'Test closed VideoFrame.'); + +test(t => { + let image = makeImageBitmap(32, 16); + let frame = new VideoFrame(image, {timestamp: -10}); + assert_equals(frame.timestamp, -10, 'timestamp'); + frame.close(); +}, 'Test we can construct a VideoFrame with a negative timestamp.'); + +promise_test(async t => { + verifyTimestampRequiredToConstructFrame(makeImageBitmap(1, 1)); +}, 'Test that timestamp is required when constructing VideoFrame from ImageBitmap'); + +promise_test(async t => { + verifyTimestampRequiredToConstructFrame(makeOffscreenCanvas(16, 16)); +}, 'Test that timestamp is required when constructing VideoFrame from OffscreenCanvas'); + +promise_test(async t => { + let init = { + format: 'I420', + timestamp: 1234, + codedWidth: 4, + codedHeight: 2 + }; + let data = new Uint8Array([ + 1, 2, 3, 4, 5, 6, 7, 8, // y + 1, 2, // u + 1, 2, // v + ]); + let i420Frame = new VideoFrame(data, init); + let validFrame = new VideoFrame(i420Frame); + validFrame.close(); +}, 'Test that timestamp is NOT required when constructing VideoFrame from another VideoFrame'); + +test(t => { + let image = makeImageBitmap(1, 1); + let frame = new VideoFrame(image, {timestamp: 10}); + + assert_equals(frame.visibleRect.width, 1, 'visibleRect.width'); + assert_equals(frame.visibleRect.height, 1, 'visibleRect.height'); + assert_equals(frame.displayWidth, 1, 'displayWidth'); + assert_equals(frame.displayHeight, 1, 'displayHeight'); + + frame.close(); +}, 'Test we can construct an odd-sized VideoFrame.'); + +test(t => { + // Test only valid for Window contexts. + if (!('document' in self)) + return; + + let video = document.createElement('video'); + + assert_throws_dom('InvalidStateError', () => { + let frame = new VideoFrame(video, {timestamp: 10}); + }) +}, 'Test constructing w/ unusable image argument throws: HAVE_NOTHING