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-streams/MediaStream-MediaElement-firstframe.https.html | |
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-streams/MediaStream-MediaElement-firstframe.https.html')
-rw-r--r-- | testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-firstframe.https.html | 106 |
1 files changed, 106 insertions, 0 deletions
diff --git a/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-firstframe.https.html b/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-firstframe.https.html new file mode 100644 index 0000000000..36641b58c9 --- /dev/null +++ b/testing/web-platform/tests/mediacapture-streams/MediaStream-MediaElement-firstframe.https.html @@ -0,0 +1,106 @@ +<!doctype html> +<html> +<head> +<title>Assigning a MediaStream to a media element and not playing it results in rendering a first frame</title> +</head> +<body> +<p class="instructions">When prompted, accept to share your video stream.</p> +<h1 class="instructions">Description</h1> +<p class="instructions">This test checks that a HTMLMediaElement with an +assigned MediaStream with a video track fires the appropriate events to reach +the "canplay" event and readyState HAVE_ENOUGH_DATA even when not playing or +autoplaying.</p> +<video id="vid"></video> +<script src=/resources/testharness.js></script> +<script src=/resources/testharnessreport.js></script> +<script src=/resources/testdriver.js></script> +<script src=/resources/testdriver-vendor.js></script> +<script src=permission-helper.js></script> +<script> +'use strict'; +const vid = document.getElementById("vid"); + +promise_test(async t => { + const wait = ms => new Promise(r => t.step_timeout(r, ms)); + const timeout = (promise, time, msg) => Promise.race([ + promise, + wait(time).then(() => Promise.reject(new Error(msg))) + ]); + await setMediaPermission("granted", ["camera"]); + const stream = await navigator.mediaDevices.getUserMedia({video: true}); + t.add_cleanup(() => stream.getTracks().forEach(track => track.stop())); + vid.srcObject = stream; + + await timeout(new Promise(r => vid.oncanplay = r), 8000, "canplay timeout"); + assert_equals(vid.readyState, vid.HAVE_ENOUGH_DATA, + "readyState is HAVE_ENOUGH_DATA after \"canplay\""); +}, "Tests that loading a MediaStream in a media element eventually results in \"canplay\" even when not playing or autoplaying"); + +promise_test(async t => { + const wait = ms => new Promise(r => t.step_timeout(r, ms)); + const timeout = (promise, time, msg) => Promise.race([ + promise, + wait(time).then(() => Promise.reject(new Error(msg))) + ]); + const unexpected = e => assert_unreached(`Got unexpected event ${e.type}`); + const stream = await navigator.mediaDevices.getUserMedia({video: true}); + t.add_cleanup(() => { + vid.ondurationchange = null; + stream.getTracks().forEach(track => track.stop()) + }); + vid.srcObject = stream; + + vid.onloadstart = unexpected; + vid.ondurationchange = unexpected; + vid.onresize = unexpected; + vid.onloadedmetadata = unexpected; + vid.onloadeddata = unexpected; + vid.oncanplay = unexpected; + vid.oncanplaythrough = unexpected; + + await timeout(new Promise(r => vid.onloadstart = r), 8000, + "loadstart timeout"); + vid.onloadstart = unexpected; + + await timeout(new Promise(r => vid.ondurationchange = r), 8000, + "durationchange timeout"); + vid.ondurationchange = unexpected; + assert_equals(vid.duration, Infinity, "duration changes to Infinity"); + + await timeout(new Promise(r => vid.onresize = r), 8000, + "resize timeout"); + vid.onresize = unexpected; + assert_not_equals(vid.videoWidth, 0, + "videoWidth is something after \"resize\""); + assert_not_equals(vid.videoHeight, 0, + "videoHeight is something after \"resize\""); + + await timeout(new Promise(r => vid.onloadedmetadata = r), 8000, + "loadedmetadata timeout"); + vid.onloadedmetadata = unexpected; + assert_greater_than_equal(vid.readyState, vid.HAVE_METADATA, + "readyState is at least HAVE_METADATA after \"loadedmetadata\""); + + await timeout(new Promise(r => vid.onloadeddata = r), 8000, + "loadeddata timeout"); + vid.onloadeddata = unexpected; + assert_equals(vid.readyState, vid.HAVE_ENOUGH_DATA, + "readyState is HAVE_ENOUGH_DATA after \"loadeddata\" since there's no buffering"); + + await timeout(new Promise(r => vid.oncanplay = r), 8000, "canplay timeout"); + vid.oncanplay = unexpected; + assert_equals(vid.readyState, vid.HAVE_ENOUGH_DATA, + "readyState is HAVE_ENOUGH_DATA after \"canplay\" since there's no buffering"); + + await timeout(new Promise(r => vid.oncanplaythrough = r), 8000, + "canplaythrough timeout"); + vid.oncanplaythrough = unexpected; + assert_equals(vid.readyState, vid.HAVE_ENOUGH_DATA, + "readyState is HAVE_ENOUGH_DATA after \"canplaythrough\""); + + // Crank the event loop to see whether any more events are fired. + await wait(100); +}, "Tests that loading a MediaStream in a media element sees all the expected (deterministic) events even when not playing or autoplaying"); +</script> +</body> +</html> |