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> 6 7 <script> 8 if (window.layoutTestController) { 9 layoutTestController.dumpAsText(); 10 layoutTestController.waitUntilDone(); 11 } 12 13 function log(message) 14 { 15 document.getElementById("result").innerHTML += message + "<br>"; 16 } 17 18 function createFrame1() 19 { 20 applicationCache.onnoupdate = function() { log("FAIL: Unexpected noupdate event") } 21 applicationCache.oncached = function() { log("FAIL: Unexpected cached event") } 22 23 var ifr = document.createElement("iframe"); 24 ifr.setAttribute("src", "resources/xhr-foreign-resource-frame.html"); 25 document.body.appendChild(ifr); 26 } 27 28 function createFrame2() 29 { 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); 34 } 35 36 applicationCache.onnoupdate = function() { createFrame1() } 37 applicationCache.oncached = function() { createFrame1() } 38 39 applicationCache.onupdateready = function() { log("FAIL: received unexpected updateready event") } 40 applicationCache.onerror = function() { log("FAIL: received unexpected error event") } 41 42 var hadErrorFromSubframe = false; 43 var subframeMessagesReceived = 0; 44 function frameMessageReceived(evt) 45 { 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(); 53 } 54 55 function test(evt) 56 { 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); 67 } 68 } else 69 log("FAIL: subframe didn't get a correct cache"); 70 71 if (window.layoutTestController) 72 layoutTestController.notifyDone(); 73 } 74 75 window.addEventListener("message", frameMessageReceived, false); 76 77 </script> 78 </body> 79 </html> 80