<html>
<head>
    <style type="text/css">
        .pass { color: green; }
        .fail { color: red; }
    </style>
    <script>
        function printOut(msg)
        {
            var console = document.getElementById("console");
            var span = document.createElement('span');
            span.innerHTML = msg + '<br>';
            console.appendChild(span);
        }

        function resultStringifier(result)
        {
            if (result === "")
                return "<b>the empty string</b>";
            else if (result === null)
                return "<b>null</b>";
            else if (result === undefined)
                return "<b>undefined</b>";
            return "the string '" + result + "'";
        }

        function nullTestDocumentAttribute(documentType, doc, attr, expected, expectedExceptionCode)
        {
            var result;
            try {
                doc[attr] = null;
                if (expectedExceptionCode != undefined)
                    result = "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode + " but threw nothing.";
                else if (doc[attr] === expected)
                    result = "<span class='pass'>TEST SUCCEEDED:</span> The value was " + resultStringifier(expected) + ".";
                else
                    result = "<span class='fail'>TEST FAILED:</span> The value should have been " + resultStringifier(expected) + " but was " + resultStringifier(doc[attr]) + ".";

            } catch (ex) {
                if (ex.code == expectedExceptionCode)
                    result = "<span class='pass'>TEST SUCCEEDED:</span> Got the expected exception (" + ex.code + ").";
                else
                    result = "<span class='fail'>TEST FAILED:</span> Should've thrown " + expectedExceptionCode + " but threw " + ex.code + ".";
            }

            result += " [tested " + documentType + "." + attr + "]";
            printOut(result);
        }

        function runTests()
        {
            if (window.testRunner)
                testRunner.dumpAsText();

            // Others to test:
            //  Functions

            var xmlDoc = document.implementation.createDocument(null, null, null);
            var htmlDoc = document.implementation.createHTMLDocument('A Title');
            htmlDoc.body = htmlDoc.createElement('body');

            var listing = [
                {
                    typeName: 'Document',
                    docToUse: xmlDoc,
                    attributes: [
                        {name: 'xmlVersion', expectedExceptionCode: 9},
                        {name: 'selectedStylesheetSet', expectedNull: null}
                    ]
                },
                {
                    typeName: 'HTMLDocument',
                    docToUse: htmlDoc,
                    attributes: [
                        {name: 'title', expectedNull: 'null'},
                        {name: 'cookie', expectedNull: ''},
                        {name: 'bgColor', expectedNull: ''},
                        {name: 'fgColor', expectedNull: ''},
                        {name: 'alinkColor', expectedNull: ''},
                        {name: 'linkColor', expectedNull: ''},
                        {name: 'vlinkColor', expectedNull: ''},
                        {name: 'dir', expectedNull: ''},
                        {name: 'designMode', expectedNull: 'off'}
                    ]
                }
            ];

            for (doc in listing) {
                var typeName = listing[doc].typeName;
                var docToUse = listing[doc].docToUse;
                var attrs = listing[doc].attributes;
                for (attr in attrs) {
                    nullTestDocumentAttribute(typeName, docToUse, attrs[attr].name, attrs[attr].expectedNull, attrs[attr].expectedExceptionCode);
                }
                printOut('');
            }
        }
    </script>
</head>
<body onload="runTests()">
    <p>This test setting various attributes of documents to JavaScript null.</p>
    <div id="console"></div>
</body>
</html>
