1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/toolkit/mozapps/extensions/test/browser/browser_CTP_plugins.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,228 @@ 1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.7 + 1.8 +const gHttpTestRoot = "http://127.0.0.1:8888/" + RELATIVE_DIR + "/"; 1.9 +let gManagerWindow; 1.10 +let gTestPluginId; 1.11 +let gPluginBrowser; 1.12 + 1.13 +function updateBlocklist(aCallback) { 1.14 + var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"] 1.15 + .getService(Ci.nsITimerCallback); 1.16 + var observer = function() { 1.17 + Services.obs.removeObserver(observer, "blocklist-updated"); 1.18 + SimpleTest.executeSoon(aCallback); 1.19 + }; 1.20 + Services.obs.addObserver(observer, "blocklist-updated", false); 1.21 + blocklistNotifier.notify(null); 1.22 +} 1.23 + 1.24 +var _originalBlocklistURL = null; 1.25 +function setAndUpdateBlocklist(aURL, aCallback) { 1.26 + if (!_originalBlocklistURL) { 1.27 + _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url"); 1.28 + } 1.29 + Services.prefs.setCharPref("extensions.blocklist.url", aURL); 1.30 + updateBlocklist(aCallback); 1.31 +} 1.32 + 1.33 +function resetBlocklist(aCallback) { 1.34 + Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL); 1.35 +} 1.36 + 1.37 +function test() { 1.38 + waitForExplicitFinish(); 1.39 + Services.prefs.setBoolPref("plugins.click_to_play", true); 1.40 + Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true); 1.41 + let pluginTag = getTestPluginTag(); 1.42 + pluginTag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY; 1.43 + open_manager("addons://list/plugin", part1); 1.44 +} 1.45 + 1.46 +function part1(aWindow) { 1.47 + gManagerWindow = aWindow; 1.48 + AddonManager.getAddonsByTypes(["plugin"], part2); 1.49 +} 1.50 + 1.51 +function part2(aPlugins) { 1.52 + for (let plugin of aPlugins) { 1.53 + if (plugin.name == "Test Plug-in") { 1.54 + gTestPluginId = plugin.id; 1.55 + break; 1.56 + } 1.57 + } 1.58 + ok(gTestPluginId, "part2: Test Plug-in should exist"); 1.59 + AddonManager.getAddonByID(gTestPluginId, part3); 1.60 +} 1.61 + 1.62 +function part3(aTestPlugin) { 1.63 + let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); 1.64 + pluginEl.parentNode.ensureElementIsVisible(pluginEl); 1.65 + let enableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn"); 1.66 + is_element_hidden(enableButton, "part3: enable button should not be visible"); 1.67 + let disableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn"); 1.68 + is_element_hidden(disableButton, "part3: disable button should not be visible"); 1.69 + let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); 1.70 + is_element_visible(menu, "part3: state menu should be visible"); 1.71 + let askToActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "ask-to-activate-menuitem"); 1.72 + is(menu.selectedItem, askToActivateItem, "part3: state menu should have 'Ask To Activate' selected"); 1.73 + 1.74 + gBrowser.selectedTab = gBrowser.addTab(); 1.75 + gPluginBrowser = gBrowser.selectedBrowser; 1.76 + gPluginBrowser.addEventListener("PluginBindingAttached", part4, true, true); 1.77 + gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; 1.78 +} 1.79 + 1.80 +function part4() { 1.81 + ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part4: should have a click-to-play notification"); 1.82 + gPluginBrowser.removeEventListener("PluginBindingAttached", part4); 1.83 + gBrowser.removeCurrentTab(); 1.84 + 1.85 + let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); 1.86 + let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); 1.87 + let alwaysActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "always-activate-menuitem"); 1.88 + menu.selectedItem = alwaysActivateItem; 1.89 + alwaysActivateItem.doCommand(); 1.90 + gBrowser.selectedTab = gBrowser.addTab(); 1.91 + gPluginBrowser = gBrowser.selectedBrowser; 1.92 + gPluginBrowser.addEventListener("load", part5, true); 1.93 + gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; 1.94 +} 1.95 + 1.96 +function part5() { 1.97 + let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); 1.98 + ok(testPlugin, "part5: should have a plugin element in the page"); 1.99 + let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.100 + let condition = function() objLoadingContent.activated; 1.101 + waitForCondition(condition, part6, "part5: waited too long for plugin to activate"); 1.102 +} 1.103 + 1.104 +function part6() { 1.105 + let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); 1.106 + ok(testPlugin, "part6: should have a plugin element in the page"); 1.107 + let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.108 + ok(objLoadingContent.activated, "part6: plugin should be activated"); 1.109 + gPluginBrowser.removeEventListener("load", part5); 1.110 + gBrowser.removeCurrentTab(); 1.111 + 1.112 + let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); 1.113 + let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); 1.114 + let neverActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "never-activate-menuitem"); 1.115 + menu.selectedItem = neverActivateItem; 1.116 + neverActivateItem.doCommand(); 1.117 + gBrowser.selectedTab = gBrowser.addTab(); 1.118 + gPluginBrowser = gBrowser.selectedBrowser; 1.119 + gPluginBrowser.addEventListener("PluginBindingAttached", part7, true, true); 1.120 + gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; 1.121 +} 1.122 + 1.123 +function part7() { 1.124 + ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part7: disabled plugins still show a notification"); 1.125 + let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); 1.126 + ok(testPlugin, "part7: should have a plugin element in the page"); 1.127 + let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.128 + ok(!objLoadingContent.activated, "part7: plugin should not be activated"); 1.129 + 1.130 + gPluginBrowser.removeEventListener("PluginBindingAttached", part7); 1.131 + gBrowser.removeCurrentTab(); 1.132 + 1.133 + let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); 1.134 + let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn"); 1.135 + is_element_visible(details, "part7: details link should be visible"); 1.136 + EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow); 1.137 + wait_for_view_load(gManagerWindow, part8); 1.138 +} 1.139 + 1.140 +function part8() { 1.141 + let enableButton = gManagerWindow.document.getElementById("detail-enable-btn"); 1.142 + is_element_hidden(enableButton, "part8: detail enable button should be hidden"); 1.143 + let disableButton = gManagerWindow.document.getElementById("detail-disable-btn"); 1.144 + is_element_hidden(disableButton, "part8: detail disable button should be hidden"); 1.145 + let menu = gManagerWindow.document.getElementById("detail-state-menulist"); 1.146 + is_element_visible(menu, "part8: detail state menu should be visible"); 1.147 + let neverActivateItem = gManagerWindow.document.getElementById("detail-never-activate-menuitem"); 1.148 + is(menu.selectedItem, neverActivateItem, "part8: state menu should have 'Never Activate' selected"); 1.149 + 1.150 + let alwaysActivateItem = gManagerWindow.document.getElementById("detail-always-activate-menuitem"); 1.151 + menu.selectedItem = alwaysActivateItem; 1.152 + alwaysActivateItem.doCommand(); 1.153 + gBrowser.selectedTab = gBrowser.addTab(); 1.154 + gPluginBrowser = gBrowser.selectedBrowser; 1.155 + gPluginBrowser.addEventListener("load", part9, true); 1.156 + gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; 1.157 +} 1.158 + 1.159 +function part9() { 1.160 + let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); 1.161 + ok(testPlugin, "part9: should have a plugin element in the page"); 1.162 + let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.163 + let condition = function() objLoadingContent.activated; 1.164 + waitForCondition(condition, part10, "part9: waited too long for plugin to activate"); 1.165 +} 1.166 + 1.167 +function part10() { 1.168 + let testPlugin = gPluginBrowser.contentDocument.getElementById("test"); 1.169 + ok(testPlugin, "part10: should have a plugin element in the page"); 1.170 + let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent); 1.171 + ok(objLoadingContent.activated, "part10: plugin should be activated"); 1.172 + gPluginBrowser.removeEventListener("load", part9); 1.173 + gBrowser.removeCurrentTab(); 1.174 + 1.175 + let menu = gManagerWindow.document.getElementById("detail-state-menulist"); 1.176 + let askToActivateItem = gManagerWindow.document.getElementById("detail-ask-to-activate-menuitem"); 1.177 + menu.selectedItem = askToActivateItem; 1.178 + askToActivateItem.doCommand(); 1.179 + gBrowser.selectedTab = gBrowser.addTab(); 1.180 + gPluginBrowser = gBrowser.selectedBrowser; 1.181 + gPluginBrowser.addEventListener("PluginBindingAttached", part11, true, true); 1.182 + gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html"; 1.183 +} 1.184 + 1.185 +function part11() { 1.186 + ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part11: should have a click-to-play notification"); 1.187 + gPluginBrowser.removeEventListener("PluginBindingAttached", part11); 1.188 + gBrowser.removeCurrentTab(); 1.189 + 1.190 + let pluginTag = getTestPluginTag(); 1.191 + 1.192 +// causes appDisabled to be set 1.193 + setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml", 1.194 + function() { 1.195 + close_manager(gManagerWindow, function() { 1.196 + open_manager("addons://list/plugin", part12); 1.197 + }); 1.198 + }); 1.199 +} 1.200 + 1.201 +function part12(aWindow) { 1.202 + gManagerWindow = aWindow; 1.203 + let pluginEl = get_addon_element(gManagerWindow, gTestPluginId); 1.204 + pluginEl.parentNode.ensureElementIsVisible(pluginEl); 1.205 + let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist"); 1.206 + is_element_hidden(menu, "part12: state menu should be hidden"); 1.207 + 1.208 + let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn"); 1.209 + EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow); 1.210 + wait_for_view_load(gManagerWindow, part13); 1.211 +} 1.212 + 1.213 +function part13() { 1.214 + let menu = gManagerWindow.document.getElementById("detail-state-menulist"); 1.215 + is_element_hidden(menu, "part13: detail state menu should be hidden"); 1.216 + 1.217 + setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() { 1.218 + run_next_test(); 1.219 + }); 1.220 +} 1.221 + 1.222 +function end_test() { 1.223 + Services.prefs.clearUserPref("plugins.click_to_play"); 1.224 + Services.prefs.clearUserPref("extensions.blocklist.suppressUI"); 1.225 + let pluginTag = getTestPluginTag(); 1.226 + pluginTag.enabledState = Ci.nsIPluginTag.STATE_ENABLED; 1.227 + resetBlocklist(); 1.228 + close_manager(gManagerWindow, function() { 1.229 + finish(); 1.230 + }); 1.231 +}