test_iframe_sandbox_refresh.html (2862B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=1156059 5 --> 6 <head> 7 <meta charset="utf-8"> 8 <title>Tests for Bug 1156059</title> 9 <script src="/tests/SimpleTest/SimpleTest.js"></script> 10 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 11 <script type="application/javascript"> 12 13 // Tests for Bug 1156059 14 // See ok messages in iframes for test cases. 15 16 SimpleTest.waitForExplicitFinish(); 17 SimpleTest.requestFlakyTimeout("We cannot detect when the sandbox blocks the META REFRESH, so we need to allow a reasonable amount of time for them to fail."); 18 19 var testCases = [ 20 { 21 desc: "Meta refresh without allow-scripts should be ignored.", 22 numberOfLoads: 0, 23 numberOfLoadsExpected: 1 24 }, 25 { 26 desc: "Meta refresh check should be case insensitive.", 27 numberOfLoads: 0, 28 numberOfLoadsExpected: 1 29 }, 30 { 31 desc: "Meta refresh with allow-scripts should work.", 32 numberOfLoads: 0, 33 numberOfLoadsExpected: 2 34 }, 35 { 36 desc: "Refresh HTTP headers should not be affected by sandbox.", 37 numberOfLoads: 0, 38 numberOfLoadsExpected: 2 39 } 40 ]; 41 42 var totalLoads = 0; 43 var totalLoadsExpected = testCases.reduce(function(partialSum, testCase) { 44 return partialSum + testCase.numberOfLoadsExpected; 45 }, 0); 46 47 function processLoad(testCaseIndex) { 48 testCases[testCaseIndex].numberOfLoads++; 49 50 if (++totalLoads == totalLoadsExpected) { 51 // Give the tests that should block the refresh a bit of extra time to 52 // fail. The worst that could happen here is that we get a false pass. 53 window.setTimeout(processResults, 500); 54 } 55 } 56 57 function processResults() { 58 testCases.forEach(function(testCase, index) { 59 var msg = "Test Case " + index + ": " + testCase.desc; 60 is(testCase.numberOfLoads, testCase.numberOfLoadsExpected, msg); 61 }); 62 63 SimpleTest.finish(); 64 } 65 66 </script> 67 </head> 68 <body> 69 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=1156059">Mozilla Bug 1156059</a> 70 <p id="display"></p> 71 <div id="content" style="display: none"> 72 73 <iframe 74 onload="processLoad(0)" 75 srcdoc="<meta http-equiv='refresh' content='0; url=data:text/html,Refreshed'>" 76 sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-top-navigation" 77 ></iframe> 78 79 <iframe 80 onload="processLoad(1)" 81 srcdoc="<meta http-equiv='rEfReSh' content='0; url=data:text/html,Refreshed'>" 82 sandbox="allow-forms allow-pointer-lock allow-popups allow-same-origin allow-top-navigation" 83 ></iframe> 84 85 <iframe 86 onload="processLoad(2)" 87 srcdoc="<meta http-equiv='refresh' content='0; url=data:text/html,Refreshed'>" 88 sandbox="allow-scripts" 89 ></iframe> 90 91 <iframe 92 onload="processLoad(3)" 93 src="file_iframe_sandbox_refresh.html" 94 sandbox 95 ></iframe> 96 97 </div> 98 <pre id="test"> 99 </pre> 100 </body> 101 </html>