test_iframe_sandbox_popups.html (2934B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 https://bugzilla.mozilla.org/show_bug.cgi?id=766282 5 implement allow-popups directive for iframe sandbox 6 --> 7 <head> 8 <meta charset="utf-8"> 9 <title>Tests for Bug 766282</title> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <script src="/tests/SimpleTest/EventUtils.js"></script> 12 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 13 </head> 14 <script type="application/javascript"> 15 16 SimpleTest.waitForExplicitFinish(); 17 18 // a postMessage handler that is used by sandboxed iframes without 19 // 'allow-same-origin' to communicate pass/fail back to this main page. 20 // it expects to be called with an object like {ok: true/false, desc: 21 // <description of the test> which it then forwards to ok() 22 window.addEventListener("message", receiveMessage); 23 24 function receiveMessage(event) 25 { 26 ok_wrapper(event.data.ok, event.data.desc); 27 } 28 29 var completedTests = 0; 30 var passedTests = 0; 31 32 function ok_wrapper(result, desc) { 33 ok(result, desc); 34 35 completedTests++; 36 37 if (result) { 38 passedTests++; 39 } 40 41 if (completedTests == 3) { 42 is(passedTests, completedTests, "There are " + completedTests + " popups tests that should pass"); 43 SimpleTest.finish(); 44 } 45 } 46 47 function doTest() { 48 // passes if good 49 // 1) Test that a sandboxed iframe with "allow-popups" can open a new window using the target.attribute. 50 // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin". 51 // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok() 52 // function that calls window.parent.ok_wrapper. 53 54 // passes if good 55 // 2) Test that a sandboxed iframe with "allow-popups" can open a new window using window.open. 56 // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin". 57 // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok() 58 // function that calls window.parent.ok_wrapper. 59 60 // passes if good, fails if bad 61 // 3) Test that a sandboxed iframe with "allow-popups" can open a new window using the target.attribute 62 // for a non-existing browsing context (BC766282). 63 // This is done via file_iframe_sandbox_h_if1.html which is sandboxed with "allow-popups allow-scripts allow-same-origin". 64 // The window it attempts to open calls window.opener.ok(true, ...) and file_iframe_h_if1.html has an ok() 65 // function that calls window.parent.ok_wrapper. 66 } 67 68 addLoadEvent(doTest); 69 70 </script> 71 <body> 72 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=766282">Mozilla Bug 766282</a> - implement allow-popups directive for iframe sandbox 73 <p id="display"></p> 74 <div id="content"> 75 <iframe sandbox="allow-popups allow-same-origin allow-scripts" id="if1" src="file_iframe_sandbox_h_if1.html" height="10" width="10"></iframe> 76 </div> 77 </body> 78 </html>