<html>
    <head>
        <script>
            function test()
            {
                if (window.testRunner) {
                    testRunner.dumpAsText();
                    testRunner.waitUntilDone();
                }
                    
                if (window.navigationController)
                    navigationController.evalAfterBackForwardNavigation("continueTestAfterNavigation()");
            }
            
            function continueTestAfterNavigation()
            {
                var e = document.createEvent("MouseEvents");
                e.initEvent("click", true, false);
                document.getElementById('button').dispatchEvent(e);
                
                if (window.testRunner)
                    testRunner.notifyDone();
            }

            function button_onClick()
            {
                print('PASS: click event sent to button');
            }
            
            function print(message) {
                var paragraph = document.createElement("p");
                paragraph.appendChild(document.createTextNode(message));
                document.getElementById("console").appendChild(paragraph);
            }
        </script>
    </head>

    <body onload="test()">
        <p>Bug: <a href="http://bugzilla.opendarwin.org/show_bug.cgi?id=6331">REGRESSION: form events don't fire after back/forward navigation, due to inconsistent load state</a></p> 
        <p>To run this test in Safari:</p>
        <ol>
            <li><a href="go-back.html">Click here to do a back/forward navigation.</a></li>
            <li><a href="" onclick="continueTestAfterNavigation(); return false;">Click here to test form events.</a></li>
        </ol>
        <p>If this test passes, you'll see a PASS message below.</p>
        <hr>
        <input type=hidden id="button" onclick="button_onClick()">
        <div id="console"></div>
    </body>
</html>
