1 <html manifest=
"resources/fallback.manifest">
3 <p>Test application cache fallback entries.
</p>
4 <p>Should say SUCCESS:
</p>
8 if (window
.testRunner
) {
9 testRunner
.dumpAsText();
10 testRunner
.waitUntilDone();
17 document
.getElementById("result").innerHTML
+= message
+ "<br>";
20 function setNetworkEnabled(state
)
23 var req
= new XMLHttpRequest
;
24 req
.open("GET", "/resources/network-simulator.php?command=" + (state
? "connect" : "disconnect"), false);
27 log("Cannot access network simulator URL");
35 var req
= new XMLHttpRequest();
36 req
.open("GET", url
, false);
38 return req
.responseText
;
40 log("FAIL: Cannot load " + url
+ ", ex = " + ex
);
42 return ""; // This value should not be expected as the responseText for a url presented to this function.
46 var testURL
= "/resources/network-simulator.php?path=/appcache/resources/not-in-cache.txt";
47 var nonexistentURL
= "resources/does-not-exist";
48 var redirectURL
= "resources/fallback-redirect.php";
52 applicationCache
.onnoupdate = function() { log("FAIL: received unexpected noupdate event") }
53 applicationCache
.oncached = function() { log("FAIL: received unexpected cached event") }
55 setNetworkEnabled(true);
57 if (!/not in the cache/.test(load(testURL
))) {
58 log("FAIL: Cannot load an URL from fallback namespace when network is enabled");
62 if (load(nonexistentURL
) != "Hello, World!") {
63 log("FAIL: Fallback resource wasn't used for a 404 response");
67 if (load(redirectURL
) != "Hello, World!") {
68 log("FAIL: Fallback resource wasn't used for a redirect to a resource with another origin");
77 var req
= new XMLHttpRequest
;
78 req
.open("GET", nonexistentURL
);
79 req
.onerror = function() {
80 log("FAIL: Fallback resource wasn't used for a 404 response (async)");
84 req
.onload = function() {
85 if (req
.responseText
!= "Hello, World!") {
86 log("FAIL: Unexpected result for a 404 response (async)");
97 var req
= new XMLHttpRequest
;
98 req
.open("GET", redirectURL
);
99 req
.onerror = function() {
100 log("FAIL: Fallback resource wasn't used for a redirect to a resource with another origin (async)");
104 req
.onload = function() {
105 if (req
.responseText
!= "Hello, World!") {
106 log("FAIL: Unexpected result for a redirect response (async)");
117 // Try loading a fallback resource as main one.
119 applicationCache
.onnoupdate
= test5
;
121 var ifr
= document
.createElement("iframe");
122 ifr
.setAttribute("src", nonexistentURL
);
123 ifr
.setAttribute("onload", "test5()");
124 document
.body
.appendChild(ifr
);
132 if (test5_calls
== 1) {
135 if (!/Hello, World/.test(window
.frames
[0].document
.documentElement
.innerHTML
)) {
136 log("FAIL: Fallback URL was not honored for main resource");
144 setNetworkEnabled(false);
146 if (load(testURL
) != load("resources/simple.txt")) {
147 log("FAIL: Loading an URL from fallback namespace when network is disabled returned unexpected response");
151 log(hadError
? "FAILURE" : "SUCCESS");
152 if (window
.testRunner
)
153 testRunner
.notifyDone();
156 applicationCache
.onnoupdate = function() { test() }
157 applicationCache
.oncached = function() { test() }
159 applicationCache
.onupdateready = function() { log("FAIL: received unexpected updateready event") }
160 applicationCache
.onerror = function() { log("FAIL: received unexpected error event") }