michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: const gHttpTestRoot = "http://127.0.0.1:8888/" + RELATIVE_DIR + "/"; michael@0: let gManagerWindow; michael@0: let gTestPluginId; michael@0: let gPluginBrowser; michael@0: michael@0: function updateBlocklist(aCallback) { michael@0: var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"] michael@0: .getService(Ci.nsITimerCallback); michael@0: var observer = function() { michael@0: Services.obs.removeObserver(observer, "blocklist-updated"); michael@0: SimpleTest.executeSoon(aCallback); michael@0: }; michael@0: Services.obs.addObserver(observer, "blocklist-updated", false); michael@0: blocklistNotifier.notify(null); michael@0: } michael@0: michael@0: var _originalBlocklistURL = null; michael@0: function setAndUpdateBlocklist(aURL, aCallback) { michael@0: if (!_originalBlocklistURL) { michael@0: _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); michael@0: } michael@0: Services.prefs.setCharPref("extensions.blocklist.url", aURL); michael@0: updateBlocklist(aCallback); michael@0: } michael@0: michael@0: function resetBlocklist(aCallback) { michael@0: Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL); michael@0: } michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: Services.prefs.setBoolPref("plugins.click_to_play", true); michael@0: Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); michael@0: let pluginTag = getTestPluginTag(); michael@0: pluginTag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; michael@0: open_manager("addons://list/plugin", part1); michael@0: } michael@0: michael@0: function part1(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: AddonManager.getAddonsByTypes(["plugin"], part2); michael@0: } michael@0: michael@0: function part2(aPlugins) { michael@0: for (let plugin of aPlugins) { michael@0: if (plugin.name == "Test Plug-in") { michael@0: gTestPluginId = plugin.id; michael@0: break; michael@0: } michael@0: } michael@0: ok(gTestPluginId, "part2: Test Plug-in should exist"); michael@0: AddonManager.getAddonByID(gTestPluginId, part3); michael@0: } michael@0: michael@0: function part3(aTestPlugin) { michael@0: let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); michael@0: pluginEl.parentNode.ensureElementIsVisible(pluginEl); michael@0: let enableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn"); michael@0: is_element_hidden(enableButton, "part3: enable button should not be visible"); michael@0: let disableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn"); michael@0: is_element_hidden(disableButton, "part3: disable button should not be visible"); michael@0: let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); michael@0: is_element_visible(menu, "part3: state menu should be visible"); michael@0: let askToActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "ask-to-activate-menuitem"); michael@0: is(menu.selectedItem, askToActivateItem, "part3: state menu should have 'Ask To Activate' selected"); michael@0: michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gPluginBrowser = gBrowser.selectedBrowser; michael@0: gPluginBrowser.addEventListener("PluginBindingAttached", part4, true, true); michael@0: gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part4() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part4: should have a click-to-play notification"); michael@0: gPluginBrowser.removeEventListener("PluginBindingAttached", part4); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); michael@0: let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); michael@0: let alwaysActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "always-activate-menuitem"); michael@0: menu.selectedItem = alwaysActivateItem; michael@0: alwaysActivateItem.doCommand(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gPluginBrowser = gBrowser.selectedBrowser; michael@0: gPluginBrowser.addEventListener("load", part5, true); michael@0: gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part5() { michael@0: let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); michael@0: ok(testPlugin, "part5: should have a plugin element in the page"); michael@0: let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, part6, "part5: waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function part6() { michael@0: let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); michael@0: ok(testPlugin, "part6: should have a plugin element in the page"); michael@0: let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "part6: plugin should be activated"); michael@0: gPluginBrowser.removeEventListener("load", part5); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); michael@0: let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); michael@0: let neverActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "never-activate-menuitem"); michael@0: menu.selectedItem = neverActivateItem; michael@0: neverActivateItem.doCommand(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gPluginBrowser = gBrowser.selectedBrowser; michael@0: gPluginBrowser.addEventListener("PluginBindingAttached", part7, true, true); michael@0: gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part7() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part7: disabled plugins still show a notification"); michael@0: let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); michael@0: ok(testPlugin, "part7: should have a plugin element in the page"); michael@0: let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(!objLoadingContent.activated, "part7: plugin should not be activated"); michael@0: michael@0: gPluginBrowser.removeEventListener("PluginBindingAttached", part7); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); michael@0: let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn"); michael@0: is_element_visible(details, "part7: details link should be visible"); michael@0: EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, part8); michael@0: } michael@0: michael@0: function part8() { michael@0: let enableButton = gManagerWindow.document.getElementById("detail-enable-btn"); michael@0: is_element_hidden(enableButton, "part8: detail enable button should be hidden"); michael@0: let disableButton = gManagerWindow.document.getElementById("detail-disable-btn"); michael@0: is_element_hidden(disableButton, "part8: detail disable button should be hidden"); michael@0: let menu = gManagerWindow.document.getElementById("detail-state-menulist"); michael@0: is_element_visible(menu, "part8: detail state menu should be visible"); michael@0: let neverActivateItem = gManagerWindow.document.getElementById("detail-never-activate-menuitem"); michael@0: is(menu.selectedItem, neverActivateItem, "part8: state menu should have 'Never Activate' selected"); michael@0: michael@0: let alwaysActivateItem = gManagerWindow.document.getElementById("detail-always-activate-menuitem"); michael@0: menu.selectedItem = alwaysActivateItem; michael@0: alwaysActivateItem.doCommand(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gPluginBrowser = gBrowser.selectedBrowser; michael@0: gPluginBrowser.addEventListener("load", part9, true); michael@0: gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part9() { michael@0: let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); michael@0: ok(testPlugin, "part9: should have a plugin element in the page"); michael@0: let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: let condition = function() objLoadingContent.activated; michael@0: waitForCondition(condition, part10, "part9: waited too long for plugin to activate"); michael@0: } michael@0: michael@0: function part10() { michael@0: let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); michael@0: ok(testPlugin, "part10: should have a plugin element in the page"); michael@0: let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); michael@0: ok(objLoadingContent.activated, "part10: plugin should be activated"); michael@0: gPluginBrowser.removeEventListener("load", part9); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let menu = gManagerWindow.document.getElementById("detail-state-menulist"); michael@0: let askToActivateItem = gManagerWindow.document.getElementById("detail-ask-to-activate-menuitem"); michael@0: menu.selectedItem = askToActivateItem; michael@0: askToActivateItem.doCommand(); michael@0: gBrowser.selectedTab = gBrowser.addTab(); michael@0: gPluginBrowser = gBrowser.selectedBrowser; michael@0: gPluginBrowser.addEventListener("PluginBindingAttached", part11, true, true); michael@0: gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; michael@0: } michael@0: michael@0: function part11() { michael@0: ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part11: should have a click-to-play notification"); michael@0: gPluginBrowser.removeEventListener("PluginBindingAttached", part11); michael@0: gBrowser.removeCurrentTab(); michael@0: michael@0: let pluginTag = getTestPluginTag(); michael@0: michael@0: // causes appDisabled to be set michael@0: setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml", michael@0: function() { michael@0: close_manager(gManagerWindow, function() { michael@0: open_manager("addons://list/plugin", part12); michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function part12(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); michael@0: pluginEl.parentNode.ensureElementIsVisible(pluginEl); michael@0: let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); michael@0: is_element_hidden(menu, "part12: state menu should be hidden"); michael@0: michael@0: let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn"); michael@0: EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow); michael@0: wait_for_view_load(gManagerWindow, part13); michael@0: } michael@0: michael@0: function part13() { michael@0: let menu = gManagerWindow.document.getElementById("detail-state-menulist"); michael@0: is_element_hidden(menu, "part13: detail state menu should be hidden"); michael@0: michael@0: setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() { michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: Services.prefs.clearUserPref("plugins.click_to_play"); michael@0: Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); michael@0: let pluginTag = getTestPluginTag(); michael@0: pluginTag.enabledState = Ci.nsIPluginTag.STATE_ENABLED; michael@0: resetBlocklist(); michael@0: close_manager(gManagerWindow, function() { michael@0: finish(); michael@0: }); michael@0: }