<html>
<head>
<script>

if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.dumpChildFramesAsText();
    testRunner.setHandlesAuthenticationChallenges(true);
    testRunner.setAuthenticationUsername("wrongusername");
    testRunner.setAuthenticationPassword("wrongpassword");
    testRunner.waitUntilDone();
}

function firstFrameLoaded() {
    setTimeout(()=>{
        if (window.testRunner) {
            testRunner.setAuthenticationUsername("correctusername");
            testRunner.setAuthenticationPassword("correctpassword");
        }
        var frame = document.createElement("iframe");
        frame.setAttribute("src", "http://127.0.0.1:8000/loading/resources/test2/basic-auth-testing.py?username=correctusername&password=correctpassword");
        frame.setAttribute("onload", "secondFrameLoaded()");
        document.body.appendChild(frame);
    }, 0);
}

function secondFrameLoaded() {
    if (window.testRunner)
        testRunner.notifyDone();
}

function makeIFrame() {
    var iframe = document.createElement("iframe");
    iframe.onload=firstFrameLoaded;
    iframe.src="resources/test2/protected-resource.py";
    document.body.appendChild(iframe);
}

</script>
</head>
<body onload="setTimeout(makeIFrame, 0)">
This test makes sure that once WebCore preemptively sends out Basic credentials it thinks apply to a new resource, and that resource response with a 401 challenge, that it doesn't try to send the same wrong credentials a second time.<br>
</body>
</html>
