summaryrefslogtreecommitdiffstats
path: root/toolkit/mozapps/extensions/test/browser/browser_sorting.js
blob: 7bf697b36be98810fce7995f59c0fd1eb72ce2ef (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
/* Any copyright is dedicated to the Public Domain.
 * http://creativecommons.org/publicdomain/zero/1.0/
 */

// Tests that sorting of add-ons works correctly
// (this test uses the list view, even though it no longer has sort buttons - see bug 623207)

var gManagerWindow;
var gProvider;

function test() {
  waitForExplicitFinish();

  gProvider = new MockProvider();
  gProvider.createAddons([{
    //  enabledInstalled group
    //    * Enabled
    //    * Incompatible but enabled because compatibility checking is off
    //    * Waiting to be installed
    //    * Waiting to be enabled
    id: "test1@tests.mozilla.org",
    name: "Test add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 02, 00, 00, 00),
    size: 1,
    pendingOperations: AddonManager.PENDING_NONE,
  }, {
    id: "test2@tests.mozilla.org",
    name: "a first add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 01, 23, 59, 59),
    size: 0265,
    pendingOperations: AddonManager.PENDING_UPGRADE,
    isActive: true,
    isCompatible: false,
  }, {
    id: "test3@tests.mozilla.org",
    name: "\u010Cesk\u00FD slovn\u00EDk", // Český slovník
    description: "foo",
    updateDate: new Date(2010, 04, 02, 00, 00, 01),
    size: 12,
    pendingOperations: AddonManager.PENDING_INSTALL,
    isActive: false,
  }, {
    id: "test4@tests.mozilla.org",
    name: "canadian dictionary",
    updateDate: new Date(1970, 0, 01, 00, 00, 00),
    description: "foo",
    isActive: true,
  }, {
    id: "test5@tests.mozilla.org",
    name: "croatian dictionary",
    description: "foo",
    updateDate: new Date(2012, 12, 12, 00, 00, 00),
    size: 5,
    pendingOperations: AddonManager.PENDING_ENABLE,
    isActive: false,
  }, {
    //  pendingDisable group
    //    * Waiting to be disabled
    id: "test6@tests.mozilla.org",
    name: "orange Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 02, 00, 00, 00),
    size: 142,
    isCompatible: false,
    isActive: true,
    pendingOperations: AddonManager.PENDING_DISABLE,
  }, {
    id: "test7@tests.mozilla.org",
    name: "Blue Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 01, 23, 59, 59),
    size: 65,
    isActive: true,
    pendingOperations: AddonManager.PENDING_DISABLE,
  }, {
    id: "test8@tests.mozilla.org",
    name: "Green Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 03, 00, 00, 01),
    size: 125,
    pendingOperations: AddonManager.PENDING_DISABLE,
  }, {
    id: "test9@tests.mozilla.org",
    name: "red Add-on",
    updateDate: new Date(2011, 04, 01, 00, 00, 00),
    description: "foo",
    isCompatible: false,
    pendingOperations: AddonManager.PENDING_DISABLE,
  }, {
    id: "test10@tests.mozilla.org",
    name: "Purple Add-on",
    description: "foo",
    updateDate: new Date(2012, 12, 12, 00, 00, 00),
    size: 56,
    isCompatible: false,
    pendingOperations: AddonManager.PENDING_DISABLE,
  }, {
    //  pendingUninstall group
    //    * Waiting to be removed
    id: "test11@tests.mozilla.org",
    name: "amber Add-on",
    description: "foo",
    updateDate: new Date(1978, 04, 02, 00, 00, 00),
    size: 142,
    isActive: false,
    appDisabled: true,
    pendingOperations: AddonManager.PENDING_UNINSTALL,
  }, {
    id: "test12@tests.mozilla.org",
    name: "Salmon Add-on - pending disable",
    description: "foo",
    updateDate: new Date(2054, 04, 01, 23, 59, 59),
    size: 65,
    isActive: true,
    pendingOperations: AddonManager.PENDING_UNINSTALL,
  }, {
    id: "test13@tests.mozilla.org",
    name: "rose Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 02, 00, 00, 01),
    size: 125,
    isActive: false,
    userDisabled: true,
    pendingOperations: AddonManager.PENDING_UNINSTALL,
  }, {
    id: "test14@tests.mozilla.org",
    name: "Violet Add-on",
    updateDate: new Date(2010, 05, 01, 00, 00, 00),
    description: "foo",
    isActive: false,
    appDisabled: true,
    pendingOperations: AddonManager.PENDING_UNINSTALL,
  }, {
    id: "test15@tests.mozilla.org",
    name: "white Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 12, 00, 00, 00),
    size: 56,
    isActive: false,
    userDisabled: true,
    pendingOperations: AddonManager.PENDING_UNINSTALL,
  }, {
    //  disabledIncompatibleBlocked group
    //    * Disabled
    //    * Incompatible
    //    * Blocklisted
    id: "test16@tests.mozilla.org",
    name: "grimsby Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 01, 00, 00, 00),
    size: 142,
    isActive: false,
    appDisabled: true,
  }, {
    id: "test17@tests.mozilla.org",
    name: "beamsville Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 8, 23, 59, 59),
    size: 65,
    isActive: false,
    userDisabled: true,
  }, {
    id: "test18@tests.mozilla.org",
    name: "smithville Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 03, 00, 00, 01),
    size: 125,
    isActive: false,
    userDisabled: true,
    blocklistState: Ci.nsIBlocklistService.STATE_OUTDATED,
  }, {
    id: "test19@tests.mozilla.org",
    name: "dunnville Add-on",
    updateDate: new Date(2010, 04, 02, 00, 00, 00),
    description: "foo",
    isActive: false,
    appDisabled: true,
    isCompatible: false,
    blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED,
  }, {
    id: "test20@tests.mozilla.org",
    name: "silverdale Add-on",
    description: "foo",
    updateDate: new Date(2010, 04, 12, 00, 00, 00),
    size: 56,
    isActive: false,
    appDisabled: true,
    blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED,
  }]);


  open_manager("addons://list/extension", function(aWindow) {
    gManagerWindow = aWindow;
    run_next_test();
  });
}

function end_test() {
  close_manager(gManagerWindow, function() {
    finish();
  });
}

function set_order(aSortBy, aAscending) {
  var list = gManagerWindow.document.getElementById("addon-list");
  var elements = [];
  var node = list.firstChild;
  while (node) {
    elements.push(node);
    node = node.nextSibling;
  }
  gManagerWindow.sortElements(elements, ["uiState", aSortBy], aAscending);
  for (let element of elements)
    list.appendChild(element);
}

function check_order(aExpectedOrder) {
  var order = [];
  var list = gManagerWindow.document.getElementById("addon-list");
  var node = list.firstChild;
  while (node) {
    var id = node.getAttribute("value");
    if (id && id.endsWith("@tests.mozilla.org"))
      order.push(node.getAttribute("value"));
    node = node.nextSibling;
  }

  is(order.toSource(), aExpectedOrder.toSource(), "Should have seen the right order");
}

// Tests that ascending name ordering was the default
add_test(function() {

  check_order([
    "test2@tests.mozilla.org",
    "test4@tests.mozilla.org",
    "test3@tests.mozilla.org",
    "test5@tests.mozilla.org",
    "test1@tests.mozilla.org",
    "test7@tests.mozilla.org",
    "test8@tests.mozilla.org",
    "test6@tests.mozilla.org",
    "test10@tests.mozilla.org",
    "test9@tests.mozilla.org",
    "test11@tests.mozilla.org",
    "test13@tests.mozilla.org",
    "test12@tests.mozilla.org",
    "test14@tests.mozilla.org",
    "test15@tests.mozilla.org",
    "test17@tests.mozilla.org",
    "test19@tests.mozilla.org",
    "test16@tests.mozilla.org",
    "test20@tests.mozilla.org",
    "test18@tests.mozilla.org",
  ]);
  run_next_test();
});

// Tests that switching to date ordering works
add_test(function() {
  set_order("updateDate", false);

  // When we're ascending with updateDate, it's from newest
  // to oldest.

  check_order([
    "test5@tests.mozilla.org",
    "test3@tests.mozilla.org",
    "test1@tests.mozilla.org",
    "test2@tests.mozilla.org",
    "test4@tests.mozilla.org",
    "test10@tests.mozilla.org",
    "test9@tests.mozilla.org",
    "test8@tests.mozilla.org",
    "test6@tests.mozilla.org",
    "test7@tests.mozilla.org",
    "test12@tests.mozilla.org",
    "test14@tests.mozilla.org",
    "test15@tests.mozilla.org",
    "test13@tests.mozilla.org",
    "test11@tests.mozilla.org",
    "test20@tests.mozilla.org",
    "test17@tests.mozilla.org",
    "test18@tests.mozilla.org",
    "test19@tests.mozilla.org",
    "test16@tests.mozilla.org",
  ]);

  set_order("updateDate", true);

  check_order([
    "test4@tests.mozilla.org",
    "test2@tests.mozilla.org",
    "test1@tests.mozilla.org",
    "test3@tests.mozilla.org",
    "test5@tests.mozilla.org",
    "test7@tests.mozilla.org",
    "test6@tests.mozilla.org",
    "test8@tests.mozilla.org",
    "test9@tests.mozilla.org",
    "test10@tests.mozilla.org",
    "test11@tests.mozilla.org",
    "test13@tests.mozilla.org",
    "test15@tests.mozilla.org",
    "test14@tests.mozilla.org",
    "test12@tests.mozilla.org",
    "test16@tests.mozilla.org",
    "test19@tests.mozilla.org",
    "test18@tests.mozilla.org",
    "test17@tests.mozilla.org",
    "test20@tests.mozilla.org",
  ]);

  run_next_test();
});

// Tests that switching to name ordering works
add_test(function() {
  set_order("name", true);

  check_order([
    "test2@tests.mozilla.org",
    "test4@tests.mozilla.org",
    "test3@tests.mozilla.org",
    "test5@tests.mozilla.org",
    "test1@tests.mozilla.org",
    "test7@tests.mozilla.org",
    "test8@tests.mozilla.org",
    "test6@tests.mozilla.org",
    "test10@tests.mozilla.org",
    "test9@tests.mozilla.org",
    "test11@tests.mozilla.org",
    "test13@tests.mozilla.org",
    "test12@tests.mozilla.org",
    "test14@tests.mozilla.org",
    "test15@tests.mozilla.org",
    "test17@tests.mozilla.org",
    "test19@tests.mozilla.org",
    "test16@tests.mozilla.org",
    "test20@tests.mozilla.org",
    "test18@tests.mozilla.org",
  ]);

  set_order("name", false);

  check_order([
    "test1@tests.mozilla.org",
    "test5@tests.mozilla.org",
    "test3@tests.mozilla.org",
    "test4@tests.mozilla.org",
    "test2@tests.mozilla.org",
    "test9@tests.mozilla.org",
    "test10@tests.mozilla.org",
    "test6@tests.mozilla.org",
    "test8@tests.mozilla.org",
    "test7@tests.mozilla.org",
    "test15@tests.mozilla.org",
    "test14@tests.mozilla.org",
    "test12@tests.mozilla.org",
    "test13@tests.mozilla.org",
    "test11@tests.mozilla.org",
    "test18@tests.mozilla.org",
    "test20@tests.mozilla.org",
    "test16@tests.mozilla.org",
    "test19@tests.mozilla.org",
    "test17@tests.mozilla.org",
  ]);

  run_next_test();
});