<html>
<head>
<script>

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

function log(txt)
{
    document.getElementById("logger").appendChild(document.createTextNode(txt + "\n"));
}

function runTest()
{
    beganTest = true;
    history.replaceState("FirstEntry", "Initial entry");
    history.pushState(undefined, "undefined entry");
    history.pushState(null, "null entry");
    history.pushState(false, "false entry");
    history.pushState(true, "true entry");
    history.pushState(42, "Number entry");
    history.pushState("String", "String entry");
    history.pushState(new Date(0), "Date entry");
    history.pushState(new RegExp("foo", "gi"), "RegExp entry");
    history.pushState(new Array, "Array entry");
    history.pushState(new Object, "Object entry");
    history.pushState(document.createElement("canvas").getContext("2d").createImageData(10,10), "ImageData entry");

/* The following are not yet well enough supported in WebKit to meaningfully test here:
history.pushState([Blob], "Blob entry");
history.pushState([File], "File entry");
history.pushState([FileList], "FileList entry");
*/

    history.pushState("BufferEntry", "Last entry");
    history.back();
}

onpopstate = function(event)
{
    if (event.state instanceof Date)
        log("State popped - " + event.state.getTime() + " (type " + typeof event.state + ")");
    else
        log("State popped - " + event.state + " (type " + typeof event.state + ")");

    
    if (event.state != "FirstEntry")
        history.back();
    else if (window.testRunner)
        testRunner.notifyDone();
}

</script>
<body onload="runTest();">
<p>
This test calls pushState with state objects of all the different object types supported by the HTML5 "internal structured cloning algorithm" and makes sure the events contain the expected objects when the states are popped.
</p>
<pre id="logger"></pre>
</body>
</html>
