test_frameNavigation.html (4623B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Tests for Mixed Content Blocker 5 https://bugzilla.mozilla.org/show_bug.cgi?id=840388 6 --> 7 <head> 8 <meta charset="utf-8"> 9 <title>Tests for Bug 840388</title> 10 <script src="/tests/SimpleTest/SimpleTest.js"></script> 11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 12 13 <script> 14 var counter = 0; 15 var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 16 17 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", true); 18 var blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 19 20 21 var testsToRunInsecure = { 22 insecurePage_navigate_child: false, 23 insecurePage_navigate_grandchild: false, 24 }; 25 26 var testsToRunSecure = { 27 securePage_navigate_child: false, 28 blankTarget: false, 29 }; 30 31 function log(msg) { 32 document.getElementById("log").textContent += "\n" + msg; 33 } 34 35 var secureTestsStarted = false; 36 async function checkTestsCompleted() { 37 for (var prop in testsToRunInsecure) { 38 // some test hasn't run yet so we're not done 39 if (!testsToRunInsecure[prop]) 40 return; 41 } 42 // If we are here, all the insecure tests have run. 43 // If we haven't changed the iframe to run the secure tests, change it now. 44 if (!secureTestsStarted) { 45 document.getElementById('testing_frame').src = "https://example.com/tests/dom/security/test/mixedcontentblocker/file_frameNavigation_secure.html"; 46 secureTestsStarted = true; 47 } 48 for (var prop in testsToRunSecure) { 49 // some test hasn't run yet so we're not done 50 if (!testsToRunSecure[prop]) 51 return; 52 } 53 //if the secure and insecure testsToRun are all completed, change the block mixed active content pref and run the tests again. 54 if(counter < 1) { 55 for (var prop in testsToRunSecure) { 56 testsToRunSecure[prop] = false; 57 } 58 for (var prop in testsToRunInsecure) { 59 testsToRunInsecure[prop] = false; 60 } 61 //call to change the preferences 62 counter++; 63 await SpecialPowers.setBoolPref("security.mixed_content.block_active_content", false); 64 blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 65 log("blockActive set to "+blockActive+"."); 66 secureTestsStarted = false; 67 document.getElementById('framediv').innerHTML = '<iframe src="http://example.com/tests/dom/security/test/mixedcontentblocker/file_frameNavigation.html" id="testing_frame"></iframe>'; 68 } 69 else { 70 //set the prefs back to what they were set to originally 71 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); 72 SimpleTest.finish(); 73 } 74 } 75 76 var firstTestDebugMessage = true; 77 78 // listen for a messages from the mixed content test harness 79 window.addEventListener("message", receiveMessage); 80 function receiveMessage(event) { 81 if(firstTestDebugMessage) { 82 log("blockActive set to "+blockActive); 83 firstTestDebugMessage = false; 84 } 85 86 log("test: "+event.data.test+", msg: "+event.data.msg + "."); 87 // test that the load type matches the pref for this type of content 88 // (i.e. active vs. display) 89 90 switch(event.data.test) { 91 92 case "insecurePage_navigate_child": 93 is(event.data.msg, "navigated to insecure iframe on insecure page", "navigating to insecure iframe blocked on insecure page"); 94 testsToRunInsecure.insecurePage_navigate_child = true; 95 break; 96 97 case "insecurePage_navigate_grandchild": 98 is(event.data.msg, "navigated to insecure grandchild iframe on insecure page", "navigating to insecure grandchild iframe blocked on insecure page"); 99 testsToRunInsecure.insecurePage_navigate_grandchild = true; 100 break; 101 102 case "securePage_navigate_child": 103 ok(blockActive == (event.data.msg == "navigating to insecure iframe blocked on secure page"), "navigated to insecure iframe on secure page"); 104 testsToRunSecure.securePage_navigate_child = true; 105 break; 106 107 case "blankTarget": 108 is(event.data.msg, "opened an http link with target=_blank from a secure page", "couldn't open an http link in a new window from a secure page"); 109 testsToRunSecure.blankTarget = true; 110 break; 111 112 } 113 checkTestsCompleted(); 114 } 115 116 SimpleTest.waitForExplicitFinish(); 117 </script> 118 </head> 119 120 <body> 121 <div id="framediv"> 122 <iframe src="http://example.com/tests/dom/security/test/mixedcontentblocker/file_frameNavigation.html" id="testing_frame"></iframe> 123 </div> 124 125 <pre id="log"></pre> 126 </body> 127 </html>