summaryrefslogtreecommitdiffstats
path: root/dom/media/test/test_cloneElementVisually_mediastream_multitrack.html
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-19 01:47:29 +0000
commit0ebf5bdf043a27fd3dfb7f92e0cb63d88954c44d (patch)
treea31f07c9bcca9d56ce61e9a1ffd30ef350d513aa /dom/media/test/test_cloneElementVisually_mediastream_multitrack.html
parentInitial commit. (diff)
downloadfirefox-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 'dom/media/test/test_cloneElementVisually_mediastream_multitrack.html')
-rw-r--r--dom/media/test/test_cloneElementVisually_mediastream_multitrack.html88
1 files changed, 88 insertions, 0 deletions
diff --git a/dom/media/test/test_cloneElementVisually_mediastream_multitrack.html b/dom/media/test/test_cloneElementVisually_mediastream_multitrack.html
new file mode 100644
index 0000000000..04d1ed484c
--- /dev/null
+++ b/dom/media/test/test_cloneElementVisually_mediastream_multitrack.html
@@ -0,0 +1,88 @@
+<!DOCTYPE HTML>
+<html>
+<head>
+ <meta charset="utf-8">
+ <title>Test cloneElementVisually</title>
+ <script src="/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="https://example.com:443/tests/dom/media/test/cloneElementVisually_helpers.js"></script>
+ <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css">
+</head>
+<body>
+<div id="content">
+ <h1>Originals</h1>
+ <div id="originalContainer"></div>
+ <canvas id="canvas"></canvas>
+ <h1>MediaStream</h1>
+ <div id="streamTargetContainer"></div>
+ <h1>Clone</h1>
+</div>
+<div id="results">
+ <h1>Results</h1>
+ <canvas id="left"></canvas>
+ <canvas id="right"></canvas>
+</div>
+
+<script type="application/javascript">
+
+/* import-globals-from cloneElementVisually_helpers.js */
+
+/**
+ * Test that a clone of a video that is playing a MediaStream properly tracks
+ * the selected video track.
+ */
+add_task(async () => {
+ await SpecialPowers.pushPrefEnv({
+ set: [
+ ["media.track.enabled", true],
+ ],
+ });
+
+ let originalVideo = document.createElement("video");
+ originalVideo.id = "original";
+ document.getElementById("originalContainer").appendChild(originalVideo);
+
+ let streamTarget = document.createElement("video");
+ document.getElementById("streamTargetContainer").appendChild(streamTarget);
+
+ await setup();
+
+ let [track1] = originalVideo.mozCaptureStream().getTracks();
+ let playingPromise = waitForEventOnce(originalVideo, "playing");
+ await originalVideo.play();
+ await playingPromise;
+
+ let canvas = document.getElementById("canvas");
+ canvas.width = originalVideo.videoWidth / 2;
+ canvas.height = originalVideo.videoHeight / 2;
+ let ctx = canvas.getContext("2d");
+ let [track2] = canvas.captureStream().getTracks();
+ ctx.fillStyle = "green";
+ ctx.fillRect(0, 0, canvas.width, canvas.height);
+
+ streamTarget.srcObject = new MediaStream([track1, track2]);
+ playingPromise = waitForEventOnce(streamTarget, "playing");
+ await streamTarget.play();
+ await playingPromise;
+
+ await withNewClone(originalVideo, async clone => {
+ SpecialPowers.wrap(streamTarget).cloneElementVisually(clone);
+
+ let selectedTrackIdx = streamTarget.videoTracks.selectedIndex;
+ streamTarget.videoTracks[++selectedTrackIdx % 2].selected = true;
+ await waitForEventOnce(streamTarget, "resize");
+
+ ok(await assertVideosMatch(streamTarget, clone),
+ "Should match MediaStream");
+ });
+
+ // Capturing a stream from a video "taints" it which prevents testing
+ // shutdown decoder behaviour. To avoid interfering with future tests,
+ // we replace the video.
+ let newVideo = originalVideo.cloneNode();
+ originalVideo.parentNode.replaceChild(newVideo, originalVideo);
+});
+
+</script>
+
+</body>
+</html>