Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
1 <!DOCTYPE HTML>
2 <html>
3 <!--
4 https://bugzilla.mozilla.org/show_bug.cgi?id=391728
5 -->
6 <head>
7 <title>Test for Bug 391728</title>
8 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
9 <script type="text/javascript" src="chrome://mochikit/content/tests/SimpleTest/ChromeUtils.js"></script>
10 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
11 </head>
12 <body>
13 <a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=391728">Mozilla Bug 391728</a>
14 <p id="display"></p>
15 <div id="content">
16 <iframe id="testframe" width="150" height="250" src="about:blank"></iframe>
17 </div>
18 <pre id="test">
19 <script class="testbody" type="text/javascript">
20 const gHttpTestRoot = location.toString().replace("chrome://mochitests/content/", "http://127.0.0.1:8888/").split(/\//).slice(0, -1).join('/') + '/';
22 Components.utils.import("resource://gre/modules/Services.jsm");
24 /** Test for Bug 391728 **/
25 // Plugins that should dispatch error events and have the pseudo classes set
26 const PLUGIN_COUNT = 11;
27 // Plugins that should neither dispatch error events or have the pseudo classes set
28 const FALLBACK_COUNT = 5;
29 const OBJLC = Components.interfaces.nsIObjectLoadingContent;
31 var gNextTest = null;
32 var gUnknown = [];
33 var gBlocked = [];
34 var gDisabled = [];
36 function plugin_binding_attached(event) {
37 var plugin = event.target;
38 plugin instanceof OBJLC;
39 switch (SpecialPowers.wrap(plugin).pluginFallbackType) {
40 case OBJLC.PLUGIN_DISABLED:
41 gDisabled.push(plugin.id);
42 break;
43 case OBJLC.PLUGIN_BLOCKLISTED:
44 gBlocked.push(plugin.id);
45 break;
46 case OBJLC.PLUGIN_UNSUPPORTED:
47 gUnknown.push(plugin.id);
48 break;
49 }
50 }
52 function init_test() {
53 if (!PluginUtils.withTestPlugin(start_test))
54 SimpleTest.finish();
55 }
57 function updateBlocklist(aCallback) {
58 var blocklistNotifier = Components.classes["@mozilla.org/extensions/blocklist;1"]
59 .getService(Components.interfaces.nsITimerCallback);
60 var observer = function() {
61 Services.obs.removeObserver(observer, "blocklist-updated");
62 SimpleTest.executeSoon(aCallback);
63 };
64 Services.obs.addObserver(observer, "blocklist-updated", false);
65 blocklistNotifier.notify(null);
66 }
68 var _originalBlocklistURL = null;
69 function setAndUpdateBlocklist(aURL, aCallback) {
70 info("Setting blocklist to " + aURL);
71 if (!_originalBlocklistURL) {
72 _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
73 }
74 Services.prefs.setCharPref("extensions.blocklist.url", aURL);
75 updateBlocklist(aCallback);
76 }
78 function resetBlocklist() {
79 info("resetting blocklist URL to " + _originalBlocklistURL);
80 Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL);
81 }
83 function start_test(plugin) {
84 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
86 is(plugin.description, "Plug-in for testing purposes.\u2122 " +
87 "(\u0939\u093f\u0928\u094d\u0926\u0940 " +
88 "\u4e2d\u6587 " +
89 "\u0627\u0644\u0639\u0631\u0628\u064a\u0629)",
90 "Test plugin had an incorrect description");
91 is(plugin.version, "1.0.0.0", "Test plugin had an incorrect version");
92 ok(!plugin.disabled, "Test plugin should not be disabled");
93 ok(!plugin.blocklisted, "Test plugin should not be blocklisted");
95 var frame = document.getElementById("testframe");
96 frame.addEventListener("load", frame_loaded, true);
97 load_frame(test_normal, "file_bug391728");
98 }
100 function finish_test(plugin) {
101 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
102 resetBlocklist();
103 plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
104 SimpleTest.finish();
105 }
107 function load_frame(nextTest, file) {
108 gNextTest = nextTest;
109 gDisabled = [];
110 gUnknown = [];
111 gBlocked = [];
112 var frame = document.getElementById("testframe");
113 frame.src = file + ".html?" + Math.random();
114 }
116 function next_text() {
117 PluginUtils.withTestPlugin(gNextTest);
118 }
120 function frame_loaded() {
121 // We must delay to wait for the plugin sources to be loaded :(
122 setTimeout(next_text, 500);
123 }
125 function test_style(expected) {
126 var frame = document.getElementById("testframe");
127 for (var i = 1; i <= PLUGIN_COUNT; i++) {
128 var tag = frame.contentDocument.getElementById("plugin" + i);
129 ok(tag, "Plugin " + i + " did not exist");
130 var style = frame.contentWindow.getComputedStyle(tag, null);
131 is(style.borderTopStyle, expected, "Plugin " + i + " had an incorrect border style");
132 }
133 for (i = 1; i <= FALLBACK_COUNT; i++) {
134 var tag = frame.contentDocument.getElementById("fallback" + i);
135 ok(tag, "Fallback plugin " + i + " did not exist");
136 var style = frame.contentWindow.getComputedStyle(tag, null);
137 is(style.borderTopStyle, "solid", "Fallback plugin " + i + " had an incorrect border style");
138 }
139 }
141 function test_list(list) {
142 for (var i = 1; i <= PLUGIN_COUNT; i++) {
143 ok(list.indexOf("plugin" + i) >= 0, "Plugin " + i + " did not send the event");
144 }
145 for (i = 1; i <= FALLBACK_COUNT; i++) {
146 ok(list.indexOf("fallback" + i) < 0, "Fallback plugin " + i + " should not have sent the event");
147 }
148 }
150 function test_normal(plugin) {
151 is(gUnknown.length, 0, "Should not have been any unknown plugins");
152 is(gDisabled.length, 0, "Should not have been any disabled plugins");
153 is(gBlocked.length, 0, "Should not have been any blocked plugins");
154 test_style("solid");
155 plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_DISABLED;
156 load_frame(test_disabled, "file_bug391728");
157 }
159 function test_disabled(plugin) {
160 is(gUnknown.length, 0, "Should not have been any unknown plugins");
161 is(gDisabled.length, PLUGIN_COUNT, "Should have been disabled plugins");
162 test_list(gDisabled);
163 is(gBlocked.length, 0, "Should not have been any blocked plugins");
164 test_style("dotted");
165 ok(plugin.disabled, "Plugin lost its disabled status");
166 plugin.enabledState = Components.interfaces.nsIPluginTag.STATE_ENABLED;
168 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml",
169 function() {
170 load_frame(test_blocked, "file_bug391728");
171 });
172 }
174 function test_blocked(plugin) {
175 is(gUnknown.length, 0, "Should not have been any unknown plugins");
176 is(gDisabled.length, 0, "Should not have been any disabled plugins");
177 is(gBlocked.length, PLUGIN_COUNT, "Should have been blocked plugins");
178 test_list(gBlocked);
179 test_style("dashed");
180 ok(plugin.blocklisted, "Plugin lost its blocklist status");
181 load_frame(test_unknown, "file_bug391728_2");
182 }
184 function test_unknown(plugin) {
185 is(gUnknown.length, PLUGIN_COUNT, "Should have been unknown plugins");
186 test_list(gUnknown);
187 is(gDisabled.length, 0, "Should not have been any disabled plugins");
188 is(gBlocked.length, 0, "Should not have been any blocked plugins");
189 test_style("none");
190 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
191 ok(!plugin.blocklisted, "Plugin shouldn't remain blocklisted");
192 finish_test(plugin);
193 });
194 }
196 SimpleTest.waitForExplicitFinish();
197 window.addEventListener("load", init_test, false);
198 </script>
199 </pre>
200 </body>
201 </html>