summaryrefslogtreecommitdiffstats
path: root/testing/web-platform/tests/html/semantics/embedded-content/media-elements/track/track-element/track-element-src-change.html
blob: f3c78668b4ac6862dc60eb9d4f6c30e149fa07af (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<!DOCTYPE html>
<title>HTMLTrackElement 'src' attribute mutations</title>
<script src="/resources/testharness.js"></script>
<script src="/resources/testharnessreport.js"></script>
<video>
    <track src="resources/settings.vtt" default>
    <script>
    async_test(function(t) {
        var cues = null;
        var testTrack = document.querySelector("track");
        var stage = 0;
        function step_onLoad() {
            switch (stage) {
                case 0:
                    cues = testTrack.track.cues;
                    assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after first loading of the track");
                    assert_equals(cues.length, 4, "Number of cues after first loading of the track");
                    assert_equals(cues[cues.length-1].text, 'I said Bear is coming now!!!! Tab separators.', "Last cue content check");
                    ++stage;
                    testTrack.src = "resources/entities.vtt";
                    assert_equals(cues.length, 0, "cues list is reset immediately after 'src' mutation with the new URL");
                    break;
                case 1:
                    assert_equals(testTrack.readyState, HTMLTrackElement.LOADED), "readyState after loading of the second track";
                    assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation");
                    assert_equals(cues.length, 7, "Number of cues after loading of the second track");
                    assert_equals(cues[cues.length-1].text, 'This & is parsed to the same as &amp;.', "Last cue content check");
                    ++stage;
                    testTrack.src = "resources/settings.vtt";
                    break;
                case 2:
                    assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after after loading of the first track again");
                    assert_equals(cues[cues.length-1].text, 'I said Bear is coming now!!!! Tab separators.', "Last cue content check");
                    assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation");
                    assert_equals(cues.length, 4, "Number of cues after loading of the first track");
                    ++stage;
                    testTrack.src = "resources/settings.vtt";
                    // This should not raise onLoad or onError event, so we'll wait for it for some time
                    t.step_timeout(t.step_func_done(function() {
                        assert_equals(testTrack.readyState, HTMLTrackElement.LOADED, "readyState after changing 'src' to the same value");
                        assert_equals(cues, testTrack.track.cues, ".cues object are the same after 'src' attr mutation");
                        assert_equals(cues.length, 4, "Number of cues after changing 'src' to the same value");
                    }, 100));
                    break;
                case 3:
                    assert_unreached("'load' event should not fire, stage = " + stage);
                    break;
            }
        }

        testTrack.onload = t.step_func(step_onLoad);
        testTrack.onerror = t.unreached_func("'error' event should not fire");
    });
    </script>
</video>