<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
    <head>
        <script src="../../resources/js-test-pre.js"></script>
        <script src="./resources/sdp-utils.js"></script>
    </head>
    <body>
        <script>
            if (window.internals)
                internals.useMockRTCPeerConnectionFactory("");

            var stream;
            var audioTrack;
            var videoTrack;
            var mediaDescriptionVariables = [];

            description("Inspect the result of RTCPeerConnection.createOffer()");

            if (window.testRunner)
                testRunner.setUserMediaPermission(true);
            else {
                debug("This test can not be run without the testRunner");
                finishJSTest();
            }

            var pc = new RTCPeerConnection({iceServers:[{urls:'stun:foo.com'}]});

            navigator.mediaDevices.getUserMedia({ "audio": true, "video": true })
            .then(function (s) {
                stream = s;
                audioTrack = stream.getAudioTracks()[0];
                videoTrack = stream.getVideoTracks()[0];

                pc.addTrack(audioTrack, stream);
                return pc.createOffer();
            })
            .then(function (offer) {
                testPassed("Got offer");
                mediaDescriptionVariables.push({ "trackId": audioTrack.id, "streamId": stream.id });
                printComparableSessionDescription(offer, mediaDescriptionVariables);

                pc.addTrack(videoTrack, stream);
                return pc.createOffer();
            })
            .then(function (offer) {
                testPassed("Got offer");
                mediaDescriptionVariables.push({ "trackId": videoTrack.id, "streamId": stream.id });
                printComparableSessionDescription(offer, mediaDescriptionVariables);

                testPassed("End of promise chain");
                finishJSTest();
            })
            .catch(function (error) {
                testFailed("Error caught in promise chain: " + error);
                finishJSTest();
            });

            window.jsTestIsAsync = true;
            window.successfullyParsed = true;

        </script>
        <script src="../../resources/js-test-post.js"></script>
    </body>
</html>
