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