test_bug803225.html (4979B)
1 <!DOCTYPE HTML> 2 <html> 3 <!-- 4 Testing Allowlist of Resource Scheme for Mixed Content Blocker 5 https://bugzilla.mozilla.org/show_bug.cgi?id=803225 6 --> 7 <head> 8 <meta charset="utf-8"> 9 <title>Tests for Bug 803225</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 const { AppConstants } = SpecialPowers.ChromeUtils.importESModule( 15 "resource://gre/modules/AppConstants.sys.mjs" 16 ); 17 18 var counter = 0; 19 var settings = [ [true, true], [true, false], [false, true], [false, false] ]; 20 21 var blockActive; 22 var blockDisplay; 23 24 //Cycle through 4 different preference settings. 25 function changePrefs(callback) { 26 let newPrefs = [ 27 ["security.all_resource_uri_content_accessible", true], // Temporarily allow content to access all resource:// URIs. 28 ["security.mixed_content.block_display_content", settings[counter][0]], 29 ["security.mixed_content.block_active_content", settings[counter][1]] 30 ]; 31 32 SpecialPowers.pushPrefEnv({"set": newPrefs}, function () { 33 blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); 34 blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 35 counter++; 36 callback(); 37 }); 38 } 39 40 var testsToRun = { 41 /* https - Tests already run as part of bug 62178. */ 42 about: false, 43 resource: false, 44 unsafe_about: false, 45 data_protocol: false, 46 javascript: false, 47 }; 48 49 if (AppConstants.platform !== "android") { 50 // WebSocket tests are not supported on Android Yet. Bug 1566168. 51 testsToRun.wss = false; 52 testsToRun.mailto = false; 53 } 54 55 function log(msg) { 56 document.getElementById("log").textContent += "\n" + msg; 57 } 58 59 function reloadFrame() { 60 document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/dom/security/test/mixedcontentblocker/file_main_bug803225.html"></iframe>'; 61 } 62 63 function checkTestsCompleted() { 64 for (var prop in testsToRun) { 65 // some test hasn't run yet so we're not done 66 if (!testsToRun[prop]) 67 return; 68 } 69 //if the testsToRun are all completed, change the pref and run the tests again until we have cycled through all the prefs. 70 if(counter < 4) { 71 for (var prop in testsToRun) { 72 testsToRun[prop] = false; 73 } 74 //call to change the preferences 75 changePrefs(function() { 76 log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); 77 reloadFrame(); 78 }); 79 } 80 else { 81 SimpleTest.finish(); 82 } 83 } 84 85 var firstTest = true; 86 87 function receiveMessage(event) { 88 if(firstTest) { 89 log("blockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); 90 firstTest = false; 91 } 92 93 log("test: "+event.data.test+", msg: "+event.data.msg + " logging message."); 94 // test that the load type matches the pref for this type of content 95 // (i.e. active vs. display) 96 97 switch(event.data.test) { 98 99 /* Mixed Script tests */ 100 case "about": 101 ok(event.data.msg == "resource with about protocol loaded", "resource with about protocol did not load"); 102 testsToRun.about = true; 103 break; 104 105 case "resource": 106 ok(event.data.msg == "resource with resource protocol loaded", "resource with resource protocol did not load"); 107 testsToRun.resource = true; 108 break; 109 110 case "unsafe_about": 111 // This one should not load 112 ok(event.data.msg == "resource with unsafe about protocol did not load", "resource with unsafe about protocol loaded"); 113 testsToRun.unsafe_about = true; 114 break; 115 116 case "data_protocol": 117 ok(event.data.msg == "resource with data protocol loaded", "resource with data protocol did not load"); 118 testsToRun.data_protocol = true; 119 break; 120 121 case "javascript": 122 ok(event.data.msg == "resource with javascript protocol loaded", "resource with javascript protocol did not load"); 123 testsToRun.javascript = true; 124 break; 125 126 case "wss": 127 ok(event.data.msg == "resource with wss protocol loaded", "resource with wss protocol did not load"); 128 testsToRun.wss = true; 129 break; 130 131 case "mailto": 132 ok(event.data.msg == "resource with mailto protocol loaded", "resource with mailto protocol did not load"); 133 testsToRun.mailto = true; 134 break; 135 } 136 checkTestsCompleted(); 137 } 138 139 function startTest() { 140 //Set the first set of settings (true, true) and increment the counter. 141 changePrefs(function() { 142 // listen for a messages from the mixed content test harness 143 window.addEventListener("message", receiveMessage); 144 145 reloadFrame(); 146 }); 147 } 148 149 SimpleTest.waitForExplicitFinish(); 150 </script> 151 </head> 152 153 <body onload='startTest()'> 154 <div id="framediv"></div> 155 <pre id="log"></pre> 156 </body> 157 </html>