Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / appcache / non-html.xhtml
bloba92e61840e65110e7b14e47ac8932b6462c90047
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">
9 if (window.testRunner) {
10 testRunner.dumpAsText()
11 testRunner.waitUntilDone();
14 function log(message)
16 document.getElementById("result").innerHTML += message + "&lt;br/>";
19 function setNetworkEnabled(state)
21 var req = new XMLHttpRequest;
22 req.open("GET", "/resources/network-simulator.php?command=" + (state ? "connect" : "disconnect"), false);
23 req.send("");
26 function createFrame()
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);
34 function cached()
36 var hadError = false;
38 applicationCache.removeEventListener('noupdate', cached, false);
39 applicationCache.removeEventListener('cached', cached, false);
41 setNetworkEnabled(false);
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 == DOMException.NETWORK_ERR)
50 hadError = true;
53 if (!hadError) {
54 document.getElementById('result').innerHTML = "FAILURE: Did not get the right exception"
55 return;
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;
68 if (req.responseText != 'Hello, World!') {
69 document.getElementById('result').innerHTML = "FAILURE: Did not get correct data from cached resource"
70 return;
73 createFrame();
76 function frameCreated()
78 setNetworkEnabled(true);
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.");
85 if (window.testRunner) {
86 applicationCache.onerror = null;
87 testRunner.notifyDone();
91 function error()
93 // The simulator was in a wrong state, reset it.
94 setNetworkEnabled(true);
95 window.location.reload();
98 applicationCache.addEventListener('cached', cached, false);
99 applicationCache.addEventListener('noupdate', cached, false);
101 applicationCache.onerror = error;
103 </script>
104 </body>
105 </html>