summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/non-html.xhtml
blob: d27681eb1e25b9295fd170e637b51e66db68c0f4 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
<html xmlns="http://www.w3.org/1999/xhtml"
      manifest="/resources/network-simulator.php?path=/appcache/resources/non-html.manifest">
<head><title/></head>
<body>
<p>Test that non-HTML main resources work with application cache correctly.</p>
<p>Should say SUCCESS:</p>
<div id="result"></div>
<script type="text/javascript">
if (window.layoutTestController) {
    layoutTestController.dumpAsText()
    layoutTestController.waitUntilDone();
}

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

function setNetworkEnabled(state)
{
    var req = new XMLHttpRequest;
    req.open("GET", "/resources/network-simulator.php?command=" + (state ? "connect" : "disconnect"), false);
    req.send("");
}

function createFrame()
{
    var ifr = document.createElement("iframe");
    ifr.setAttribute("src", "/resources/network-simulator.php?path=/appcache/resources/abe.png");
    ifr.onload = frameCreated;
    document.body.appendChild(ifr);
}

function cached()
{
    var hadError = false;

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

    setNetworkEnabled(false);

    // Load a resource that does not exist in the cache.
    try {
        var req = new XMLHttpRequest();
        req.open("GET", "/resources/network-simulator.php?path=/appcache/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/network-simulator.php?path=/appcache/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;
    }

    createFrame();
}

function frameCreated()
{
    setNetworkEnabled(true);
    
    if (frames[0].document.documentElement.innerHTML.match(/abe\.png/))
        log("SUCCESS")
    else
        log("FAIL: Frame.onload was called, but the image doesn't seem to be loaded.");
    
    if (window.layoutTestController)
        layoutTestController.notifyDone();
}

function error()
{
    // The simulator was in a wrong state, reset it.
    setNetworkEnabled(true);
    window.location.reload();
}

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

applicationCache.addEventListener('error', error, false);

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