<script>

shouldFinishJSOnXHRLoad = false;

function doXHR()
{
    xhr = new XMLHttpRequest();
    xhr.open("GET", "/navigation/resources/slow-resource.pl?delay=1000");
    xhr.addEventListener("load", () => {
        if (shouldFinishJSOnXHRLoad) {
            parent.testPassed("XHR finished after restoring from the cache");
            parent.restoredFromCache = false;
            parent.finishJSTest();
        } else
            doXHR();
    });
    xhr.addEventListener("error", () => {
        doXHR();
    });
    xhr.addEventListener("progress", () => {
    });

    xhr.send();
}

parent.debug("* iframe starting XHR");
doXHR();

parent.navigate();

</script>
