Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / http / tests / appcache / xhr-foreign-resource.html
blob5d9fe46fe7241634aa59e16eed6a4df7eae4fe3d
1 <html manifest="resources/xhr-foreign-resource.manifest">
2 <body>
3 <p>Test that a resource marked as foreign can still be loaded via XHR.</p>
4 <p>Should say SUCCESS:</p>
5 <div id=result></div>
7 <script>
8 if (window.testRunner) {
9 testRunner.dumpAsText();
10 testRunner.waitUntilDone();
13 function log(message)
15 document.getElementById("result").innerHTML += message + "<br>";
18 function createFrame1()
20 applicationCache.onnoupdate = function() { log("FAIL: Unexpected noupdate event") }
21 applicationCache.oncached = function() { log("FAIL: Unexpected cached event") }
23 var ifr = document.createElement("iframe");
24 ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html");
25 document.body.appendChild(ifr);
28 function createFrame2()
30 // A copy that doesn't have its main resource in cache manifest.
31 var ifr = document.createElement("iframe");
32 ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html?");
33 document.body.appendChild(ifr);
36 applicationCache.onnoupdate = function() { createFrame1() }
37 applicationCache.oncached = function() { createFrame1() }
39 applicationCache.onupdateready = function() { log("FAIL: received unexpected updateready event") }
40 applicationCache.onerror = function() { log("FAIL: received unexpected error event") }
42 var hadErrorFromSubframe = false;
43 var subframeMessagesReceived = 0;
44 function frameMessageReceived(evt)
46 ++subframeMessagesReceived;
47 if (evt.data != "SUCCESS")
48 hadErrorFromSubframe = true;
49 if (subframeMessagesReceived == 1)
50 setTimeout(createFrame2, 0);
51 else if (subframeMessagesReceived == 2)
52 test();
55 function test(evt)
57 if (!hadErrorFromSubframe) {
58 // The subframe has a different cache, but it is also listed as a resource in main frame's
59 // manifest, so it should be loaded successfully despite being marked as foreign now.
60 try {
61 var req = new XMLHttpRequest;
62 req.open("GET", "resources/xhr-foreign-resource-frame.html", false);
63 req.send("");
64 log("SUCCESS");
65 } catch (ex) {
66 log (ex);
68 } else
69 log("FAIL: subframe didn't get a correct cache");
71 if (window.testRunner)
72 testRunner.notifyDone();
75 window.addEventListener("message", frameMessageReceived, false);
77 </script>
78 </body>
79 </html>