<video controls></video>
<p>Test that a waiting event is sent when media loading stalls after having sent 'canplay'.</p>
<script src=../../media-resources/media-file.js></script>
<script src=../../media-resources/video-test.js></script>
<script>

    var timeupdateCount = 0;

    waitForEvent('durationchange');
    waitForEvent('loadedmetadata');
    waitForEvent('loadeddata');
    waitForEventAndEnd('waiting', function() {
        // TestRunner waits for the complete frame download before finishing, so having the video load stalled
        // prevents TestRunner from finishing. Changing the src will abort the download and let the test finish.
        video.src = "";
    });

    waitForEvent('canplay', function () {
        run("video.play()");
    } );

    mediaElement.addEventListener('timeupdate', function () {
        // 'timeupdate' events are also fired as playback progresses so only verify that at least one
        // event is fired.
        if (++timeupdateCount == 1)
            consoleWrite("EVENT(timeupdate)");
    } );

    // Find a supported media file.
    var mediaFile = findMediaFile("video", "../../../../media/content/long-test");
    var mimeType = mimeTypeForFile(mediaFile);

    video.src = "http://127.0.0.1:8000/media/resources/serve_video.py?name=" + mediaFile + "&type=" + mimeType + "&stallOffset=100000&stallDuration=60&chunkSize=1024";
</script>
