browser/base/content/test/plugins/browser_pluginnotification.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 var rootDir = getRootDirectory(gTestPath);
michael@0 2 const gTestRoot = rootDir;
michael@0 3 const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/");
michael@0 4
michael@0 5 var gTestBrowser = null;
michael@0 6 var gNextTest = null;
michael@0 7 var gPluginHost = Components.classes["@mozilla.org/plugin/host;1"].getService(Components.interfaces.nsIPluginHost);
michael@0 8
michael@0 9 Components.utils.import("resource://gre/modules/Services.jsm");
michael@0 10
michael@0 11 // This listens for the next opened tab and checks it is of the right url.
michael@0 12 // opencallback is called when the new tab is fully loaded
michael@0 13 // closecallback is called when the tab is closed
michael@0 14 function TabOpenListener(url, opencallback, closecallback) {
michael@0 15 this.url = url;
michael@0 16 this.opencallback = opencallback;
michael@0 17 this.closecallback = closecallback;
michael@0 18
michael@0 19 gBrowser.tabContainer.addEventListener("TabOpen", this, false);
michael@0 20 }
michael@0 21
michael@0 22 TabOpenListener.prototype = {
michael@0 23 url: null,
michael@0 24 opencallback: null,
michael@0 25 closecallback: null,
michael@0 26 tab: null,
michael@0 27 browser: null,
michael@0 28
michael@0 29 handleEvent: function(event) {
michael@0 30 if (event.type == "TabOpen") {
michael@0 31 gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
michael@0 32 this.tab = event.originalTarget;
michael@0 33 this.browser = this.tab.linkedBrowser;
michael@0 34 gBrowser.addEventListener("pageshow", this, false);
michael@0 35 } else if (event.type == "pageshow") {
michael@0 36 if (event.target.location.href != this.url)
michael@0 37 return;
michael@0 38 gBrowser.removeEventListener("pageshow", this, false);
michael@0 39 this.tab.addEventListener("TabClose", this, false);
michael@0 40 var url = this.browser.contentDocument.location.href;
michael@0 41 is(url, this.url, "Should have opened the correct tab");
michael@0 42 this.opencallback(this.tab, this.browser.contentWindow);
michael@0 43 } else if (event.type == "TabClose") {
michael@0 44 if (event.originalTarget != this.tab)
michael@0 45 return;
michael@0 46 this.tab.removeEventListener("TabClose", this, false);
michael@0 47 this.opencallback = null;
michael@0 48 this.tab = null;
michael@0 49 this.browser = null;
michael@0 50 // Let the window close complete
michael@0 51 executeSoon(this.closecallback);
michael@0 52 this.closecallback = null;
michael@0 53 }
michael@0 54 }
michael@0 55 };
michael@0 56
michael@0 57 function test() {
michael@0 58 waitForExplicitFinish();
michael@0 59 requestLongerTimeout(2);
michael@0 60 registerCleanupFunction(function() {
michael@0 61 clearAllPluginPermissions();
michael@0 62 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
michael@0 63 Services.prefs.clearUserPref("plugins.hideMissingPluginsNotification");
michael@0 64 });
michael@0 65 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
michael@0 66
michael@0 67 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY);
michael@0 68 setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY, "Second Test Plug-in");
michael@0 69
michael@0 70 var newTab = gBrowser.addTab();
michael@0 71 gBrowser.selectedTab = newTab;
michael@0 72 gTestBrowser = gBrowser.selectedBrowser;
michael@0 73 gTestBrowser.addEventListener("load", pageLoad, true);
michael@0 74 prepareTest(runAfterPluginBindingAttached(test1a), gTestRoot + "plugin_unknown.html");
michael@0 75 }
michael@0 76
michael@0 77 function finishTest() {
michael@0 78 clearAllPluginPermissions();
michael@0 79 gTestBrowser.removeEventListener("load", pageLoad, true);
michael@0 80 gBrowser.removeCurrentTab();
michael@0 81 window.focus();
michael@0 82 finish();
michael@0 83 }
michael@0 84
michael@0 85 function pageLoad() {
michael@0 86 // The plugin events are async dispatched and can come after the load event
michael@0 87 // This just allows the events to fire before we then go on to test the states
michael@0 88 executeSoon(gNextTest);
michael@0 89 }
michael@0 90
michael@0 91 function prepareTest(nextTest, url) {
michael@0 92 gNextTest = nextTest;
michael@0 93 gTestBrowser.contentWindow.location = url;
michael@0 94 }
michael@0 95
michael@0 96 // Due to layout being async, "PluginBindAttached" may trigger later.
michael@0 97 // This wraps a function to force a layout flush, thus triggering it,
michael@0 98 // and schedules the function execution so they're definitely executed
michael@0 99 // afterwards.
michael@0 100 function runAfterPluginBindingAttached(func) {
michael@0 101 return function() {
michael@0 102 let doc = gTestBrowser.contentDocument;
michael@0 103 let elems = doc.getElementsByTagName('embed');
michael@0 104 if (elems.length < 1) {
michael@0 105 elems = doc.getElementsByTagName('object');
michael@0 106 }
michael@0 107 elems[0].clientTop;
michael@0 108 executeSoon(func);
michael@0 109 };
michael@0 110 }
michael@0 111
michael@0 112 // Tests a page with an unknown plugin in it.
michael@0 113 function test1a() {
michael@0 114 ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 1a, Should have displayed the missing plugin notification");
michael@0 115 ok(gTestBrowser.missingPlugins, "Test 1a, Should be a missing plugin list");
michael@0 116 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 1a, Should know about application/x-unknown");
michael@0 117 ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 1a, Should not know about application/x-test");
michael@0 118
michael@0 119 var pluginNode = gTestBrowser.contentDocument.getElementById("unknown");
michael@0 120 ok(pluginNode, "Test 1a, Found plugin in page");
michael@0 121 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 122 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_UNSUPPORTED, "Test 1a, plugin fallback type should be PLUGIN_UNSUPPORTED");
michael@0 123
michael@0 124 Services.prefs.setBoolPref("plugins.hideMissingPluginsNotification", true);
michael@0 125 prepareTest(runAfterPluginBindingAttached(test1b), gTestRoot + "plugin_unknown.html");
michael@0 126 }
michael@0 127
michael@0 128
michael@0 129 function test1b() {
michael@0 130 ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 1b, Should not have displayed the missing plugin notification");
michael@0 131 ok(!gTestBrowser.missingPlugins, "Test 1b, Should not be a missing plugin list");
michael@0 132 Services.prefs.clearUserPref("plugins.hideMissingPluginsNotification");
michael@0 133
michael@0 134 var plugin = getTestPlugin();
michael@0 135 ok(plugin, "Test 1b, Should have a test plugin");
michael@0 136 plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 137 prepareTest(runAfterPluginBindingAttached(test2), gTestRoot + "plugin_test.html");
michael@0 138 }
michael@0 139
michael@0 140 // Tests a page with a working plugin in it.
michael@0 141 function test2() {
michael@0 142 ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 2, Should not have displayed the missing plugin notification");
michael@0 143 ok(!gTestBrowser.missingPlugins, "Test 2, Should not be a missing plugin list");
michael@0 144
michael@0 145 var plugin = getTestPlugin();
michael@0 146 ok(plugin, "Should have a test plugin");
michael@0 147 plugin.enabledState = Ci.nsIPluginTag.STATE_DISABLED;
michael@0 148 prepareTest(runAfterPluginBindingAttached(test3), gTestRoot + "plugin_test.html");
michael@0 149 }
michael@0 150
michael@0 151 // Tests a page with a disabled plugin in it.
michael@0 152 function test3() {
michael@0 153 ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 3, Should not have displayed the missing plugin notification");
michael@0 154 ok(!gTestBrowser.missingPlugins, "Test 3, Should not be a missing plugin list");
michael@0 155
michael@0 156 new TabOpenListener("about:addons", test4, prepareTest5);
michael@0 157
michael@0 158 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
michael@0 159 ok(pluginNode, "Test 3, Found plugin in page");
michael@0 160 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 161 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_DISABLED, "Test 3, plugin fallback type should be PLUGIN_DISABLED");
michael@0 162 var manageLink = gTestBrowser.contentDocument.getAnonymousElementByAttribute(pluginNode, "anonid", "managePluginsLink");
michael@0 163 ok(manageLink, "Test 3, found 'manage' link in plugin-problem binding");
michael@0 164
michael@0 165 EventUtils.synthesizeMouseAtCenter(manageLink, {}, gTestBrowser.contentWindow);
michael@0 166 }
michael@0 167
michael@0 168 function test4(tab, win) {
michael@0 169 is(win.wrappedJSObject.gViewController.currentViewId, "addons://list/plugin", "Test 4, Should have displayed the plugins pane");
michael@0 170 gBrowser.removeTab(tab);
michael@0 171 }
michael@0 172
michael@0 173 function prepareTest5() {
michael@0 174 info("prepareTest5");
michael@0 175 var plugin = getTestPlugin();
michael@0 176 plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 177 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml",
michael@0 178 function() {
michael@0 179 info("prepareTest5 callback");
michael@0 180 prepareTest(runAfterPluginBindingAttached(test5), gTestRoot + "plugin_test.html");
michael@0 181 });
michael@0 182 }
michael@0 183
michael@0 184 // Tests a page with a blocked plugin in it.
michael@0 185 function test5() {
michael@0 186 info("test5");
michael@0 187 ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 5, Should not have displayed the missing plugin notification");
michael@0 188 let notification = PopupNotifications.getNotification("click-to-play-plugins");
michael@0 189 ok(notification, "Test 5: There should be a plugin notification for blocked plugins");
michael@0 190 ok(notification.dismissed, "Test 5: The plugin notification should be dismissed by default");
michael@0 191
michael@0 192 notification.reshow();
michael@0 193 is(notification.options.pluginData.size, 1, "Test 5: Only the blocked plugin should be present in the notification");
michael@0 194 ok(PopupNotifications.panel.firstChild._buttonContainer.hidden, "Part 5: The blocked plugins notification should not have any buttons visible.");
michael@0 195
michael@0 196 ok(!gTestBrowser.missingPlugins, "Test 5, Should not be a missing plugin list");
michael@0 197 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
michael@0 198 ok(pluginNode, "Test 5, Found plugin in page");
michael@0 199 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 200 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_BLOCKLISTED, "Test 5, plugin fallback type should be PLUGIN_BLOCKLISTED");
michael@0 201
michael@0 202 prepareTest(runAfterPluginBindingAttached(test6), gTestRoot + "plugin_both.html");
michael@0 203 }
michael@0 204
michael@0 205 // Tests a page with a blocked and unknown plugin in it.
michael@0 206 function test6() {
michael@0 207 ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 6, Should have displayed the missing plugin notification");
michael@0 208 ok(gTestBrowser.missingPlugins, "Test 6, Should be a missing plugin list");
michael@0 209 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 6, Should know about application/x-unknown");
michael@0 210 ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 6, application/x-test should not be a missing plugin");
michael@0 211
michael@0 212 prepareTest(runAfterPluginBindingAttached(test7), gTestRoot + "plugin_both2.html");
michael@0 213 }
michael@0 214
michael@0 215 // Tests a page with a blocked and unknown plugin in it (alternate order to above).
michael@0 216 function test7() {
michael@0 217 ok(PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 7, Should have displayed the missing plugin notification");
michael@0 218 ok(gTestBrowser.missingPlugins, "Test 7, Should be a missing plugin list");
michael@0 219 ok(gTestBrowser.missingPlugins.has("application/x-unknown"), "Test 7, Should know about application/x-unknown");
michael@0 220 ok(!gTestBrowser.missingPlugins.has("application/x-test"), "Test 7, application/x-test should not be a missing plugin");
michael@0 221
michael@0 222 var plugin = getTestPlugin();
michael@0 223 plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 224 getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 225
michael@0 226 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
michael@0 227 prepareTest(runAfterPluginBindingAttached(test8), gTestRoot + "plugin_test.html");
michael@0 228 });
michael@0 229 }
michael@0 230
michael@0 231 // Tests a page with a working plugin that is click-to-play
michael@0 232 function test8() {
michael@0 233 ok(!PopupNotifications.getNotification("plugins-not-found", gTestBrowser), "Test 8, Should not have displayed the missing plugin notification");
michael@0 234 ok(!gTestBrowser.missingPlugins, "Test 8, Should not be a missing plugin list");
michael@0 235 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 8, Should have a click-to-play notification");
michael@0 236
michael@0 237 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
michael@0 238 ok(pluginNode, "Test 8, Found plugin in page");
michael@0 239 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 240 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 8, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
michael@0 241
michael@0 242 prepareTest(runAfterPluginBindingAttached(test11a), gTestRoot + "plugin_test3.html");
michael@0 243 }
michael@0 244
michael@0 245 // Tests 9 & 10 removed
michael@0 246
michael@0 247 // Tests that the going back will reshow the notification for click-to-play plugins (part 1/4)
michael@0 248 function test11a() {
michael@0 249 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 250 ok(popupNotification, "Test 11a, Should have a click-to-play notification");
michael@0 251
michael@0 252 prepareTest(test11b, "about:blank");
michael@0 253 }
michael@0 254
michael@0 255 // Tests that the going back will reshow the notification for click-to-play plugins (part 2/4)
michael@0 256 function test11b() {
michael@0 257 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 258 ok(!popupNotification, "Test 11b, Should not have a click-to-play notification");
michael@0 259
michael@0 260 Services.obs.addObserver(test11c, "PopupNotifications-updateNotShowing", false);
michael@0 261 gTestBrowser.contentWindow.history.back();
michael@0 262 }
michael@0 263
michael@0 264 // Tests that the going back will reshow the notification for click-to-play plugins (part 3/4)
michael@0 265 function test11c() {
michael@0 266 Services.obs.removeObserver(test11c, "PopupNotifications-updateNotShowing");
michael@0 267 var condition = function() PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 268 waitForCondition(condition, test11d, "Test 11c, waited too long for click-to-play-plugin notification");
michael@0 269 }
michael@0 270
michael@0 271 // Tests that the going back will reshow the notification for click-to-play plugins (part 4/4)
michael@0 272 function test11d() {
michael@0 273 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 274 ok(popupNotification, "Test 11d, Should have a click-to-play notification");
michael@0 275
michael@0 276 prepareTest(runAfterPluginBindingAttached(test12a), gHttpTestRoot + "plugin_clickToPlayAllow.html");
michael@0 277 }
michael@0 278
michael@0 279 // Tests that the "Allow Always" permission works for click-to-play plugins
michael@0 280 function test12a() {
michael@0 281 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 282 ok(popupNotification, "Test 12a, Should have a click-to-play notification");
michael@0 283 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 284 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 285 ok(!objLoadingContent.activated, "Test 12a, Plugin should not be activated");
michael@0 286
michael@0 287 // Simulate clicking the "Allow Always" button.
michael@0 288 popupNotification.reshow();
michael@0 289 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 290
michael@0 291 var condition = function() objLoadingContent.activated;
michael@0 292 waitForCondition(condition, test12b, "Test 12a, Waited too long for plugin to activate");
michael@0 293 }
michael@0 294
michael@0 295 function test12b() {
michael@0 296 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 297 ok(popupNotification, "Test 12d, Should have a click-to-play notification");
michael@0 298 prepareTest(runAfterPluginBindingAttached(test12c), gHttpTestRoot + "plugin_two_types.html");
michael@0 299 }
michael@0 300
michael@0 301 // Test that the "Always" permission, when set for just the Test plugin,
michael@0 302 // does not also allow the Second Test plugin.
michael@0 303 function test12c() {
michael@0 304 var popupNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 305 ok(popupNotification, "Test 12d, Should have a click-to-play notification");
michael@0 306 var test = gTestBrowser.contentDocument.getElementById("test");
michael@0 307 var secondtestA = gTestBrowser.contentDocument.getElementById("secondtestA");
michael@0 308 var secondtestB = gTestBrowser.contentDocument.getElementById("secondtestB");
michael@0 309 ok(test.activated, "Test 12d, Test plugin should be activated");
michael@0 310 ok(!secondtestA.activated, "Test 12d, Second Test plugin (A) should not be activated");
michael@0 311 ok(!secondtestB.activated, "Test 12d, Second Test plugin (B) should not be activated");
michael@0 312
michael@0 313 clearAllPluginPermissions();
michael@0 314 var plugin = getTestPlugin();
michael@0 315 plugin.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 316 prepareTest(test14, gTestRoot + "plugin_test2.html");
michael@0 317 }
michael@0 318
michael@0 319 // Test 13 removed
michael@0 320
michael@0 321 // Tests that the plugin's "activated" property is true for working plugins with click-to-play disabled.
michael@0 322 function test14() {
michael@0 323 var plugin = gTestBrowser.contentDocument.getElementById("test1");
michael@0 324 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 325 ok(objLoadingContent.activated, "Test 14, Plugin should be activated");
michael@0 326
michael@0 327 var plugin = getTestPlugin();
michael@0 328 plugin.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 329 getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 330 prepareTest(runAfterPluginBindingAttached(test15), gTestRoot + "plugin_alternate_content.html");
michael@0 331 }
michael@0 332
michael@0 333 // Tests that the overlay is shown instead of alternate content when
michael@0 334 // plugins are click to play
michael@0 335 function test15() {
michael@0 336 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 337 var doc = gTestBrowser.contentDocument;
michael@0 338 var mainBox = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 339 ok(mainBox, "Test 15, Plugin with id=" + plugin.id + " overlay should exist");
michael@0 340
michael@0 341 prepareTest(runAfterPluginBindingAttached(test17), gTestRoot + "plugin_bug749455.html");
michael@0 342 }
michael@0 343
michael@0 344 // Test 16 removed
michael@0 345
michael@0 346 // Tests that mContentType is used for click-to-play plugins, and not the
michael@0 347 // inspected type.
michael@0 348 function test17() {
michael@0 349 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 350 ok(clickToPlayNotification, "Test 17, Should have a click-to-play notification");
michael@0 351 var missingNotification = PopupNotifications.getNotification("missing-plugins", gTestBrowser);
michael@0 352 ok(!missingNotification, "Test 17, Should not have a missing plugin notification");
michael@0 353
michael@0 354 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
michael@0 355 function() {
michael@0 356 prepareTest(runAfterPluginBindingAttached(test18a), gHttpTestRoot + "plugin_test.html");
michael@0 357 });
michael@0 358 }
michael@0 359
michael@0 360 // Tests a vulnerable, updatable plugin
michael@0 361 function test18a() {
michael@0 362 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 363 ok(clickToPlayNotification, "Test 18a, Should have a click-to-play notification");
michael@0 364 var doc = gTestBrowser.contentDocument;
michael@0 365 var plugin = doc.getElementById("test");
michael@0 366 ok(plugin, "Test 18a, Found plugin in page");
michael@0 367 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 368 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 18a, plugin fallback type should be PLUGIN_VULNERABLE_UPDATABLE");
michael@0 369 ok(!objLoadingContent.activated, "Test 18a, Plugin should not be activated");
michael@0 370 var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 371 ok(overlay.classList.contains("visible"), "Test 18a, Plugin overlay should exist, not be hidden");
michael@0 372 var updateLink = doc.getAnonymousElementByAttribute(plugin, "anonid", "checkForUpdatesLink");
michael@0 373 ok(updateLink.style.visibility != "hidden", "Test 18a, Plugin should have an update link");
michael@0 374
michael@0 375 var tabOpenListener = new TabOpenListener(Services.urlFormatter.formatURLPref("plugins.update.url"), false, false);
michael@0 376 tabOpenListener.handleEvent = function(event) {
michael@0 377 if (event.type == "TabOpen") {
michael@0 378 gBrowser.tabContainer.removeEventListener("TabOpen", this, false);
michael@0 379 this.tab = event.originalTarget;
michael@0 380 is(event.target.label, this.url, "Test 18a, Update link should open up the plugin check page");
michael@0 381 gBrowser.removeTab(this.tab);
michael@0 382 test18b();
michael@0 383 }
michael@0 384 };
michael@0 385 EventUtils.synthesizeMouseAtCenter(updateLink, {}, gTestBrowser.contentWindow);
michael@0 386 }
michael@0 387
michael@0 388 function test18b() {
michael@0 389 // clicking the update link should not activate the plugin
michael@0 390 var doc = gTestBrowser.contentDocument;
michael@0 391 var plugin = doc.getElementById("test");
michael@0 392 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 393 ok(!objLoadingContent.activated, "Test 18b, Plugin should not be activated");
michael@0 394 var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 395 ok(overlay.classList.contains("visible"), "Test 18b, Plugin overlay should exist, not be hidden");
michael@0 396
michael@0 397 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableNoUpdate.xml",
michael@0 398 function() {
michael@0 399 prepareTest(runAfterPluginBindingAttached(test18c), gHttpTestRoot + "plugin_test.html");
michael@0 400 });
michael@0 401 }
michael@0 402
michael@0 403 // Tests a vulnerable plugin with no update
michael@0 404 function test18c() {
michael@0 405 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 406 ok(clickToPlayNotification, "Test 18c, Should have a click-to-play notification");
michael@0 407 var doc = gTestBrowser.contentDocument;
michael@0 408 var plugin = doc.getElementById("test");
michael@0 409 ok(plugin, "Test 18c, Found plugin in page");
michael@0 410 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 411 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_NO_UPDATE, "Test 18c, plugin fallback type should be PLUGIN_VULNERABLE_NO_UPDATE");
michael@0 412 ok(!objLoadingContent.activated, "Test 18c, Plugin should not be activated");
michael@0 413 var overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 414 ok(overlay.classList.contains("visible"), "Test 18c, Plugin overlay should exist, not be hidden");
michael@0 415 var updateLink = doc.getAnonymousElementByAttribute(plugin, "anonid", "checkForUpdatesLink");
michael@0 416 ok(updateLink.style.display != "block", "Test 18c, Plugin should not have an update link");
michael@0 417
michael@0 418 // check that click "Always allow" works with blocklisted plugins
michael@0 419 clickToPlayNotification.reshow();
michael@0 420 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 421
michael@0 422 var condition = function() objLoadingContent.activated;
michael@0 423 waitForCondition(condition, test18d, "Test 18d, Waited too long for plugin to activate");
michael@0 424 }
michael@0 425
michael@0 426 // continue testing "Always allow"
michael@0 427 function test18d() {
michael@0 428 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 429 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 430 ok(objLoadingContent.activated, "Test 18d, Plugin should be activated");
michael@0 431
michael@0 432 prepareTest(test18e, gHttpTestRoot + "plugin_test.html");
michael@0 433 }
michael@0 434
michael@0 435 // continue testing "Always allow"
michael@0 436 function test18e() {
michael@0 437 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 438 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 439 ok(objLoadingContent.activated, "Test 18e, Plugin should be activated");
michael@0 440
michael@0 441 clearAllPluginPermissions();
michael@0 442 prepareTest(runAfterPluginBindingAttached(test18f), gHttpTestRoot + "plugin_test.html");
michael@0 443 }
michael@0 444
michael@0 445 // clicking the in-content overlay of a vulnerable plugin should bring
michael@0 446 // up the notification and not directly activate the plugin
michael@0 447 function test18f() {
michael@0 448 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 449 ok(notification, "Test 18f, Should have a click-to-play notification");
michael@0 450 ok(notification.dismissed, "Test 18f, notification should start dismissed");
michael@0 451 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 452 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 453 ok(!objLoadingContent.activated, "Test 18f, Plugin should not be activated");
michael@0 454
michael@0 455 var oldEventCallback = notification.options.eventCallback;
michael@0 456 notification.options.eventCallback = function() {
michael@0 457 oldEventCallback();
michael@0 458 executeSoon(test18g);
michael@0 459 };
michael@0 460 EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow);
michael@0 461 }
michael@0 462
michael@0 463 function test18g() {
michael@0 464 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 465 ok(notification, "Test 18g, Should have a click-to-play notification");
michael@0 466 ok(!notification.dismissed, "Test 18g, notification should be open");
michael@0 467 notification.options.eventCallback = null;
michael@0 468 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 469 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 470 ok(!objLoadingContent.activated, "Test 18g, Plugin should not be activated");
michael@0 471
michael@0 472 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
michael@0 473 function() {
michael@0 474 resetBlocklist();
michael@0 475 prepareTest(runAfterPluginBindingAttached(test19a), gTestRoot + "plugin_test.html");
michael@0 476 });
michael@0 477 }
michael@0 478
michael@0 479 // Tests that clicking the icon of the overlay activates the doorhanger
michael@0 480 function test19a() {
michael@0 481 var doc = gTestBrowser.contentDocument;
michael@0 482 var plugin = doc.getElementById("test");
michael@0 483 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 484 ok(!objLoadingContent.activated, "Test 19a, Plugin should not be activated");
michael@0 485 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19a, Doorhanger should start out dismissed");
michael@0 486
michael@0 487 var icon = doc.getAnonymousElementByAttribute(plugin, "class", "icon");
michael@0 488 EventUtils.synthesizeMouseAtCenter(icon, {}, gTestBrowser.contentWindow);
michael@0 489 let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed;
michael@0 490 waitForCondition(condition, test19b, "Test 19a, Waited too long for doorhanger to activate");
michael@0 491 }
michael@0 492
michael@0 493 function test19b() {
michael@0 494 prepareTest(runAfterPluginBindingAttached(test19c), gTestRoot + "plugin_test.html");
michael@0 495 }
michael@0 496
michael@0 497 // Tests that clicking the text of the overlay activates the plugin
michael@0 498 function test19c() {
michael@0 499 var doc = gTestBrowser.contentDocument;
michael@0 500 var plugin = doc.getElementById("test");
michael@0 501 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 502 ok(!objLoadingContent.activated, "Test 19c, Plugin should not be activated");
michael@0 503
michael@0 504 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19c, Doorhanger should start out dismissed");
michael@0 505
michael@0 506 var text = doc.getAnonymousElementByAttribute(plugin, "class", "msg msgClickToPlay");
michael@0 507 EventUtils.synthesizeMouseAtCenter(text, {}, gTestBrowser.contentWindow);
michael@0 508 let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed;
michael@0 509 waitForCondition(condition, test19d, "Test 19c, Waited too long for doorhanger to activate");
michael@0 510 }
michael@0 511
michael@0 512 function test19d() {
michael@0 513 prepareTest(runAfterPluginBindingAttached(test19e), gTestRoot + "plugin_test.html");
michael@0 514 }
michael@0 515
michael@0 516 // Tests that clicking the box of the overlay activates the doorhanger
michael@0 517 // (just to be thorough)
michael@0 518 function test19e() {
michael@0 519 var doc = gTestBrowser.contentDocument;
michael@0 520 var plugin = doc.getElementById("test");
michael@0 521 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 522 ok(!objLoadingContent.activated, "Test 19e, Plugin should not be activated");
michael@0 523
michael@0 524 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 19e, Doorhanger should start out dismissed");
michael@0 525
michael@0 526 EventUtils.synthesizeMouse(plugin, 50, 50, {}, gTestBrowser.contentWindow);
michael@0 527 let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed;
michael@0 528 waitForCondition(condition, test19f, "Test 19e, Waited too long for plugin to activate");
michael@0 529 }
michael@0 530
michael@0 531 function test19f() {
michael@0 532 prepareTest(test20a, gTestRoot + "plugin_hidden_to_visible.html");
michael@0 533 }
michael@0 534
michael@0 535 // Tests that a plugin in a div that goes from style="display: none" to
michael@0 536 // "display: block" can be clicked to activate.
michael@0 537 function test20a() {
michael@0 538 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 539 ok(!clickToPlayNotification, "Test 20a, Should not have a click-to-play notification");
michael@0 540 var doc = gTestBrowser.contentDocument;
michael@0 541 var plugin = doc.getElementById("plugin");
michael@0 542 var mainBox = doc.getAnonymousElementByAttribute(plugin, "anonid", "main");
michael@0 543 ok(mainBox, "Test 20a, plugin overlay should not be null");
michael@0 544 var pluginRect = mainBox.getBoundingClientRect();
michael@0 545 ok(pluginRect.width == 0, "Test 20a, plugin should have an overlay with 0px width");
michael@0 546 ok(pluginRect.height == 0, "Test 20a, plugin should have an overlay with 0px height");
michael@0 547 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 548 ok(!objLoadingContent.activated, "Test 20a, plugin should not be activated");
michael@0 549 var div = doc.getElementById("container");
michael@0 550 ok(div.style.display == "none", "Test 20a, container div should be display: none");
michael@0 551
michael@0 552 div.style.display = "block";
michael@0 553 var condition = function() {
michael@0 554 var pluginRect = mainBox.getBoundingClientRect();
michael@0 555 return (pluginRect.width == 200);
michael@0 556 }
michael@0 557 waitForCondition(condition, test20b, "Test 20a, Waited too long for plugin to become visible");
michael@0 558 }
michael@0 559
michael@0 560 function test20b() {
michael@0 561 var clickToPlayNotification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 562 ok(clickToPlayNotification, "Test 20b, Should now have a click-to-play notification");
michael@0 563 var doc = gTestBrowser.contentDocument;
michael@0 564 var plugin = doc.getElementById("plugin");
michael@0 565 var pluginRect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 566 ok(pluginRect.width == 200, "Test 20b, plugin should have an overlay with 200px width");
michael@0 567 ok(pluginRect.height == 200, "Test 20b, plugin should have an overlay with 200px height");
michael@0 568 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 569 ok(!objLoadingContent.activated, "Test 20b, plugin should not be activated");
michael@0 570
michael@0 571 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed, "Test 20b, Doorhanger should start out dismissed");
michael@0 572
michael@0 573 EventUtils.synthesizeMouseAtCenter(plugin, {}, gTestBrowser.contentWindow);
michael@0 574 let condition = function() !PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser).dismissed;
michael@0 575 waitForCondition(condition, test20c, "Test 20b, Waited too long for plugin to activate");
michael@0 576 }
michael@0 577
michael@0 578 function test20c() {
michael@0 579 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 580 var doc = gTestBrowser.contentDocument;
michael@0 581 var plugin = doc.getElementById("plugin");
michael@0 582 let condition = function() plugin.activated;
michael@0 583 waitForCondition(condition, test20d, "Test 20c", "Waiting for plugin to activate");
michael@0 584 }
michael@0 585
michael@0 586 function test20d() {
michael@0 587 var doc = gTestBrowser.contentDocument;
michael@0 588 var plugin = doc.getElementById("plugin");
michael@0 589 var pluginRect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 590 ok(pluginRect.width == 0, "Test 20d, plugin should have click-to-play overlay with zero width");
michael@0 591 ok(pluginRect.height == 0, "Test 20d, plugin should have click-to-play overlay with zero height");
michael@0 592 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 593 ok(objLoadingContent.activated, "Test 20d, plugin should be activated");
michael@0 594
michael@0 595 clearAllPluginPermissions();
michael@0 596
michael@0 597 prepareTest(runAfterPluginBindingAttached(test21a), gTestRoot + "plugin_two_types.html");
michael@0 598 }
michael@0 599
michael@0 600 // Test having multiple different types of plugin on one page
michael@0 601 function test21a() {
michael@0 602 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 603 ok(notification, "Test 21a, Should have a click-to-play notification");
michael@0 604
michael@0 605 var doc = gTestBrowser.contentDocument;
michael@0 606 var ids = ["test", "secondtestA", "secondtestB"];
michael@0 607 for (var id of ids) {
michael@0 608 var plugin = doc.getElementById(id);
michael@0 609 var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 610 ok(rect.width == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked");
michael@0 611 ok(rect.height == 200, "Test 21a, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked");
michael@0 612 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 613 ok(!objLoadingContent.activated, "Test 21a, Plugin with id=" + plugin.id + " should not be activated");
michael@0 614 }
michael@0 615
michael@0 616 // we have to actually show the panel to get the bindings to instantiate
michael@0 617 notification.reshow();
michael@0 618 is(notification.options.pluginData.size, 2, "Test 21a, Should have two types of plugin in the notification");
michael@0 619
michael@0 620 var centerAction = null;
michael@0 621 for (var action of notification.options.pluginData.values()) {
michael@0 622 if (action.pluginName == "Test") {
michael@0 623 centerAction = action;
michael@0 624 break;
michael@0 625 }
michael@0 626 }
michael@0 627 ok(centerAction, "Test 21b, found center action for the Test plugin");
michael@0 628
michael@0 629 var centerItem = null;
michael@0 630 for (var item of PopupNotifications.panel.firstChild.childNodes) {
michael@0 631 is(item.value, "block", "Test 21b, all plugins should start out blocked");
michael@0 632 if (item.action == centerAction) {
michael@0 633 centerItem = item;
michael@0 634 break;
michael@0 635 }
michael@0 636 }
michael@0 637 ok(centerItem, "Test 21b, found center item for the Test plugin");
michael@0 638
michael@0 639 // "click" the button to activate the Test plugin
michael@0 640 centerItem.value = "allownow";
michael@0 641 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 642
michael@0 643 var doc = gTestBrowser.contentDocument;
michael@0 644 var plugin = doc.getElementById("test");
michael@0 645 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 646 var condition = function() objLoadingContent.activated;
michael@0 647 waitForCondition(condition, test21c, "Test 21b, Waited too long for plugin to activate");
michael@0 648 }
michael@0 649
michael@0 650 function test21c() {
michael@0 651 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 652 ok(notification, "Test 21c, Should have a click-to-play notification");
michael@0 653
michael@0 654 notification.reshow();
michael@0 655 ok(notification.options.pluginData.size == 2, "Test 21c, Should have one type of plugin in the notification");
michael@0 656
michael@0 657 var doc = gTestBrowser.contentDocument;
michael@0 658 var plugin = doc.getElementById("test");
michael@0 659 var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 660 ok(rect.width == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked");
michael@0 661 ok(rect.height == 0, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked");
michael@0 662 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 663 ok(objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should be activated");
michael@0 664
michael@0 665 var ids = ["secondtestA", "secondtestB"];
michael@0 666 for (var id of ids) {
michael@0 667 var plugin = doc.getElementById(id);
michael@0 668 var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 669 ok(rect.width == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px width before being clicked");
michael@0 670 ok(rect.height == 200, "Test 21c, Plugin with id=" + plugin.id + " overlay rect should have 200px height before being clicked");
michael@0 671 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 672 ok(!objLoadingContent.activated, "Test 21c, Plugin with id=" + plugin.id + " should not be activated");
michael@0 673 }
michael@0 674
michael@0 675 var centerAction = null;
michael@0 676 for (var action of notification.options.pluginData.values()) {
michael@0 677 if (action.pluginName == "Second Test") {
michael@0 678 centerAction = action;
michael@0 679 break;
michael@0 680 }
michael@0 681 }
michael@0 682 ok(centerAction, "Test 21d, found center action for the Second Test plugin");
michael@0 683
michael@0 684 var centerItem = null;
michael@0 685 for (var item of PopupNotifications.panel.firstChild.childNodes) {
michael@0 686 if (item.action == centerAction) {
michael@0 687 is(item.value, "block", "Test 21d, test plugin 2 should start blocked");
michael@0 688 centerItem = item;
michael@0 689 break;
michael@0 690 }
michael@0 691 else {
michael@0 692 is(item.value, "allownow", "Test 21d, test plugin should be enabled");
michael@0 693 }
michael@0 694 }
michael@0 695 ok(centerItem, "Test 21d, found center item for the Second Test plugin");
michael@0 696
michael@0 697 // "click" the button to activate the Second Test plugins
michael@0 698 centerItem.value = "allownow";
michael@0 699 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 700
michael@0 701 var doc = gTestBrowser.contentDocument;
michael@0 702 var plugin = doc.getElementById("secondtestA");
michael@0 703 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 704 var condition = function() objLoadingContent.activated;
michael@0 705 waitForCondition(condition, test21e, "Test 21d, Waited too long for plugin to activate");
michael@0 706 }
michael@0 707
michael@0 708 function test21e() {
michael@0 709 var doc = gTestBrowser.contentDocument;
michael@0 710 var ids = ["test", "secondtestA", "secondtestB"];
michael@0 711 for (var id of ids) {
michael@0 712 var plugin = doc.getElementById(id);
michael@0 713 var rect = doc.getAnonymousElementByAttribute(plugin, "anonid", "main").getBoundingClientRect();
michael@0 714 ok(rect.width == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px width after being clicked");
michael@0 715 ok(rect.height == 0, "Test 21e, Plugin with id=" + plugin.id + " overlay rect should have 0px height after being clicked");
michael@0 716 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 717 ok(objLoadingContent.activated, "Test 21e, Plugin with id=" + plugin.id + " should be activated");
michael@0 718 }
michael@0 719
michael@0 720 getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 721 getTestPlugin("Second Test Plug-in").enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 722
michael@0 723 clearAllPluginPermissions();
michael@0 724
michael@0 725 prepareTest(runAfterPluginBindingAttached(test22), gTestRoot + "plugin_test.html");
michael@0 726 }
michael@0 727
michael@0 728 // Tests that a click-to-play plugin retains its activated state upon reloading
michael@0 729 function test22() {
michael@0 730 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 22, Should have a click-to-play notification");
michael@0 731
michael@0 732 // Plugin should start as CTP
michael@0 733 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
michael@0 734 ok(pluginNode, "Test 22, Found plugin in page");
michael@0 735 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 736 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 22, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
michael@0 737
michael@0 738 // Activate
michael@0 739 objLoadingContent.playPlugin();
michael@0 740 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, plugin should have started");
michael@0 741 ok(pluginNode.activated, "Test 22, plugin should be activated");
michael@0 742
michael@0 743 // Spin event loop for plugin to finish spawning
michael@0 744 executeSoon(function() {
michael@0 745 var oldVal = pluginNode.getObjectValue();
michael@0 746 pluginNode.src = pluginNode.src;
michael@0 747 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 22, Plugin should have retained activated state");
michael@0 748 ok(pluginNode.activated, "Test 22, plugin should have remained activated");
michael@0 749 // Sanity, ensure that we actually reloaded the instance, since this behavior might change in the future.
michael@0 750 var pluginsDiffer;
michael@0 751 try {
michael@0 752 pluginNode.checkObjectValue(oldVal);
michael@0 753 } catch (e) {
michael@0 754 pluginsDiffer = true;
michael@0 755 }
michael@0 756 ok(pluginsDiffer, "Test 22, plugin should have reloaded");
michael@0 757
michael@0 758 prepareTest(runAfterPluginBindingAttached(test23), gTestRoot + "plugin_test.html");
michael@0 759 });
michael@0 760 }
michael@0 761
michael@0 762 // Tests that a click-to-play plugin resets its activated state when changing types
michael@0 763 function test23() {
michael@0 764 ok(PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser), "Test 23, Should have a click-to-play notification");
michael@0 765
michael@0 766 // Plugin should start as CTP
michael@0 767 var pluginNode = gTestBrowser.contentDocument.getElementById("test");
michael@0 768 ok(pluginNode, "Test 23, Found plugin in page");
michael@0 769 var objLoadingContent = pluginNode.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 770 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, plugin fallback type should be PLUGIN_CLICK_TO_PLAY");
michael@0 771
michael@0 772 // Activate
michael@0 773 objLoadingContent.playPlugin();
michael@0 774 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_PLUGIN, "Test 23, plugin should have started");
michael@0 775 ok(pluginNode.activated, "Test 23, plugin should be activated");
michael@0 776
michael@0 777 // Reload plugin (this may need RunSoon() in the future when plugins change state asynchronously)
michael@0 778 pluginNode.type = null;
michael@0 779 // We currently don't properly change state just on type change,
michael@0 780 // so rebind the plugin to tree. bug 767631
michael@0 781 pluginNode.parentNode.appendChild(pluginNode);
michael@0 782 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, plugin should be unloaded");
michael@0 783 pluginNode.type = "application/x-test";
michael@0 784 pluginNode.parentNode.appendChild(pluginNode);
michael@0 785 is(objLoadingContent.displayedType, Ci.nsIObjectLoadingContent.TYPE_NULL, "Test 23, Plugin should not have activated");
michael@0 786 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 23, Plugin should be click-to-play");
michael@0 787 ok(!pluginNode.activated, "Test 23, plugin node should not be activated");
michael@0 788
michael@0 789 prepareTest(runAfterPluginBindingAttached(test24a), gHttpTestRoot + "plugin_test.html");
michael@0 790 }
michael@0 791
michael@0 792 // Test that "always allow"-ing a plugin will not allow it when it becomes
michael@0 793 // blocklisted.
michael@0 794 function test24a() {
michael@0 795 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 796 ok(notification, "Test 24a, Should have a click-to-play notification");
michael@0 797 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 798 ok(plugin, "Test 24a, Found plugin in page");
michael@0 799 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 800 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, "Test 24a, Plugin should be click-to-play");
michael@0 801 ok(!objLoadingContent.activated, "Test 24a, plugin should not be activated");
michael@0 802
michael@0 803 // simulate "always allow"
michael@0 804 notification.reshow();
michael@0 805 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 806 prepareTest(test24b, gHttpTestRoot + "plugin_test.html");
michael@0 807 }
michael@0 808
michael@0 809 // did the "always allow" work as intended?
michael@0 810 function test24b() {
michael@0 811 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 812 ok(plugin, "Test 24b, Found plugin in page");
michael@0 813 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 814 ok(objLoadingContent.activated, "Test 24b, plugin should be activated");
michael@0 815 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginVulnerableUpdatable.xml",
michael@0 816 function() {
michael@0 817 prepareTest(runAfterPluginBindingAttached(test24c), gHttpTestRoot + "plugin_test.html");
michael@0 818 });
michael@0 819 }
michael@0 820
michael@0 821 // the plugin is now blocklisted, so it should not automatically load
michael@0 822 function test24c() {
michael@0 823 var notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser);
michael@0 824 ok(notification, "Test 24c, Should have a click-to-play notification");
michael@0 825 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 826 ok(plugin, "Test 24c, Found plugin in page");
michael@0 827 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 828 is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_VULNERABLE_UPDATABLE, "Test 24c, Plugin should be vulnerable/updatable");
michael@0 829 ok(!objLoadingContent.activated, "Test 24c, plugin should not be activated");
michael@0 830
michael@0 831 // simulate "always allow"
michael@0 832 notification.reshow();
michael@0 833 PopupNotifications.panel.firstChild._primaryButton.click();
michael@0 834
michael@0 835 prepareTest(test24d, gHttpTestRoot + "plugin_test.html");
michael@0 836 }
michael@0 837
michael@0 838 // We should still be able to always allow a plugin after we've seen that it's
michael@0 839 // blocklisted.
michael@0 840 function test24d() {
michael@0 841 var plugin = gTestBrowser.contentDocument.getElementById("test");
michael@0 842 ok(plugin, "Test 24d, Found plugin in page");
michael@0 843 var objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 844 ok(objLoadingContent.activated, "Test 24d, plugin should be activated");
michael@0 845
michael@0 846 // this resets the vulnerable plugin permission
michael@0 847 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml",
michael@0 848 function() {
michael@0 849 clearAllPluginPermissions();
michael@0 850 resetBlocklist();
michael@0 851 prepareTest(test25, gTestRoot + "plugin_syncRemoved.html");
michael@0 852 });
michael@0 853 }
michael@0 854
michael@0 855 function test25() {
michael@0 856 let notification = PopupNotifications.getNotification("click-to-play-plugins");
michael@0 857 ok(notification, "Test 25: There should be a plugin notification even if the plugin was immediately removed");
michael@0 858 ok(notification.dismissed, "Test 25: The notification should be dismissed by default");
michael@0 859
michael@0 860 finishTest();
michael@0 861 }

mercurial