Truly independent web browser
LibWeb: Seek to the nearest seekable point when no other point ties
sideshowbarkerd9d53a0836dc
diff --git a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp b/Libraries/LibWeb/HTML/HTMLMediaElement.cppindex 9beca541a99..1b98a3822e7 100644--- a/Libraries/LibWeb/HTML/HTMLMediaElement.cpp+++ b/Libraries/LibWeb/HTML/HTMLMediaElement.cpp@@ -3303,6 +3303,8 @@ void HTMLMediaElement::seek_element(double playback_position, MediaSeekMode seek} else {new_playback_position = other_nearest_point.value();}+ } else {+ new_playback_position = nearest_point;}}diff --git a/Tests/LibWeb/TestConfig.ini b/Tests/LibWeb/TestConfig.iniindex 55ac277cbe1..db30be21c3d 100644--- a/Tests/LibWeb/TestConfig.ini+++ b/Tests/LibWeb/TestConfig.ini@@ -207,6 +207,7 @@ Text/input/HTML/media-source-split-initialization-segment.htmlText/input/HTML/media-source-append-window-trims-audio.htmlText/input/HTML/media-source-buffered.htmlText/input/HTML/media-source-duration.html+Text/input/HTML/media-source-seek-past-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-past-seekable-ranges.txt b/Tests/LibWeb/Text/expected/HTML/media-source-seek-past-seekable-ranges.txtnew file mode 100644index 00000000000..fae5905c5f9--- /dev/null+++ b/Tests/LibWeb/Text/expected/HTML/media-source-seek-past-seekable-ranges.txt@@ -0,0 +1,3 @@+buffered: [0, 1.999666666]+seekable: [0, 42]+seeking to 50 lands at 42diff --git a/Tests/LibWeb/Text/input/HTML/media-source-seek-past-seekable-ranges.html b/Tests/LibWeb/Text/input/HTML/media-source-seek-past-seekable-ranges.htmlnew file mode 100644index 00000000000..c53f9a34e3a--- /dev/null+++ b/Tests/LibWeb/Text/input/HTML/media-source-seek-past-seekable-ranges.html@@ -0,0 +1,39 @@+<!DOCTYPE html>+<video id="video"></video>+<script src="../include.js"></script>+<script>+ asyncTest(done => {+ const video = document.getElementById("video");+ const mediaSource = new MediaSource();+ video.src = URL.createObjectURL(mediaSource);++ function rangesOf(timeRanges) {+ const ranges = [];+ for (let i = 0; i < timeRanges.length; ++i)+ ranges.push(`[${timeRanges.start(i)}, ${timeRanges.end(i)}]`);+ return ranges.join(" ") || "none";+ }++ 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());+ await new Promise(resolve => {+ sourceBuffer.addEventListener("updateend", resolve, { once: true });+ sourceBuffer.appendBuffer(data);+ });++ mediaSource.duration = Infinity;+ mediaSource.setLiveSeekableRange(40, 42);+ println(`buffered: ${rangesOf(video.buffered)}`);+ println(`seekable: ${rangesOf(video.seekable)}`);++ // A seek past the end of every seekable range lands on the nearest point of one.+ video.addEventListener("seeking", () => {+ println(`seeking to 50 lands at ${video.currentTime}`);+ done();+ }, { once: true });+ video.currentTime = 50;+ });+ });+</script>