1 var rootDir = getRootDirectory(gTestPath);
2 const gTestRoot = rootDir;
3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
5 var gTestBrowser = null;
7 var gClickToPlayPluginActualEvents = 0;
8 var gClickToPlayPluginExpectedEvents = 5;
9 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
11 Components.utils.import("resource://gre/modules/Services.jsm");
13 // This listens for the next opened tab and checks it is of the right url.
14 // opencallback is called when the new tab is fully loaded
15 // closecallback is called when the tab is closed
16 function TabOpenListener(url, opencallback, closecallback) {
18 this.opencallback = opencallback;
19 this.closecallback = closecallback;
21 gBrowser.tabContainer.addEventListener("TabOpen", this, false);
24 TabOpenListener.prototype = {
31 handleEvent: function(event) {
32 if (event.type == "TabOpen") {
33 gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
34 this.tab = event.originalTarget;
35 this.browser = this.tab.linkedBrowser;
36 gBrowser.addEventListener("pageshow", this, false);
37 } else if (event.type == "pageshow") {
38 if (event.target.location.href != this.url)
40 gBrowser.removeEventListener("pageshow", this, false);
41 this.tab.addEventListener("TabClose", this, false);
42 var url = this.browser.contentDocument.location.href;
43 is(url, this.url, "Should have opened the correct tab");
44 this.opencallback(this.tab, this.browser.contentWindow);
45 } else if (event.type == "TabClose") {
46 if (event.originalTarget != this.tab)
48 this.tab.removeEventListener("TabClose", this, false);
49 this.opencallback = null;
52 // Let the window close complete
53 executeSoon(this.closecallback);
54 this.closecallback = null;
60 waitForExplicitFinish();
61 registerCleanupFunction(function() { Services.prefs.clearUserPref("plugins.click_to_play"); });
62 Services.prefs.setBoolPref("plugins.click_to_play", false);
64 var newTab = gBrowser.addTab();
65 gBrowser.selectedTab = newTab;
66 gTestBrowser = gBrowser.selectedBrowser;
67 gTestBrowser.addEventListener("load", pageLoad, true);
68 gTestBrowser.addEventListener("PluginBindingAttached", handleBindingAttached, true, true);
69 prepareTest(test1, gTestRoot + "plugin_unknown.html");
72 function finishTest() {
73 gTestBrowser.removeEventListener("load", pageLoad, true);
74 gTestBrowser.removeEventListener("PluginBindingAttached", handleBindingAttached, true, true);
75 gBrowser.removeCurrentTab();
80 function handleBindingAttached(evt) {
81 evt.target instanceof Ci.nsIObjectLoadingContent;
82 if (evt.target.pluginFallbackType == Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY)
83 gClickToPlayPluginActualEvents++;
87 // The plugin events are async dispatched and can come after the load event
88 // This just allows the events to fire before we then go on to test the states
89 executeSoon(gNextTest);
92 function prepareTest(nextTest, url) {
94 gTestBrowser.contentWindow.location = url;
97 // Tests a page with an unknown plugin in it.
99 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
100 ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 1, Should have displayed the missing plugin notification");
101 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 1, Should not have displayed the blocked plugin notification");
102 ok(gTestBrowser.missingPlugins, "Test 1, Should be a missing plugin list");
103 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 1, Should know about application/x-unknown");
104 ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 1, Should not know about application/x-test");
106 var pluginNode = gTestBrowser.contentDocument.getElementById("unknown");
107 ok(pluginNode, "Test 1, Found plugin in page");
108 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
109 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED, "Test 1, plugin fallback type should be PLUGIN_UNSUPPORTED");
111 var plugin = getTestPlugin();
112 ok(plugin, "Should have a test plugin");
113 plugin.disabled = false;
114 plugin.blocklisted = false;
115 prepareTest(test2, gTestRoot + "plugin_test.html");
118 // Tests a page with a working plugin in it.
120 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
121 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 2, Should not have displayed the missing plugin notification");
122 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 2, Should not have displayed the blocked plugin notification");
123 ok(!gTestBrowser.missingPlugins, "Test 2, Should not be a missing plugin list");
125 var plugin = getTestPlugin();
126 ok(plugin, "Should have a test plugin");
127 plugin.disabled = true;
128 prepareTest(test3, gTestRoot + "plugin_test.html");
131 // Tests a page with a disabled plugin in it.
133 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
134 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 3, Should not have displayed the missing plugin notification");
135 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 3, Should not have displayed the blocked plugin notification");
136 ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list");
138 new TabOpenListener("about:addons", test4, prepareTest5);
140 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
141 ok(pluginNode, "Test 3, Found plugin in page");
142 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
143 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, "Test 3, plugin fallback type should be PLUGIN_DISABLED");
144 var manageLink = gTestBrowser.contentDocument.getAnonymousElementByAttribute(pluginNode, "class", "managePluginsLink");
145 ok(manageLink, "Test 3, found 'manage' link in plugin-problem binding");
147 EventUtils.synthesizeMouseAtCenter(manageLink, {}, gTestBrowser.contentWindow);
150 function test4(tab, win) {
151 is(win.wrappedJSObject.gViewController.currentViewId, "addons://list/plugin", "Test 4, Should have displayed the plugins pane");
152 gBrowser.removeTab(tab);
155 function prepareTest5() {
156 var plugin = getTestPlugin();
157 plugin.disabled = false;
158 plugin.blocklisted = true;
159 prepareTest(test5, gTestRoot + "plugin_test.html");
162 // Tests a page with a blocked plugin in it.
164 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
165 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 5, Should not have displayed the missing plugin notification");
166 ok(notificationBox.getNotificationWithValue("blocked-plugins"), "Test 5, Should have displayed the blocked plugin notification");
167 ok(gTestBrowser.missingPlugins, "Test 5, Should be a missing plugin list");
168 ok(gTestBrowser.missingPlugins.has("application/x-test"), "Test 5, Should know about application/x-test");
169 ok(!gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 5, Should not know about application/x-unknown");
170 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
171 ok(pluginNode, "Test 5, Found plugin in page");
172 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
173 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_BLOCKLISTED, "Test 5, plugin fallback type should be PLUGIN_BLOCKLISTED");
175 prepareTest(test6, gTestRoot + "plugin_both.html");
178 // Tests a page with a blocked and unknown plugin in it.
180 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
181 ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 6, Should have displayed the missing plugin notification");
182 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 6, Should not have displayed the blocked plugin notification");
183 ok(gTestBrowser.missingPlugins, "Test 6, Should be a missing plugin list");
184 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 6, Should know about application/x-unknown");
185 ok(gTestBrowser.missingPlugins.has("application/x-test"), "Test 6, Should know about application/x-test");
187 prepareTest(test7, gTestRoot + "plugin_both2.html");
190 // Tests a page with a blocked and unknown plugin in it (alternate order to above).
192 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
193 ok(notificationBox.getNotificationWithValue("missing-plugins"), "Test 7, Should have displayed the missing plugin notification");
194 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 7, Should not have displayed the blocked plugin notification");
195 ok(gTestBrowser.missingPlugins, "Test 7, Should be a missing plugin list");
196 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 7, Should know about application/x-unknown");
197 ok(gTestBrowser.missingPlugins.has("application/x-test"), "Test 7, Should know about application/x-test");
199 var plugin = getTestPlugin();
200 plugin.disabled = false;
201 plugin.blocklisted = false;
202 Services.prefs.setBoolPref("plugins.click_to_play", true);
204 prepareTest(test8, gTestRoot + "plugin_test.html");
207 // Tests a page with a working plugin that is click-to-play
209 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
210 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 8, Should not have displayed the missing plugin notification");
211 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 8, Should not have displayed the blocked plugin notification");
212 ok(!gTestBrowser.missingPlugins, "Test 8, Should not be a missing plugin list");
213 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 8, Should have a click-to-play notification");
215 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
216 ok(pluginNode, "Test 8, Found plugin in page");
217 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
218 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 8, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
220 prepareTest(test9a, gTestRoot + "plugin_test2.html");
223 // Tests that activating one click-to-play plugin will activate only that plugin (part 1/3)
225 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
226 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 9a, Should not have displayed the missing plugin notification");
227 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 9a, Should not have displayed the blocked plugin notification");
228 ok(!gTestBrowser.missingPlugins, "Test 9a, Should not be a missing plugin list");
229 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
230 ok(notification, "Test 9a, Should have a click-to-play notification");
231 ok(notification.options.centerActions.length == 1, "Test 9a, Should have only one type of plugin in the notification");
233 var doc = gTestBrowser.contentDocument;
234 var plugin1 = doc.getElementById("test1");
235 var rect = doc.getAnonymousElementByAttribute(plugin1, "class", "mainBox").getBoundingClientRect();
236 ok(rect.width == 200, "Test 9a, Plugin with id=" + plugin1.id + " overlay rect should have 200px width before being clicked");
237 ok(rect.height == 200, "Test 9a, Plugin with id=" + plugin1.id + " overlay rect should have 200px height before being clicked");
238 var objLoadingContent = plugin1.QueryInterface(Ci.nsIObjectLoadingContent);
239 ok(!objLoadingContent.activated, "Test 9a, Plugin with id=" + plugin1.id + " should not be activated");
241 var plugin2 = doc.getElementById("test2");
242 var rect = doc.getAnonymousElementByAttribute(plugin2, "class", "mainBox").getBoundingClientRect();
243 ok(rect.width == 200, "Test 9a, Plugin with id=" + plugin2.id + " overlay rect should have 200px width before being clicked");
244 ok(rect.height == 200, "Test 9a, Plugin with id=" + plugin2.id + " overlay rect should have 200px height before being clicked");
245 var objLoadingContent = plugin2.QueryInterface(Ci.nsIObjectLoadingContent);
246 ok(!objLoadingContent.activated, "Test 9a, Plugin with id=" + plugin2.id + " should not be activated");
248 EventUtils.synthesizeMouseAtCenter(plugin1, {}, gTestBrowser.contentWindow);
249 var objLoadingContent = plugin1.QueryInterface(Ci.nsIObjectLoadingContent);
250 var condition = function() objLoadingContent.activated;
251 waitForCondition(condition, test9b, "Test 9a, Waited too long for plugin to activate");
254 // Tests that activating one click-to-play plugin will activate only that plugin (part 2/3)
256 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
257 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 9b, Should not have displayed the missing plugin notification");
258 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 9b, Should not have displayed the blocked plugin notification");
259 ok(!gTestBrowser.missingPlugins, "Test 9b, Should not be a missing plugin list");
260 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
261 ok(notification, "Test 9b, Click to play notification should not be removed now");
262 ok(notification.options.centerActions.length == 1, "Test 9b, Should have only one type of plugin in the notification");
264 var doc = gTestBrowser.contentDocument;
265 var plugin1 = doc.getElementById("test1");
266 var pluginRect1 = doc.getAnonymousElementByAttribute(plugin1, "class", "mainBox").getBoundingClientRect();
267 ok(pluginRect1.width == 0, "Test 9b, Plugin with id=" + plugin1.id + " should have click-to-play overlay with zero width");
268 ok(pluginRect1.height == 0, "Test 9b, Plugin with id=" + plugin1.id + " should have click-to-play overlay with zero height");
269 var objLoadingContent = plugin1.QueryInterface(Ci.nsIObjectLoadingContent);
270 ok(objLoadingContent.activated, "Test 9b, Plugin with id=" + plugin1.id + " should be activated");
272 var plugin2 = doc.getElementById("test2");
273 var pluginRect2 = doc.getAnonymousElementByAttribute(plugin2, "class", "mainBox").getBoundingClientRect();
274 ok(pluginRect2.width != 0, "Test 9b, Plugin with id=" + plugin2.id + " should not have click-to-play overlay with zero width");
275 ok(pluginRect2.height != 0, "Test 9b, Plugin with id=" + plugin2.id + " should not have click-to-play overlay with zero height");
276 var objLoadingContent = plugin2.QueryInterface(Ci.nsIObjectLoadingContent);
277 ok(!objLoadingContent.activated, "Test 9b, Plugin with id=" + plugin2.id + " should not be activated");
279 EventUtils.synthesizeMouseAtCenter(plugin2, {}, gTestBrowser.contentWindow);
280 var objLoadingContent = plugin2.QueryInterface(Ci.nsIObjectLoadingContent);
281 var condition = function() objLoadingContent.activated;
282 waitForCondition(condition, test9c, "Test 9b, Waited too long for plugin to activate");
286 // Tests that activating one click-to-play plugin will activate only that plugin (part 3/3)
288 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
289 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 9c, Should not have displayed the missing plugin notification");
290 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 9c, Should not have displayed the blocked plugin notification");
291 ok(!gTestBrowser.missingPlugins, "Test 9c, Should not be a missing plugin list");
292 ok(!PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 9c, Click to play notification should be removed now");
294 var doc = gTestBrowser.contentDocument;
295 var plugin1 = doc.getElementById("test1");
296 var pluginRect1 = doc.getAnonymousElementByAttribute(plugin1, "class", "mainBox").getBoundingClientRect();
297 ok(pluginRect1.width == 0, "Test 9c, Plugin with id=" + plugin1.id + " should have click-to-play overlay with zero width");
298 ok(pluginRect1.height == 0, "Test 9c, Plugin with id=" + plugin1.id + " should have click-to-play overlay with zero height");
299 var objLoadingContent = plugin1.QueryInterface(Ci.nsIObjectLoadingContent);
300 ok(objLoadingContent.activated, "Test 9c, Plugin with id=" + plugin1.id + " should be activated");
302 var plugin2 = doc.getElementById("test1");
303 var pluginRect2 = doc.getAnonymousElementByAttribute(plugin2, "class", "mainBox").getBoundingClientRect();
304 ok(pluginRect2.width == 0, "Test 9c, Plugin with id=" + plugin2.id + " should have click-to-play overlay with zero width");
305 ok(pluginRect2.height == 0, "Test 9c, Plugin with id=" + plugin2.id + " should have click-to-play overlay with zero height");
306 var objLoadingContent = plugin2.QueryInterface(Ci.nsIObjectLoadingContent);
307 ok(objLoadingContent.activated, "Test 9c, Plugin with id=" + plugin2.id + " should be activated");
309 prepareTest(test10a, gTestRoot + "plugin_test3.html");
312 // Tests that activating a hidden click-to-play plugin through the notification works (part 1/2)
314 var notificationBox = gBrowser.getNotificationBox(gTestBrowser);
315 ok(!notificationBox.getNotificationWithValue("missing-plugins"), "Test 10a, Should not have displayed the missing plugin notification");
316 ok(!notificationBox.getNotificationWithValue("blocked-plugins"), "Test 10a, Should not have displayed the blocked plugin notification");
317 ok(!gTestBrowser.missingPlugins, "Test 10a, Should not be a missing plugin list");
318 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
319 ok(popupNotification, "Test 10a, Should have a click-to-play notification");
320 var plugin = gTestBrowser.contentDocument.getElementById("test");
321 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
322 ok(!objLoadingContent.activated, "Test 10a, Plugin should not be activated");
324 popupNotification.mainAction.callback();
325 var condition = function() objLoadingContent.activated;
326 waitForCondition(condition, test10b, "Test 10a, Waited too long for plugin to activate");
329 // Tests that activating a hidden click-to-play plugin through the notification works (part 2/2)
331 var plugin = gTestBrowser.contentDocument.getElementById("test");
332 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
333 ok(objLoadingContent.activated, "Test 10b, Plugin should be activated");
335 prepareTest(test11a, gTestRoot + "plugin_test3.html");
338 // Tests that the going back will reshow the notification for click-to-play plugins (part 1/4)
340 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
341 ok(popupNotification, "Test 11a, Should have a click-to-play notification");
343 prepareTest(test11b, "about:blank");
346 // Tests that the going back will reshow the notification for click-to-play plugins (part 2/4)
348 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
349 ok(!popupNotification, "Test 11b, Should not have a click-to-play notification");
351 Services.obs.addObserver(test11c, "PopupNotifications-updateNotShowing", false);
352 gTestBrowser.contentWindow.history.back();
355 // Tests that the going back will reshow the notification for click-to-play plugins (part 3/4)
357 Services.obs.removeObserver(test11c, "PopupNotifications-updateNotShowing", false);
358 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
359 waitForCondition(condition, test11d, "Test 11c, waited too long for click-to-play-plugin notification");
362 // Tests that the going back will reshow the notification for click-to-play plugins (part 4/4)
364 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
365 ok(popupNotification, "Test 11d, Should have a click-to-play notification");
366 is(gClickToPlayPluginActualEvents, gClickToPlayPluginExpectedEvents,
367 "There should be a PluginClickToPlay event for each plugin that was " +
368 "blocked due to the plugins.click_to_play pref");
370 prepareTest(test12a, gHttpTestRoot + "plugin_clickToPlayAllow.html");
373 // Tests that the "Allow Always" permission works for click-to-play plugins (part 1/3)
375 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
376 ok(popupNotification, "Test 12a, Should have a click-to-play notification");
377 var plugin = gTestBrowser.contentDocument.getElementById("test");
378 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
379 ok(!objLoadingContent.activated, "Test 12a, Plugin should not be activated");
381 // Simulate clicking the "Allow Always" button.
382 popupNotification.secondaryActions[0].callback();
383 var condition = function() objLoadingContent.activated;
384 waitForCondition(condition, test12b, "Test 12a, Waited too long for plugin to activate");
387 // Tests that the "Always" permission works for click-to-play plugins (part 2/3)
389 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
390 ok(!popupNotification, "Test 12b, Should not have a click-to-play notification");
391 var plugin = gTestBrowser.contentDocument.getElementById("test");
392 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
393 ok(objLoadingContent.activated, "Test 12b, Plugin should be activated");
395 prepareTest(test12c, gHttpTestRoot + "plugin_clickToPlayAllow.html");
398 // Tests that the "Always" permission works for click-to-play plugins (part 3/3)
400 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
401 ok(!popupNotification, "Test 12c, Should not have a click-to-play notification");
402 var plugin = gTestBrowser.contentDocument.getElementById("test");
403 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
404 ok(objLoadingContent.activated, "Test 12c, Plugin should be activated");
406 prepareTest(test12d, gHttpTestRoot + "plugin_two_types.html");
409 // Test that the "Always" permission, when set for just the Test plugin,
410 // does not also allow the Second Test plugin.
412 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
413 ok(popupNotification, "Test 12d, Should have a click-to-play notification");
414 var test = gTestBrowser.contentDocument.getElementById("test");
415 var secondtestA = gTestBrowser.contentDocument.getElementById("secondtestA");
416 var secondtestB = gTestBrowser.contentDocument.getElementById("secondtestB");
417 var objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
418 ok(objLoadingContent.activated, "Test 12d, Test plugin should be activated");
419 var objLoadingContent = secondtestA.QueryInterface(Ci.nsIObjectLoadingContent);
420 ok(!objLoadingContent.activated, "Test 12d, Second Test plugin (A) should not be activated");
421 var objLoadingContent = secondtestB.QueryInterface(Ci.nsIObjectLoadingContent);
422 ok(!objLoadingContent.activated, "Test 12d, Second Test plugin (B) should not be activated");
424 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
425 prepareTest(test13a, gHttpTestRoot + "plugin_clickToPlayDeny.html");
428 // Tests that the "Deny Always" permission works for click-to-play plugins (part 1/3)
430 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
431 ok(popupNotification, "Test 13a, Should have a click-to-play notification");
432 var plugin = gTestBrowser.contentDocument.getElementById("test");
433 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
434 ok(!objLoadingContent.activated, "Test 13a, Plugin should not be activated");
436 // Simulate clicking the "Deny Always" button.
437 popupNotification.secondaryActions[1].callback();
441 // Tests that the "Deny Always" permission works for click-to-play plugins (part 2/3)
443 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
444 ok(!popupNotification, "Test 13b, Should not have a click-to-play notification");
445 var plugin = gTestBrowser.contentDocument.getElementById("test");
446 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
447 ok(!objLoadingContent.activated, "Test 13b, Plugin should not be activated");
448 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(plugin, "class", "mainBox");
449 ok(overlay.style.visibility == "hidden", "Test 13b, Plugin should not have visible overlay");
452 gTestBrowser.reload();
455 // Tests that the "Deny Always" permission works for click-to-play plugins (part 3/3)
457 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
458 ok(!popupNotification, "Test 13c, Should not have a click-to-play notification");
459 var plugin = gTestBrowser.contentDocument.getElementById("test");
460 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
461 ok(!objLoadingContent.activated, "Test 13c, Plugin should not be activated");
462 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(plugin, "class", "mainBox");
463 ok(overlay.style.visibility == "hidden", "Test 13c, Plugin should not have visible overlay");
465 prepareTest(test13d, gHttpTestRoot + "plugin_two_types.html");
468 // Test that the "Deny Always" permission, when set for just the Test plugin,
469 // does not also block the Second Test plugin (i.e. it gets an overlay and
470 // there's a notification and everything).
472 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
473 ok(popupNotification, "Test 13d, Should have a click-to-play notification");
475 var test = gTestBrowser.contentDocument.getElementById("test");
476 var objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
477 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(test, "class", "mainBox");
478 ok(overlay.style.visibility == "hidden", "Test 13d, Test plugin should not have visible overlay");
479 ok(!objLoadingContent.activated, "Test 13d, Test plugin should not be activated");
481 var secondtestA = gTestBrowser.contentDocument.getElementById("secondtestA");
482 var objLoadingContent = secondtestA.QueryInterface(Ci.nsIObjectLoadingContent);
483 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(secondtestA, "class", "mainBox");
484 ok(overlay.style.visibility != "hidden", "Test 13d, Test plugin should have visible overlay");
485 ok(!objLoadingContent.activated, "Test 13d, Second Test plugin (A) should not be activated");
487 var secondtestB = gTestBrowser.contentDocument.getElementById("secondtestB");
488 var objLoadingContent = secondtestB.QueryInterface(Ci.nsIObjectLoadingContent);
489 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(secondtestB, "class", "mainBox");
490 ok(overlay.style.visibility != "hidden", "Test 13d, Test plugin should have visible overlay");
491 ok(!objLoadingContent.activated, "Test 13d, Second Test plugin (B) should not be activated");
493 var condition = function() objLoadingContent.activated;
494 // "click" "Activate All Plugins"
495 popupNotification.mainAction.callback();
496 waitForCondition(condition, test13e, "Test 13d, Waited too long for plugin to activate");
499 // Test that clicking "Activate All Plugins" won't activate plugins that
500 // have previously been "Deny Always"-ed.
502 var test = gTestBrowser.contentDocument.getElementById("test");
503 var objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
504 ok(!objLoadingContent.activated, "Test 13e, Test plugin should not be activated");
506 var secondtestA = gTestBrowser.contentDocument.getElementById("secondtestA");
507 var objLoadingContent = secondtestA.QueryInterface(Ci.nsIObjectLoadingContent);
508 ok(objLoadingContent.activated, "Test 13e, Second Test plugin (A) should be activated");
510 var secondtestB = gTestBrowser.contentDocument.getElementById("secondtestB");
511 var objLoadingContent = secondtestB.QueryInterface(Ci.nsIObjectLoadingContent);
512 ok(objLoadingContent.activated, "Test 13e, Second Test plugin (B) should be activated");
514 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
515 Services.prefs.setBoolPref("plugins.click_to_play", false);
516 prepareTest(test14, gTestRoot + "plugin_test2.html");
519 // Tests that the plugin's "activated" property is true for working plugins with click-to-play disabled.
521 var plugin = gTestBrowser.contentDocument.getElementById("test1");
522 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
523 ok(objLoadingContent.activated, "Test 14, Plugin should be activated");
525 var plugin = getTestPlugin();
526 plugin.disabled = false;
527 plugin.blocklisted = false;
528 Services.prefs.setBoolPref("plugins.click_to_play", true);
529 prepareTest(test15, gTestRoot + "plugin_alternate_content.html");
532 // Tests that the overlay is shown instead of alternate content when
533 // plugins are click to play
535 var plugin = gTestBrowser.contentDocument.getElementById("test");
536 var doc = gTestBrowser.contentDocument;
537 var mainBox = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
538 ok(mainBox, "Test 15, Plugin with id=" + plugin.id + " overlay should exist");
540 prepareTest(test16a, gTestRoot + "plugin_add_dynamically.html");
543 // Tests that a plugin dynamically added to a page after one plugin is clicked
544 // to play (which removes the notification) gets its own notification (1/4)
546 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
547 ok(!popupNotification, "Test 16a, Should not have a click-to-play notification");
548 var plugin = gTestBrowser.contentWindow.addPlugin();
549 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
550 waitForCondition(condition, test16b, "Test 16a, Waited too long for click-to-play-plugin notification");
555 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
556 ok(popupNotification, "Test 16b, Should have a click-to-play notification");
557 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
558 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
559 ok(!objLoadingContent.activated, "Test 16b, Plugin should not be activated");
560 EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow);
561 var condition = function() objLoadingContent.activated;
562 waitForCondition(condition, test16c, "Test 16b, Waited too long for plugin to activate");
567 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
568 ok(!popupNotification, "Test 16c, Should not have a click-to-play notification");
569 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[0];
570 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
571 ok(objLoadingContent.activated, "Test 16c, Plugin should be activated");
572 var plugin = gTestBrowser.contentWindow.addPlugin();
573 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
574 waitForCondition(condition, test16d, "Test 16c, Waited too long for click-to-play-plugin notification");
579 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
580 ok(popupNotification, "Test 16d, Should have a click-to-play notification");
581 var plugin = gTestBrowser.contentDocument.getElementsByTagName("embed")[1];
582 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
583 ok(!objLoadingContent.activated, "Test 16d, Plugin should not be activated");
585 prepareTest(test17, gTestRoot + "plugin_bug749455.html");
588 // Tests that mContentType is used for click-to-play plugins, and not the
591 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
592 ok(clickToPlayNotification, "Test 17, Should have a click-to-play notification");
593 var missingNotification = PopupNotifications.getNotification("missing-plugins", gTestBrowser);
594 ok(!missingNotification, "Test 17, Should not have a missing plugin notification");
596 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
598 prepareTest(test18a, gHttpTestRoot + "plugin_test.html");
602 // Tests a vulnerable, updatable plugin
604 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
605 ok(clickToPlayNotification, "Test 18a, Should have a click-to-play notification");
606 var doc = gTestBrowser.contentDocument;
607 var plugin = doc.getElementById("test");
608 ok(plugin, "Test 18a, Found plugin in page");
609 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
610 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 18a, plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
611 ok(!objLoadingContent.activated, "Test 18a, Plugin should not be activated");
612 var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
613 ok(overlay.style.visibility != "hidden", "Test 18a, Plugin overlay should exist, not be hidden");
614 var updateLink = doc.getAnonymousElementByAttribute(plugin, "class", "checkForUpdatesLink");
615 ok(updateLink.style.visibility != "hidden", "Test 18a, Plugin should have an update link");
617 var tabOpenListener = new TabOpenListener(Services.urlFormatter.formatURLPref("plugins.update.url"), false, false);
618 tabOpenListener.handleEvent = function(event) {
619 if (event.type == "TabOpen") {
620 gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
621 this.tab = event.originalTarget;
622 ok(event.target.label == this.url, "Test 18a, Update link should open up the plugin check page");
623 gBrowser.removeTab(this.tab);
627 EventUtils.synthesizeMouseAtCenter(updateLink, {}, gTestBrowser.contentWindow);
631 // clicking the update link should not activate the plugin
632 var doc = gTestBrowser.contentDocument;
633 var plugin = doc.getElementById("test");
634 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
635 ok(!objLoadingContent.activated, "Test 18b, Plugin should not be activated");
636 var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
637 ok(overlay.style.visibility != "hidden", "Test 18b, Plugin overlay should exist, not be hidden");
639 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableNoUpdate.xml",
641 prepareTest(test18c, gHttpTestRoot + "plugin_test.html");
645 // Tests a vulnerable plugin with no update
647 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
648 ok(clickToPlayNotification, "Test 18c, Should have a click-to-play notification");
649 var doc = gTestBrowser.contentDocument;
650 var plugin = doc.getElementById("test");
651 ok(plugin, "Test 18c, Found plugin in page");
652 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
653 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE, "Test 18c, plugin fallback type should be PLUGIN_VULNERABLE_NO_UPDATE");
654 ok(!objLoadingContent.activated, "Test 18c, Plugin should not be activated");
655 var overlay = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
656 ok(overlay.style.visibility != "hidden", "Test 18c, Plugin overlay should exist, not be hidden");
657 var updateLink = doc.getAnonymousElementByAttribute(plugin, "class", "checkForUpdatesLink");
658 ok(updateLink.style.display != "block", "Test 18c, Plugin should not have an update link");
660 // check that click "Always allow" works with blocklisted plugins
661 clickToPlayNotification.secondaryActions[0].callback();
662 var condition = function() objLoadingContent.activated;
663 waitForCondition(condition, test18d, "Test 18d, Waited too long for plugin to activate");
666 // continue testing "Always allow"
668 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
669 ok(!popupNotification, "Test 18d, Should not have a click-to-play notification");
670 var plugin = gTestBrowser.contentDocument.getElementById("test");
671 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
672 ok(objLoadingContent.activated, "Test 18d, Plugin should be activated");
674 prepareTest(test18e, gHttpTestRoot + "plugin_test.html");
677 // continue testing "Always allow"
679 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
680 ok(!popupNotification, "Test 18e, Should not have a click-to-play notification");
681 var plugin = gTestBrowser.contentDocument.getElementById("test");
682 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
683 ok(objLoadingContent.activated, "Test 18e, Plugin should be activated");
685 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
686 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
689 prepareTest(test19a, gTestRoot + "plugin_test.html");
693 // Tests that clicking the icon of the overlay activates the plugin
695 var doc = gTestBrowser.contentDocument;
696 var plugin = doc.getElementById("test");
697 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
698 ok(!objLoadingContent.activated, "Test 19a, Plugin should not be activated");
700 var icon = doc.getAnonymousElementByAttribute(plugin, "class", "icon");
701 EventUtils.synthesizeMouseAtCenter(icon, {}, gTestBrowser.contentWindow);
702 var condition = function() objLoadingContent.activated;
703 waitForCondition(condition, test19b, "Test 19a, Waited too long for plugin to activate");
707 var doc = gTestBrowser.contentDocument;
708 var plugin = doc.getElementById("test");
709 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
710 ok(objLoadingContent.activated, "Test 19b, Plugin should be activated");
712 prepareTest(test19c, gTestRoot + "plugin_test.html");
715 // Tests that clicking the text of the overlay activates the plugin
717 var doc = gTestBrowser.contentDocument;
718 var plugin = doc.getElementById("test");
719 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
720 ok(!objLoadingContent.activated, "Test 19c, Plugin should not be activated");
722 var text = doc.getAnonymousElementByAttribute(plugin, "class", "msg msgClickToPlay");
723 EventUtils.synthesizeMouseAtCenter(text, {}, gTestBrowser.contentWindow);
724 var condition = function() objLoadingContent.activated;
725 waitForCondition(condition, test19d, "Test 19c, Waited too long for plugin to activate");
729 var doc = gTestBrowser.contentDocument;
730 var plugin = doc.getElementById("test");
731 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
732 ok(objLoadingContent.activated, "Test 19d, Plugin should be activated");
734 prepareTest(test19e, gTestRoot + "plugin_test.html");
737 // Tests that clicking the box of the overlay activates the plugin
738 // (just to be thorough)
740 var doc = gTestBrowser.contentDocument;
741 var plugin = doc.getElementById("test");
742 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
743 ok(!objLoadingContent.activated, "Test 19e, Plugin should not be activated");
745 EventUtils.synthesizeMouse(plugin, 50, 50, {}, gTestBrowser.contentWindow);
746 var condition = function() objLoadingContent.activated;
747 waitForCondition(condition, test19f, "Test 19e, Waited too long for plugin to activate");
751 var doc = gTestBrowser.contentDocument;
752 var plugin = doc.getElementById("test");
753 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
754 ok(objLoadingContent.activated, "Test 19f, Plugin should be activated");
756 prepareTest(test20a, gTestRoot + "plugin_hidden_to_visible.html");
759 // Tests that a plugin in a div that goes from style="display: none" to
760 // "display: block" can be clicked to activate.
762 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
763 ok(!clickToPlayNotification, "Test 20a, Should not have a click-to-play notification");
764 var doc = gTestBrowser.contentDocument;
765 var plugin = doc.getElementById("plugin");
766 var mainBox = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox");
767 ok(mainBox, "Test 20a, plugin overlay should not be null");
768 var pluginRect = mainBox.getBoundingClientRect();
769 ok(pluginRect.width == 0, "Test 20a, plugin should have an overlay with 0px width");
770 ok(pluginRect.height == 0, "Test 20a, plugin should have an overlay with 0px height");
771 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
772 ok(!objLoadingContent.activated, "Test 20a, plugin should not be activated");
773 var div = doc.getElementById("container");
774 ok(div.style.display == "none", "Test 20a, container div should be display: none");
776 div.style.display = "block";
777 var condition = function() {
778 var pluginRect = mainBox.getBoundingClientRect();
779 return (pluginRect.width == 200);
781 waitForCondition(condition, test20b, "Test 20a, Waited too long for plugin to become visible");
785 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
786 ok(clickToPlayNotification, "Test 20b, Should now have a click-to-play notification");
787 var doc = gTestBrowser.contentDocument;
788 var plugin = doc.getElementById("plugin");
789 var pluginRect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
790 ok(pluginRect.width == 200, "Test 20b, plugin should have an overlay with 200px width");
791 ok(pluginRect.height == 200, "Test 20b, plugin should have an overlay with 200px height");
792 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
793 ok(!objLoadingContent.activated, "Test 20b, plugin should not be activated");
795 EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow);
796 var condition = function() objLoadingContent.activated;
797 waitForCondition(condition, test20c, "Test 20b, Waited too long for plugin to activate");
801 var doc = gTestBrowser.contentDocument;
802 var plugin = doc.getElementById("plugin");
803 var pluginRect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
804 ok(pluginRect.width == 0, "Test 20c, plugin should have click-to-play overlay with zero width");
805 ok(pluginRect.height == 0, "Test 20c, plugin should have click-to-play overlay with zero height");
806 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
807 ok(objLoadingContent.activated, "Test 20c, plugin should be activated");
809 prepareTest(test21a, gTestRoot + "plugin_two_types.html");
812 // Test having multiple different types of plugin on one page
814 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
815 ok(notification, "Test 21a, Should have a click-to-play notification");
816 ok(notification.options.centerActions.length == 2, "Test 21a, Should have two types of plugin in the notification");
818 var doc = gTestBrowser.contentDocument;
819 var ids = ["test", "secondtestA", "secondtestB"];
820 for (var id of ids) {
821 var plugin = doc.getElementById(id);
822 var rect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
823 ok(rect.width == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked");
824 ok(rect.height == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked");
825 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
826 ok(!objLoadingContent.activated, "Test 21a, Plugin with id=" + plugin.id + " should not be activated");
829 // we have to actually show the panel to get the bindings to instantiate
830 notification.options.eventCallback = test21b;
831 notification.reshow();
835 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
836 notification.options.eventCallback = null;
837 var centerAction = null;
838 for (var action of notification.options.centerActions) {
839 if (action.message == "Test") {
840 centerAction = action;
844 ok(centerAction, "Test 21b, found center action for the Test plugin");
846 var centerItem = null;
847 for (var item of centerAction.popupnotification.childNodes) {
848 if (item.action == centerAction) {
853 ok(centerItem, "Test 21b, found center item for the Test plugin");
855 // "click" the button to activate the Test plugin
856 centerItem.runCallback.apply(centerItem);
858 var doc = gTestBrowser.contentDocument;
859 var plugin = doc.getElementById("test");
860 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
861 var condition = function() objLoadingContent.activated;
862 waitForCondition(condition, test21c, "Test 21b, Waited too long for plugin to activate");
866 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
867 ok(notification, "Test 21c, Should have a click-to-play notification");
868 ok(notification.options.centerActions.length == 1, "Test 21c, Should have one type of plugin in the notification");
870 var doc = gTestBrowser.contentDocument;
871 var plugin = doc.getElementById("test");
872 var rect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
873 ok(rect.width == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked");
874 ok(rect.height == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked");
875 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
876 ok(objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should be activated");
878 var ids = ["secondtestA", "secondtestB"];
879 for (var id of ids) {
880 var plugin = doc.getElementById(id);
881 var rect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
882 ok(rect.width == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked");
883 ok(rect.height == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked");
884 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
885 ok(!objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should not be activated");
888 // we have to actually show the panel to get the bindings to instantiate
889 notification.options.eventCallback = test21d;
890 notification.reshow();
894 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
895 notification.options.eventCallback = null;
897 var centerAction = null;
898 for (var action of notification.options.centerActions) {
899 if (action.message == "Second Test") {
900 centerAction = action;
904 ok(centerAction, "Test 21d, found center action for the Second Test plugin");
906 var centerItem = null;
907 for (var item of centerAction.popupnotification.childNodes) {
908 if (item.action == centerAction) {
913 ok(centerItem, "Test 21d, found center item for the Second Test plugin");
915 // "click" the button to activate the Second Test plugins
916 centerItem.runCallback.apply(centerItem);
918 var doc = gTestBrowser.contentDocument;
919 var plugin = doc.getElementById("secondtestA");
920 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
921 var condition = function() objLoadingContent.activated;
922 waitForCondition(condition, test21e, "Test 21d, Waited too long for plugin to activate");
926 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
927 ok(!notification, "Test 21e, Should not have a click-to-play notification");
929 var doc = gTestBrowser.contentDocument;
930 var ids = ["test", "secondtestA", "secondtestB"];
931 for (var id of ids) {
932 var plugin = doc.getElementById(id);
933 var rect = doc.getAnonymousElementByAttribute(plugin, "class", "mainBox").getBoundingClientRect();
934 ok(rect.width == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked");
935 ok(rect.height == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked");
936 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
937 ok(objLoadingContent.activated, "Test 21e, Plugin with id=" + plugin.id + " should be activated");
940 Services.prefs.setBoolPref("plugins.click_to_play", true);
941 prepareTest(test22, gTestRoot + "plugin_test.html");
944 // Tests that a click-to-play plugin retains its activated state upon reloading
946 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 22, Should have a click-to-play notification");
948 // Plugin should start as CTP
949 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
950 ok(pluginNode, "Test 22, Found plugin in page");
951 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
952 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 22, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
955 objLoadingContent.playPlugin();
956 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, plugin should have started");
957 ok(pluginNode.activated, "Test 22, plugin should be activated");
960 var oldVal = pluginNode.getObjectValue();
961 pluginNode.src = pluginNode.src;
962 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, Plugin should have retained activated state");
963 ok(pluginNode.activated, "Test 22, plugin should have remained activated");
964 // Sanity, ensure that we actually reloaded the instance, since this behavior might change in the future.
967 pluginNode.checkObjectValue(oldVal);
969 pluginsDiffer = true;
971 ok(pluginsDiffer, "Test 22, plugin should have reloaded");
973 prepareTest(test23, gTestRoot + "plugin_test.html");
976 // Tests that a click-to-play plugin resets its activated state when changing types
978 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 23, Should have a click-to-play notification");
980 // Plugin should start as CTP
981 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
982 ok(pluginNode, "Test 23, Found plugin in page");
983 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
984 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
987 objLoadingContent.playPlugin();
988 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 23, plugin should have started");
989 ok(pluginNode.activated, "Test 23, plugin should be activated");
991 // Reload plugin (this may need RunSoon() in the future when plugins change state asynchronously)
992 pluginNode.type = null;
993 // We currently don't properly change state just on type change,
994 // so rebind the plugin to tree. bug 767631
995 pluginNode.parentNode.appendChild(pluginNode);
996 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, plugin should be unloaded");
997 pluginNode.type = "application/x-test";
998 pluginNode.parentNode.appendChild(pluginNode);
999 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, Plugin should not have activated");
1000 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, Plugin should be click-to-play");
1001 ok(!pluginNode.activated, "Test 23, plugin node should not be activated");
1003 prepareTest(test24a, gHttpTestRoot + "plugin_test.html");
1006 // Test that "always allow"-ing a plugin will not allow it when it becomes
1008 function test24a() {
1009 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1010 ok(notification, "Test 24a, Should have a click-to-play notification");
1011 var plugin = gTestBrowser.contentDocument.getElementById("test");
1012 ok(plugin, "Test 24a, Found plugin in page");
1013 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
1014 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 24a, Plugin should be click-to-play");
1015 ok(!objLoadingContent.activated, "Test 24a, plugin should not be activated");
1017 // simulate "always allow"
1018 notification.secondaryActions[0].callback();
1019 prepareTest(test24b, gHttpTestRoot + "plugin_test.html");
1022 // did the "always allow" work as intended?
1023 function test24b() {
1024 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1025 ok(!notification, "Test 24b, Should not have a click-to-play notification");
1026 var plugin = gTestBrowser.contentDocument.getElementById("test");
1027 ok(plugin, "Test 24b, Found plugin in page");
1028 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
1029 ok(objLoadingContent.activated, "Test 24b, plugin should be activated");
1030 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
1032 prepareTest(test24c, gHttpTestRoot + "plugin_test.html");
1036 // the plugin is now blocklisted, so it should not automatically load
1037 function test24c() {
1038 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1039 ok(notification, "Test 24c, Should have a click-to-play notification");
1040 var plugin = gTestBrowser.contentDocument.getElementById("test");
1041 ok(plugin, "Test 24c, Found plugin in page");
1042 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
1043 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 24c, Plugin should be vulnerable/updatable");
1044 ok(!objLoadingContent.activated, "Test 24c, plugin should not be activated");
1046 // simulate "always allow"
1047 notification.secondaryActions[0].callback();
1048 prepareTest(test24d, gHttpTestRoot + "plugin_test.html");
1051 // We should still be able to always allow a plugin after we've seen that it's
1053 function test24d() {
1054 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1055 ok(!notification, "Test 24d, Should not have a click-to-play notification");
1056 var plugin = gTestBrowser.contentDocument.getElementById("test");
1057 ok(plugin, "Test 24d, Found plugin in page");
1058 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
1059 ok(objLoadingContent.activated, "Test 24d, plugin should be activated");
1061 // this resets the vulnerable plugin permission
1062 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
1063 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
1065 // this resets the normal plugin permission
1066 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
1068 prepareTest(test25a, gHttpTestRoot + "plugin_test.html");
1072 // Test that clicking "always allow" or "always deny" doesn't affect plugins
1073 // that already have permission given to them
1074 function test25a() {
1075 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1076 ok(notification, "Test 25a, Should have a click-to-play notification");
1077 var plugin = gTestBrowser.contentDocument.getElementById("test");
1078 ok(plugin, "Test 25a, Found plugin in page");
1079 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
1080 ok(!objLoadingContent.activated, "Test 25a, plugin should not be activated");
1082 // simulate "always allow"
1083 notification.secondaryActions[0].callback();
1084 prepareTest(test25b, gHttpTestRoot + "plugin_two_types.html");
1087 function test25b() {
1088 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1089 ok(notification, "Test 25b, Should have a click-to-play notification");
1091 var test = gTestBrowser.contentDocument.getElementById("test");
1092 ok(test, "Test 25b, Found test plugin in page");
1093 var objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
1094 ok(objLoadingContent.activated, "Test 25b, test plugin should be activated");
1096 var secondtest = gTestBrowser.contentDocument.getElementById("secondtestA");
1097 ok(secondtest, "Test 25b, Found second test plugin in page");
1098 var objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent);
1099 ok(!objLoadingContent.activated, "Test 25b, second test plugin should not be activated");
1101 // simulate "always deny"
1102 notification.secondaryActions[1].callback();
1103 prepareTest(test25c, gHttpTestRoot + "plugin_two_types.html");
1106 // we should have one plugin allowed to activate and the other plugin(s) denied
1107 // (so it should have an invisible overlay)
1108 function test25c() {
1109 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
1110 ok(!notification, "Test 25c, Should not have a click-to-play notification");
1112 var test = gTestBrowser.contentDocument.getElementById("test");
1113 ok(test, "Test 25c, Found test plugin in page");
1114 var objLoadingContent = test.QueryInterface(Ci.nsIObjectLoadingContent);
1115 ok(objLoadingContent.activated, "Test 25c, test plugin should be activated");
1117 var secondtest = gTestBrowser.contentDocument.getElementById("secondtestA");
1118 ok(secondtest, "Test 25c, Found second test plugin in page");
1119 var objLoadingContent = secondtest.QueryInterface(Ci.nsIObjectLoadingContent);
1120 ok(!objLoadingContent.activated, "Test 25c, second test plugin should not be activated");
1121 var overlay = gTestBrowser.contentDocument.getAnonymousElementByAttribute(secondtest, "class", "mainBox");
1122 ok(overlay.style.visibility == "hidden", "Test 25c, second test plugin should not have visible overlay");
1124 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-test"));
1125 Services.perms.remove("127.0.0.1:8888", gPluginHost.getPermissionStringForType("application/x-second-test"));