<!-- webkit-test-runner [ ShowModalDialogEnabled=true ] -->
<!DOCTYPE html>
<html>
<head>
    <script src="resources/WindowProperties.js"></script>
    <script>
        if (window.testRunner)
            testRunner.dumpAsText();

        function log(message, color) 
        {
            var paragraph = document.createElement("div");
            paragraph.appendChild(document.createTextNode(message));
            paragraph.style.fontFamily = "monospace";
            if (color)
                paragraph.style.color = color;
            document.getElementById("console").appendChild(paragraph);
        }

        function shouldBe(a, b, printOnlyOnFailure)
        {
            var evalA;
            try {
                evalA = eval(a);
            } catch(e) {
                evalA = e;
            }
            if (evalA == b) {
                if (!printOnlyOnFailure)
                    log("PASS: " + a + " should be " + b + " and is.", "green");
            } else
                log("FAIL: " + a + " should be " + b + " but instead is " + evalA, "red");
        }

        function testFunction(functionName)
        {
            var iframe = document.createElement('iframe');
            iframe.src = "about:blank";
            iframe.name = functionName;
            document.body.appendChild(iframe);

            // showModalDialog only works on mac in the DRT.  So run this test only if its defined and print output only on failure.
            // This'll keep the output consistent on all platforms.
            if (functionName == "showModalDialog") {
                if (window.showModalDialog != undefined)
                    shouldBe("typeof window." + functionName, "function", true);
            } else
                shouldBe("typeof window." + functionName, "function");

            document.body.removeChild(iframe);
        }

        function runTests()
        {
            for (var func in windowFunctions) {
                testFunction(windowFunctions[func])
            }

            window.myFunction = function() { return "myFunction"; }
            testFunction("myFunction");
            window.__proto__.myPrototypeFunction = function() { return "myPrototypeFunction"; }
            testFunction("myPrototypeFunction");
        }
    </script>
</head>
<body onload="runTests();">
    <p>This tests that a frame with a the same name as function on the window object, has precedence in the lookup.</p>
    <pre id="console"></pre>
</body>
</html>
