<body>
<p><a href="rdar://problem/7062824">rdar://problem/7062824</a> A wrong password entered for site or proxy auth remains in WebCore credential storage, and is sent with subsequent requests.</p>
<p>This test counts the number of failed requests server side.</p>
<div id = result>Testing... Please cancel all authentication dialogs.</div></br>
<div>Sync</div>
<button onclick="sendWithCredentials(false)">With credentials</button>
<button onclick="sendWithoutCredentials(false)">Without credentials</button>
<div>Async</div>
<button onclick="sendWithCredentials(true)">With credentials</button>
<button onclick="sendWithoutCredentials(true)">Without credentials</button>
<br>
<button onclick="status()">Status</button>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone()
}

function sendWithCredentials(next)
{
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "resources/remember-bad-password/count-failures.py", next ? true : false, "foo", "bar");
    xhr.send("");
    if (next) {
        xhr.onload = next;
        xhr.onerror = next;
    }
}

function sendWithoutCredentials(next)
{
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "resources/remember-bad-password/count-failures.py", next ? true : false);
    xhr.send("");

    if (next) {
        xhr.onload = next;
        xhr.onerror = next;
    }
}

function status()
{
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "resources/remember-bad-password/count-failures.py?command=status", false);
    xhr.send("");
    return xhr.responseText;
}

function reset()
{
    var xhr = new XMLHttpRequest;
    xhr.open("GET", "resources/remember-bad-password/count-failures.py?command=reset", false);
    xhr.send("");
}

reset();
sendWithCredentials();
sendWithoutCredentials();
sendWithCredentials(function() {
sendWithoutCredentials(function() {
var s = status();
document.getElementById("result").innerHTML = (s == 2 ? "PASS" : ("FAIL: " + s));
if (window.testRunner)
    testRunner.notifyDone();
})});
</script>
</body>
