<html>
<head>
    <script src="resources/cross-frame-access.js"></script>
    <script>
        window.onload = function()
        {
            if (window.testRunner) {
                testRunner.dumpAsText();
                testRunner.waitUntilDone();
            }

            if (window.testRunner) {
                setTimeout(pollForTest, 1);
            } else {
                log("To run the test, click the button below when the opened window finishes loading.");
                var button = document.createElement("button");
                button.appendChild(document.createTextNode("Run Test"));
                button.onclick = runTest;
                document.body.appendChild(button);
            }
        }

        pollForTest = function()
        {
            if (!testRunner.globalFlag) {
                setTimeout(pollForTest, 1);
                return;
            }
            runTest();
            testRunner.notifyDone();
        }

        runTest = function()
        {
            window.targetWindow = frames[0];

            log("----- tests for getting a targetWindow's functions which have custom overrides.  The desired " + 
                " behavior is for the targetWindow to return the built-in function, not the override -----\n");

            // Overriden using window.focus = function() { return "new focus" }
            shouldBeTrue("canGet('targetWindow.focus')");
            shouldBe("toString('targetWindow.focus')", "toString('window.focus')");

            // Overriden using window.__proto__.blur = function() { return "new blur;" }
            shouldBeTrue("canGet('targetWindow.blur')");
            shouldBe("toString('targetWindow.blur')", "toString('window.blur')");

            // Overriden using window.history.close = "new close"
            shouldBeTrue("canGet('targetWindow.close')");
            shouldBe("toString('targetWindow.close')", "toString('window.close')");
        }
    </script>
</head>
<body>
<iframe src="http://localhost:8000/security/resources/cross-frame-iframe-for-get-override-test.html"></iframe>
<pre id="console"></pre>
</body>
</html>
