<!DOCTYPE html>
<html>
<body>
<p>This test ensures a beforeunload event handler can safely remove the frame to which the event is fired. You should see PASS below:</p>
<pre id="log"></pre>
<script>

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.dumpChildFramesAsText();
    testRunner.waitUntilDone();
}

var log = document.getElementById('log');
var done = false;

function test() {
    if (done) {
        // log's not having any content implies that load event was dispatched for the second time before beforeunload is dispatched.
        if (!log.innerHTML.length)
            log.innerHTML = 'FAIL: beforeunload event was never dispatched.\n';
        else
            log.innerHTML = 'FAIL: beforeunload event handler did not remove the frame.\n';
        if (window.testRunner)
            testRunner.notifyDone();
        return;
    }
    done = true;
    document.getElementsByTagName('iframe')[0].contentWindow.location.href = 'resources/before-unload-in-subframe-child.html';
}

function fired() {
    document.body.removeChild(document.body.getElementsByTagName('iframe')[0]);
    log.innerHTML = 'PASS\n';
    if (window.testRunner)
        testRunner.notifyDone();
}

</script>
<iframe onload="test()" src="resources/before-unload-in-subframe-child.html"></iframe>
</body>
</html>
