Backed out changeset e4bf227a6224 (bug 1801501) for causing mochitest plain failures...
[gecko.git] / dom / security / test / mixedcontentblocker / test_bug803225.html
blob87b372adf7f79a55aa3c6daa846fc559e3d0e433
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"/>
13 <script>
14 const { AppConstants } = SpecialPowers.ChromeUtils.importESModule(
15 "resource://gre/modules/AppConstants.sys.mjs"
18 var counter = 0;
19 var settings = [ [true, true], [true, false], [false, true], [false, false] ];
21 var blockActive;
22 var blockDisplay;
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]]
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 });
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,
49 if (AppConstants.platform !== "android") {
50 // WebSocket tests are not supported on Android Yet. Bug 1566168.
51 testsToRun.wss = false;
52 testsToRun.mailto = false;
55 function log(msg) {
56 document.getElementById("log").textContent += "\n" + msg;
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>';
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;
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;
74 //call to change the preferences
75 changePrefs(function() {
76 log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+".");
77 reloadFrame();
78 });
80 else {
81 SimpleTest.finish();
85 var firstTest = true;
87 function receiveMessage(event) {
88 if(firstTest) {
89 log("blockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+".");
90 firstTest = false;
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)
97 switch(event.data.test) {
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;
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;
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;
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;
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;
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;
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;
136 checkTestsCompleted();
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);
145 reloadFrame();
149 SimpleTest.waitForExplicitFinish();
150 </script>
151 </head>
153 <body onload='startTest()'>
154 <div id="framediv"></div>
155 <pre id="log"></pre>
156 </body>
157 </html>