• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1<html xmlns="http://www.w3.org/1999/xhtml"
2      manifest="/resources/network-simulator.php?path=/appcache/resources/non-html.manifest">
3<head><title/></head>
4<body>
5<p>Test that non-HTML main resources work with application cache correctly.</p>
6<p>Should say SUCCESS:</p>
7<div id="result"></div>
8<script type="text/javascript">
9if (window.layoutTestController) {
10    layoutTestController.dumpAsText()
11    layoutTestController.waitUntilDone();
12}
13
14function log(message)
15{
16    document.getElementById("result").innerHTML += message + "&lt;br/>";
17}
18
19function setNetworkEnabled(state)
20{
21    var req = new XMLHttpRequest;
22    req.open("GET", "/resources/network-simulator.php?command=" + (state ? "connect" : "disconnect"), false);
23    req.send("");
24}
25
26function createFrame()
27{
28    var ifr = document.createElement("iframe");
29    ifr.setAttribute("src", "/resources/network-simulator.php?path=/appcache/resources/abe.png");
30    ifr.onload = frameCreated;
31    document.body.appendChild(ifr);
32}
33
34function cached()
35{
36    var hadError = false;
37
38    applicationCache.removeEventListener('noupdate', cached, false);
39    applicationCache.removeEventListener('cached', cached, false);
40
41    setNetworkEnabled(false);
42
43    // Load a resource that does not exist in the cache.
44    try {
45        var req = new XMLHttpRequest();
46        req.open("GET", "/resources/network-simulator.php?path=/appcache/resources/not-in-cache.txt", false);
47        req.send();
48    } catch (e) {
49        if (e.code == XMLHttpRequestException.NETWORK_ERR)
50            hadError = true;
51    }
52
53    if (!hadError) {
54        document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
55        return;
56    }
57
58    // Load a resource that exists in the cache.
59    try {
60        var req = new XMLHttpRequest();
61        req.open("GET", "/resources/network-simulator.php?path=/appcache/resources/simple.txt", false);
62        req.send();
63    } catch (e) {
64        document.getElementById('result').innerHTML = "FAILURE: Could not load data from cache"
65        return;
66    }
67
68    if (req.responseText != 'Hello, World!') {
69        document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
70        return;
71    }
72
73    createFrame();
74}
75
76function frameCreated()
77{
78    setNetworkEnabled(true);
79
80    if (frames[0].document.documentElement.innerHTML.match(/abe\.png/))
81        log("SUCCESS")
82    else
83        log("FAIL: Frame.onload was called, but the image doesn't seem to be loaded.");
84
85    if (window.layoutTestController)
86        layoutTestController.notifyDone();
87}
88
89function error()
90{
91    // The simulator was in a wrong state, reset it.
92    setNetworkEnabled(true);
93    window.location.reload();
94}
95
96applicationCache.addEventListener('cached', cached, false);
97applicationCache.addEventListener('noupdate', cached, false);
98
99applicationCache.addEventListener('error', error, false);
100
101</script>
102</body>
103</html>
104