summaryrefslogtreecommitdiffstats
path: root/LayoutTests/http/tests/appcache/xhr-foreign-resource.html
diff options
context:
space:
mode:
Diffstat (limited to 'LayoutTests/http/tests/appcache/xhr-foreign-resource.html')
-rw-r--r--LayoutTests/http/tests/appcache/xhr-foreign-resource.html79
1 files changed, 79 insertions, 0 deletions
diff --git a/LayoutTests/http/tests/appcache/xhr-foreign-resource.html b/LayoutTests/http/tests/appcache/xhr-foreign-resource.html
new file mode 100644
index 0000000..df08d3f
--- /dev/null
+++ b/LayoutTests/http/tests/appcache/xhr-foreign-resource.html
@@ -0,0 +1,79 @@
+<html manifest="resources/xhr-foreign-resource.manifest">
+<body>
+<p>Test that a resource marked as foreign can still be loaded via XHR.</p>
+<p>Should say SUCCESS:</p>
+<div id=result></div>
+
+<script>
+if (window.layoutTestController) {
+ layoutTestController.dumpAsText();
+ layoutTestController.waitUntilDone();
+}
+
+function log(message)
+{
+ document.getElementById("result").innerHTML += message + "<br>";
+}
+
+function createFrame1()
+{
+ applicationCache.onnoupdate = function() { log("FAIL: Unexpected noupdate event") }
+ applicationCache.oncached = function() { log("FAIL: Unexpected cached event") }
+
+ var ifr = document.createElement("iframe");
+ ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html");
+ document.body.appendChild(ifr);
+}
+
+function createFrame2()
+{
+ // A copy that doesn't have its main resource in cache manifest.
+ var ifr = document.createElement("iframe");
+ ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html?");
+ document.body.appendChild(ifr);
+}
+
+applicationCache.onnoupdate = function() { createFrame1() }
+applicationCache.oncached = function() { createFrame1() }
+
+applicationCache.onupdateready = function() { log("FAIL: received unexpected updateready event") }
+applicationCache.onerror = function() { log("FAIL: received unexpected error event") }
+
+var hadErrorFromSubframe = false;
+var subframeMessagesReceived = 0;
+function frameMessageReceived(evt)
+{
+ ++subframeMessagesReceived;
+ if (evt.data != "SUCCESS")
+ hadErrorFromSubframe = true;
+ if (subframeMessagesReceived == 1)
+ setTimeout(createFrame2, 0);
+ else if (subframeMessagesReceived == 2)
+ test();
+}
+
+function test(evt)
+{
+ if (!hadErrorFromSubframe) {
+ // The subframe has a different cache, but it is also listed as a resource in main frame's
+ // manifest, so it should be loaded successfully despite being marked as foreign now.
+ try {
+ var req = new XMLHttpRequest;
+ req.open("GET", "resources/xhr-foreign-resource-frame.html", false);
+ req.send("");
+ log("SUCCESS");
+ } catch (ex) {
+ log (ex);
+ }
+ } else
+ log("FAIL: subframe didn't get a correct cache");
+
+ if (window.layoutTestController)
+ layoutTestController.notifyDone();
+}
+
+window.addEventListener("message", frameMessageReceived, false);
+
+</script>
+</body>
+</html>