<html>
<body>
<pre id='console'></pre>
<script type="text/javascript">
function log(message)
{
    document.getElementById('console').appendChild(document.createTextNode(message + "\n"));
}

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

function errorHandler(event)
{
    log("FAIL: Network error. ");
    if (window.testRunner)
        testRunner.notifyDone();
}

var filename = "filename=preflightCacheInvalidationByMethod.txt";

var xhr = new XMLHttpRequest;
xhr.onerror = errorHandler;

start = function()
{
    // Temp file removed.  We can start the test now.
    if (xhr.readyState == xhr.DONE) {
        firstRequest();
    }
}

xhr.open("GET", "/resources/reset-temp-file.py?" + filename, true);
xhr.onreadystatechange = start;
xhr.send();

function firstRequest()
{
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == xhr.DONE) {
            log(xhr.responseText);
            log("PASS: First request complete");
            secondRequest();
        }
    }

    xhr.open("PUT", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.py?" + filename, true);
    xhr.send();
}

function secondRequest()
{
    xhr.onreadystatechange = function()
    {
        if (xhr.readyState == xhr.DONE) {
            log(xhr.responseText);
            log("PASS: Second request complete");
            if (window.testRunner)
                testRunner.notifyDone();
        }
    }

    // Send a method not included in the initial cache.
    xhr.open("XMETHOD", "http://localhost:8000/xmlhttprequest/resources/access-control-basic-preflight-cache-invalidation.py?" + filename, true);
    xhr.send();
}

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