Skip to content

Truly independent web browser

Tests/LibWeb: Sample playing media source video at any delay

Jelle Raaijmakers616c44738c43
diff --git a/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.txt b/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.txt
index cc3e1f31bf2..2ae8f280035 100644
--- a/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.txt
+++ b/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.txt
@@ -1 +1 @@
-playing past 6.2: red 1
+playing past 6.2: blue
diff --git a/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-replaced-after-decoding-ahead.txt b/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-replaced-after-decoding-ahead.txt
index e48cebf3808..9a2a908e90c 100644
--- a/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-replaced-after-decoding-ahead.txt
+++ b/Tests/LibWeb/Text/expected/HTML/media-source-presented-frame-replaced-after-decoding-ahead.txt
@@ -1,3 +1,3 @@
before replacing: red 0
after replacing ahead: red 0
-playing past 6: blue
+first frame presented past 0.65: blue
diff --git a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.html b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.html
index b118781d404..09d609ecaee 100644
--- a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.html
+++ b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-advances-when-first-painted-during-playback.html
@@ -7,17 +7,19 @@
// video is only updated on the display's vsync, so that paint must start it for the presented frame to advance.
promiseTest(async () => {
const red = await fetchColoredStream("red");
+ const blue = await fetchColoredStream("blue");
const video = document.createElement("video");
video.muted = true;
document.body.append(video);
const { sourceBuffer } = await openColoredStreamSource(video);
- await appendWithinWindow(sourceBuffer, red);
+ await appendWithinWindow(sourceBuffer, red, 0, 6);
+ await appendWithinWindow(sourceBuffer, blue, 6);
await seekAndWait(video, 5.55);
await video.play();
await waitForCondition(() => video.currentTime >= 6.2, 200, 10);
- println(`playing past 6.2: ${await samplePresentedFrameOnceItMatches(video, "red 1")}`);
+ println(`playing past 6.2: ${await samplePresentedColorOnceItMatches(video, "blue")}`);
video.pause();
});
</script>
diff --git a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-include.js b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-include.js
index 946583307e1..0a8b3ebb71a 100644
--- a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-include.js
+++ b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-include.js
@@ -56,3 +56,22 @@ async function samplePresentedFrameOnceItMatches(video, expected) {
await waitForCondition(() => samplePresentedFrame(video) === expected, 40, 25);
return samplePresentedFrame(video);
}
+
+async function samplePresentedColorOnceItMatches(video, expected) {
+ const presentedColor = () => samplePresentedFrame(video).split(" ")[0];
+ await waitForCondition(() => presentedColor() === expected, 40, 25);
+ return presentedColor();
+}
+
+function presentedColorOfFirstFrameFrom(video, time) {
+ return new Promise(resolve => {
+ const onFrame = (now, metadata) => {
+ if (metadata.mediaTime < time) {
+ video.requestVideoFrameCallback(onFrame);
+ return;
+ }
+ resolve(samplePresentedFrame(video).split(" ")[0]);
+ };
+ video.requestVideoFrameCallback(onFrame);
+ });
+}
diff --git a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-replaced-after-decoding-ahead.html b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-replaced-after-decoding-ahead.html
index 5dc685deef1..87797f2baae 100644
--- a/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-replaced-after-decoding-ahead.html
+++ b/Tests/LibWeb/Text/input/HTML/media-source-presented-frame-replaced-after-decoding-ahead.html
@@ -15,19 +15,18 @@
const { sourceBuffer } = await openColoredStreamSource(video);
await appendWithinWindow(sourceBuffer, red);
- await seekAndWait(video, 5.55);
+ await seekAndWait(video, 0.55);
println(`before replacing: ${await samplePresentedFrameOnceItMatches(video, "red 0")}`);
await timeout(500);
- // Frames are at multiples of 0.1, so this keeps the presented frame at 5.5 and the next at 5.6.
- await appendWithinWindow(sourceBuffer, blue, 5.65, 8);
+ // Frames are at multiples of 0.1, so this keeps the presented frame at 0.5 and the next at 0.6. Reads that skip
+ // the replacement go on to the red frames from 11.
+ await appendWithinWindow(sourceBuffer, blue, 0.65, 11);
println(`after replacing ahead: ${samplePresentedFrame(video)}`);
+ const firstReplacedFrameColor = presentedColorOfFirstFrameFrom(video, 0.65);
await video.play();
- await waitForCondition(() => video.currentTime >= 6.05, 200, 10);
- // Only the stream is printed, since whether stale frames get presented is timing-dependent.
- const sample = await samplePresentedFrameOnceItMatches(video, "blue 1");
- println(`playing past 6: ${sample.split(" ")[0]}`);
+ println(`first frame presented past 0.65: ${await firstReplacedFrameColor}`);
video.pause();
});
</script>