test_blob_uri_blocks_modals.html (2206B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <meta charset="utf-8"> 5 <title>Bug 1432170 - Block alert box and new window open as per the sandbox 6 allow-scripts CSP</title> 7 <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"> 8 </script> 9 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 10 </head> 11 <body> 12 <iframe style="width:100%;" id="testframe"></iframe> 13 <script> 14 15 /* Description of the test: 16 * We apply the sanbox allow-scripts CSP to the blob iframe and check 17 * if the alert box and new window open is blocked correctly by the CSP. 18 */ 19 var testsToRun = { 20 block_window_open_test: false, 21 block_alert_test: false, 22 block_top_nav_alert_test: false, 23 }; 24 25 SimpleTest.waitForExplicitFinish(); 26 SimpleTest.requestFlakyTimeout("have to test that alert dialogue is blocked"); 27 28 window.addEventListener("message", receiveMessage); 29 function receiveMessage(event) { 30 switch (event.data.test) { 31 case "block_window_open_test": 32 testsToRun.block_window_open_test = true; 33 break; 34 case "block_alert_test": 35 is(event.data.msg, "alert blocked by CSP", "alert blocked by CSP"); 36 testsToRun.block_alert_test = true; 37 break; 38 case "block_top_nav_alert_test": 39 testsToRun.block_top_nav_alert_test = true; 40 break; 41 } 42 } 43 44 var w; 45 document.getElementById("testframe").src = "file_blob_uri_blocks_modals.html"; 46 w = window.open("file_blob_top_nav_block_modals.html"); 47 48 49 // If alert window is not blocked by CSP then event message is not recieved and 50 // test fails after setTimeout interval of 1 second. 51 setTimeout(function () { 52 is(testsToRun.block_top_nav_alert_test, true, 53 "blob top nav alert should be blocked by CSP"); 54 testsToRun.block_top_nav_alert_test = true; 55 is(testsToRun.block_alert_test, true, 56 "alert should be blocked by CSP"); 57 testsToRun.block_alert_test = true; 58 checkTestsCompleted(); 59 },1000); 60 61 function checkTestsCompleted() { 62 for (var prop in testsToRun) { 63 // some test hasn't run yet so we're not done 64 if (!testsToRun[prop]) { 65 return; 66 } 67 } 68 window.removeEventListener("message", receiveMessage); 69 w.close(); 70 SimpleTest.finish(); 71 } 72 73 </script> 74 </body> 75 </html>