<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
    <head>
        <script src="../../resources/js-test-pre.js"></script>
    </head>
    <body>
        <p id="description"></p>
        <div id="console"></div>
        <script>
            description("Tests RTCSessionDescription.");

            var initializer = {type:"offer", sdp:"foobar"};
            var sessionDescription;
            shouldNotThrow("sessionDescription = new RTCSessionDescription(initializer);");
            shouldBe('sessionDescription.type', '"offer"');
            shouldBe('sessionDescription.sdp', '"foobar"');
            shouldBeEqualToString('JSON.stringify(sessionDescription.toJSON())', '{"type":"offer","sdp":"foobar"}');

            debug("*** Attributes are read-only.");
            shouldNotThrow("sessionDescription.type = 'answer'");
            shouldBe("sessionDescription.type", "'offer'");
            shouldNotThrow("sessionDescription.sdp = 'football'");
            shouldBe("sessionDescription.sdp", "'foobar'");

            debug("*** Argument is mandatory");
            shouldThrow("new RTCSessionDescription();");

            debug("*** Dictionary member type is required");
            shouldThrow("new RTCSessionDescription({});");
            shouldThrow("new RTCSessionDescription({sdp:'x'});");
            shouldThrow("new RTCSessionDescription({foo:'bar'});");
            shouldNotThrow("new RTCSessionDescription({type:'offer'});");

            shouldThrow("new RTCSessionDescription(null);");
            shouldThrow("new RTCSessionDescription(5);");
            shouldThrow("new RTCSessionDescription('foobar');");
            shouldThrow("new RTCSessionDescription({type:'foobar', sdp:'x'});");

            debug("*** Valid types");
            ["offer", "answer", "pranswer", "rollback"].forEach(type => {
                shouldNotThrow(`sessionDescription = new RTCSessionDescription({type:'${type}', sdp:'x'});`);
                shouldBe("sessionDescription.type", `'${type}'`);
            });

            window.successfullyParsed = true;
        </script>
        <script src="../../resources/js-test-post.js"></script>
    </body>
</html>
