chromium/third_party/blink/web_tests/media/video-delay-load-event.html

<!DOCTYPE html>
<title>Test that the document's load event is delayed until a video's meta data is available.</title>
<script src="../resources/testharness.js"></script>
<script src="../resources/testharnessreport.js"></script>
<video id="video1"></video>
<video id="video2"></video>
<video id="video3"><source></source></video>
<script>
async_test(function(t) {
    assertVideoNoSrcNoLoad(document.getElementById("video1"));

    var video = document.getElementById("video2");
    video.src = "content/test.ogv";
    assertVideoSrcNoLoad(video);

    var source = document.querySelector("source");
    source.src = "content/test.ogv";
    assertVideoSrcNoLoad(document.getElementById("video3"));

    window.onload = t.step_func_done(function() {
        assertVideoNoSrcNoLoad(document.getElementById("video1"));
        assertVideoSrcLoad(document.getElementById("video2"));
        assertVideoSrcLoad(document.getElementById("video3"));
    });

    function assertVideoNoSrcNoLoad(video) {
        // Video should not load as there is no "src".
        assert_equals(video.networkState, HTMLMediaElement.NETWORK_EMPTY);
        assert_equals(video.readyState, HTMLMediaElement.HAVE_NOTHING);
    }

    function assertVideoSrcNoLoad(video) {
        // Video loading has just triggered.
        assert_equals(video.networkState, HTMLMediaElement.NETWORK_NO_SOURCE);
        assert_equals(video.readyState, HTMLMediaElement.HAVE_NOTHING);
    }

    function assertVideoSrcLoad(video) {
        // The Video should have loaded at least to HAVE_CURRENT_DATA
        assert_not_equals(video.networkState, HTMLMediaElement.NETWORK_NO_SOURCE);
        assert_greater_than_equal(video.networkState, HTMLMediaElement.NETWORK_IDLE);
        assert_greater_than_equal(video.readyState, HTMLMediaElement.HAVE_CURRENT_DATA);
    }
});
</script>