child-src-blocked.sub.html (2264B)
1 <!DOCTYPE html> 2 <html> 3 4 <head> 5 <!-- Programmatically converted from a WebKit Reftest, please forgive resulting idiosyncracies.--> 6 <meta http-equiv="Content-Security-Policy" content="child-src 'none'; script-src 'self' 'unsafe-inline'; connect-src 'self';"> 7 <title>child-src-blocked</title> 8 <script src="/resources/testharness.js"></script> 9 <script src="/resources/testharnessreport.js"></script> 10 <script src='../support/logTest.sub.js?logs=["PASS IFrame %231 generated a load event.", "violated-directive=frame-src"]'></script> 11 <script> 12 window.addEventListener("message", function(event) { 13 alert_assert(event.data); 14 }, false); 15 16 window.addEventListener("securitypolicyviolation", function(e) { 17 log("violated-directive=" + e.violatedDirective); 18 }); 19 20 function alert_assert(msg) { 21 t_log.step(function() { 22 if (msg.match(/^FAIL/i)) { 23 assert_unreached(msg); 24 t_log.done(); 25 } 26 for (var i = 0; i < expected_alerts.length; i++) { 27 if (expected_alerts[i] == msg) { 28 assert_equals(expected_alerts[i], msg); 29 expected_alerts.splice(i, 1); 30 if (expected_alerts.length == 0) { 31 t_log.done(); 32 } 33 return; 34 } 35 } 36 assert_unreached('unexpected alert: ' + msg); 37 t_log.done(); 38 }); 39 } 40 41 </script> 42 <p> 43 IFrames blocked by CSP should generate a 'load', not 'error' event, regardless of blocked state. This means they appear to be normal cross-origin loads, thereby not leaking URL information directly to JS. 44 </p> 45 <script> 46 window.wasPostTestScriptParsed = true; 47 var loads = 0; 48 49 function loadEvent() { 50 loads++; 51 log("PASS " + "IFrame #" + loads + " generated a load event."); 52 } 53 54 </script> 55 </head> 56 57 <body> 58 <iframe src="/content-security-policy/support/postmessage-fail.html" onload="loadEvent()" onerror="log('FAIL')"></iframe> 59 <div id="log"></div> 60 </body> 61 62 </html>