toolkit/mozapps/extensions/test/browser/browser_CTP_plugins.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 /* This Source Code Form is subject to the terms of the Mozilla Public
michael@0 2 * License, v. 2.0. If a copy of the MPL was not distributed with this
michael@0 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
michael@0 4
michael@0 5 const gHttpTestRoot = "http://127.0.0.1:8888/" + RELATIVE_DIR + "/";
michael@0 6 let gManagerWindow;
michael@0 7 let gTestPluginId;
michael@0 8 let gPluginBrowser;
michael@0 9
michael@0 10 function updateBlocklist(aCallback) {
michael@0 11 var blocklistNotifier = Cc["@mozilla.org/extensions/blocklist;1"]
michael@0 12 .getService(Ci.nsITimerCallback);
michael@0 13 var observer = function() {
michael@0 14 Services.obs.removeObserver(observer, "blocklist-updated");
michael@0 15 SimpleTest.executeSoon(aCallback);
michael@0 16 };
michael@0 17 Services.obs.addObserver(observer, "blocklist-updated", false);
michael@0 18 blocklistNotifier.notify(null);
michael@0 19 }
michael@0 20
michael@0 21 var _originalBlocklistURL = null;
michael@0 22 function setAndUpdateBlocklist(aURL, aCallback) {
michael@0 23 if (!_originalBlocklistURL) {
michael@0 24 _originalBlocklistURL = Services.prefs.getCharPref("extensions.blocklist.url");
michael@0 25 }
michael@0 26 Services.prefs.setCharPref("extensions.blocklist.url", aURL);
michael@0 27 updateBlocklist(aCallback);
michael@0 28 }
michael@0 29
michael@0 30 function resetBlocklist(aCallback) {
michael@0 31 Services.prefs.setCharPref("extensions.blocklist.url", _originalBlocklistURL);
michael@0 32 }
michael@0 33
michael@0 34 function test() {
michael@0 35 waitForExplicitFinish();
michael@0 36 Services.prefs.setBoolPref("plugins.click_to_play", true);
michael@0 37 Services.prefs.setBoolPref("extensions.blocklist.suppressUI", true);
michael@0 38 let pluginTag = getTestPluginTag();
michael@0 39 pluginTag.enabledState = Ci.nsIPluginTag.STATE_CLICKTOPLAY;
michael@0 40 open_manager("addons://list/plugin", part1);
michael@0 41 }
michael@0 42
michael@0 43 function part1(aWindow) {
michael@0 44 gManagerWindow = aWindow;
michael@0 45 AddonManager.getAddonsByTypes(["plugin"], part2);
michael@0 46 }
michael@0 47
michael@0 48 function part2(aPlugins) {
michael@0 49 for (let plugin of aPlugins) {
michael@0 50 if (plugin.name == "Test Plug-in") {
michael@0 51 gTestPluginId = plugin.id;
michael@0 52 break;
michael@0 53 }
michael@0 54 }
michael@0 55 ok(gTestPluginId, "part2: Test Plug-in should exist");
michael@0 56 AddonManager.getAddonByID(gTestPluginId, part3);
michael@0 57 }
michael@0 58
michael@0 59 function part3(aTestPlugin) {
michael@0 60 let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
michael@0 61 pluginEl.parentNode.ensureElementIsVisible(pluginEl);
michael@0 62 let enableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn");
michael@0 63 is_element_hidden(enableButton, "part3: enable button should not be visible");
michael@0 64 let disableButton = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "enable-btn");
michael@0 65 is_element_hidden(disableButton, "part3: disable button should not be visible");
michael@0 66 let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist");
michael@0 67 is_element_visible(menu, "part3: state menu should be visible");
michael@0 68 let askToActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "ask-to-activate-menuitem");
michael@0 69 is(menu.selectedItem, askToActivateItem, "part3: state menu should have 'Ask To Activate' selected");
michael@0 70
michael@0 71 gBrowser.selectedTab = gBrowser.addTab();
michael@0 72 gPluginBrowser = gBrowser.selectedBrowser;
michael@0 73 gPluginBrowser.addEventListener("PluginBindingAttached", part4, true, true);
michael@0 74 gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
michael@0 75 }
michael@0 76
michael@0 77 function part4() {
michael@0 78 ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part4: should have a click-to-play notification");
michael@0 79 gPluginBrowser.removeEventListener("PluginBindingAttached", part4);
michael@0 80 gBrowser.removeCurrentTab();
michael@0 81
michael@0 82 let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
michael@0 83 let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist");
michael@0 84 let alwaysActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "always-activate-menuitem");
michael@0 85 menu.selectedItem = alwaysActivateItem;
michael@0 86 alwaysActivateItem.doCommand();
michael@0 87 gBrowser.selectedTab = gBrowser.addTab();
michael@0 88 gPluginBrowser = gBrowser.selectedBrowser;
michael@0 89 gPluginBrowser.addEventListener("load", part5, true);
michael@0 90 gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
michael@0 91 }
michael@0 92
michael@0 93 function part5() {
michael@0 94 let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
michael@0 95 ok(testPlugin, "part5: should have a plugin element in the page");
michael@0 96 let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 97 let condition = function() objLoadingContent.activated;
michael@0 98 waitForCondition(condition, part6, "part5: waited too long for plugin to activate");
michael@0 99 }
michael@0 100
michael@0 101 function part6() {
michael@0 102 let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
michael@0 103 ok(testPlugin, "part6: should have a plugin element in the page");
michael@0 104 let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 105 ok(objLoadingContent.activated, "part6: plugin should be activated");
michael@0 106 gPluginBrowser.removeEventListener("load", part5);
michael@0 107 gBrowser.removeCurrentTab();
michael@0 108
michael@0 109 let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
michael@0 110 let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist");
michael@0 111 let neverActivateItem = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "never-activate-menuitem");
michael@0 112 menu.selectedItem = neverActivateItem;
michael@0 113 neverActivateItem.doCommand();
michael@0 114 gBrowser.selectedTab = gBrowser.addTab();
michael@0 115 gPluginBrowser = gBrowser.selectedBrowser;
michael@0 116 gPluginBrowser.addEventListener("PluginBindingAttached", part7, true, true);
michael@0 117 gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
michael@0 118 }
michael@0 119
michael@0 120 function part7() {
michael@0 121 ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part7: disabled plugins still show a notification");
michael@0 122 let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
michael@0 123 ok(testPlugin, "part7: should have a plugin element in the page");
michael@0 124 let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 125 ok(!objLoadingContent.activated, "part7: plugin should not be activated");
michael@0 126
michael@0 127 gPluginBrowser.removeEventListener("PluginBindingAttached", part7);
michael@0 128 gBrowser.removeCurrentTab();
michael@0 129
michael@0 130 let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
michael@0 131 let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn");
michael@0 132 is_element_visible(details, "part7: details link should be visible");
michael@0 133 EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow);
michael@0 134 wait_for_view_load(gManagerWindow, part8);
michael@0 135 }
michael@0 136
michael@0 137 function part8() {
michael@0 138 let enableButton = gManagerWindow.document.getElementById("detail-enable-btn");
michael@0 139 is_element_hidden(enableButton, "part8: detail enable button should be hidden");
michael@0 140 let disableButton = gManagerWindow.document.getElementById("detail-disable-btn");
michael@0 141 is_element_hidden(disableButton, "part8: detail disable button should be hidden");
michael@0 142 let menu = gManagerWindow.document.getElementById("detail-state-menulist");
michael@0 143 is_element_visible(menu, "part8: detail state menu should be visible");
michael@0 144 let neverActivateItem = gManagerWindow.document.getElementById("detail-never-activate-menuitem");
michael@0 145 is(menu.selectedItem, neverActivateItem, "part8: state menu should have 'Never Activate' selected");
michael@0 146
michael@0 147 let alwaysActivateItem = gManagerWindow.document.getElementById("detail-always-activate-menuitem");
michael@0 148 menu.selectedItem = alwaysActivateItem;
michael@0 149 alwaysActivateItem.doCommand();
michael@0 150 gBrowser.selectedTab = gBrowser.addTab();
michael@0 151 gPluginBrowser = gBrowser.selectedBrowser;
michael@0 152 gPluginBrowser.addEventListener("load", part9, true);
michael@0 153 gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
michael@0 154 }
michael@0 155
michael@0 156 function part9() {
michael@0 157 let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
michael@0 158 ok(testPlugin, "part9: should have a plugin element in the page");
michael@0 159 let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 160 let condition = function() objLoadingContent.activated;
michael@0 161 waitForCondition(condition, part10, "part9: waited too long for plugin to activate");
michael@0 162 }
michael@0 163
michael@0 164 function part10() {
michael@0 165 let testPlugin = gPluginBrowser.contentDocument.getElementById("test");
michael@0 166 ok(testPlugin, "part10: should have a plugin element in the page");
michael@0 167 let objLoadingContent = testPlugin.QueryInterface(Ci.nsIObjectLoadingContent);
michael@0 168 ok(objLoadingContent.activated, "part10: plugin should be activated");
michael@0 169 gPluginBrowser.removeEventListener("load", part9);
michael@0 170 gBrowser.removeCurrentTab();
michael@0 171
michael@0 172 let menu = gManagerWindow.document.getElementById("detail-state-menulist");
michael@0 173 let askToActivateItem = gManagerWindow.document.getElementById("detail-ask-to-activate-menuitem");
michael@0 174 menu.selectedItem = askToActivateItem;
michael@0 175 askToActivateItem.doCommand();
michael@0 176 gBrowser.selectedTab = gBrowser.addTab();
michael@0 177 gPluginBrowser = gBrowser.selectedBrowser;
michael@0 178 gPluginBrowser.addEventListener("PluginBindingAttached", part11, true, true);
michael@0 179 gPluginBrowser.contentWindow.location = gHttpTestRoot + "plugin_test.html";
michael@0 180 }
michael@0 181
michael@0 182 function part11() {
michael@0 183 ok(PopupNotifications.getNotification("click-to-play-plugins", gPluginBrowser), "part11: should have a click-to-play notification");
michael@0 184 gPluginBrowser.removeEventListener("PluginBindingAttached", part11);
michael@0 185 gBrowser.removeCurrentTab();
michael@0 186
michael@0 187 let pluginTag = getTestPluginTag();
michael@0 188
michael@0 189 // causes appDisabled to be set
michael@0 190 setAndUpdateBlocklist(gHttpTestRoot + "blockPluginHard.xml",
michael@0 191 function() {
michael@0 192 close_manager(gManagerWindow, function() {
michael@0 193 open_manager("addons://list/plugin", part12);
michael@0 194 });
michael@0 195 });
michael@0 196 }
michael@0 197
michael@0 198 function part12(aWindow) {
michael@0 199 gManagerWindow = aWindow;
michael@0 200 let pluginEl = get_addon_element(gManagerWindow, gTestPluginId);
michael@0 201 pluginEl.parentNode.ensureElementIsVisible(pluginEl);
michael@0 202 let menu = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "state-menulist");
michael@0 203 is_element_hidden(menu, "part12: state menu should be hidden");
michael@0 204
michael@0 205 let details = gManagerWindow.document.getAnonymousElementByAttribute(pluginEl, "anonid", "details-btn");
michael@0 206 EventUtils.synthesizeMouseAtCenter(details, {}, gManagerWindow);
michael@0 207 wait_for_view_load(gManagerWindow, part13);
michael@0 208 }
michael@0 209
michael@0 210 function part13() {
michael@0 211 let menu = gManagerWindow.document.getElementById("detail-state-menulist");
michael@0 212 is_element_hidden(menu, "part13: detail state menu should be hidden");
michael@0 213
michael@0 214 setAndUpdateBlocklist(gHttpTestRoot + "blockNoPlugins.xml", function() {
michael@0 215 run_next_test();
michael@0 216 });
michael@0 217 }
michael@0 218
michael@0 219 function end_test() {
michael@0 220 Services.prefs.clearUserPref("plugins.click_to_play");
michael@0 221 Services.prefs.clearUserPref("extensions.blocklist.suppressUI");
michael@0 222 let pluginTag = getTestPluginTag();
michael@0 223 pluginTag.enabledState = Ci.nsIPluginTag.STATE_ENABLED;
michael@0 224 resetBlocklist();
michael@0 225 close_manager(gManagerWindow, function() {
michael@0 226 finish();
michael@0 227 });
michael@0 228 }

mercurial