mirror of
https://github.com/LadybirdBrowser/ladybird
synced 2026-04-27 18:17:22 +02:00
Use promises to await the expected sequence of events. Also, don't assume that canplaythrough will fire after error. That depends on the implementation.
34 lines
1.0 KiB
HTML
34 lines
1.0 KiB
HTML
<!DOCTYPE html>
|
|
<script src="../include.js"></script>
|
|
<video id="video"></video>
|
|
<script>
|
|
const video = document.getElementById("video");
|
|
|
|
function logEvent(name) {
|
|
let entry = `${name}: readyState=${video.readyState}`;
|
|
if (name === "durationchange")
|
|
entry += ` duration=${video.duration}`;
|
|
if (name === "error")
|
|
entry += ` code=${video.error.code}`;
|
|
println(entry);
|
|
}
|
|
|
|
for (const name of [
|
|
"loadstart", "abort", "error", "emptied",
|
|
"loadedmetadata", "loadeddata", "canplay",
|
|
"canplaythrough", "durationchange", "ended",
|
|
]) {
|
|
video.addEventListener(name, () => logEvent(name));
|
|
}
|
|
|
|
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>
|