Files
ladybird/Tests/LibWeb/Text/input/HTML/HTMLMediaElement-load-during-error.html
Zaggy1024 44ed83f4fe Tests: Add a test for media element event ordering
This test will try to load an invalid src, then in the error handler,
set the src to a valid URL. In the process, any events that should have
deterministic ordering will be logged to compare to the expectation.
2026-02-26 22:02:47 -06:00

68 lines
2.0 KiB
HTML

<!DOCTYPE html>
<script src="../include.js"></script>
<video id="video" src="nonexistent-video.webm"></video>
<script>
// The video must exist before DOMContentLoaded can fire, so that the load event is
// delayed. Therefore, we must attach handlers to the events and cache all the events
// outside the async test.
const video = document.getElementById("video");
const events = [];
function logEvent(name) {
let entry = `${name}: readyState=${video.readyState}`;
if (name === "durationchange")
entry += ` duration=${video.duration}`;
events.push(entry);
}
for (const name of [
"loadstart", "abort", "error", "emptied",
"loadedmetadata", "loadeddata", "canplay",
"canplaythrough", "durationchange", "ended",
]) {
video.addEventListener(name, () => logEvent(name));
}
video.addEventListener("error", () => {
logEvent("error handler: setting good src");
video.src = "../../../Assets/test-webm.webm";
logEvent("error handler: src setter returned");
});
let documentLoaded = false;
let videoLoaded = false;
let videoCanPlayThrough = false;
let triggerCompletion = null;
function checkCompletion() {
if (documentLoaded && videoLoaded && 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("loadeddata", () => {
videoLoaded = true;
checkCompletion();
});
video.addEventListener("canplaythrough", () => {
videoCanPlayThrough = true;
checkCompletion();
});
asyncTest(done => {
triggerCompletion = done;
checkCompletion();
});
</script>