Truly independent web browser
<!DOCTYPE html>
<script src="../include.js"></script>
<script src="HTMLMediaElement-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. Nothing orders the first loadstart after DOMContentLoaded,
// when the output element appears, so the lines are printed once the test completes.
const video = document.getElementById("video");
const lines = [];
function logEvent(name) {
lines.push(`${name}: ${formatReadyStateExpectation(video, name)}`);
}
for (const name of [
"loadstart", "abort", "error", "emptied",
"loadedmetadata", "loadeddata", "canplay",
"canplaythrough", "ended",
]) {
video.addEventListener(name, () => logEvent(name));
}
video.addEventListener("error", () => {
lines.push("error handler: setting good src");
video.src = "../../../Assets/test-webm.webm";
lines.push("error handler: src setter returned");
});
let documentLoaded = false;
let videoLoaded = false;
let videoCanPlayThrough = false;
let triggerCompletion = null;
function checkCompletion() {
if (!documentLoaded || !videoLoaded || !videoCanPlayThrough)
return;
lines.push(`document loaded after loadeddata: ${documentLoadedAfterLoadedData}`);
for (const line of lines)
println(line);
triggerCompletion();
}
let documentLoadedAfterLoadedData = false;
window.addEventListener("load", () => {
documentLoadedAfterLoadedData = videoLoaded;
documentLoaded = true;
checkCompletion();
});
video.addEventListener("loadeddata", () => {
videoLoaded = true;
checkCompletion();
});
video.addEventListener("canplaythrough", () => {
videoCanPlayThrough = true;
checkCompletion();
});
asyncTest(done => {
triggerCompletion = done;
checkCompletion();
});
</script>