Html程序  |  56行  |  1.65 KB

<html manifest="resources/simple.manifest">
<script>
if (window.layoutTestController) {
    layoutTestController.dumpAsText()
    layoutTestController.waitUntilDone();
}

function cached()
{
    var hadError = false;
    
    // Load a resource that does not exist in the cache.
    try {
        var req = new XMLHttpRequest();
        req.open("GET", "resources/not-in-cache.txt", false);
        req.send();
    } catch (e) {
        if (e.code == XMLHttpRequestException.NETWORK_ERR)
            hadError = true;
    }

    if (!hadError) {
        document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
        return;
    }
   
    // Load a resource that exists in the cache.
    try {
        var req = new XMLHttpRequest();
        req.open("GET", "resources/simple.txt", false);
        req.send();
    } catch (e) {
        document.getElementById('result').innerHTML = "FAILURE: Could not load data from cache"
        return;
    }
        
    if (req.responseText != 'Hello, World!') {
        document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
        return;
    }
    
    document.getElementById('result').innerHTML = "SUCCESS"
    
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

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

</script>
<div>This tests that the application cache works by first loading a file that does not exist in the cache (to verify that a cache has been associated) and then loads a file that is in the cache</div>

<div id="result">FAILURE</div>
</html>