Html程序  |  78行  |  1.88 KB

<html manifest="resources/online-whitelist.manifest">
<body>
<p>Test online whitelist functionality. Should say PASS:</p>

<div id="result"></div>
<script>
if (window.layoutTestController) {
    layoutTestController.dumpAsText()
    layoutTestController.waitUntilDone();
}

function log(message)
{
    document.getElementById("result").innerHTML += message + "<br>";
}

var hadError = false;

function canLoad(url)
{
    try {
        var req = new XMLHttpRequest();
        req.open("GET", url, false);
        req.send("");
        return true;
    } catch (e) {
        return false;
    }
}

function load(url)
{
    try {
        var req = new XMLHttpRequest();
        req.open("GET", url, false);
        req.send("");
        return req.responseText;
    } catch (ex) {
        alert("Unexpected error loading " + url + ": " + ex);
        hadError = true;
    }
}

function test()
{
    if (load("resources/counter.php?cached") != load("resources/counter.php?cached")) {
        log("FAIL: Explicit entry didn't override online whitelist.");
        hadError = true;
    }

    if (load("resources/counter.php?uncached") == load("resources/counter.php?uncached")) {
        log("FAIL: Online whitelist resource wasn't reloaded from network.");
        hadError = true;
    }

    if (load("resources/counter.php?uncachedxxx") == load("resources/counter.php?uncachedxxx")) {
        log("FAIL: Online whitelist resource wasn't reloaded from network (prefix matching).");
        hadError = true;
    }

    if (canLoad("resources/counter.php?foobar")) {
        log("FAIL: Uncached resource was successfully loaded.");
        hadError = true;
    }

    log(hadError ? "FAIL" : "PASS");

    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

applicationCache.addEventListener('cached', test, false);
applicationCache.addEventListener('noupdate', test, false);

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