<body onload="startTest()">
<p>Test that failing revalidation with a network error does not cause a crash.</p>
<pre id=log></pre>
<script>
if (window.testRunner) {
    testRunner.dumpAsText();
    testRunner.waitUntilDone();
}

function log(message)
{
    document.getElementById("log").innerHTML += message + "\n";
}

function setNetworkEnabled(state)
{
    log(state ? "Enabling network" : "Disabling network");
    var req = new XMLHttpRequest;
    req.open("GET", "/resources/network-simulator.py?test=cache-network-error-during-revalidation&command=" + (state ? "connect" : "disconnect"), false);
    req.send("");
}

function startTest()
{
    setNetworkEnabled(true);
    log("Loading an image once to cache it");
    var iframe = document.createElement("iframe");
    iframe.src = "resources/network-error-during-revalidation-frame.html";
    iframe.onload = imageLoaded;
    document.body.appendChild(iframe);
}

function imageLoaded()
{
    setNetworkEnabled(false);
    log("Reloading to revalidate the image");
    var iframe = document.getElementsByTagName("iframe")[0];
    iframe.onload = cachedLoadComplete;
    iframe.contentWindow.location.reload();
}

function cachedLoadComplete()
{
    setNetworkEnabled(true);
    log("Done");
    if (window.testRunner)
        testRunner.notifyDone();
}

function unexpectedError()
{
    log("Unexpected error");
    setNetworkEnabled(true);
    if (window.testRunner)
        testRunner.notifyDone();
}

</script>

</head>
</body>
