Truly independent web browser
Tests: Cover a media element seek while nothing is seekable
Zaggy102448a3e0721d4c
diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 37874b3d99f..04518384d50 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -214,6 +214,7 @@ Text/input/HTML/media-source-append-window-trims-audio.htmlText/input/HTML/media-source-buffered.htmlText/input/HTML/media-source-duration.htmlText/input/HTML/media-source-seek-past-seekable-ranges.html+Text/input/HTML/media-source-seek-without-seekable-ranges.htmlText/input/HTML/media-source-duration-truncation.htmlText/input/HTML/media-source-ended-cleared-by-seek-after-remove.htmlText/input/HTML/media-source-frame-rate-change.htmldiff --git a/Tests/LibWeb/Text/expected/HTML/media-source-seek-without-seekable-ranges.txt b/Tests/LibWeb/Text/expected/HTML/media-source-seek-without-seekable-ranges.txtnew file mode 100644index 00000000000..8a301a0e541--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/media-source-seek-without-seekable-ranges.txt@@ -0,0 +1,7 @@+seekable ranges: 0+after setting currentTime: seeking false+after the seek is skipped: currentTime 0+seekable ranges after appending media: 1+seeking event, seeking true, currentTime 1+timeupdate event, seeking false, currentTime 1+seeked event, seeking false, currentTime 1diff --git a/Tests/LibWeb/Text/input/HTML/media-source-seek-without-seekable-ranges.html b/Tests/LibWeb/Text/input/HTML/media-source-seek-without-seekable-ranges.htmlnew file mode 100644index 00000000000..c2e8841a41d--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/media-source-seek-without-seekable-ranges.html@@ -0,0 +1,73 @@+<!DOCTYPE html>+<video id="video"></video>+<script src="../include.js"></script>+<script>+ // A seek while nothing is seekable sets the seeking attribute and then clears it, without firing any events or+ // moving the playback position. A later seek that succeeds queues its events on the same task source, so any+ // events from the first seek would be logged before them.+ asyncTest(done => {+ const video = document.getElementById("video");+ const mediaSource = new MediaSource();+ video.src = URL.createObjectURL(mediaSource);++ for (const eventName of ["seeking", "timeupdate", "seeked"]) {+ video.addEventListener(eventName, () => {+ println(`${eventName} event, seeking ${video.seeking}, currentTime ${video.currentTime}`);+ });+ }++ function clusterOffsetOf(data) {+ const clusterID = [0x1f, 0x43, 0xb6, 0x75];+ for (let i = 0; i + clusterID.length <= data.length; i++) {+ if (clusterID.every((byte, offset) => data[i + offset] === byte))+ return i;+ }+ return data.length;+ }++ function append(sourceBuffer, bytes) {+ return new Promise(resolve => {+ sourceBuffer.addEventListener("updateend", resolve, { once: true });+ sourceBuffer.appendBuffer(bytes);+ });+ }++ function waitUntilNotSeeking() {+ return new Promise(resolve => {+ function check() {+ if (video.seeking) {+ setTimeout(check, 0);+ return;+ }+ resolve();+ }+ check();+ });+ }++ mediaSource.addEventListener("sourceopen", async () => {+ const sourceBuffer = mediaSource.addSourceBuffer('video/webm;codecs="vp9"');+ const response = await fetch("../../../Assets/vp9-frame-rate-change.webm");+ const data = new Uint8Array(await response.arrayBuffer());+ const clusterOffset = clusterOffsetOf(data);+ await append(sourceBuffer, data.subarray(0, clusterOffset));+ if (video.readyState < HTMLMediaElement.HAVE_METADATA)+ await new Promise(resolve => video.addEventListener("loadedmetadata", resolve, { once: true }));++ // With an unbounded duration, nothing buffered and no live seekable range, nothing is seekable.+ mediaSource.duration = Infinity;+ println(`seekable ranges: ${video.seekable.length}`);++ video.currentTime = 12;+ println(`after setting currentTime: seeking ${video.seeking}`);+ await waitUntilNotSeeking();+ println(`after the seek is skipped: currentTime ${video.currentTime}`);++ await append(sourceBuffer, data.subarray(clusterOffset));+ println(`seekable ranges after appending media: ${video.seekable.length}`);+ video.currentTime = 1;+ await new Promise(resolve => video.addEventListener("seeked", resolve, { once: true }));+ done();+ });+ });+</script>