|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 * http://creativecommons.org/publicdomain/zero/1.0/ |
|
3 */ |
|
4 |
|
5 // Tests that sorting of add-ons works correctly |
|
6 // (this test uses the list view, even though it no longer has sort buttons - see bug 623207) |
|
7 |
|
8 var gManagerWindow; |
|
9 var gProvider; |
|
10 |
|
11 function test() { |
|
12 waitForExplicitFinish(); |
|
13 |
|
14 gProvider = new MockProvider(); |
|
15 gProvider.createAddons([{ |
|
16 // enabledInstalled group |
|
17 // * Enabled |
|
18 // * Incompatible but enabled because compatibility checking is off |
|
19 // * Waiting to be installed |
|
20 // * Waiting to be enabled |
|
21 id: "test1@tests.mozilla.org", |
|
22 name: "Test add-on", |
|
23 description: "foo", |
|
24 updateDate: new Date(2010, 04, 02, 00, 00, 00), |
|
25 size: 1, |
|
26 pendingOperations: AddonManager.PENDING_NONE, |
|
27 }, { |
|
28 id: "test2@tests.mozilla.org", |
|
29 name: "a first add-on", |
|
30 description: "foo", |
|
31 updateDate: new Date(2010, 04, 01, 23, 59, 59), |
|
32 size: 0265, |
|
33 pendingOperations: AddonManager.PENDING_UPGRADE, |
|
34 isActive: true, |
|
35 isCompatible: false, |
|
36 }, { |
|
37 id: "test3@tests.mozilla.org", |
|
38 name: "\u010Cesk\u00FD slovn\u00EDk", // Český slovník |
|
39 description: "foo", |
|
40 updateDate: new Date(2010, 04, 02, 00, 00, 01), |
|
41 size: 12, |
|
42 pendingOperations: AddonManager.PENDING_INSTALL, |
|
43 isActive: false, |
|
44 }, { |
|
45 id: "test4@tests.mozilla.org", |
|
46 name: "canadian dictionary", |
|
47 updateDate: new Date(1970, 0, 01, 00, 00, 00), |
|
48 description: "foo", |
|
49 isActive: true, |
|
50 }, { |
|
51 id: "test5@tests.mozilla.org", |
|
52 name: "croatian dictionary", |
|
53 description: "foo", |
|
54 updateDate: new Date(2012, 12, 12, 00, 00, 00), |
|
55 size: 5, |
|
56 pendingOperations: AddonManager.PENDING_ENABLE, |
|
57 isActive: false, |
|
58 }, { |
|
59 // pendingDisable group |
|
60 // * Waiting to be disabled |
|
61 id: "test6@tests.mozilla.org", |
|
62 name: "orange Add-on", |
|
63 description: "foo", |
|
64 updateDate: new Date(2010, 04, 02, 00, 00, 00), |
|
65 size: 142, |
|
66 isCompatible: false, |
|
67 isActive: true, |
|
68 pendingOperations: AddonManager.PENDING_DISABLE, |
|
69 }, { |
|
70 id: "test7@tests.mozilla.org", |
|
71 name: "Blue Add-on", |
|
72 description: "foo", |
|
73 updateDate: new Date(2010, 04, 01, 23, 59, 59), |
|
74 size: 65, |
|
75 isActive: true, |
|
76 pendingOperations: AddonManager.PENDING_DISABLE, |
|
77 }, { |
|
78 id: "test8@tests.mozilla.org", |
|
79 name: "Green Add-on", |
|
80 description: "foo", |
|
81 updateDate: new Date(2010, 04, 03, 00, 00, 01), |
|
82 size: 125, |
|
83 pendingOperations: AddonManager.PENDING_DISABLE, |
|
84 }, { |
|
85 id: "test9@tests.mozilla.org", |
|
86 name: "red Add-on", |
|
87 updateDate: new Date(2011, 04, 01, 00, 00, 00), |
|
88 description: "foo", |
|
89 isCompatible: false, |
|
90 pendingOperations: AddonManager.PENDING_DISABLE, |
|
91 }, { |
|
92 id: "test10@tests.mozilla.org", |
|
93 name: "Purple Add-on", |
|
94 description: "foo", |
|
95 updateDate: new Date(2012, 12, 12, 00, 00, 00), |
|
96 size: 56, |
|
97 isCompatible: false, |
|
98 pendingOperations: AddonManager.PENDING_DISABLE, |
|
99 }, { |
|
100 // pendingUninstall group |
|
101 // * Waiting to be removed |
|
102 id: "test11@tests.mozilla.org", |
|
103 name: "amber Add-on", |
|
104 description: "foo", |
|
105 updateDate: new Date(1978, 04, 02, 00, 00, 00), |
|
106 size: 142, |
|
107 isActive: false, |
|
108 appDisabled: true, |
|
109 pendingOperations: AddonManager.PENDING_UNINSTALL, |
|
110 }, { |
|
111 id: "test12@tests.mozilla.org", |
|
112 name: "Salmon Add-on - pending disable", |
|
113 description: "foo", |
|
114 updateDate: new Date(2054, 04, 01, 23, 59, 59), |
|
115 size: 65, |
|
116 isActive: true, |
|
117 pendingOperations: AddonManager.PENDING_UNINSTALL, |
|
118 }, { |
|
119 id: "test13@tests.mozilla.org", |
|
120 name: "rose Add-on", |
|
121 description: "foo", |
|
122 updateDate: new Date(2010, 04, 02, 00, 00, 01), |
|
123 size: 125, |
|
124 isActive: false, |
|
125 userDisabled: true, |
|
126 pendingOperations: AddonManager.PENDING_UNINSTALL, |
|
127 }, { |
|
128 id: "test14@tests.mozilla.org", |
|
129 name: "Violet Add-on", |
|
130 updateDate: new Date(2010, 05, 01, 00, 00, 00), |
|
131 description: "foo", |
|
132 isActive: false, |
|
133 appDisabled: true, |
|
134 pendingOperations: AddonManager.PENDING_UNINSTALL, |
|
135 }, { |
|
136 id: "test15@tests.mozilla.org", |
|
137 name: "white Add-on", |
|
138 description: "foo", |
|
139 updateDate: new Date(2010, 04, 12, 00, 00, 00), |
|
140 size: 56, |
|
141 isActive: false, |
|
142 userDisabled: true, |
|
143 pendingOperations: AddonManager.PENDING_UNINSTALL, |
|
144 }, { |
|
145 // disabledIncompatibleBlocked group |
|
146 // * Disabled |
|
147 // * Incompatible |
|
148 // * Blocklisted |
|
149 id: "test16@tests.mozilla.org", |
|
150 name: "grimsby Add-on", |
|
151 description: "foo", |
|
152 updateDate: new Date(2010, 04, 01, 00, 00, 00), |
|
153 size: 142, |
|
154 isActive: false, |
|
155 appDisabled: true, |
|
156 }, { |
|
157 id: "test17@tests.mozilla.org", |
|
158 name: "beamsville Add-on", |
|
159 description: "foo", |
|
160 updateDate: new Date(2010, 04, 8, 23, 59, 59), |
|
161 size: 65, |
|
162 isActive: false, |
|
163 userDisabled: true, |
|
164 }, { |
|
165 id: "test18@tests.mozilla.org", |
|
166 name: "smithville Add-on", |
|
167 description: "foo", |
|
168 updateDate: new Date(2010, 04, 03, 00, 00, 01), |
|
169 size: 125, |
|
170 isActive: false, |
|
171 userDisabled: true, |
|
172 blocklistState: Ci.nsIBlocklistService.STATE_OUTDATED, |
|
173 }, { |
|
174 id: "test19@tests.mozilla.org", |
|
175 name: "dunnville Add-on", |
|
176 updateDate: new Date(2010, 04, 02, 00, 00, 00), |
|
177 description: "foo", |
|
178 isActive: false, |
|
179 appDisabled: true, |
|
180 isCompatible: false, |
|
181 blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED, |
|
182 }, { |
|
183 id: "test20@tests.mozilla.org", |
|
184 name: "silverdale Add-on", |
|
185 description: "foo", |
|
186 updateDate: new Date(2010, 04, 12, 00, 00, 00), |
|
187 size: 56, |
|
188 isActive: false, |
|
189 appDisabled: true, |
|
190 blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, |
|
191 }]); |
|
192 |
|
193 |
|
194 open_manager("addons://list/extension", function(aWindow) { |
|
195 gManagerWindow = aWindow; |
|
196 run_next_test(); |
|
197 }); |
|
198 } |
|
199 |
|
200 function end_test() { |
|
201 close_manager(gManagerWindow, function() { |
|
202 finish(); |
|
203 }); |
|
204 } |
|
205 |
|
206 function set_order(aSortBy, aAscending) { |
|
207 var list = gManagerWindow.document.getElementById("addon-list"); |
|
208 var elements = []; |
|
209 var node = list.firstChild; |
|
210 while (node) { |
|
211 elements.push(node); |
|
212 node = node.nextSibling; |
|
213 } |
|
214 gManagerWindow.sortElements(elements, ["uiState", aSortBy], aAscending); |
|
215 for (let element of elements) |
|
216 list.appendChild(element); |
|
217 } |
|
218 |
|
219 function check_order(aExpectedOrder) { |
|
220 var order = []; |
|
221 var list = gManagerWindow.document.getElementById("addon-list"); |
|
222 var node = list.firstChild; |
|
223 while (node) { |
|
224 var id = node.getAttribute("value"); |
|
225 if (id && id.substring(id.length - 18) == "@tests.mozilla.org") |
|
226 order.push(node.getAttribute("value")); |
|
227 node = node.nextSibling; |
|
228 } |
|
229 |
|
230 is(order.toSource(), aExpectedOrder.toSource(), "Should have seen the right order"); |
|
231 } |
|
232 |
|
233 // Tests that ascending name ordering was the default |
|
234 add_test(function() { |
|
235 |
|
236 check_order([ |
|
237 "test2@tests.mozilla.org", |
|
238 "test4@tests.mozilla.org", |
|
239 "test3@tests.mozilla.org", |
|
240 "test5@tests.mozilla.org", |
|
241 "test1@tests.mozilla.org", |
|
242 "test7@tests.mozilla.org", |
|
243 "test8@tests.mozilla.org", |
|
244 "test6@tests.mozilla.org", |
|
245 "test10@tests.mozilla.org", |
|
246 "test9@tests.mozilla.org", |
|
247 "test11@tests.mozilla.org", |
|
248 "test13@tests.mozilla.org", |
|
249 "test12@tests.mozilla.org", |
|
250 "test14@tests.mozilla.org", |
|
251 "test15@tests.mozilla.org", |
|
252 "test17@tests.mozilla.org", |
|
253 "test19@tests.mozilla.org", |
|
254 "test16@tests.mozilla.org", |
|
255 "test20@tests.mozilla.org", |
|
256 "test18@tests.mozilla.org", |
|
257 ]); |
|
258 run_next_test(); |
|
259 }); |
|
260 |
|
261 // Tests that switching to date ordering works |
|
262 add_test(function() { |
|
263 set_order("updateDate", false); |
|
264 |
|
265 // When we're ascending with updateDate, it's from newest |
|
266 // to oldest. |
|
267 |
|
268 check_order([ |
|
269 "test5@tests.mozilla.org", |
|
270 "test3@tests.mozilla.org", |
|
271 "test1@tests.mozilla.org", |
|
272 "test2@tests.mozilla.org", |
|
273 "test4@tests.mozilla.org", |
|
274 "test10@tests.mozilla.org", |
|
275 "test9@tests.mozilla.org", |
|
276 "test8@tests.mozilla.org", |
|
277 "test6@tests.mozilla.org", |
|
278 "test7@tests.mozilla.org", |
|
279 "test12@tests.mozilla.org", |
|
280 "test14@tests.mozilla.org", |
|
281 "test15@tests.mozilla.org", |
|
282 "test13@tests.mozilla.org", |
|
283 "test11@tests.mozilla.org", |
|
284 "test20@tests.mozilla.org", |
|
285 "test17@tests.mozilla.org", |
|
286 "test18@tests.mozilla.org", |
|
287 "test19@tests.mozilla.org", |
|
288 "test16@tests.mozilla.org", |
|
289 ]); |
|
290 |
|
291 set_order("updateDate", true); |
|
292 |
|
293 check_order([ |
|
294 "test4@tests.mozilla.org", |
|
295 "test2@tests.mozilla.org", |
|
296 "test1@tests.mozilla.org", |
|
297 "test3@tests.mozilla.org", |
|
298 "test5@tests.mozilla.org", |
|
299 "test7@tests.mozilla.org", |
|
300 "test6@tests.mozilla.org", |
|
301 "test8@tests.mozilla.org", |
|
302 "test9@tests.mozilla.org", |
|
303 "test10@tests.mozilla.org", |
|
304 "test11@tests.mozilla.org", |
|
305 "test13@tests.mozilla.org", |
|
306 "test15@tests.mozilla.org", |
|
307 "test14@tests.mozilla.org", |
|
308 "test12@tests.mozilla.org", |
|
309 "test16@tests.mozilla.org", |
|
310 "test19@tests.mozilla.org", |
|
311 "test18@tests.mozilla.org", |
|
312 "test17@tests.mozilla.org", |
|
313 "test20@tests.mozilla.org", |
|
314 ]); |
|
315 |
|
316 run_next_test(); |
|
317 }); |
|
318 |
|
319 // Tests that switching to name ordering works |
|
320 add_test(function() { |
|
321 set_order("name", true); |
|
322 |
|
323 check_order([ |
|
324 "test2@tests.mozilla.org", |
|
325 "test4@tests.mozilla.org", |
|
326 "test3@tests.mozilla.org", |
|
327 "test5@tests.mozilla.org", |
|
328 "test1@tests.mozilla.org", |
|
329 "test7@tests.mozilla.org", |
|
330 "test8@tests.mozilla.org", |
|
331 "test6@tests.mozilla.org", |
|
332 "test10@tests.mozilla.org", |
|
333 "test9@tests.mozilla.org", |
|
334 "test11@tests.mozilla.org", |
|
335 "test13@tests.mozilla.org", |
|
336 "test12@tests.mozilla.org", |
|
337 "test14@tests.mozilla.org", |
|
338 "test15@tests.mozilla.org", |
|
339 "test17@tests.mozilla.org", |
|
340 "test19@tests.mozilla.org", |
|
341 "test16@tests.mozilla.org", |
|
342 "test20@tests.mozilla.org", |
|
343 "test18@tests.mozilla.org", |
|
344 ]); |
|
345 |
|
346 set_order("name", false); |
|
347 |
|
348 check_order([ |
|
349 "test1@tests.mozilla.org", |
|
350 "test5@tests.mozilla.org", |
|
351 "test3@tests.mozilla.org", |
|
352 "test4@tests.mozilla.org", |
|
353 "test2@tests.mozilla.org", |
|
354 "test9@tests.mozilla.org", |
|
355 "test10@tests.mozilla.org", |
|
356 "test6@tests.mozilla.org", |
|
357 "test8@tests.mozilla.org", |
|
358 "test7@tests.mozilla.org", |
|
359 "test15@tests.mozilla.org", |
|
360 "test14@tests.mozilla.org", |
|
361 "test12@tests.mozilla.org", |
|
362 "test13@tests.mozilla.org", |
|
363 "test11@tests.mozilla.org", |
|
364 "test18@tests.mozilla.org", |
|
365 "test20@tests.mozilla.org", |
|
366 "test16@tests.mozilla.org", |
|
367 "test19@tests.mozilla.org", |
|
368 "test17@tests.mozilla.org", |
|
369 ]); |
|
370 |
|
371 run_next_test(); |
|
372 }); |