<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
    <head>
        <script src="../../resources/js-test-pre.js"></script>
        <script src="./resources/getUserMedia-helper.js"></script>
        <script>
            var mediaStream;
            var videoTrack;
            var audioTrack;
            var newMediaStream;
            var mediaStreamCopy;

            function gotStream(stream) {
                mediaStream = stream;
                debug("");
                shouldEvaluateTo('mediaStream.active', true);

                evalAndLog("videoTrack = mediaStream.getVideoTracks()[0]");
                evalAndLog("audioTrack = mediaStream.getAudioTracks()[0]");

                shouldNotBeEqualToString('videoTrack.readyState', 'ended');
                shouldNotBeEqualToString('audioTrack.readyState', 'ended');

                videoTrack.stop();
                audioTrack.stop();
                shouldBeEqualToString('videoTrack.readyState', 'ended');
                shouldBeEqualToString('audioTrack.readyState', 'ended');

                var tracksArray = [];
                tracksArray.push(videoTrack);
                tracksArray.push(audioTrack);
                newMediaStream = new MediaStream(tracksArray);

                shouldEvaluateTo('newMediaStream.active', false);
                shouldNotBe('mediaStream.id', 'newMediaStream.id');

                mediaStreamCopy = new MediaStream(newMediaStream);
                shouldEvaluateTo('mediaStreamCopy.active', false);
                shouldNotBe('mediaStreamCopy.id', 'newMediaStream.id');

                finishJSTest();
            }

            function start() {
                getUserMedia("allow", {audio:true, video:true}, gotStream);
            }

            window.jsTestIsAsync = true;
            window.successfullyParsed = true;
        </script>
    </head>
    <body onload="start()">
        <p id="description"></p>
        <div id="console"></div>
        <script src="../../resources/js-test-post.js"></script>
    </body>
</html>
