summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/simple.html
blob: 4342cb7a4096b467e22061853aee24d3562158c9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
<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>