chromium/third_party/blink/web_tests/fast/events/constructors/track-event-constructor.html

<!DOCTYPE html>
<html>
<head>
    <script src="../../../resources/js-test.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>*** Bubbles and cancelable true, invalid track ***");
            shouldThrow("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true, track: HTMLTrackElement }).bubbles");
            shouldThrow("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true, track: HTMLTrackElement }).cancelable");
            shouldThrow("new TrackEvent('TrackEvent', { bubbles: true, cancelable: true, track: HTMLTrackElement }).track");
    
            debug("<br>*** Initialize 'track' with a invalid values ***");
            shouldThrow("new TrackEvent('TrackEvent', { track: 10 }).track");
            shouldThrow("new TrackEvent('TrackEvent', { track: \'string\' }).track");
            emptyObject = { };
            shouldThrow("new TrackEvent('TrackEvent', { track: emptyObject }).track");
            shouldThrow("new TrackEvent('TrackEvent', { track: document }).track");

            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>

</body>
</html>