|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests tha installs and undoing installs show up correctly |
|
6 |
|
7 var gManagerWindow; |
|
8 var gCategoryUtilities; |
|
9 |
|
10 var gApp = document.getElementById("bundle_brand").getString("brandShortName"); |
|
11 var gSearchCount = 0; |
|
12 |
|
13 function test() { |
|
14 requestLongerTimeout(2); |
|
15 waitForExplicitFinish(); |
|
16 |
|
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); |
|
22 |
|
23 open_manager(null, function(aWindow) { |
|
24 gManagerWindow = aWindow; |
|
25 gCategoryUtilities = new CategoryUtilities(gManagerWindow); |
|
26 run_next_test(); |
|
27 }); |
|
28 } |
|
29 |
|
30 function end_test() { |
|
31 close_manager(gManagerWindow, function() { |
|
32 Services.prefs.clearUserPref("extensions.checkUpdateSecurity"); |
|
33 |
|
34 AddonManager.getAddonByID("addon1@tests.mozilla.org", function(aAddon) { |
|
35 aAddon.uninstall(); |
|
36 finish(); |
|
37 }); |
|
38 }); |
|
39 } |
|
40 |
|
41 function get_node(parent, anonid) { |
|
42 return parent.ownerDocument.getAnonymousElementByAttribute(parent, "anonid", anonid); |
|
43 } |
|
44 |
|
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 } |
|
56 |
|
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"); |
|
62 |
|
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 } |
|
76 |
|
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 } |
|
92 |
|
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++; |
|
98 |
|
99 EventUtils.synthesizeMouseAtCenter(searchBox, { }, gManagerWindow); |
|
100 EventUtils.synthesizeKey("VK_RETURN", { }, gManagerWindow); |
|
101 |
|
102 wait_for_view_load(gManagerWindow, function() { |
|
103 let remote = gManagerWindow.document.getElementById("search-filter-remote") |
|
104 EventUtils.synthesizeMouseAtCenter(remote, { }, gManagerWindow); |
|
105 |
|
106 let item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
107 ok(!!item, "Should see the search result in the list"); |
|
108 |
|
109 let status = get_node(item, "install-status"); |
|
110 EventUtils.synthesizeMouseAtCenter(get_node(status, "install-remote-btn"), {}, gManagerWindow); |
|
111 |
|
112 item.mInstall.addListener({ |
|
113 onInstallEnded: function() { |
|
114 executeSoon(aCallback); |
|
115 } |
|
116 }); |
|
117 }); |
|
118 } |
|
119 |
|
120 function get_list_item_count() { |
|
121 return get_test_items_in_list(gManagerWindow).length; |
|
122 } |
|
123 |
|
124 function check_undo_install() { |
|
125 is(get_list_item_count(), 1, "Should be only one item in the list"); |
|
126 |
|
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"); |
|
133 |
|
134 EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); |
|
135 |
|
136 is(get_list_item_count(), 0, "Should be no items in the list"); |
|
137 |
|
138 item = get_addon_element(gManagerWindow, "addon1@tests.mozilla.org"); |
|
139 ok(!item, "Should no longer see the pending install"); |
|
140 } |
|
141 |
|
142 function check_undo_upgrade() { |
|
143 is(get_list_item_count(), 1, "Should be only one item in the list"); |
|
144 |
|
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"); |
|
151 |
|
152 EventUtils.synthesizeMouseAtCenter(get_node(item, "undo-btn"), {}, gManagerWindow); |
|
153 |
|
154 is(get_list_item_count(), 1, "Should be only one item in the list"); |
|
155 |
|
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 } |
|
160 |
|
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 }); |
|
170 |
|
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 }); |
|
184 |
|
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 }); |
|
192 |
|
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 }); |
|
203 |
|
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 }); |
|
218 |
|
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"); |
|
223 |
|
224 run_next_test(); |
|
225 }); |
|
226 }); |
|
227 |
|
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"); |
|
236 |
|
237 run_next_test(); |
|
238 }); |
|
239 }); |
|
240 }); |
|
241 }); |
|
242 |
|
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 }); |
|
255 |
|
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 }); |
|
263 |
|
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 }); |
|
271 |
|
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 }); |
|
285 |
|
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"); |
|
293 |
|
294 run_next_test(); |
|
295 }); |
|
296 }); |
|
297 |
|
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"); |
|
309 |
|
310 run_next_test(); |
|
311 }); |
|
312 }); |
|
313 }); |
|
314 }); |