4 Testing Allowlist of Resource Scheme for Mixed Content Blocker
5 https://bugzilla.mozilla.org/show_bug.cgi?id=803225
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"/>
14 const { AppConstants
} = SpecialPowers
.ChromeUtils
.importESModule(
15 "resource://gre/modules/AppConstants.sys.mjs"
19 var settings
= [ [true, true], [true, false], [false, true], [false, false] ];
24 //Cycle through 4 different preference settings.
25 function changePrefs(callback
) {
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");
41 /* https - Tests already run as part of bug 62178. */
49 if (AppConstants
.platform
!== "android") {
50 // WebSocket tests are not supported on Android Yet. Bug 1566168.
51 testsToRun
.wss
= false;
52 testsToRun
.mailto
= false;
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
])
69 //if the testsToRun are all completed, change the pref and run the tests again until we have cycled through all the prefs.
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
+".");
87 function receiveMessage(event
) {
89 log("blockDisplay set to "+blockDisplay
+", blockActive set to "+blockActive
+".");
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 */
101 ok(event
.data
.msg
== "resource with about protocol loaded", "resource with about protocol did not load");
102 testsToRun
.about
= true;
106 ok(event
.data
.msg
== "resource with resource protocol loaded", "resource with resource protocol did not load");
107 testsToRun
.resource
= true;
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;
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;
122 ok(event
.data
.msg
== "resource with javascript protocol loaded", "resource with javascript protocol did not load");
123 testsToRun
.javascript
= true;
127 ok(event
.data
.msg
== "resource with wss protocol loaded", "resource with wss protocol did not load");
128 testsToRun
.wss
= true;
132 ok(event
.data
.msg
== "resource with mailto protocol loaded", "resource with mailto protocol did not load");
133 testsToRun
.mailto
= true;
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
);
149 SimpleTest
.waitForExplicitFinish();
153 <body onload='startTest()'
>
154 <div id=
"framediv"></div>