file_child-src_iframe.html (1973B)
1 <!DOCTYPE HTML> 2 <html> 3 <head> 4 <title>Bug 1045891</title> 5 </head> 6 <body> 7 <iframe id="testframe"> </iframe> 8 <script type="text/javascript"> 9 page_id = window.location.hash.substring(1); 10 11 function executeTest(ev) { 12 testframe = document.getElementById('testframe'); 13 testframe.contentWindow.postMessage({id:page_id, message:"execute"}, 'http://mochi.test:8888'); 14 } 15 16 function reportError(ev) { 17 window.parent.postMessage({id:page_id, message:"blocked"}, 'http://mochi.test:8888'); 18 cleanup(); 19 } 20 21 function recvMessage(ev) { 22 if (ev.data.id == page_id) { 23 window.parent.postMessage({id:ev.data.id, message:ev.data.message}, 'http://mochi.test:8888'); 24 cleanup(); 25 } 26 } 27 28 function cleanup() { 29 testframe = document.getElementById('testframe'); 30 window.removeEventListener('message', recvMessage); 31 testframe.removeEventListener('load', executeTest); 32 testframe.removeEventListener('error', reportError); 33 } 34 35 36 window.addEventListener('message', recvMessage); 37 38 try { 39 // Please note that file_testserver.sjs?foo does not return a response. 40 // For testing purposes this is not necessary because we only want to check 41 // whether CSP allows or blocks the load. 42 src = "file_testserver.sjs"; 43 src += "?file=" + escape("tests/dom/security/test/csp/file_child-src_inner_frame.html"); 44 src += "#" + escape(page_id); 45 testframe = document.getElementById('testframe'); 46 47 testframe.addEventListener('load', executeTest); 48 testframe.addEventListener('error', reportError); 49 50 testframe.src = src; 51 } 52 catch (e) { 53 if (e.message.match(/Failed to load script/)) { 54 window.parent.postMessage({id:page_id, message:"blocked"}, 'http://mochi.test:8888'); 55 } else { 56 window.parent.postMessage({id:page_id, message:"exception"}, 'http://mochi.test:8888'); 57 } 58 } 59 </script> 60 </body> 61 </html>