Bug 629521 - Extensions and themes which are marked to get removed are not grouped but remain at the original location; r,a=Mossop
authorMike Conley <mconley@mozillamessaging.com>
Thu, 03 Feb 2011 15:15:33 -0500
changeset 61949 cff79fb2f133b50e5349b6edf27e746407b7038f
parent 61948 9414d1eaeeeb0342fc6e44e6c4efcdb10f213803
child 61950 c14b6fd8ed6d5626f1a157c08bcf35c1923513c2
push idunknown
push userunknown
push dateunknown
reviewersMossop
bugs629521
milestone2.0b12pre
Bug 629521 - Extensions and themes which are marked to get removed are not grouped but remain at the original location; r,a=Mossop
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_sorting.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -1201,17 +1201,38 @@ function createItem(aObj, aIsInstall, aI
 }
 
 function sortElements(aElements, aSortBy, aAscending) {
   // aSortBy is an Array of attributes to sort by, in decending
   // order of priority.
 
   const DATE_FIELDS = ["updateDate"];
   const NUMERIC_FIELDS = ["size", "relevancescore", "purchaseAmount"];
-  const UISTATE_ORDER = ["enabled", "incompatible", "disabled", "blocked"]
+
+  // We're going to group add-ons into the following buckets:
+  //
+  //  enabledInstalled
+  //    * Enabled
+  //    * Incompatible but enabled because compatibility checking is off
+  //    * Waiting to be installed
+  //    * Waiting to be enabled
+  //
+  //  pendingDisable
+  //    * Waiting to be disabled
+  //
+  //  pendingUninstall
+  //    * Waiting to be removed
+  //
+  //  disabledIncompatibleBlocked
+  //    * Disabled
+  //    * Incompatible
+  //    * Blocklisted
+
+  const UISTATE_ORDER = ["enabled", "pendingDisable", "pendingUninstall",
+                         "disabled"];
 
   function dateCompare(a, b) {
     var aTime = a.getTime();
     var bTime = b.getTime();
     if (aTime < bTime)
       return -1;
     if (aTime > bTime)
       return 1;
@@ -1240,29 +1261,30 @@ function sortElements(aElements, aSortBy
       return null;
 
     if (aObj.hasAttribute(aKey))
       return aObj.getAttribute(aKey);
 
     addon = aObj.mAddon || aObj.mInstall;
     if (!addon)
       return null;
+
     if (aKey == "uiState") {
-      if (addon.isActive)
+      if (addon.pendingOperations == AddonManager.PENDING_DISABLE)
+        return "pendingDisable";
+      if (addon.pendingOperations == AddonManager.PENDING_UNINSTALL)
+        return "pendingUninstall";
+      if (!addon.isActive &&
+          (addon.pendingOperations != AddonManager.PENDING_ENABLE &&
+           addon.pendingOperations != AddonManager.PENDING_INSTALL))
+        return "disabled";
+      else
         return "enabled";
-      else if (!addon.isCompatible)
-        return "incompatible";
-      else if (addon.blocklistState == Ci.nsIBlocklistService.STATE_NOT_BLOCKED)
-        return "disabled";
-      else if (addon.isCompatible &&
-               addon.blocklistState != Ci.nsIBlocklistService.STATE_NOT_BLOCKED)
-        return "blocked";
     }
 
-
     return addon[aKey];
   }
 
   // aSortFuncs will hold the sorting functions that we'll
   // use per element, in the correct order.
   var aSortFuncs = [];
 
   for (let i = 0; i < aSortBy.length; i++) {
--- a/toolkit/mozapps/extensions/test/browser/browser_sorting.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_sorting.js
@@ -8,162 +8,194 @@
 var gManagerWindow;
 var gProvider;
 
 function test() {
   waitForExplicitFinish();
 
   gProvider = new MockProvider();
   gProvider.createAddons([{
-    // Enabled extensions
+    //  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
+    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
+    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
+    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
+    size: 5,
+    pendingOperations: AddonManager.PENDING_ENABLE,
+    isActive: false,
   }, {
-    // Incompatible, disabled extensions
+    //  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: 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,
-    isCompatible: false,
-    isActive: false,
+    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,
-    isCompatible: false,
-    isActive: false,
+    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,
-    isActive: 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,
-    isActive: false,
+    pendingOperations: AddonManager.PENDING_DISABLE,
   }, {
-    // Disabled, compatible extensions
+    //  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",
+    name: "Salmon Add-on - pending disable",
     description: "foo",
     updateDate: new Date(2054, 04, 01, 23, 59, 59),
     size: 65,
-    isActive: false,
+    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,
   }, {
-    // Blocked extensions
+    //  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,
-    blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
+    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,
-    blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
+    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,
-    blocklistState: Ci.nsIBlocklistService.STATE_SOFTBLOCKED,
+    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() {
@@ -219,17 +251,16 @@ add_test(function() {
     "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