diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:47:29 +0000 |
commit | 0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch) | |
tree | a31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /testing/web-platform/tests/mediacapture-fromelement | |
parent | Initial commit. (diff) | |
download | firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.tar.xz firefox-esr-0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d.zip |
Adding upstream version 115.8.0esr.upstream/115.8.0esr
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'testing/web-platform/tests/mediacapture-fromelement')
8 files changed, 256 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mediacapture-fromelement/HTMLCanvasElement-getImageData-noframe.html b/testing/web-platform/tests/mediacapture-fromelement/HTMLCanvasElement-getImageData-noframe.html new file mode 100644 index 0000000000..48d445f897 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/HTMLCanvasElement-getImageData-noframe.html @@ -0,0 +1,30 @@ +<!DOCTYPE html> +<html> +<body> +<canvas id="canvas"></canvas> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script> +promise_test(async t => { + const canvas = document.getElementById("canvas"); + const ctx = canvas.getContext("2d"); + const stream = canvas.captureStream(); + t.add_cleanup(() => stream.getTracks().forEach(track => track.stop())); + + const video = document.createElement("video"); + video.srcObject = stream; + + ctx.getImageData(0, 0, canvas.width, canvas.height); + + assert_equals(video.readyState, video.HAVE_NOTHING, + "Video element was just created"); + + // Wait a bit so the video element can update readyState in case of a frame. + await new Promise(r => t.step_timeout(r, 100)); + + assert_equals(video.readyState, video.HAVE_NOTHING, + "Video element did not get a frame from the canvas"); +}, "CanvasRenderingContext2D.getImageData() does not lead to a frame being captured"); +</script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/META.yml b/testing/web-platform/tests/mediacapture-fromelement/META.yml new file mode 100644 index 0000000000..17195009fa --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/META.yml @@ -0,0 +1,5 @@ +spec: https://w3c.github.io/mediacapture-fromelement/ +suggested_reviewers: + - yellowdoge + - martinthomson + - uysalere diff --git a/testing/web-platform/tests/mediacapture-fromelement/capture.html b/testing/web-platform/tests/mediacapture-fromelement/capture.html new file mode 100644 index 0000000000..74858737f1 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/capture.html @@ -0,0 +1,38 @@ +<!DOCTYPE html> +<html> +<head> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +</head> +<body> +<script> + +// Run captureStream() on different videos, and assert data is flowing. + +function makeAsyncTest(filename) { + promise_test(async test => { + const video = document.createElement('video'); + video.src = "/media/" + filename; + video.onerror = this.unreached_func("<video> error"); + video.play(); + + const stream = video.captureStream(); + + await new Promise(r => stream.onaddtrack = r); + const recorder = new MediaRecorder(stream); + + recorder.start(0); + const {data} = await new Promise(r => recorder.ondataavailable = r); + assert_true(data.size > 0, 'Recorded data size should be > 0'); + }), "<video>.captureStream() and assert data flows."; +} + +generate_tests(makeAsyncTest, [ + [ "video-only", "test-v-128k-320x240-24fps-8kfr.webm" ], + [ "audio-only", "test-a-128k-44100Hz-1ch.webm" ], + [ "video+audio", "test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm" ] +]); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/creation.html b/testing/web-platform/tests/mediacapture-fromelement/creation.html new file mode 100644 index 0000000000..b025a3ad6c --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/creation.html @@ -0,0 +1,46 @@ +<!DOCTYPE html> +<html> +<head> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +</head> +<body> +<script> + +// Run captureStream() on <video>/<audio>s and inspect the generated Stream. + +var makeAsyncTest = function(filename, numTracks) { + async_test(function() { + var video = document.createElement('video'); + video.src = "/media/" + filename; + video.onerror = this.unreached_func("<video> error"); + + assert_true('captureStream' in video); + + var stream = video.captureStream(); + assert_not_equals(stream, null, "error generating stream"); + + stream.onaddtrack = this.step_func_done(function() { + var tracks = stream.getTracks(); + var idx; + + for (idx = 0; idx < tracks.length; idx += 1) { + assert_equals(tracks[idx].readyState, 'live') + } + + // The stream got a (number of) MediaStreamTracks added. + assert_equals(stream.getVideoTracks().length, numTracks['vid'], 'video'); + assert_equals(stream.getAudioTracks().length, numTracks['aud'], 'audio'); + }); + }), "<video>.captureStream()"; +}; + +generate_tests(makeAsyncTest, [ + [ "video-only", "test-v-128k-320x240-24fps-8kfr.webm", {vid : 1, aud : 0} ], + [ "audio-only", "test-a-128k-44100Hz-1ch.webm", {vid : 0, aud : 1} ], + [ "video+audio", "test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm", {vid : 1, aud : 1} ] +]); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/cross-origin.html b/testing/web-platform/tests/mediacapture-fromelement/cross-origin.html new file mode 100644 index 0000000000..14d92c8fc8 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/cross-origin.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +</head> +<body> +<video autoplay controls id="output"></video> +<script> + +// Run captureStream() on cross-origin <video> content + async_test(function() { + const video = document.createElement('video'); + video.src = location.origin.replace("//", "//www1.") + "/media/white.webm"; + video.onerror = this.unreached_func("<video> error"); + video.loop = true; + video.play(); + + const stream = video.captureStream(); + assert_not_equals(stream, null, "error generating stream"); + const output = document.getElementById("output"); + const canvas = document.createElement("canvas"); + const ctx = canvas.getContext('2d'); + + stream.onaddtrack = this.step_func_done(function() { + canvas.width = output.videoWidth || 320; + canvas.height = output.videoHeight || 240; + // The stream got a (number of) MediaStreamTracks added. + assert_equals(stream.getVideoTracks().length, 1, 'video tracks'); + assert_equals(stream.getAudioTracks().length, 0, 'audio'); + assert_true(stream.getVideoTracks()[0].muted, 'cross-origin video is muted'); + ctx.drawImage(output, 0, 0, canvas.width, canvas.height); + + const pixels = ctx.getImageData(0,0,canvas.width, canvas.height); + assert_equals(pixels.data[canvas.width*canvas.height*4 - 4], 0, "cross-origin content appears black"); + }, "<video>.captureStream() returns muted/black stream"); + }, "Capturing stream from cross-origin video"); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/ended.html b/testing/web-platform/tests/mediacapture-fromelement/ended.html new file mode 100644 index 0000000000..845fbcbaa6 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/ended.html @@ -0,0 +1,41 @@ +<!DOCTYPE html> +<html> +<head> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +</head> +<body> +<script> + +// Run captureStream() on different videos, and assert the mediastream is +// ended when the source HTMLMediaElement finishes + +var makeAsyncTest = function(filename) { + async_test(function(test) { + var video = document.createElement('video'); + video.src = "/media/" + filename; + video.onerror = this.unreached_func("<video> error"); + video.play(); + + assert_true('captureStream' in video); + + var stream = video.captureStream(); + + stream.onremovetrack = this.step_func_done(function() { + assert_true(video.ended, 'video must be ended'); + assert_equals(stream.getTracks().length, 0, 'stream must have no tracks'); + assert_false(stream.active, 'stream must be inactive'); + }); + + }), "<video>.captureStream() and assert ended event."; +}; + +generate_tests(makeAsyncTest, [ + [ "video-only", "test-v-128k-320x240-24fps-8kfr.webm" ], + [ "audio-only", "test-a-128k-44100Hz-1ch.webm" ], + [ "video+audio", "test-av-384k-44100Hz-1ch-320x240-30fps-10kfr.webm" ] +]); + +</script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/historical.html b/testing/web-platform/tests/mediacapture-fromelement/historical.html new file mode 100644 index 0000000000..3b86e9de35 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/historical.html @@ -0,0 +1,17 @@ +<!DOCTYPE html> +<html> +<head> + <meta charset="utf-8"> + <title>Historical features</title> + <script src="/resources/testharness.js"></script> + <script src="/resources/testharnessreport.js"></script> +</head> +<body> + <script> + // https://lists.w3.org/Archives/Public/public-media-capture/2015Nov/0012.html + test(function() { + assert_false(MediaStream.prototype.hasOwnProperty('onactive')); + }, 'the deprecated MediaStream `onactive` event handler property is not available'); + </script> +</body> +</html> diff --git a/testing/web-platform/tests/mediacapture-fromelement/idlharness.window.js b/testing/web-platform/tests/mediacapture-fromelement/idlharness.window.js new file mode 100644 index 0000000000..970f3cd5c6 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-fromelement/idlharness.window.js @@ -0,0 +1,38 @@ +// META: script=/resources/WebIDLParser.js +// META: script=/resources/idlharness.js + +// https://w3c.github.io/mediacapture-fromelement/ + +'use strict'; + +idl_test( + ['mediacapture-fromelement'], + ['mediacapture-streams', 'html', 'dom'], + idl_array => { + // Ignored errors will be surfaced when the elements are undefined below. + try { + self.video = document.createElement('video'); + video.width = video.height = 10; + document.body.appendChild(video); + } catch (e) { } + + try { + self.audio = document.createElement('audio'); + document.body.appendChild(audio); + } catch (e) { } + + try { + self.canvas = document.createElement('canvas'); + document.body.appendChild(canvas); + canvas.width = canvas.height = 10; + self.track = canvas.captureStream().getTracks()[0]; + } catch (e) { } + + idl_array.add_objects({ + HTMLVideoElement: ['video'], + HTMLAudioElement: ['audio'], + HTMLCanvasElement: ['canvas'], + CanvasCaptureMediaStreamTrack: ['track'], + }); + } +); |