diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 19:33:14 +0000 |
commit | 36d22d82aa202bb199967e9512281e9a53db42c9 (patch) | |
tree | 105e8c98ddea1c1e4784a60a5a6410fa416be2de /dom/media/test/test_streams_individual_pause.html | |
parent | Initial commit. (diff) | |
download | firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.tar.xz firefox-esr-36d22d82aa202bb199967e9512281e9a53db42c9.zip |
Adding upstream version 115.7.0esr.upstream/115.7.0esrupstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'dom/media/test/test_streams_individual_pause.html')
-rw-r--r-- | dom/media/test/test_streams_individual_pause.html | 77 |
1 files changed, 77 insertions, 0 deletions
diff --git a/dom/media/test/test_streams_individual_pause.html b/dom/media/test/test_streams_individual_pause.html new file mode 100644 index 0000000000..c49b563d76 --- /dev/null +++ b/dom/media/test/test_streams_individual_pause.html @@ -0,0 +1,77 @@ +<!DOCTYPE HTML> +<html> +<head> + <title>Test for bug 1073406. Pausing a video element should not pause another playing the same stream.</title> + <script src="/tests/SimpleTest/SimpleTest.js"></script> + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css" /> + <script type="text/javascript" src="manifest.js"></script> + <script type="text/javascript" src="gUM_support.js"></script> +</head> +<body> +<video id="video1" autoplay></video> +<video id="video2" autoplay></video> +<script class="testbody" type="text/javascript"> +function getVideoImagePixelData(v) { + const canvas = document.createElement("canvas"); + const ctx = canvas.getContext("2d"); + ctx.drawImage(v, 0, 0); + const imgData = ctx.getImageData(canvas.width/2, canvas.height/2, 1, 1).data; + return "r" + imgData[0] + + "g" + imgData[1] + + "b" + imgData[2] + + "a" + imgData[3]; +} + +async function startTest() { + // This test expects fake devices so that the video color will change + // over time, explicitly request fakes. + await pushGetUserMediaTestPrefs({fakeAudio: true, fakeVideo: true}); + const stream = await navigator.mediaDevices.getUserMedia({video: true}); + const video1 = document.getElementById('video1'); + const video2 = document.getElementById('video2'); + + video1.srcObject = stream; + video2.srcObject = stream; + + await new Promise(r => video1.onplaying = r); + video1.pause(); + await new Promise(r => video1.onpause = r); + + const v1PausedImageData = getVideoImagePixelData(video1); + const v2PausedImageData = getVideoImagePixelData(video2); + + while (getVideoImagePixelData(video2) == v2PausedImageData) { + info("video2 has not progressed. Waiting."); + await new Promise(r => video2.ontimeupdate = r); + } + + // Wait for a while to be sure video1 would have gotten a frame + // if it is playing. + for (let i = 3; i != 0; i--) { + await new Promise(r => video2.ontimeupdate = r); + } + info("video2 progressed OK"); + + isnot(video1.currentTime, video2.currentTime, + "v1 and v2 should not be at the same currentTime"); + is(getVideoImagePixelData(video1), v1PausedImageData, + "video1 video frame should not have updated since video1 paused"); + + for (const t of stream.getTracks()) { + t.stop(); + } +} + +SimpleTest.waitForExplicitFinish(); +(async function() { + try { + await startTest(); + } catch(error) { + ok(false, "getUserMedia should not fail, got " + error.name); + } finally { + SimpleTest.finish(); + } +})(); +</script> +</body> +</html> |