<html><head></head><body>

<p>Test bug 17481: Several consecutive calls to XMLHttpRequest::open should dispatch only one readyState event</p>
<p>You should see "PASS" once:</p>
<div id="ans"></div>

<script type="text/javascript">
function log(message)
{
    document.getElementById("ans").appendChild(document.createTextNode(message));
    document.getElementById("ans").appendChild(document.createElement("br"));
}

Array.prototype.isEqual = function(expected)
{
    if (this.length != expected.length)
        return false;
    for (i = 0; i < this.length; i++)
        if (this[i] != expected[i])
            return false;
    return true;
}

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

var xhr;

if (window.XMLHttpRequest) {
    xhr = new XMLHttpRequest();
} else {
    try {
        xhr = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (ex) {
        xhr = new ActiveXObject("Microsoft.XMLHTTP");
    }
}

var results = [],
    expected = ['before first open', 1, 'before second open', 'before third open'];

xhr.onreadystatechange = function () {
    results.push(this.readyState);
}

results.push('before first open');
xhr.open("GET", "resources/1251.html", true);
results.push('before second open');
xhr.open("GET", "resources/1251.html", true);
results.push('before third open');
xhr.open("GET", "resources/print-headers.cgi", true);

log(results.isEqual(expected) ? "PASS" : "FAILED results : " + results + " expected : " + expected);

if (window.testRunner)
    testRunner.notifyDone();

</script>
</body></html>
