Html程序  |  65行  |  2.07 KB

<html manifest="fail-on-update.php">
<body>
<div id=result></div>
<script>
function log(message)
{
    document.getElementById("result").innerHTML += message + "<br>";
}

function onObsolete()
{
    log("obsolete")
    log("status=" + applicationCache.status + " (expected 5)");
    applicationCache.onobsolete = function() { log("obsolete") }
    applicationCache.onupdateready = function() { log("updateready") }
    applicationCache.onnoupdate = function() { log("noupdate") }
    applicationCache.onnoupdate = function() { log("error") }

    // We still have a cache, so loading should fail
    try {
        var req = new XMLHttpRequest;
        req.open("GET", "empty.txt", false);
        req.send(null);
        alert("FAIL: XMLHttpRequest for an uncached resource didn't raise an exception");
    } catch (ex) {
    }
    log("There should be no messages below.");
}

function onError()
{
    if (applicationCache.status != applicationCache.UNCACHED && applicationCache.status != applicationCache.OBSOLETE) {
        timeoutId = setTimeout(onNoManifest, 100);
        return;
    }

    log("error");
    applicationCache.onobsolete = function() { log("obsolete") }
    applicationCache.onupdateready = function() { log("updateready") }
    applicationCache.onnoupdate = function() { log("noupdate") }
    applicationCache.onnoupdate = function() { log("error") }

    // Ensure that we are not associated with a cache.
    try {
        var req = new XMLHttpRequest;
        req.open("GET", "empty.txt", false);
        req.send(null);
    } catch (ex) {
        alert("FAIL: XMLHttpRequest raised an exception, " + ex);
    }
    log("There should be no messages below.");
    parent.postMessage("frameDone - timeout", "*");
}

applicationCache.onupdateready = function() { log("updateready"); alert("Unexpected updateready event in frame") }
applicationCache.onnoupdate = function() { log("noupdate") }
applicationCache.oncached = function() { log("cached"); alert("Unexpected cached event in frame") }

applicationCache.onobsolete = onObsolete;
applicationCache.onerror = onError;

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