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

        var openedWindow;

        function loaded() {
            var url = "data:text/html,<html>"
                + "<head>"
                +     "<scr" + "ipt>"
                +         "function fireSentinel() {"
                +             "if (window.testRunner)"
                +                 "testRunner.globalFlag = true;"
                +         "}"
                +     "</scr" + "ipt>"
                + "</head>"
                + "<body onload=\"fireSentinel();\">"
                +     "<p>Opened Frame</p>"
                +     "<p id='accessMe'>PASS: Cross frame access from an opener frame was denied</p>"
                + "</body>"
                + "</html>";
    
            openedWindow = window.open(url);

            if (window.testRunner) {
                setTimeout(waitForFlag, 1);
                function waitForFlag() {
                    if (!testRunner.globalFlag) {
                        setTimeout(waitForFlag, 1);
                        return;
                    }
                    performTest();
                }
            } else {
                log("Click the button when all the subframes have finished loading.");
            }
        }
    
        function performTest() {
            try {
                openedWindow.document.getElementById('accessMe').innerHTML = 'FAIL: Access to a window opened with a data: URL was allowed.';
            } catch (e) {
                console.log(e);
            }

            if (window.testRunner)
                closeWindowAndNotifyDone(openedWindow);
        }    
    </script>
</head>
<body onload="loaded();">
    <p>Opener Frame</p>
    <button onclick="performTest()">Test</button>
    <pre id="console"></pre>
</body>
</html>
