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 /* Any copyright is dedicated to the Public Domain.
2 * http://creativecommons.org/publicdomain/zero/1.0/
3 */
5 // Tests tha installs and undoing installs show up correctly
7 var gManagerWindow;
8 var gCategoryUtilities;
10 var gApp = document.getElementById("bundle_brand").getString("brandShortName");
11 var gSearchCount = 0;
13 function test() {
14 requestLongerTimeout(2);
15 waitForExplicitFinish();
17 // Turn on searching for this test
18 Services.prefs.setIntPref(PREF_SEARCH_MAXRESULTS, 15);
19 Services.prefs.setCharPref("extensions.getAddons.search.url", TESTROOT + "browser_install.xml");
20 // Allow http update checks
21 Services.prefs.setBoolPref("extensions.checkUpdateSecurity", false);
23 open_manager(null, function(aWindow) {
24 gManagerWindow = aWindow;
25 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
26 run_next_test();
27 });
28 }
30 function end_test() {
31 close_manager(gManagerWindow, function() {
32 Services.prefs.clearUserPref("extensions.checkUpdateSecurity");
34 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
35 aAddon.uninstall();
36 finish();
37 });
38 });
39 }
41 function get_node(parent, anonid) {
42 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid);
43 }
45 function installAddon(aCallback) {
46 AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi",
47 function(aInstall) {
48 aInstall.addListener({
49 onInstallEnded: function() {
50 executeSoon(aCallback);
51 }
52 });
53 aInstall.install();
54 }, "application/x-xpinstall");
55 }
57 function installUpgrade(aCallback) {
58 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) {
59 aAddon.findUpdates({
60 onUpdateAvailable: function(aAddon, aInstall) {
61 is(get_list_item_count(), 1, "Should be only one item in the list");
63 aInstall.addListener({
64 onDownloadEnded: function() {
65 is(get_list_item_count(), 1, "Should be only one item in the list once the update has started");
66 },
67 onInstallEnded: function() {
68 executeSoon(aCallback);
69 }
70 });
71 aInstall.install();
72 }
73 }, AddonManager.UPDATE_WHEN_USER_REQUESTED);
74 });
75 }
77 function cancelInstall(aCallback) {
78 AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_2.xpi",
79 function(aInstall) {
80 aInstall.addListener({
81 onDownloadEnded: function(aInstall) {
82 executeSoon(function() {
83 aInstall.cancel();
84 aCallback();
85 });
86 return false;
87 }
88 });
89 aInstall.install();
90 }, "application/x-xpinstall");
91 }
93 function installSearchResult(aCallback) {
94 var searchBox = gManagerWindow.document.getElementById("header-search");
95 // Search for something different each time
96 searchBox.value = "foo" + gSearchCount;
97 gSearchCount++;
99 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow);
100 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow);
102 wait_for_view_load(gManagerWindow, function() {
103 let remote = gManagerWindow.document.getElementById("search-filter-remote")
104 EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow);
106 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
107 ok(!!item, "Should see the search result in the list");
109 let status = get_node(item, "install-status");
110 EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow);
112 item.mInstall.addListener({
113 onInstallEnded: function() {
114 executeSoon(aCallback);
115 }
116 });
117 });
118 }
120 function get_list_item_count() {
121 return get_test_items_in_list(gManagerWindow).length;
122 }
124 function check_undo_install() {
125 is(get_list_item_count(), 1, "Should be only one item in the list");
127 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
128 ok(!!item, "Should see the pending install in the list");
129 // Force XBL to apply
130 item.clientTop;
131 is_element_visible(get_node(item, "pending"), "Pending message should be visible");
132 is(get_node(item, "pending").textContent, "Install Tests will be installed after you restart " + gApp + ".", "Pending message should be correct");
134 EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow);
136 is(get_list_item_count(), 0, "Should be no items in the list");
138 item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
139 ok(!item, "Should no longer see the pending install");
140 }
142 function check_undo_upgrade() {
143 is(get_list_item_count(), 1, "Should be only one item in the list");
145 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
146 ok(!!item, "Should see the pending upgrade in the list");
147 // Force XBL to apply
148 item.clientTop;
149 is_element_visible(get_node(item, "pending"), "Pending message should be visible");
150 is(get_node(item, "pending").textContent, "Install Tests will be updated after you restart " + gApp + ".", "Pending message should be correct");
152 EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow);
154 is(get_list_item_count(), 1, "Should be only one item in the list");
156 item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
157 ok(!!item, "Should still see installed item in the list");
158 is_element_hidden(get_node(item, "pending"), "Pending message should be hidden");
159 }
161 // Install an add-on through the API with the manager open
162 add_test(function() {
163 gCategoryUtilities.openType("extension", function() {
164 installAddon(function() {
165 check_undo_install();
166 run_next_test();
167 });
168 });
169 });
171 // Install an add-on with the manager closed then open it
172 add_test(function() {
173 close_manager(gManagerWindow, function() {
174 installAddon(function() {
175 open_manager(null, function(aWindow) {
176 gManagerWindow = aWindow;
177 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
178 check_undo_install();
179 run_next_test();
180 });
181 });
182 });
183 });
185 // Install an add-on through the search page and then undo it
186 add_test(function() {
187 installSearchResult(function() {
188 check_undo_install();
189 run_next_test();
190 });
191 });
193 // Install an add-on through the search page then switch to the extensions page
194 // and then undo it
195 add_test(function() {
196 installSearchResult(function() {
197 gCategoryUtilities.openType("extension", function() {
198 check_undo_install();
199 run_next_test();
200 });
201 });
202 });
204 // Install an add-on through the search page then re-open the manager and then
205 // undo it
206 add_test(function() {
207 installSearchResult(function() {
208 close_manager(gManagerWindow, function() {
209 open_manager("addons://list/extension", function(aWindow) {
210 gManagerWindow = aWindow;
211 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
212 check_undo_install();
213 run_next_test();
214 });
215 });
216 });
217 });
219 // Cancel an install after download with the manager open
220 add_test(function() {
221 cancelInstall(function() {
222 is(get_list_item_count(), 0, "Should be no items in the list");
224 run_next_test();
225 });
226 });
228 // Cancel an install after download with the manager closed
229 add_test(function() {
230 close_manager(gManagerWindow, function() {
231 cancelInstall(function() {
232 open_manager(null, function(aWindow) {
233 gManagerWindow = aWindow;
234 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
235 is(get_list_item_count(), 0, "Should be no items in the list");
237 run_next_test();
238 });
239 });
240 });
241 });
243 // Install an existing add-on for the subsequent tests
244 add_test(function() {
245 AddonManager.getInstallForURL(TESTROOT + "addons/browser_install1_1.xpi",
246 function(aInstall) {
247 aInstall.addListener({
248 onInstallEnded: function() {
249 executeSoon(run_next_test);
250 }
251 });
252 aInstall.install();
253 }, "application/x-xpinstall");
254 });
256 // Install an upgrade through the API with the manager open
257 add_test(function() {
258 installAddon(function() {
259 check_undo_upgrade();
260 run_next_test();
261 });
262 });
264 // Install an upgrade through the API with the manager open
265 add_test(function() {
266 installUpgrade(function() {
267 check_undo_upgrade();
268 run_next_test();
269 });
270 });
272 // Install an upgrade through the API with the manager closed
273 add_test(function() {
274 close_manager(gManagerWindow, function() {
275 installAddon(function() {
276 open_manager(null, function(aWindow) {
277 gManagerWindow = aWindow;
278 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
279 check_undo_upgrade();
280 run_next_test();
281 });
282 });
283 });
284 });
286 // Cancel an upgrade after download with the manager open
287 add_test(function() {
288 cancelInstall(function() {
289 is(get_list_item_count(), 1, "Should be no items in the list");
290 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
291 ok(!!item, "Should still see installed item in the list");
292 is_element_hidden(get_node(item, "pending"), "Pending message should be hidden");
294 run_next_test();
295 });
296 });
298 // Cancel an upgrade after download with the manager closed
299 add_test(function() {
300 close_manager(gManagerWindow, function() {
301 cancelInstall(function() {
302 open_manager(null, function(aWindow) {
303 gManagerWindow = aWindow;
304 gCategoryUtilities = new CategoryUtilities(gManagerWindow);
305 is(get_list_item_count(), 1, "Should be no items in the list");
306 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org");
307 ok(!!item, "Should still see installed item in the list");
308 is_element_hidden(get_node(item, "pending"), "Pending message should be hidden");
310 run_next_test();
311 });
312 });
313 });
314 });