toolkit/mozapps/extensions/test/browser/browser_sorting.js

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

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

mercurial