mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-28 02:27:19 +02:00
Tests: Simplify the HTMLMediaElement-load-after-decode-error.html test
Use promises to await the expected sequence of events. Also, don't assume that canplaythrough will fire after error. That depends on the implementation.
This commit is contained in:
committed by
Gregory Bertilson
parent
d8cff1838a
commit
2d00a28f08
Notes:
github-actions[bot]
2026-04-10 20:22:49 +00:00
Author: https://github.com/Zaggy1024 Commit: https://github.com/LadybirdBrowser/ladybird/commit/2d00a28f088 Pull-request: https://github.com/LadybirdBrowser/ladybird/pull/8809
@@ -3,7 +3,6 @@
|
||||
<video id="video"></video>
|
||||
<script>
|
||||
const video = document.getElementById("video");
|
||||
const events = [];
|
||||
|
||||
function logEvent(name) {
|
||||
let entry = `${name}: readyState=${video.readyState}`;
|
||||
@@ -11,7 +10,7 @@
|
||||
entry += ` duration=${video.duration}`;
|
||||
if (name === "error")
|
||||
entry += ` code=${video.error.code}`;
|
||||
events.push(entry);
|
||||
println(entry);
|
||||
}
|
||||
|
||||
for (const name of [
|
||||
@@ -22,43 +21,13 @@
|
||||
video.addEventListener(name, () => logEvent(name));
|
||||
}
|
||||
|
||||
let hasSetGoodSrc = false;
|
||||
video.addEventListener("error", () => {
|
||||
if (hasSetGoodSrc)
|
||||
return;
|
||||
hasSetGoodSrc = true;
|
||||
logEvent("error handler: setting good src");
|
||||
video.src = "../../../Assets/test-webm.webm";
|
||||
logEvent("error handler: src setter returned");
|
||||
});
|
||||
|
||||
let documentLoaded = false;
|
||||
let videoCanPlayThrough = false;
|
||||
let triggerCompletion = null;
|
||||
|
||||
function checkCompletion() {
|
||||
if (documentLoaded && videoCanPlayThrough) {
|
||||
println("Events:");
|
||||
for (const e of events)
|
||||
println(` ${e}`);
|
||||
println(`Final: readyState=${video.readyState} duration=${video.duration}`);
|
||||
triggerCompletion();
|
||||
}
|
||||
}
|
||||
|
||||
window.addEventListener("load", () => {
|
||||
logEvent("document load");
|
||||
documentLoaded = true;
|
||||
checkCompletion();
|
||||
});
|
||||
|
||||
video.addEventListener("canplaythrough", () => {
|
||||
videoCanPlayThrough = true;
|
||||
checkCompletion();
|
||||
});
|
||||
|
||||
asyncTest(done => {
|
||||
triggerCompletion = done;
|
||||
asyncTest(async done => {
|
||||
video.src = "../../../Assets/corrupt-video.webm";
|
||||
|
||||
await new Promise(resolve => video.addEventListener("error", resolve, { once: true }));
|
||||
video.src = "../../../Assets/test-webm.webm";
|
||||
|
||||
await new Promise(resolve => video.addEventListener("canplaythrough", resolve, { once: true }));
|
||||
done();
|
||||
});
|
||||
</script>
|
||||
|
||||
Reference in New Issue
Block a user