<html>
    <head>
        <script src=media-file.js></script>
        <script src=video-test.js></script>
        <script>
            var playCount = 0;
            var playThroughCount = 0;
            var videos = [];

            function logEvent(evt)
            {
                consoleWrite("EVENT(" + evt.type + ")");
            }

            function playing(evt)
            {
                logEvent(evt);
                consoleWrite("");

                switch (++playCount)
                {
                case 1:
                    consoleWrite("** Starting the second video, the first one should pause.");
                    run("videos[1].play()");
                    setTimeout(endTest, 100);
                    break;
                case 2:
                    testExpected("videos[0].paused", true);
                    testExpected("videos[1].paused", false);

                    consoleWrite("");
                    endTest();
                    break;
                }
            }

            function canplaythrough(evt)
            {
                logEvent(evt);

                if (++playThroughCount < 2)
                    return;

                consoleWrite("<br>** Play first video...");
                run("videos[0].play()");
            }

            function start()
            {
                if (!window.internals) {
                    failTest('This test requires window.internals.');
                    return;
                }

                videos = document.getElementsByTagName('video');
                for (var i = 0; i < videos.length; ++i) {
                    video = videos[i];
                    video.addEventListener("canplaythrough", canplaythrough);
                    video.addEventListener('playing', playing);
                    video.src = findMediaFile("video", "content/test");
                }
                run("internals.setMediaSessionRestrictions('video', 'ConcurrentPlaybackNotPermitted')");
                consoleWrite("");
            }
        </script>
    </head>

    <body onload="start()">
        <video controls id="one"></video>
        <video controls id="two"></video>
        <p>Test play() when concurrent playback not allowed.</p>
    </body>
</html>
