mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-26 09:45:06 +02:00
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.
68 lines
2.0 KiB
HTML
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>
|