<!DOCTYPE html>
<html>
<head>
    <script src="../../../resources/js-test-pre.js"></script>
</head>

<body>
    <script>

        window.jsTestIsAsync = true;

        description("This tests the constructor for the TrackEvent DOM class.");

        function test()
        {
            // Make sure the track actually loaded.
            shouldBe("trackElement.track.readyState", "TextTrack.LOADED", true);

            debug("<br>*** No initializer passed ***");
            shouldBe("new TrackEvent('TrackEvent').bubbles", "false");
            shouldBe("new TrackEvent('TrackEvent').cancelable", "false");
            shouldBeNull("new TrackEvent('TrackEvent').track");
    
            debug("<br>*** Bubbles and cancelable true, track is missing ***");
            shouldBe("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true }).bubbles", "true");
            shouldBe("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true }).cancelable", "true");
            shouldBeNull("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true }).track");
    
            debug("<br>*** Invalid track ***");
            shouldThrowErrorName("new TrackEvent('TrackEvent', { track: HTMLTrackElement })", "TypeError");
            shouldThrowErrorName("new TrackEvent('TrackEvent', { track: 10 })", "TypeError");
            shouldThrowErrorName("new TrackEvent('TrackEvent', { track: \'string\' })", "TypeError");
            emptyObject = { };
            shouldThrowErrorName("new TrackEvent('TrackEvent', { track: emptyObject })", "TypeError");
            shouldThrowErrorName("new TrackEvent('TrackEvent', { track: document })", "TypeError");

            debug("<br>*** Bubbles and cancelable true, valid track ***");
            shouldBe("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true, track: trackElement.track }).bubbles", "true");
            shouldBe("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true, track: trackElement.track }).cancelable", "true");
            shouldBe("new TrackEvent('TrackEvent', { track: trackElement.track }).track", "trackElement.track");

            debug("<br>*** Initialize 'track' with valid track object ***");
            shouldBe("new TrackEvent('TrackEvent', { track: trackElement.track }).track", "trackElement.track");

            debug("");
            finishJSTest();
        }

        video = document.createElement('video');
        document.body.appendChild(video);

        trackElement = document.createElement('track');
        video.appendChild(trackElement);
        trackElement.track.mode = "hidden";
        trackElement.addEventListener('load', test);
        trackElement.src='data:text/vtt,WEBVTT FILE \r\r1\r00:00:00.000 --> 00:00:30.500\ronly one caption';

    </script>
    <script src="../../../resources/js-test-post.js"></script>

</body>
</html>
