michael@0: var rootDir = getRootDirectory(gTestPath); michael@0: const gTestRoot = rootDir; michael@0: const gHttpTestRoot = rootDir.replace("chrome://mochitests/content/", "http://127.0.0.1:8888/"); michael@0: michael@0: var gTestBrowser = null; michael@0: var gNextTest = null; michael@0: michael@0: Components.utils.import("resource://gre/modules/Services.jsm"); michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: registerCleanupFunction(function() { michael@0: clearAllPluginPermissions(); michael@0: Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); michael@0: }); michael@0: Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); michael@0: michael@0: var newTab = gBrowser.addTab(); michael@0: gBrowser.selectedTab = newTab; michael@0: gTestBrowser = gBrowser.selectedBrowser; michael@0: gTestBrowser.addEventListener("load", pageLoad, true); michael@0: michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: setTestPluginEnabledState(Ci.nsIPluginTag.STATE_CLICKTOPLAY); michael@0: michael@0: prepareTest(runAfterPluginBindingAttached(test1), gHttpTestRoot + "plugin_small.html"); michael@0: } michael@0: michael@0: function finishTest() { michael@0: gTestBrowser.removeEventListener("load", pageLoad, true); michael@0: gBrowser.removeCurrentTab(); michael@0: window.focus(); michael@0: finish(); michael@0: } michael@0: michael@0: function pageLoad() { michael@0: // The plugin events are async dispatched and can come after the load event michael@0: // This just allows the events to fire before we then go on to test the states michael@0: executeSoon(gNextTest); michael@0: } michael@0: michael@0: function prepareTest(nextTest, url) { michael@0: gNextTest = nextTest; michael@0: gTestBrowser.contentWindow.location = url; michael@0: } michael@0: michael@0: // Due to layout being async, "PluginBindAttached" may trigger later. michael@0: // This wraps a function to force a layout flush, thus triggering it, michael@0: // and schedules the function execution so they're definitely executed michael@0: // afterwards. michael@0: function runAfterPluginBindingAttached(func) { michael@0: return function() { michael@0: let doc = gTestBrowser.contentDocument; michael@0: let elems = doc.getElementsByTagName('embed'); michael@0: if (elems.length < 1) { michael@0: elems = doc.getElementsByTagName('object'); michael@0: } michael@0: elems[0].clientTop; michael@0: executeSoon(func); michael@0: }; michael@0: } michael@0: michael@0: // Tests for the notification bar for hidden plugins. michael@0: michael@0: function test1() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins"); michael@0: ok(notification, "Test 1: There should be a plugin notification"); michael@0: michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, michael@0: () => { michael@0: // Don't use setTestPluginEnabledState here because we already saved the michael@0: // prior value michael@0: getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_ENABLED; michael@0: prepareTest(test2, gTestRoot + "plugin_small.html"); michael@0: }, michael@0: "Test 1, expected to have a plugin notification bar"); michael@0: } michael@0: michael@0: function test2() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins"); michael@0: ok(notification, "Test 2: There should be a plugin notification"); michael@0: michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, michael@0: () => { michael@0: getTestPlugin().enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; michael@0: prepareTest(test3, gTestRoot + "plugin_overlayed.html"); michael@0: }, michael@0: "Test 2, expected to not have a plugin notification bar"); michael@0: } michael@0: michael@0: function test3() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins"); michael@0: ok(notification, "Test 3: There should be a plugin notification"); michael@0: michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, michael@0: test3b, michael@0: "Test 3, expected the plugin infobar to be triggered when plugin was overlayed"); michael@0: } michael@0: michael@0: function test3b() michael@0: { michael@0: let doc = gTestBrowser.contentDocument; michael@0: let plugin = doc.getElementById("test"); michael@0: ok(plugin, "Test 3b, Found plugin in page"); michael@0: plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, michael@0: "Test 3b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); michael@0: ok(!plugin.activated, "Test 3b, Plugin should not be activated"); michael@0: let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); michael@0: ok(!overlay.classList.contains("visible"), "Test 3b, Plugin overlay should be hidden"); michael@0: michael@0: prepareTest(test4, gTestRoot + "plugin_positioned.html"); michael@0: } michael@0: michael@0: function test4() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins"); michael@0: ok(notification, "Test 4: There should be a plugin notification"); michael@0: michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, michael@0: test4b, michael@0: "Test 4, expected the plugin infobar to be triggered when plugin was overlayed"); michael@0: } michael@0: michael@0: function test4b() { michael@0: let doc = gTestBrowser.contentDocument; michael@0: let plugin = doc.getElementById("test"); michael@0: ok(plugin, "Test 4b, Found plugin in page"); michael@0: plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: is(plugin.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, michael@0: "Test 4b, plugin fallback type should be PLUGIN_CLICK_TO_PLAY"); michael@0: ok(!plugin.activated, "Test 4b, Plugin should not be activated"); michael@0: let overlay = doc.getAnonymousElementByAttribute(plugin, "anonid", "main"); michael@0: ok(!overlay.classList.contains("visible"), "Test 4b, Plugin overlay should be hidden"); michael@0: michael@0: prepareTest(runAfterPluginBindingAttached(test5), gHttpTestRoot + "plugin_small.html"); michael@0: } michael@0: michael@0: // Test that the notification bar is getting dismissed when directly activating plugins michael@0: // via the doorhanger. michael@0: michael@0: function test5() { michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") !== null, michael@0: test6, michael@0: "Test 5, expected a notification bar for hidden plugins"); michael@0: } michael@0: michael@0: function test6() { michael@0: let notification = PopupNotifications.getNotification("click-to-play-plugins", gTestBrowser); michael@0: ok(notification, "Test 6, Should have a click-to-play notification"); michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: ok(plugin, "Test 6, Found plugin in page"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: is(objLoadingContent.pluginFallbackType, Ci.nsIObjectLoadingContent.PLUGIN_CLICK_TO_PLAY, michael@0: "Test 6, Plugin should be click-to-play"); michael@0: michael@0: // simulate "always allow" michael@0: notification.reshow(); michael@0: PopupNotifications.panel.firstChild._primaryButton.click(); michael@0: michael@0: let notificationBox = gBrowser.getNotificationBox(gTestBrowser); michael@0: waitForCondition(() => notificationBox.getNotificationWithValue("plugin-hidden") === null, michael@0: test7, michael@0: "Test 6, expected the notification bar for hidden plugins to get dismissed"); michael@0: } michael@0: michael@0: function test7() { michael@0: let plugin = gTestBrowser.contentDocument.getElementById("test"); michael@0: ok(plugin, "Test 7, Found plugin in page"); michael@0: let objLoadingContent = plugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: waitForCondition(() => objLoadingContent.activated, finishTest, michael@0: "Test 7, Waited too long for plugin to activate"); michael@0: }