chromium/third_party/blink/web_tests/media/avtrack/track-switching.html

<!doctype html>
<html>
    <head>
        <title>Media track switching during playback</title>
        <script src="../../resources/testharness.js"></script>
        <script src="../../resources/testharnessreport.js"></script>
            </head>
    <body>
        <script>
            async_test(function(t)
            {
                var video = document.createElement("video");
                video.src = "../content/multitrack-3video-2audio.webm";

                video.onloadedmetadata = t.step_func(function()
                {
                    assert_equals(video.videoTracks.length, 3, "videoTracks.length");
                    assert_equals(video.audioTracks.length, 2, "audioTracks.length");

                    assert_true(video.videoTracks[0].selected, "videoTrack[0].selected");
                    assert_false(video.videoTracks[1].selected, "videoTrack[1].selected");
                    assert_false(video.videoTracks[2].selected, "videoTrack[2].selected");
                    assert_true(video.audioTracks[0].enabled, "audioTracks[0].enabled");
                    assert_false(video.audioTracks[1].enabled, "audioTracks[1].enabled");

                    var videoWatcher = new EventWatcher(t, video, ["playing"]);
                    var audioTracksWatcher = new EventWatcher(t, video.audioTracks, ["change"]);
                    var videoTracksWatcher = new EventWatcher(t, video.videoTracks, ["change"]);

                    videoWatcher.wait_for("playing").then(t.step_func(function() {
                        video.videoTracks[1].selected = true;
                        return videoTracksWatcher.wait_for("change");
                    })).then(t.step_func(function() {
                        assert_false(video.videoTracks[0].selected, "videoTrack[0].selected");
                        assert_true(video.videoTracks[1].selected, "videoTrack[1].selected");
                        video.audioTracks[0].enabled = false;
                        return audioTracksWatcher.wait_for("change");
                    })).then(t.step_func(function() {
                        assert_false(video.audioTracks[0].enabled, "audioTracks[0].enabled");
                        assert_false(video.audioTracks[1].enabled, "audioTracks[1].enabled");
                        video.audioTracks[1].enabled = true;
                        return audioTracksWatcher.wait_for("change");
                    })).then(t.step_func(function() {
                        assert_false(video.audioTracks[0].enabled, "audioTracks[0].enabled");
                        assert_true(video.audioTracks[1].enabled, "audioTracks[1].enabled");
                        setTimeout(t.step_func_done(), 500);
                    }));
                    video.play();
                });
            }, "VideoTrackList track change");
        </script>
    </body>
</html>