|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 Testing Whitelist of Resource Schemed 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 type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/> |
|
12 |
|
13 <script> |
|
14 |
|
15 var origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); |
|
16 var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
|
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(x) { |
|
26 SpecialPowers.setBoolPref("security.mixed_content.block_display_content", settings[x][0]); |
|
27 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", settings[x][1]); |
|
28 blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); |
|
29 blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
|
30 } |
|
31 |
|
32 //Set the first set of settings (true, true) and increment the counter. |
|
33 changePrefs(counter); |
|
34 counter++; |
|
35 |
|
36 var testsToRun = { |
|
37 /* https - Tests already run as part of bug 62178. */ |
|
38 about: false, |
|
39 mozicon: false, |
|
40 resource: false, |
|
41 unsafe_about: false, |
|
42 data_protocol: false, |
|
43 javascript: false, |
|
44 mailto: false, |
|
45 wss: false, |
|
46 }; |
|
47 |
|
48 function log(msg) { |
|
49 document.getElementById("log").textContent += "\n" + msg; |
|
50 } |
|
51 |
|
52 function checkTestsCompleted() { |
|
53 for (var prop in testsToRun) { |
|
54 // some test hasn't run yet so we're not done |
|
55 if (!testsToRun[prop]) |
|
56 return; |
|
57 } |
|
58 //if the testsToRun are all completed, change the pref and run the tests again until we have cycled through all the prefs. |
|
59 if(counter < 4) { |
|
60 for (var prop in testsToRun) { |
|
61 testsToRun[prop] = false; |
|
62 } |
|
63 //call to change the preferences |
|
64 changePrefs(counter); |
|
65 counter++; |
|
66 log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); |
|
67 document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main_bug803225.html"></iframe>'; |
|
68 } |
|
69 else { |
|
70 //set the prefs back to what they were set to originally |
|
71 SpecialPowers.setBoolPref("security.mixed_content.block_display_content", origBlockDisplay); |
|
72 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); |
|
73 SimpleTest.finish(); |
|
74 } |
|
75 } |
|
76 |
|
77 var firstTest = true; |
|
78 |
|
79 // listen for a messages from the mixed content test harness |
|
80 window.addEventListener("message", receiveMessage, false); |
|
81 function receiveMessage(event) { |
|
82 if(firstTest) { |
|
83 log("blockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); |
|
84 firstTest = false; |
|
85 } |
|
86 |
|
87 log("test: "+event.data.test+", msg: "+event.data.msg + " logging message."); |
|
88 // test that the load type matches the pref for this type of content |
|
89 // (i.e. active vs. display) |
|
90 |
|
91 switch(event.data.test) { |
|
92 |
|
93 /* Mixed Script tests */ |
|
94 case "about": |
|
95 ok(event.data.msg == "resource with about protocol loaded", "resource with about protocol did not load"); |
|
96 testsToRun["about"] = true; |
|
97 break; |
|
98 |
|
99 case "resource": |
|
100 ok(event.data.msg == "resource with resource protocol loaded", "resource with resource protocol did not load"); |
|
101 testsToRun["resource"] = true; |
|
102 break; |
|
103 |
|
104 case "mozicon": |
|
105 ok(event.data.msg == "resource with mozicon protocol loaded", "resource with mozicon protocol did not load"); |
|
106 testsToRun["mozicon"] = true; |
|
107 break; |
|
108 |
|
109 case "unsafe_about": |
|
110 // This one should not load |
|
111 ok(event.data.msg == "resource with unsafe about protocol did not load", "resource with unsafe about protocol loaded"); |
|
112 testsToRun["unsafe_about"] = true; |
|
113 break; |
|
114 |
|
115 case "data_protocol": |
|
116 ok(event.data.msg == "resource with data protocol loaded", "resource with data protocol did not load"); |
|
117 testsToRun["data_protocol"] = true; |
|
118 break; |
|
119 |
|
120 case "javascript": |
|
121 ok(event.data.msg == "resource with javascript protocol loaded", "resource with javascript protocol did not load"); |
|
122 testsToRun["javascript"] = true; |
|
123 break; |
|
124 |
|
125 case "wss": |
|
126 ok(event.data.msg == "resource with wss protocol loaded", "resource with wss protocol did not load"); |
|
127 testsToRun["wss"] = true; |
|
128 break; |
|
129 |
|
130 case "mailto": |
|
131 ok(event.data.msg == "resource with mailto protocol loaded", "resource with mailto protocol did not load"); |
|
132 testsToRun["mailto"] = true; |
|
133 break; |
|
134 } |
|
135 checkTestsCompleted(); |
|
136 } |
|
137 |
|
138 SimpleTest.waitForExplicitFinish(); |
|
139 </script> |
|
140 </head> |
|
141 |
|
142 <body> |
|
143 <div id="framediv"> |
|
144 <iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main_bug803225.html"></iframe> |
|
145 </div> |
|
146 <pre id="log"></pre> |
|
147 </body> |
|
148 </html> |