|
1 <!DOCTYPE HTML> |
|
2 <html> |
|
3 <!-- |
|
4 Tests for Mixed Content Blocker |
|
5 https://bugzilla.mozilla.org/show_bug.cgi?id=62178 |
|
6 --> |
|
7 <head> |
|
8 <meta charset="utf-8"> |
|
9 <title>Tests for Bug 62178</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 var ph = SpecialPowers.Cc["@mozilla.org/plugin/host;1"] |
|
15 .getService(SpecialPowers.Ci.nsIPluginHost); |
|
16 var tags = ph.getPluginTags(); |
|
17 for (var tag of tags) { |
|
18 if (tag.name == "Test Plug-in") { |
|
19 tag.enabledState = SpecialPowers.Ci.nsIPluginTag.STATE_ENABLED;; |
|
20 } |
|
21 } |
|
22 |
|
23 |
|
24 var origBlockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); |
|
25 var origBlockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
|
26 |
|
27 var counter = 0; |
|
28 var settings = [ [true, true], [true, false], [false, true], [false, false] ]; |
|
29 |
|
30 var blockActive; |
|
31 var blockDisplay; |
|
32 |
|
33 //Cycle through 4 different preference settings. |
|
34 function changePrefs(x) { |
|
35 SpecialPowers.setBoolPref("security.mixed_content.block_display_content", settings[x][0]); |
|
36 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", settings[x][1]); |
|
37 blockDisplay = SpecialPowers.getBoolPref("security.mixed_content.block_display_content"); |
|
38 blockActive = SpecialPowers.getBoolPref("security.mixed_content.block_active_content"); |
|
39 } |
|
40 |
|
41 //Set the first set of settings (true, true) and increment the counter. |
|
42 changePrefs(counter); |
|
43 counter++; |
|
44 |
|
45 var testsToRun = { |
|
46 iframe: false, |
|
47 image: false, |
|
48 script: false, |
|
49 stylesheet: false, |
|
50 object: false, |
|
51 media: false, |
|
52 xhr: false, |
|
53 }; |
|
54 |
|
55 function log(msg) { |
|
56 document.getElementById("log").textContent += "\n" + msg; |
|
57 } |
|
58 |
|
59 function checkTestsCompleted() { |
|
60 for (var prop in testsToRun) { |
|
61 // some test hasn't run yet so we're not done |
|
62 if (!testsToRun[prop]) |
|
63 return; |
|
64 } |
|
65 //if the testsToRun are all completed, chnage the pref and run the tests again until we have cycled through all the prefs. |
|
66 if(counter < 4) { |
|
67 for (var prop in testsToRun) { |
|
68 testsToRun[prop] = false; |
|
69 } |
|
70 //call to change the preferences |
|
71 changePrefs(counter); |
|
72 counter++; |
|
73 log("\nblockDisplay set to "+blockDisplay+", blockActive set to "+blockActive+"."); |
|
74 document.getElementById('framediv').innerHTML = '<iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main.html"></iframe>'; |
|
75 } |
|
76 else { |
|
77 //set the prefs back to what they were set to originally |
|
78 SpecialPowers.setBoolPref("security.mixed_content.block_display_content", origBlockDisplay); |
|
79 SpecialPowers.setBoolPref("security.mixed_content.block_active_content", origBlockActive); |
|
80 SimpleTest.finish(); |
|
81 } |
|
82 } |
|
83 |
|
84 var firstTest = true; |
|
85 |
|
86 // listen for a messages from the mixed content test harness |
|
87 window.addEventListener("message", receiveMessage, false); |
|
88 function receiveMessage(event) { |
|
89 if(firstTest) { |
|
90 log("blockActive set to "+blockActive+", blockDisplay set to "+blockDisplay+"."); |
|
91 firstTest = false; |
|
92 } |
|
93 |
|
94 log("test: "+event.data.test+", msg: "+event.data.msg + " logging message."); |
|
95 // test that the load type matches the pref for this type of content |
|
96 // (i.e. active vs. display) |
|
97 |
|
98 switch(event.data.test) { |
|
99 |
|
100 /* Mixed Script tests */ |
|
101 case "iframe": |
|
102 ok(blockActive == (event.data.msg == "insecure iframe blocked"), "iframe did not follow block_active_content pref"); |
|
103 testsToRun["iframe"] = true; |
|
104 break; |
|
105 |
|
106 case "object": |
|
107 ok(blockActive == (event.data.msg == "insecure object blocked"), "object did not follow block_active_content pref"); |
|
108 testsToRun["object"] = true; |
|
109 break; |
|
110 |
|
111 case "script": |
|
112 ok(blockActive == (event.data.msg == "insecure script blocked"), "script did not follow block_active_content pref"); |
|
113 testsToRun["script"] = true; |
|
114 break; |
|
115 |
|
116 case "stylesheet": |
|
117 ok(blockActive == (event.data.msg == "insecure stylesheet blocked"), "stylesheet did not follow block_active_content pref"); |
|
118 testsToRun["stylesheet"] = true; |
|
119 break; |
|
120 |
|
121 case "xhr": |
|
122 ok(blockActive == (event.data.msg == "insecure xhr blocked"), "xhr did not follow block_active_content pref"); |
|
123 testsToRun["xhr"] = true; |
|
124 break; |
|
125 |
|
126 /* Mixed Display tests */ |
|
127 case "image": |
|
128 //test that the image load matches the pref for dipslay content |
|
129 ok(blockDisplay == (event.data.msg == "insecure image blocked"), "image did not follow block_display_content pref"); |
|
130 testsToRun["image"] = true; |
|
131 break; |
|
132 |
|
133 case "media": |
|
134 ok(blockDisplay == (event.data.msg == "insecure media blocked"), "media did not follow block_display_content pref"); |
|
135 testsToRun["media"] = true; |
|
136 break; |
|
137 } |
|
138 checkTestsCompleted(); |
|
139 } |
|
140 |
|
141 SimpleTest.waitForExplicitFinish(); |
|
142 </script> |
|
143 </head> |
|
144 |
|
145 <body> |
|
146 <div id="framediv"> |
|
147 <iframe id="testHarness" src="https://example.com/tests/content/base/test/file_mixed_content_main.html"></iframe> |
|
148 </div> |
|
149 <pre id="log"></pre> |
|
150 </body> |
|
151 </html> |