michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: * http://creativecommons.org/publicdomain/zero/1.0/ michael@0: */ michael@0: michael@0: // Tests that sorting of add-ons works correctly michael@0: // (this test uses the list view, even though it no longer has sort buttons - see bug 623207) michael@0: michael@0: var gManagerWindow; michael@0: var gProvider; michael@0: michael@0: function test() { michael@0: waitForExplicitFinish(); michael@0: michael@0: gProvider = new MockProvider(); michael@0: gProvider.createAddons([{ michael@0: // enabledInstalled group michael@0: // * Enabled michael@0: // * Incompatible but enabled because compatibility checking is off michael@0: // * Waiting to be installed michael@0: // * Waiting to be enabled michael@0: id: "test1@tests.mozilla.org", michael@0: name: "Test add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 02, 00, 00, 00), michael@0: size: 1, michael@0: pendingOperations: AddonManager.PENDING_NONE, michael@0: }, { michael@0: id: "test2@tests.mozilla.org", michael@0: name: "a first add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 01, 23, 59, 59), michael@0: size: 0265, michael@0: pendingOperations: AddonManager.PENDING_UPGRADE, michael@0: isActive: true, michael@0: isCompatible: false, michael@0: }, { michael@0: id: "test3@tests.mozilla.org", michael@0: name: "\u010Cesk\u00FD slovn\u00EDk", // Český slovník michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 02, 00, 00, 01), michael@0: size: 12, michael@0: pendingOperations: AddonManager.PENDING_INSTALL, michael@0: isActive: false, michael@0: }, { michael@0: id: "test4@tests.mozilla.org", michael@0: name: "canadian dictionary", michael@0: updateDate: new Date(1970, 0, 01, 00, 00, 00), michael@0: description: "foo", michael@0: isActive: true, michael@0: }, { michael@0: id: "test5@tests.mozilla.org", michael@0: name: "croatian dictionary", michael@0: description: "foo", michael@0: updateDate: new Date(2012, 12, 12, 00, 00, 00), michael@0: size: 5, michael@0: pendingOperations: AddonManager.PENDING_ENABLE, michael@0: isActive: false, michael@0: }, { michael@0: // pendingDisable group michael@0: // * Waiting to be disabled michael@0: id: "test6@tests.mozilla.org", michael@0: name: "orange Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 02, 00, 00, 00), michael@0: size: 142, michael@0: isCompatible: false, michael@0: isActive: true, michael@0: pendingOperations: AddonManager.PENDING_DISABLE, michael@0: }, { michael@0: id: "test7@tests.mozilla.org", michael@0: name: "Blue Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 01, 23, 59, 59), michael@0: size: 65, michael@0: isActive: true, michael@0: pendingOperations: AddonManager.PENDING_DISABLE, michael@0: }, { michael@0: id: "test8@tests.mozilla.org", michael@0: name: "Green Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 03, 00, 00, 01), michael@0: size: 125, michael@0: pendingOperations: AddonManager.PENDING_DISABLE, michael@0: }, { michael@0: id: "test9@tests.mozilla.org", michael@0: name: "red Add-on", michael@0: updateDate: new Date(2011, 04, 01, 00, 00, 00), michael@0: description: "foo", michael@0: isCompatible: false, michael@0: pendingOperations: AddonManager.PENDING_DISABLE, michael@0: }, { michael@0: id: "test10@tests.mozilla.org", michael@0: name: "Purple Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2012, 12, 12, 00, 00, 00), michael@0: size: 56, michael@0: isCompatible: false, michael@0: pendingOperations: AddonManager.PENDING_DISABLE, michael@0: }, { michael@0: // pendingUninstall group michael@0: // * Waiting to be removed michael@0: id: "test11@tests.mozilla.org", michael@0: name: "amber Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(1978, 04, 02, 00, 00, 00), michael@0: size: 142, michael@0: isActive: false, michael@0: appDisabled: true, michael@0: pendingOperations: AddonManager.PENDING_UNINSTALL, michael@0: }, { michael@0: id: "test12@tests.mozilla.org", michael@0: name: "Salmon Add-on - pending disable", michael@0: description: "foo", michael@0: updateDate: new Date(2054, 04, 01, 23, 59, 59), michael@0: size: 65, michael@0: isActive: true, michael@0: pendingOperations: AddonManager.PENDING_UNINSTALL, michael@0: }, { michael@0: id: "test13@tests.mozilla.org", michael@0: name: "rose Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 02, 00, 00, 01), michael@0: size: 125, michael@0: isActive: false, michael@0: userDisabled: true, michael@0: pendingOperations: AddonManager.PENDING_UNINSTALL, michael@0: }, { michael@0: id: "test14@tests.mozilla.org", michael@0: name: "Violet Add-on", michael@0: updateDate: new Date(2010, 05, 01, 00, 00, 00), michael@0: description: "foo", michael@0: isActive: false, michael@0: appDisabled: true, michael@0: pendingOperations: AddonManager.PENDING_UNINSTALL, michael@0: }, { michael@0: id: "test15@tests.mozilla.org", michael@0: name: "white Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 12, 00, 00, 00), michael@0: size: 56, michael@0: isActive: false, michael@0: userDisabled: true, michael@0: pendingOperations: AddonManager.PENDING_UNINSTALL, michael@0: }, { michael@0: // disabledIncompatibleBlocked group michael@0: // * Disabled michael@0: // * Incompatible michael@0: // * Blocklisted michael@0: id: "test16@tests.mozilla.org", michael@0: name: "grimsby Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 01, 00, 00, 00), michael@0: size: 142, michael@0: isActive: false, michael@0: appDisabled: true, michael@0: }, { michael@0: id: "test17@tests.mozilla.org", michael@0: name: "beamsville Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 8, 23, 59, 59), michael@0: size: 65, michael@0: isActive: false, michael@0: userDisabled: true, michael@0: }, { michael@0: id: "test18@tests.mozilla.org", michael@0: name: "smithville Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 03, 00, 00, 01), michael@0: size: 125, michael@0: isActive: false, michael@0: userDisabled: true, michael@0: blocklistState: Ci.nsIBlocklistService.STATE_OUTDATED, michael@0: }, { michael@0: id: "test19@tests.mozilla.org", michael@0: name: "dunnville Add-on", michael@0: updateDate: new Date(2010, 04, 02, 00, 00, 00), michael@0: description: "foo", michael@0: isActive: false, michael@0: appDisabled: true, michael@0: isCompatible: false, michael@0: blocklistState: Ci.nsIBlocklistService.STATE_NOT_BLOCKED, michael@0: }, { michael@0: id: "test20@tests.mozilla.org", michael@0: name: "silverdale Add-on", michael@0: description: "foo", michael@0: updateDate: new Date(2010, 04, 12, 00, 00, 00), michael@0: size: 56, michael@0: isActive: false, michael@0: appDisabled: true, michael@0: blocklistState: Ci.nsIBlocklistService.STATE_BLOCKED, michael@0: }]); michael@0: michael@0: michael@0: open_manager("addons://list/extension", function(aWindow) { michael@0: gManagerWindow = aWindow; michael@0: run_next_test(); michael@0: }); michael@0: } michael@0: michael@0: function end_test() { michael@0: close_manager(gManagerWindow, function() { michael@0: finish(); michael@0: }); michael@0: } michael@0: michael@0: function set_order(aSortBy, aAscending) { michael@0: var list = gManagerWindow.document.getElementById("addon-list"); michael@0: var elements = []; michael@0: var node = list.firstChild; michael@0: while (node) { michael@0: elements.push(node); michael@0: node = node.nextSibling; michael@0: } michael@0: gManagerWindow.sortElements(elements, ["uiState", aSortBy], aAscending); michael@0: for (let element of elements) michael@0: list.appendChild(element); michael@0: } michael@0: michael@0: function check_order(aExpectedOrder) { michael@0: var order = []; michael@0: var list = gManagerWindow.document.getElementById("addon-list"); michael@0: var node = list.firstChild; michael@0: while (node) { michael@0: var id = node.getAttribute("value"); michael@0: if (id && id.substring(id.length - 18) == "@tests.mozilla.org") michael@0: order.push(node.getAttribute("value")); michael@0: node = node.nextSibling; michael@0: } michael@0: michael@0: is(order.toSource(), aExpectedOrder.toSource(), "Should have seen the right order"); michael@0: } michael@0: michael@0: // Tests that ascending name ordering was the default michael@0: add_test(function() { michael@0: michael@0: check_order([ michael@0: "test2@tests.mozilla.org", michael@0: "test4@tests.mozilla.org", michael@0: "test3@tests.mozilla.org", michael@0: "test5@tests.mozilla.org", michael@0: "test1@tests.mozilla.org", michael@0: "test7@tests.mozilla.org", michael@0: "test8@tests.mozilla.org", michael@0: "test6@tests.mozilla.org", michael@0: "test10@tests.mozilla.org", michael@0: "test9@tests.mozilla.org", michael@0: "test11@tests.mozilla.org", michael@0: "test13@tests.mozilla.org", michael@0: "test12@tests.mozilla.org", michael@0: "test14@tests.mozilla.org", michael@0: "test15@tests.mozilla.org", michael@0: "test17@tests.mozilla.org", michael@0: "test19@tests.mozilla.org", michael@0: "test16@tests.mozilla.org", michael@0: "test20@tests.mozilla.org", michael@0: "test18@tests.mozilla.org", michael@0: ]); michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Tests that switching to date ordering works michael@0: add_test(function() { michael@0: set_order("updateDate", false); michael@0: michael@0: // When we're ascending with updateDate, it's from newest michael@0: // to oldest. michael@0: michael@0: check_order([ michael@0: "test5@tests.mozilla.org", michael@0: "test3@tests.mozilla.org", michael@0: "test1@tests.mozilla.org", michael@0: "test2@tests.mozilla.org", michael@0: "test4@tests.mozilla.org", michael@0: "test10@tests.mozilla.org", michael@0: "test9@tests.mozilla.org", michael@0: "test8@tests.mozilla.org", michael@0: "test6@tests.mozilla.org", michael@0: "test7@tests.mozilla.org", michael@0: "test12@tests.mozilla.org", michael@0: "test14@tests.mozilla.org", michael@0: "test15@tests.mozilla.org", michael@0: "test13@tests.mozilla.org", michael@0: "test11@tests.mozilla.org", michael@0: "test20@tests.mozilla.org", michael@0: "test17@tests.mozilla.org", michael@0: "test18@tests.mozilla.org", michael@0: "test19@tests.mozilla.org", michael@0: "test16@tests.mozilla.org", michael@0: ]); michael@0: michael@0: set_order("updateDate", true); michael@0: michael@0: check_order([ michael@0: "test4@tests.mozilla.org", michael@0: "test2@tests.mozilla.org", michael@0: "test1@tests.mozilla.org", michael@0: "test3@tests.mozilla.org", michael@0: "test5@tests.mozilla.org", michael@0: "test7@tests.mozilla.org", michael@0: "test6@tests.mozilla.org", michael@0: "test8@tests.mozilla.org", michael@0: "test9@tests.mozilla.org", michael@0: "test10@tests.mozilla.org", michael@0: "test11@tests.mozilla.org", michael@0: "test13@tests.mozilla.org", michael@0: "test15@tests.mozilla.org", michael@0: "test14@tests.mozilla.org", michael@0: "test12@tests.mozilla.org", michael@0: "test16@tests.mozilla.org", michael@0: "test19@tests.mozilla.org", michael@0: "test18@tests.mozilla.org", michael@0: "test17@tests.mozilla.org", michael@0: "test20@tests.mozilla.org", michael@0: ]); michael@0: michael@0: run_next_test(); michael@0: }); michael@0: michael@0: // Tests that switching to name ordering works michael@0: add_test(function() { michael@0: set_order("name", true); michael@0: michael@0: check_order([ michael@0: "test2@tests.mozilla.org", michael@0: "test4@tests.mozilla.org", michael@0: "test3@tests.mozilla.org", michael@0: "test5@tests.mozilla.org", michael@0: "test1@tests.mozilla.org", michael@0: "test7@tests.mozilla.org", michael@0: "test8@tests.mozilla.org", michael@0: "test6@tests.mozilla.org", michael@0: "test10@tests.mozilla.org", michael@0: "test9@tests.mozilla.org", michael@0: "test11@tests.mozilla.org", michael@0: "test13@tests.mozilla.org", michael@0: "test12@tests.mozilla.org", michael@0: "test14@tests.mozilla.org", michael@0: "test15@tests.mozilla.org", michael@0: "test17@tests.mozilla.org", michael@0: "test19@tests.mozilla.org", michael@0: "test16@tests.mozilla.org", michael@0: "test20@tests.mozilla.org", michael@0: "test18@tests.mozilla.org", michael@0: ]); michael@0: michael@0: set_order("name", false); michael@0: michael@0: check_order([ michael@0: "test1@tests.mozilla.org", michael@0: "test5@tests.mozilla.org", michael@0: "test3@tests.mozilla.org", michael@0: "test4@tests.mozilla.org", michael@0: "test2@tests.mozilla.org", michael@0: "test9@tests.mozilla.org", michael@0: "test10@tests.mozilla.org", michael@0: "test6@tests.mozilla.org", michael@0: "test8@tests.mozilla.org", michael@0: "test7@tests.mozilla.org", michael@0: "test15@tests.mozilla.org", michael@0: "test14@tests.mozilla.org", michael@0: "test12@tests.mozilla.org", michael@0: "test13@tests.mozilla.org", michael@0: "test11@tests.mozilla.org", michael@0: "test18@tests.mozilla.org", michael@0: "test20@tests.mozilla.org", michael@0: "test16@tests.mozilla.org", michael@0: "test19@tests.mozilla.org", michael@0: "test17@tests.mozilla.org", michael@0: ]); michael@0: michael@0: run_next_test(); michael@0: });