1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/content/base/test/test_mixed_content_blocker_bug803225.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,148 @@ 1.4 +<!DOCTYPE HTML> 1.5 +<html> 1.6 +<!-- 1.7 +Testing Whitelist of Resource Schemed for Mixed Content Blocker 1.8 +https://bugzilla.mozilla.org/show_bug.cgi?id=803225 1.9 +--> 1.10 +<head> 1.11 + <meta charset="utf-8"> 1.12 + <title>Tests for Bug 803225</title> 1.13 + <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> 1.15 + 1.16 + <script> 1.17 + 1.18 + var origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); 1.19 + var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 1.20 + 1.21 + var counter = 0; 1.22 + var settings = [ [true, true], [true, false], [false, true], [false, false] ]; 1.23 + 1.24 + var blockActive; 1.25 + var blockDisplay; 1.26 + 1.27 + //Cycle through 4 different preference settings. 1.28 + function changePrefs(x) { 1.29 + SpecialPowers.setBoolPref("security.mixed_content.block_display_content", settings[x][0]); 1.30 + SpecialPowers.setBoolPref("security.mixed_content.block_active_content", settings[x][1]); 1.31 + blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); 1.32 + blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); 1.33 + } 1.34 + 1.35 + //Set the first set of settings (true, true) and increment the counter. 1.36 + changePrefs(counter); 1.37 + counter++; 1.38 + 1.39 + var testsToRun = { 1.40 + /* https - Tests already run as part of bug 62178. */ 1.41 + about: false, 1.42 + mozicon: false, 1.43 + resource: false, 1.44 + unsafe_about: false, 1.45 + data_protocol: false, 1.46 + javascript: false, 1.47 + mailto: false, 1.48 + wss: false, 1.49 + }; 1.50 + 1.51 + function log(msg) { 1.52 + document.getElementById("log").textContent += "\n" + msg; 1.53 + } 1.54 + 1.55 + function checkTestsCompleted() { 1.56 + for (var prop in testsToRun) { 1.57 + // some test hasn't run yet so we're not done 1.58 + if (!testsToRun[prop]) 1.59 + return; 1.60 + } 1.61 + //if the testsToRun are all completed, change the pref and run the tests again until we have cycled through all the prefs. 1.62 + if(counter < 4) { 1.63 + for (var prop in testsToRun) { 1.64 + testsToRun[prop] = false; 1.65 + } 1.66 + //call to change the preferences 1.67 + changePrefs(counter); 1.68 + counter++; 1.69 + log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); 1.70 + document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main_bug803225.html"></iframe>'; 1.71 + } 1.72 + else { 1.73 + //set the prefs back to what they were set to originally 1.74 + SpecialPowers.setBoolPref("security.mixed_content.block_display_content", origBlockDisplay); 1.75 + SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); 1.76 + SimpleTest.finish(); 1.77 + } 1.78 + } 1.79 + 1.80 + var firstTest = true; 1.81 + 1.82 + // listen for a messages from the mixed content test harness 1.83 + window.addEventListener("message", receiveMessage, false); 1.84 + function receiveMessage(event) { 1.85 + if(firstTest) { 1.86 + log("blockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); 1.87 + firstTest = false; 1.88 + } 1.89 + 1.90 + log("test: "+event.data.test+", msg: "+event.data.msg + " logging message."); 1.91 + // test that the load type matches the pref for this type of content 1.92 + // (i.e. active vs. display) 1.93 + 1.94 + switch(event.data.test) { 1.95 + 1.96 + /* Mixed Script tests */ 1.97 + case "about": 1.98 + ok(event.data.msg == "resource with about protocol loaded", "resource with about protocol did not load"); 1.99 + testsToRun["about"] = true; 1.100 + break; 1.101 + 1.102 + case "resource": 1.103 + ok(event.data.msg == "resource with resource protocol loaded", "resource with resource protocol did not load"); 1.104 + testsToRun["resource"] = true; 1.105 + break; 1.106 + 1.107 + case "mozicon": 1.108 + ok(event.data.msg == "resource with mozicon protocol loaded", "resource with mozicon protocol did not load"); 1.109 + testsToRun["mozicon"] = true; 1.110 + break; 1.111 + 1.112 + case "unsafe_about": 1.113 + // This one should not load 1.114 + ok(event.data.msg == "resource with unsafe about protocol did not load", "resource with unsafe about protocol loaded"); 1.115 + testsToRun["unsafe_about"] = true; 1.116 + break; 1.117 + 1.118 + case "data_protocol": 1.119 + ok(event.data.msg == "resource with data protocol loaded", "resource with data protocol did not load"); 1.120 + testsToRun["data_protocol"] = true; 1.121 + break; 1.122 + 1.123 + case "javascript": 1.124 + ok(event.data.msg == "resource with javascript protocol loaded", "resource with javascript protocol did not load"); 1.125 + testsToRun["javascript"] = true; 1.126 + break; 1.127 + 1.128 + case "wss": 1.129 + ok(event.data.msg == "resource with wss protocol loaded", "resource with wss protocol did not load"); 1.130 + testsToRun["wss"] = true; 1.131 + break; 1.132 + 1.133 + case "mailto": 1.134 + ok(event.data.msg == "resource with mailto protocol loaded", "resource with mailto protocol did not load"); 1.135 + testsToRun["mailto"] = true; 1.136 + break; 1.137 + } 1.138 + checkTestsCompleted(); 1.139 + } 1.140 + 1.141 + SimpleTest.waitForExplicitFinish(); 1.142 + </script> 1.143 +</head> 1.144 + 1.145 +<body> 1.146 + <div id="framediv"> 1.147 + <iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main_bug803225.html"></iframe> 1.148 + </div> 1.149 + <pre id="log"></pre> 1.150 +</body> 1.151 +</html>