<html>
<body>
<p>Tests for <a href="https://bugs.webkit.org/show_bug.cgi?id=15102">bug 15102</a> - 
XMLHttpRequest should dispatch readystatechange event.</p>
<p>If this passes you should see alerts for onreadystatechange and for a readystatechange listener.</p>
<script>
    if (window.testRunner)
        testRunner.dumpAsText();

    function called1(evt) {
        alert("onreadystatechange called");
        evt.foo = "bar";
    }

    function called2(evt) {
        evt.stopPropagation(); // stopPropagation shouldn't have any effect, as we don't have an hierarchy to traverse
    }

    function called3(evt) {
        if (evt.foo == "bar")
            alert("readystatechange listener called");
        else
            alert("ERROR: readystatechange listener called, but the event object is not the same as in onreadystatechange!");
    }

    try {
        var XHR = new XMLHttpRequest();
        XHR.onreadystatechange = called1;
        XHR.addEventListener("readystatechange", called2, false);
        XHR.addEventListener("readystatechange", called3, false);

        XHR.open("GET", "readystatechange.html", true);
    } catch (ex) {
        alert(ex);
    }
</script>
</body>
</html>
