1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/base/content/test/plugins/browser_pluginnotification.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,861 @@ 1.4 +var rootDir = getRootDirectory(gTestPath); 1.5 +const gTestRoot = rootDir; 1.6 +const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); 1.7 + 1.8 +var gTestBrowser = null; 1.9 +var gNextTest = null; 1.10 +var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost); 1.11 + 1.12 +Components.utils.import("resource://gre/modules/Services.jsm"); 1.13 + 1.14 +// This listens for the next opened tab and checks it is of the right url. 1.15 +// opencallback is called when the new tab is fully loaded 1.16 +// closecallback is called when the tab is closed 1.17 +function TabOpenListener(url, opencallback, closecallback) { 1.18 + this.url = url; 1.19 + this.opencallback = opencallback; 1.20 + this.closecallback = closecallback; 1.21 + 1.22 + gBrowser.tabContainer.addEventListener("TabOpen", this, false); 1.23 +} 1.24 + 1.25 +TabOpenListener.prototype = { 1.26 + url: null, 1.27 + opencallback: null, 1.28 + closecallback: null, 1.29 + tab: null, 1.30 + browser: null, 1.31 + 1.32 + handleEvent: function(event) { 1.33 + if (event.type == "TabOpen") { 1.34 + gBrowser.tabContainer.removeEventListener("TabOpen", this, false); 1.35 + this.tab = event.originalTarget; 1.36 + this.browser = this.tab.linkedBrowser; 1.37 + gBrowser.addEventListener("pageshow", this, false); 1.38 + } else if (event.type == "pageshow") { 1.39 + if (event.target.location.href != this.url) 1.40 + return; 1.41 + gBrowser.removeEventListener("pageshow", this, false); 1.42 + this.tab.addEventListener("TabClose", this, false); 1.43 + var url = this.browser.contentDocument.location.href; 1.44 + is(url, this.url, "Should have opened the correct tab"); 1.45 + this.opencallback(this.tab, this.browser.contentWindow); 1.46 + } else if (event.type == "TabClose") { 1.47 + if (event.originalTarget != this.tab) 1.48 + return; 1.49 + this.tab.removeEventListener("TabClose", this, false); 1.50 + this.opencallback = null; 1.51 + this.tab = null; 1.52 + this.browser = null; 1.53 + // Let the window close complete 1.54 + executeSoon(this.closecallback); 1.55 + this.closecallback = null; 1.56 + } 1.57 + } 1.58 +}; 1.59 + 1.60 +function test() { 1.61 + waitForExplicitFinish(); 1.62 + requestLongerTimeout(2); 1.63 + registerCleanupFunction(function() { 1.64 + clearAllPluginPermissions(); 1.65 + Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); 1.66 + Services.prefs.clearUserPref("plugins.hideMissingPluginsNotification"); 1.67 + }); 1.68 + Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 1.69 + 1.70 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); 1.71 + setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in"); 1.72 + 1.73 + var newTab = gBrowser.addTab(); 1.74 + gBrowser.selectedTab = newTab; 1.75 + gTestBrowser = gBrowser.selectedBrowser; 1.76 + gTestBrowser.addEventListener("load", pageLoad, true); 1.77 + prepareTest(runAfterPluginBindingAttached(test1a), gTestRoot + "plugin_unknown.html"); 1.78 +} 1.79 + 1.80 +function finishTest() { 1.81 + clearAllPluginPermissions(); 1.82 + gTestBrowser.removeEventListener("load", pageLoad, true); 1.83 + gBrowser.removeCurrentTab(); 1.84 + window.focus(); 1.85 + finish(); 1.86 +} 1.87 + 1.88 +function pageLoad() { 1.89 + // The plugin events are async dispatched and can come after the load event 1.90 + // This just allows the events to fire before we then go on to test the states 1.91 + executeSoon(gNextTest); 1.92 +} 1.93 + 1.94 +function prepareTest(nextTest, url) { 1.95 + gNextTest = nextTest; 1.96 + gTestBrowser.contentWindow.location = url; 1.97 +} 1.98 + 1.99 +// Due to layout being async, "PluginBindAttached" may trigger later. 1.100 +// This wraps a function to force a layout flush, thus triggering it, 1.101 +// and schedules the function execution so they're definitely executed 1.102 +// afterwards. 1.103 +function runAfterPluginBindingAttached(func) { 1.104 + return function() { 1.105 + let doc = gTestBrowser.contentDocument; 1.106 + let elems = doc.getElementsByTagName('embed'); 1.107 + if (elems.length < 1) { 1.108 + elems = doc.getElementsByTagName('object'); 1.109 + } 1.110 + elems[0].clientTop; 1.111 + executeSoon(func); 1.112 + }; 1.113 +} 1.114 + 1.115 +// Tests a page with an unknown plugin in it. 1.116 +function test1a() { 1.117 + ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 1a, Should have displayed the missing plugin notification"); 1.118 + ok(gTestBrowser.missingPlugins, "Test 1a, Should be a missing plugin list"); 1.119 + ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 1a, Should know about application/x-unknown"); 1.120 + ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 1a, Should not know about application/x-test"); 1.121 + 1.122 + var pluginNode = gTestBrowser.contentDocument.getElementById("unknown"); 1.123 + ok(pluginNode, "Test 1a, Found plugin in page"); 1.124 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.125 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED, "Test 1a, plugin fallback type should be PLUGIN_UNSUPPORTED"); 1.126 + 1.127 + Services.prefs.setBoolPref("plugins.hideMissingPluginsNotification", true); 1.128 + prepareTest(runAfterPluginBindingAttached(test1b), gTestRoot + "plugin_unknown.html"); 1.129 +} 1.130 + 1.131 + 1.132 +function test1b() { 1.133 + ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 1b, Should not have displayed the missing plugin notification"); 1.134 + ok(!gTestBrowser.missingPlugins, "Test 1b, Should not be a missing plugin list"); 1.135 + Services.prefs.clearUserPref("plugins.hideMissingPluginsNotification"); 1.136 + 1.137 + var plugin = getTestPlugin(); 1.138 + ok(plugin, "Test 1b, Should have a test plugin"); 1.139 + plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED; 1.140 + prepareTest(runAfterPluginBindingAttached(test2), gTestRoot + "plugin_test.html"); 1.141 +} 1.142 + 1.143 +// Tests a page with a working plugin in it. 1.144 +function test2() { 1.145 + ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 2, Should not have displayed the missing plugin notification"); 1.146 + ok(!gTestBrowser.missingPlugins, "Test 2, Should not be a missing plugin list"); 1.147 + 1.148 + var plugin = getTestPlugin(); 1.149 + ok(plugin, "Should have a test plugin"); 1.150 + plugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED; 1.151 + prepareTest(runAfterPluginBindingAttached(test3), gTestRoot + "plugin_test.html"); 1.152 +} 1.153 + 1.154 +// Tests a page with a disabled plugin in it. 1.155 +function test3() { 1.156 + ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 3, Should not have displayed the missing plugin notification"); 1.157 + ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list"); 1.158 + 1.159 + new TabOpenListener("about:addons", test4, prepareTest5); 1.160 + 1.161 + var pluginNode = gTestBrowser.contentDocument.getElementById("test"); 1.162 + ok(pluginNode, "Test 3, Found plugin in page"); 1.163 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.164 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, "Test 3, plugin fallback type should be PLUGIN_DISABLED"); 1.165 + var manageLink = gTestBrowser.contentDocument.getAnonymousElementByAttribute(pluginNode, "anonid", "managePluginsLink"); 1.166 + ok(manageLink, "Test 3, found 'manage' link in plugin-problem binding"); 1.167 + 1.168 + EventUtils.synthesizeMouseAtCenter(manageLink, {}, gTestBrowser.contentWindow); 1.169 +} 1.170 + 1.171 +function test4(tab, win) { 1.172 + is(win.wrappedJSObject.gViewController.currentViewId, "addons://list/plugin", "Test 4, Should have displayed the plugins pane"); 1.173 + gBrowser.removeTab(tab); 1.174 +} 1.175 + 1.176 +function prepareTest5() { 1.177 + info("prepareTest5"); 1.178 + var plugin = getTestPlugin(); 1.179 + plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED; 1.180 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml", 1.181 + function() { 1.182 + info("prepareTest5 callback"); 1.183 + prepareTest(runAfterPluginBindingAttached(test5), gTestRoot + "plugin_test.html"); 1.184 + }); 1.185 +} 1.186 + 1.187 +// Tests a page with a blocked plugin in it. 1.188 +function test5() { 1.189 + info("test5"); 1.190 + ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 5, Should not have displayed the missing plugin notification"); 1.191 + let notification = PopupNotifications.getNotification("click-to-play-plugins"); 1.192 + ok(notification, "Test 5: There should be a plugin notification for blocked plugins"); 1.193 + ok(notification.dismissed, "Test 5: The plugin notification should be dismissed by default"); 1.194 + 1.195 + notification.reshow(); 1.196 + is(notification.options.pluginData.size, 1, "Test 5: Only the blocked plugin should be present in the notification"); 1.197 + ok(PopupNotifications.panel.firstChild._buttonContainer.hidden, "Part 5: The blocked plugins notification should not have any buttons visible."); 1.198 + 1.199 + ok(!gTestBrowser.missingPlugins, "Test 5, Should not be a missing plugin list"); 1.200 + var pluginNode = gTestBrowser.contentDocument.getElementById("test"); 1.201 + ok(pluginNode, "Test 5, Found plugin in page"); 1.202 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.203 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_BLOCKLISTED, "Test 5, plugin fallback type should be PLUGIN_BLOCKLISTED"); 1.204 + 1.205 + prepareTest(runAfterPluginBindingAttached(test6), gTestRoot + "plugin_both.html"); 1.206 +} 1.207 + 1.208 +// Tests a page with a blocked and unknown plugin in it. 1.209 +function test6() { 1.210 + ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 6, Should have displayed the missing plugin notification"); 1.211 + ok(gTestBrowser.missingPlugins, "Test 6, Should be a missing plugin list"); 1.212 + ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 6, Should know about application/x-unknown"); 1.213 + ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 6, application/x-test should not be a missing plugin"); 1.214 + 1.215 + prepareTest(runAfterPluginBindingAttached(test7), gTestRoot + "plugin_both2.html"); 1.216 +} 1.217 + 1.218 +// Tests a page with a blocked and unknown plugin in it (alternate order to above). 1.219 +function test7() { 1.220 + ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 7, Should have displayed the missing plugin notification"); 1.221 + ok(gTestBrowser.missingPlugins, "Test 7, Should be a missing plugin list"); 1.222 + ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 7, Should know about application/x-unknown"); 1.223 + ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 7, application/x-test should not be a missing plugin"); 1.224 + 1.225 + var plugin = getTestPlugin(); 1.226 + plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.227 + getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.228 + 1.229 + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() { 1.230 + prepareTest(runAfterPluginBindingAttached(test8), gTestRoot + "plugin_test.html"); 1.231 + }); 1.232 +} 1.233 + 1.234 +// Tests a page with a working plugin that is click-to-play 1.235 +function test8() { 1.236 + ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 8, Should not have displayed the missing plugin notification"); 1.237 + ok(!gTestBrowser.missingPlugins, "Test 8, Should not be a missing plugin list"); 1.238 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 8, Should have a click-to-play notification"); 1.239 + 1.240 + var pluginNode = gTestBrowser.contentDocument.getElementById("test"); 1.241 + ok(pluginNode, "Test 8, Found plugin in page"); 1.242 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.243 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 8, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); 1.244 + 1.245 + prepareTest(runAfterPluginBindingAttached(test11a), gTestRoot + "plugin_test3.html"); 1.246 +} 1.247 + 1.248 +// Tests 9 & 10 removed 1.249 + 1.250 +// Tests that the going back will reshow the notification for click-to-play plugins (part 1/4) 1.251 +function test11a() { 1.252 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.253 + ok(popupNotification, "Test 11a, Should have a click-to-play notification"); 1.254 + 1.255 + prepareTest(test11b, "about:blank"); 1.256 +} 1.257 + 1.258 +// Tests that the going back will reshow the notification for click-to-play plugins (part 2/4) 1.259 +function test11b() { 1.260 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.261 + ok(!popupNotification, "Test 11b, Should not have a click-to-play notification"); 1.262 + 1.263 + Services.obs.addObserver(test11c, "PopupNotifications-updateNotShowing", false); 1.264 + gTestBrowser.contentWindow.history.back(); 1.265 +} 1.266 + 1.267 +// Tests that the going back will reshow the notification for click-to-play plugins (part 3/4) 1.268 +function test11c() { 1.269 + Services.obs.removeObserver(test11c, "PopupNotifications-updateNotShowing"); 1.270 + var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.271 + waitForCondition(condition, test11d, "Test 11c, waited too long for click-to-play-plugin notification"); 1.272 +} 1.273 + 1.274 +// Tests that the going back will reshow the notification for click-to-play plugins (part 4/4) 1.275 +function test11d() { 1.276 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.277 + ok(popupNotification, "Test 11d, Should have a click-to-play notification"); 1.278 + 1.279 + prepareTest(runAfterPluginBindingAttached(test12a), gHttpTestRoot + "plugin_clickToPlayAllow.html"); 1.280 +} 1.281 + 1.282 +// Tests that the "Allow Always" permission works for click-to-play plugins 1.283 +function test12a() { 1.284 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.285 + ok(popupNotification, "Test 12a, Should have a click-to-play notification"); 1.286 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.287 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.288 + ok(!objLoadingContent.activated, "Test 12a, Plugin should not be activated"); 1.289 + 1.290 + // Simulate clicking the "Allow Always" button. 1.291 + popupNotification.reshow(); 1.292 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.293 + 1.294 + var condition = function() objLoadingContent.activated; 1.295 + waitForCondition(condition, test12b, "Test 12a, Waited too long for plugin to activate"); 1.296 +} 1.297 + 1.298 +function test12b() { 1.299 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.300 + ok(popupNotification, "Test 12d, Should have a click-to-play notification"); 1.301 + prepareTest(runAfterPluginBindingAttached(test12c), gHttpTestRoot + "plugin_two_types.html"); 1.302 +} 1.303 + 1.304 +// Test that the "Always" permission, when set for just the Test plugin, 1.305 +// does not also allow the Second Test plugin. 1.306 +function test12c() { 1.307 + var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.308 + ok(popupNotification, "Test 12d, Should have a click-to-play notification"); 1.309 + var test = gTestBrowser.contentDocument.getElementById("test"); 1.310 + var secondtestA = gTestBrowser.contentDocument.getElementById("secondtestA"); 1.311 + var secondtestB = gTestBrowser.contentDocument.getElementById("secondtestB"); 1.312 + ok(test.activated, "Test 12d, Test plugin should be activated"); 1.313 + ok(!secondtestA.activated, "Test 12d, Second Test plugin (A) should not be activated"); 1.314 + ok(!secondtestB.activated, "Test 12d, Second Test plugin (B) should not be activated"); 1.315 + 1.316 + clearAllPluginPermissions(); 1.317 + var plugin = getTestPlugin(); 1.318 + plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED; 1.319 + prepareTest(test14, gTestRoot + "plugin_test2.html"); 1.320 +} 1.321 + 1.322 +// Test 13 removed 1.323 + 1.324 +// Tests that the plugin's "activated" property is true for working plugins with click-to-play disabled. 1.325 +function test14() { 1.326 + var plugin = gTestBrowser.contentDocument.getElementById("test1"); 1.327 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.328 + ok(objLoadingContent.activated, "Test 14, Plugin should be activated"); 1.329 + 1.330 + var plugin = getTestPlugin(); 1.331 + plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.332 + getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.333 + prepareTest(runAfterPluginBindingAttached(test15), gTestRoot + "plugin_alternate_content.html"); 1.334 +} 1.335 + 1.336 +// Tests that the overlay is shown instead of alternate content when 1.337 +// plugins are click to play 1.338 +function test15() { 1.339 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.340 + var doc = gTestBrowser.contentDocument; 1.341 + var mainBox = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.342 + ok(mainBox, "Test 15, Plugin with id=" + plugin.id + " overlay should exist"); 1.343 + 1.344 + prepareTest(runAfterPluginBindingAttached(test17), gTestRoot + "plugin_bug749455.html"); 1.345 +} 1.346 + 1.347 +// Test 16 removed 1.348 + 1.349 +// Tests that mContentType is used for click-to-play plugins, and not the 1.350 +// inspected type. 1.351 +function test17() { 1.352 + var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.353 + ok(clickToPlayNotification, "Test 17, Should have a click-to-play notification"); 1.354 + var missingNotification = PopupNotifications.getNotification("missing-plugins", gTestBrowser); 1.355 + ok(!missingNotification, "Test 17, Should not have a missing plugin notification"); 1.356 + 1.357 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", 1.358 + function() { 1.359 + prepareTest(runAfterPluginBindingAttached(test18a), gHttpTestRoot + "plugin_test.html"); 1.360 + }); 1.361 +} 1.362 + 1.363 +// Tests a vulnerable, updatable plugin 1.364 +function test18a() { 1.365 + var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.366 + ok(clickToPlayNotification, "Test 18a, Should have a click-to-play notification"); 1.367 + var doc = gTestBrowser.contentDocument; 1.368 + var plugin = doc.getElementById("test"); 1.369 + ok(plugin, "Test 18a, Found plugin in page"); 1.370 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.371 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 18a, plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE"); 1.372 + ok(!objLoadingContent.activated, "Test 18a, Plugin should not be activated"); 1.373 + var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.374 + ok(overlay.classList.contains("visible"), "Test 18a, Plugin overlay should exist, not be hidden"); 1.375 + var updateLink = doc.getAnonymousElementByAttribute(plugin, "anonid", "checkForUpdatesLink"); 1.376 + ok(updateLink.style.visibility != "hidden", "Test 18a, Plugin should have an update link"); 1.377 + 1.378 + var tabOpenListener = new TabOpenListener(Services.urlFormatter.formatURLPref("plugins.update.url"), false, false); 1.379 + tabOpenListener.handleEvent = function(event) { 1.380 + if (event.type == "TabOpen") { 1.381 + gBrowser.tabContainer.removeEventListener("TabOpen", this, false); 1.382 + this.tab = event.originalTarget; 1.383 + is(event.target.label, this.url, "Test 18a, Update link should open up the plugin check page"); 1.384 + gBrowser.removeTab(this.tab); 1.385 + test18b(); 1.386 + } 1.387 + }; 1.388 + EventUtils.synthesizeMouseAtCenter(updateLink, {}, gTestBrowser.contentWindow); 1.389 +} 1.390 + 1.391 +function test18b() { 1.392 + // clicking the update link should not activate the plugin 1.393 + var doc = gTestBrowser.contentDocument; 1.394 + var plugin = doc.getElementById("test"); 1.395 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.396 + ok(!objLoadingContent.activated, "Test 18b, Plugin should not be activated"); 1.397 + var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.398 + ok(overlay.classList.contains("visible"), "Test 18b, Plugin overlay should exist, not be hidden"); 1.399 + 1.400 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableNoUpdate.xml", 1.401 + function() { 1.402 + prepareTest(runAfterPluginBindingAttached(test18c), gHttpTestRoot + "plugin_test.html"); 1.403 + }); 1.404 +} 1.405 + 1.406 +// Tests a vulnerable plugin with no update 1.407 +function test18c() { 1.408 + var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.409 + ok(clickToPlayNotification, "Test 18c, Should have a click-to-play notification"); 1.410 + var doc = gTestBrowser.contentDocument; 1.411 + var plugin = doc.getElementById("test"); 1.412 + ok(plugin, "Test 18c, Found plugin in page"); 1.413 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.414 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE, "Test 18c, plugin fallback type should be PLUGIN_VULNERABLE_NO_UPDATE"); 1.415 + ok(!objLoadingContent.activated, "Test 18c, Plugin should not be activated"); 1.416 + var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.417 + ok(overlay.classList.contains("visible"), "Test 18c, Plugin overlay should exist, not be hidden"); 1.418 + var updateLink = doc.getAnonymousElementByAttribute(plugin, "anonid", "checkForUpdatesLink"); 1.419 + ok(updateLink.style.display != "block", "Test 18c, Plugin should not have an update link"); 1.420 + 1.421 + // check that click "Always allow" works with blocklisted plugins 1.422 + clickToPlayNotification.reshow(); 1.423 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.424 + 1.425 + var condition = function() objLoadingContent.activated; 1.426 + waitForCondition(condition, test18d, "Test 18d, Waited too long for plugin to activate"); 1.427 +} 1.428 + 1.429 +// continue testing "Always allow" 1.430 +function test18d() { 1.431 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.432 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.433 + ok(objLoadingContent.activated, "Test 18d, Plugin should be activated"); 1.434 + 1.435 + prepareTest(test18e, gHttpTestRoot + "plugin_test.html"); 1.436 +} 1.437 + 1.438 +// continue testing "Always allow" 1.439 +function test18e() { 1.440 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.441 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.442 + ok(objLoadingContent.activated, "Test 18e, Plugin should be activated"); 1.443 + 1.444 + clearAllPluginPermissions(); 1.445 + prepareTest(runAfterPluginBindingAttached(test18f), gHttpTestRoot + "plugin_test.html"); 1.446 +} 1.447 + 1.448 +// clicking the in-content overlay of a vulnerable plugin should bring 1.449 +// up the notification and not directly activate the plugin 1.450 +function test18f() { 1.451 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.452 + ok(notification, "Test 18f, Should have a click-to-play notification"); 1.453 + ok(notification.dismissed, "Test 18f, notification should start dismissed"); 1.454 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.455 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.456 + ok(!objLoadingContent.activated, "Test 18f, Plugin should not be activated"); 1.457 + 1.458 + var oldEventCallback = notification.options.eventCallback; 1.459 + notification.options.eventCallback = function() { 1.460 + oldEventCallback(); 1.461 + executeSoon(test18g); 1.462 + }; 1.463 + EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow); 1.464 +} 1.465 + 1.466 +function test18g() { 1.467 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.468 + ok(notification, "Test 18g, Should have a click-to-play notification"); 1.469 + ok(!notification.dismissed, "Test 18g, notification should be open"); 1.470 + notification.options.eventCallback = null; 1.471 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.472 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.473 + ok(!objLoadingContent.activated, "Test 18g, Plugin should not be activated"); 1.474 + 1.475 + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", 1.476 + function() { 1.477 + resetBlocklist(); 1.478 + prepareTest(runAfterPluginBindingAttached(test19a), gTestRoot + "plugin_test.html"); 1.479 + }); 1.480 +} 1.481 + 1.482 +// Tests that clicking the icon of the overlay activates the doorhanger 1.483 +function test19a() { 1.484 + var doc = gTestBrowser.contentDocument; 1.485 + var plugin = doc.getElementById("test"); 1.486 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.487 + ok(!objLoadingContent.activated, "Test 19a, Plugin should not be activated"); 1.488 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19a, Doorhanger should start out dismissed"); 1.489 + 1.490 + var icon = doc.getAnonymousElementByAttribute(plugin, "class", "icon"); 1.491 + EventUtils.synthesizeMouseAtCenter(icon, {}, gTestBrowser.contentWindow); 1.492 + let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed; 1.493 + waitForCondition(condition, test19b, "Test 19a, Waited too long for doorhanger to activate"); 1.494 +} 1.495 + 1.496 +function test19b() { 1.497 + prepareTest(runAfterPluginBindingAttached(test19c), gTestRoot + "plugin_test.html"); 1.498 +} 1.499 + 1.500 +// Tests that clicking the text of the overlay activates the plugin 1.501 +function test19c() { 1.502 + var doc = gTestBrowser.contentDocument; 1.503 + var plugin = doc.getElementById("test"); 1.504 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.505 + ok(!objLoadingContent.activated, "Test 19c, Plugin should not be activated"); 1.506 + 1.507 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19c, Doorhanger should start out dismissed"); 1.508 + 1.509 + var text = doc.getAnonymousElementByAttribute(plugin, "class", "msg msgClickToPlay"); 1.510 + EventUtils.synthesizeMouseAtCenter(text, {}, gTestBrowser.contentWindow); 1.511 + let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed; 1.512 + waitForCondition(condition, test19d, "Test 19c, Waited too long for doorhanger to activate"); 1.513 +} 1.514 + 1.515 +function test19d() { 1.516 + prepareTest(runAfterPluginBindingAttached(test19e), gTestRoot + "plugin_test.html"); 1.517 +} 1.518 + 1.519 +// Tests that clicking the box of the overlay activates the doorhanger 1.520 +// (just to be thorough) 1.521 +function test19e() { 1.522 + var doc = gTestBrowser.contentDocument; 1.523 + var plugin = doc.getElementById("test"); 1.524 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.525 + ok(!objLoadingContent.activated, "Test 19e, Plugin should not be activated"); 1.526 + 1.527 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19e, Doorhanger should start out dismissed"); 1.528 + 1.529 + EventUtils.synthesizeMouse(plugin, 50, 50, {}, gTestBrowser.contentWindow); 1.530 + let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed; 1.531 + waitForCondition(condition, test19f, "Test 19e, Waited too long for plugin to activate"); 1.532 +} 1.533 + 1.534 +function test19f() { 1.535 + prepareTest(test20a, gTestRoot + "plugin_hidden_to_visible.html"); 1.536 +} 1.537 + 1.538 +// Tests that a plugin in a div that goes from style="display: none" to 1.539 +// "display: block" can be clicked to activate. 1.540 +function test20a() { 1.541 + var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.542 + ok(!clickToPlayNotification, "Test 20a, Should not have a click-to-play notification"); 1.543 + var doc = gTestBrowser.contentDocument; 1.544 + var plugin = doc.getElementById("plugin"); 1.545 + var mainBox = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); 1.546 + ok(mainBox, "Test 20a, plugin overlay should not be null"); 1.547 + var pluginRect = mainBox.getBoundingClientRect(); 1.548 + ok(pluginRect.width == 0, "Test 20a, plugin should have an overlay with 0px width"); 1.549 + ok(pluginRect.height == 0, "Test 20a, plugin should have an overlay with 0px height"); 1.550 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.551 + ok(!objLoadingContent.activated, "Test 20a, plugin should not be activated"); 1.552 + var div = doc.getElementById("container"); 1.553 + ok(div.style.display == "none", "Test 20a, container div should be display: none"); 1.554 + 1.555 + div.style.display = "block"; 1.556 + var condition = function() { 1.557 + var pluginRect = mainBox.getBoundingClientRect(); 1.558 + return (pluginRect.width == 200); 1.559 + } 1.560 + waitForCondition(condition, test20b, "Test 20a, Waited too long for plugin to become visible"); 1.561 +} 1.562 + 1.563 +function test20b() { 1.564 + var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.565 + ok(clickToPlayNotification, "Test 20b, Should now have a click-to-play notification"); 1.566 + var doc = gTestBrowser.contentDocument; 1.567 + var plugin = doc.getElementById("plugin"); 1.568 + var pluginRect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.569 + ok(pluginRect.width == 200, "Test 20b, plugin should have an overlay with 200px width"); 1.570 + ok(pluginRect.height == 200, "Test 20b, plugin should have an overlay with 200px height"); 1.571 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.572 + ok(!objLoadingContent.activated, "Test 20b, plugin should not be activated"); 1.573 + 1.574 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 20b, Doorhanger should start out dismissed"); 1.575 + 1.576 + EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow); 1.577 + let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed; 1.578 + waitForCondition(condition, test20c, "Test 20b, Waited too long for plugin to activate"); 1.579 +} 1.580 + 1.581 +function test20c() { 1.582 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.583 + var doc = gTestBrowser.contentDocument; 1.584 + var plugin = doc.getElementById("plugin"); 1.585 + let condition = function() plugin.activated; 1.586 + waitForCondition(condition, test20d, "Test 20c", "Waiting for plugin to activate"); 1.587 +} 1.588 + 1.589 +function test20d() { 1.590 + var doc = gTestBrowser.contentDocument; 1.591 + var plugin = doc.getElementById("plugin"); 1.592 + var pluginRect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.593 + ok(pluginRect.width == 0, "Test 20d, plugin should have click-to-play overlay with zero width"); 1.594 + ok(pluginRect.height == 0, "Test 20d, plugin should have click-to-play overlay with zero height"); 1.595 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.596 + ok(objLoadingContent.activated, "Test 20d, plugin should be activated"); 1.597 + 1.598 + clearAllPluginPermissions(); 1.599 + 1.600 + prepareTest(runAfterPluginBindingAttached(test21a), gTestRoot + "plugin_two_types.html"); 1.601 +} 1.602 + 1.603 +// Test having multiple different types of plugin on one page 1.604 +function test21a() { 1.605 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.606 + ok(notification, "Test 21a, Should have a click-to-play notification"); 1.607 + 1.608 + var doc = gTestBrowser.contentDocument; 1.609 + var ids = ["test", "secondtestA", "secondtestB"]; 1.610 + for (var id of ids) { 1.611 + var plugin = doc.getElementById(id); 1.612 + var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.613 + ok(rect.width == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked"); 1.614 + ok(rect.height == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked"); 1.615 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.616 + ok(!objLoadingContent.activated, "Test 21a, Plugin with id=" + plugin.id + " should not be activated"); 1.617 + } 1.618 + 1.619 + // we have to actually show the panel to get the bindings to instantiate 1.620 + notification.reshow(); 1.621 + is(notification.options.pluginData.size, 2, "Test 21a, Should have two types of plugin in the notification"); 1.622 + 1.623 + var centerAction = null; 1.624 + for (var action of notification.options.pluginData.values()) { 1.625 + if (action.pluginName == "Test") { 1.626 + centerAction = action; 1.627 + break; 1.628 + } 1.629 + } 1.630 + ok(centerAction, "Test 21b, found center action for the Test plugin"); 1.631 + 1.632 + var centerItem = null; 1.633 + for (var item of PopupNotifications.panel.firstChild.childNodes) { 1.634 + is(item.value, "block", "Test 21b, all plugins should start out blocked"); 1.635 + if (item.action == centerAction) { 1.636 + centerItem = item; 1.637 + break; 1.638 + } 1.639 + } 1.640 + ok(centerItem, "Test 21b, found center item for the Test plugin"); 1.641 + 1.642 + // "click" the button to activate the Test plugin 1.643 + centerItem.value = "allownow"; 1.644 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.645 + 1.646 + var doc = gTestBrowser.contentDocument; 1.647 + var plugin = doc.getElementById("test"); 1.648 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.649 + var condition = function() objLoadingContent.activated; 1.650 + waitForCondition(condition, test21c, "Test 21b, Waited too long for plugin to activate"); 1.651 +} 1.652 + 1.653 +function test21c() { 1.654 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.655 + ok(notification, "Test 21c, Should have a click-to-play notification"); 1.656 + 1.657 + notification.reshow(); 1.658 + ok(notification.options.pluginData.size == 2, "Test 21c, Should have one type of plugin in the notification"); 1.659 + 1.660 + var doc = gTestBrowser.contentDocument; 1.661 + var plugin = doc.getElementById("test"); 1.662 + var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.663 + ok(rect.width == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked"); 1.664 + ok(rect.height == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked"); 1.665 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.666 + ok(objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should be activated"); 1.667 + 1.668 + var ids = ["secondtestA", "secondtestB"]; 1.669 + for (var id of ids) { 1.670 + var plugin = doc.getElementById(id); 1.671 + var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.672 + ok(rect.width == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked"); 1.673 + ok(rect.height == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked"); 1.674 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.675 + ok(!objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should not be activated"); 1.676 + } 1.677 + 1.678 + var centerAction = null; 1.679 + for (var action of notification.options.pluginData.values()) { 1.680 + if (action.pluginName == "Second Test") { 1.681 + centerAction = action; 1.682 + break; 1.683 + } 1.684 + } 1.685 + ok(centerAction, "Test 21d, found center action for the Second Test plugin"); 1.686 + 1.687 + var centerItem = null; 1.688 + for (var item of PopupNotifications.panel.firstChild.childNodes) { 1.689 + if (item.action == centerAction) { 1.690 + is(item.value, "block", "Test 21d, test plugin 2 should start blocked"); 1.691 + centerItem = item; 1.692 + break; 1.693 + } 1.694 + else { 1.695 + is(item.value, "allownow", "Test 21d, test plugin should be enabled"); 1.696 + } 1.697 + } 1.698 + ok(centerItem, "Test 21d, found center item for the Second Test plugin"); 1.699 + 1.700 + // "click" the button to activate the Second Test plugins 1.701 + centerItem.value = "allownow"; 1.702 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.703 + 1.704 + var doc = gTestBrowser.contentDocument; 1.705 + var plugin = doc.getElementById("secondtestA"); 1.706 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.707 + var condition = function() objLoadingContent.activated; 1.708 + waitForCondition(condition, test21e, "Test 21d, Waited too long for plugin to activate"); 1.709 +} 1.710 + 1.711 +function test21e() { 1.712 + var doc = gTestBrowser.contentDocument; 1.713 + var ids = ["test", "secondtestA", "secondtestB"]; 1.714 + for (var id of ids) { 1.715 + var plugin = doc.getElementById(id); 1.716 + var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect(); 1.717 + ok(rect.width == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked"); 1.718 + ok(rect.height == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked"); 1.719 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.720 + ok(objLoadingContent.activated, "Test 21e, Plugin with id=" + plugin.id + " should be activated"); 1.721 + } 1.722 + 1.723 + getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.724 + getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.725 + 1.726 + clearAllPluginPermissions(); 1.727 + 1.728 + prepareTest(runAfterPluginBindingAttached(test22), gTestRoot + "plugin_test.html"); 1.729 +} 1.730 + 1.731 +// Tests that a click-to-play plugin retains its activated state upon reloading 1.732 +function test22() { 1.733 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 22, Should have a click-to-play notification"); 1.734 + 1.735 + // Plugin should start as CTP 1.736 + var pluginNode = gTestBrowser.contentDocument.getElementById("test"); 1.737 + ok(pluginNode, "Test 22, Found plugin in page"); 1.738 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.739 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 22, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); 1.740 + 1.741 + // Activate 1.742 + objLoadingContent.playPlugin(); 1.743 + is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, plugin should have started"); 1.744 + ok(pluginNode.activated, "Test 22, plugin should be activated"); 1.745 + 1.746 + // Spin event loop for plugin to finish spawning 1.747 + executeSoon(function() { 1.748 + var oldVal = pluginNode.getObjectValue(); 1.749 + pluginNode.src = pluginNode.src; 1.750 + is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, Plugin should have retained activated state"); 1.751 + ok(pluginNode.activated, "Test 22, plugin should have remained activated"); 1.752 + // Sanity, ensure that we actually reloaded the instance, since this behavior might change in the future. 1.753 + var pluginsDiffer; 1.754 + try { 1.755 + pluginNode.checkObjectValue(oldVal); 1.756 + } catch (e) { 1.757 + pluginsDiffer = true; 1.758 + } 1.759 + ok(pluginsDiffer, "Test 22, plugin should have reloaded"); 1.760 + 1.761 + prepareTest(runAfterPluginBindingAttached(test23), gTestRoot + "plugin_test.html"); 1.762 + }); 1.763 +} 1.764 + 1.765 +// Tests that a click-to-play plugin resets its activated state when changing types 1.766 +function test23() { 1.767 + ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 23, Should have a click-to-play notification"); 1.768 + 1.769 + // Plugin should start as CTP 1.770 + var pluginNode = gTestBrowser.contentDocument.getElementById("test"); 1.771 + ok(pluginNode, "Test 23, Found plugin in page"); 1.772 + var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent); 1.773 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); 1.774 + 1.775 + // Activate 1.776 + objLoadingContent.playPlugin(); 1.777 + is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 23, plugin should have started"); 1.778 + ok(pluginNode.activated, "Test 23, plugin should be activated"); 1.779 + 1.780 + // Reload plugin (this may need RunSoon() in the future when plugins change state asynchronously) 1.781 + pluginNode.type = null; 1.782 + // We currently don't properly change state just on type change, 1.783 + // so rebind the plugin to tree. bug 767631 1.784 + pluginNode.parentNode.appendChild(pluginNode); 1.785 + is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, plugin should be unloaded"); 1.786 + pluginNode.type = "application/x-test"; 1.787 + pluginNode.parentNode.appendChild(pluginNode); 1.788 + is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, Plugin should not have activated"); 1.789 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, Plugin should be click-to-play"); 1.790 + ok(!pluginNode.activated, "Test 23, plugin node should not be activated"); 1.791 + 1.792 + prepareTest(runAfterPluginBindingAttached(test24a), gHttpTestRoot + "plugin_test.html"); 1.793 +} 1.794 + 1.795 +// Test that "always allow"-ing a plugin will not allow it when it becomes 1.796 +// blocklisted. 1.797 +function test24a() { 1.798 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.799 + ok(notification, "Test 24a, Should have a click-to-play notification"); 1.800 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.801 + ok(plugin, "Test 24a, Found plugin in page"); 1.802 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.803 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 24a, Plugin should be click-to-play"); 1.804 + ok(!objLoadingContent.activated, "Test 24a, plugin should not be activated"); 1.805 + 1.806 + // simulate "always allow" 1.807 + notification.reshow(); 1.808 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.809 + prepareTest(test24b, gHttpTestRoot + "plugin_test.html"); 1.810 +} 1.811 + 1.812 +// did the "always allow" work as intended? 1.813 +function test24b() { 1.814 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.815 + ok(plugin, "Test 24b, Found plugin in page"); 1.816 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.817 + ok(objLoadingContent.activated, "Test 24b, plugin should be activated"); 1.818 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml", 1.819 + function() { 1.820 + prepareTest(runAfterPluginBindingAttached(test24c), gHttpTestRoot + "plugin_test.html"); 1.821 + }); 1.822 +} 1.823 + 1.824 +// the plugin is now blocklisted, so it should not automatically load 1.825 +function test24c() { 1.826 + var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); 1.827 + ok(notification, "Test 24c, Should have a click-to-play notification"); 1.828 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.829 + ok(plugin, "Test 24c, Found plugin in page"); 1.830 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.831 + is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 24c, Plugin should be vulnerable/updatable"); 1.832 + ok(!objLoadingContent.activated, "Test 24c, plugin should not be activated"); 1.833 + 1.834 + // simulate "always allow" 1.835 + notification.reshow(); 1.836 + PopupNotifications.panel.firstChild._primaryButton.click(); 1.837 + 1.838 + prepareTest(test24d, gHttpTestRoot + "plugin_test.html"); 1.839 +} 1.840 + 1.841 +// We should still be able to always allow a plugin after we've seen that it's 1.842 +// blocklisted. 1.843 +function test24d() { 1.844 + var plugin = gTestBrowser.contentDocument.getElementById("test"); 1.845 + ok(plugin, "Test 24d, Found plugin in page"); 1.846 + var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.847 + ok(objLoadingContent.activated, "Test 24d, plugin should be activated"); 1.848 + 1.849 + // this resets the vulnerable plugin permission 1.850 + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", 1.851 + function() { 1.852 + clearAllPluginPermissions(); 1.853 + resetBlocklist(); 1.854 + prepareTest(test25, gTestRoot + "plugin_syncRemoved.html"); 1.855 + }); 1.856 +} 1.857 + 1.858 +function test25() { 1.859 + let notification = PopupNotifications.getNotification("click-to-play-plugins"); 1.860 + ok(notification, "Test 25: There should be a plugin notification even if the plugin was immediately removed"); 1.861 + ok(notification.dismissed, "Test 25: The notification should be dismissed by default"); 1.862 + 1.863 + finishTest(); 1.864 +}