Bug 1132971 - Don't assume that the add-ons discovery pane will be available, r=mossop
authorMike Kaply <mozilla@kaply.com>
Thu, 09 Apr 2015 11:18:31 -0500
changeset 238664 0b901409f138026003b0d09f9c2335f19359af75
parent 238562 3e72d91e50c21117b172065dfca3a52e1f4c18e3
child 238665 ee5ce5ae72e034bafe3c33f04499d428d306d8b8
push idunknown
push userunknown
push dateunknown
reviewersmossop
bugs1132971
milestone40.0a1
Bug 1132971 - Don't assume that the add-ons discovery pane will be available, r=mossop
toolkit/mozapps/extensions/content/extensions.js
toolkit/mozapps/extensions/test/browser/browser_discovery.js
toolkit/mozapps/extensions/test/browser/head.js
--- a/toolkit/mozapps/extensions/content/extensions.js
+++ b/toolkit/mozapps/extensions/content/extensions.js
@@ -46,17 +46,17 @@ const SEARCH_SCORE_MATCH_WHOLEWORD = 10;
 const SEARCH_SCORE_MATCH_WORDBOUNDRY = 6;
 const SEARCH_SCORE_MATCH_SUBSTRING = 3;
 
 const UPDATES_RECENT_TIMESPAN = 2 * 24 * 3600000; // 2 days (in milliseconds)
 const UPDATES_RELEASENOTES_TRANSFORMFILE = "chrome://mozapps/content/extensions/updateinfo.xsl";
 
 const XMLURI_PARSE_ERROR = "http://www.mozilla.org/newlayout/xml/parsererror.xml"
 
-const VIEW_DEFAULT = "addons://discover/";
+var gViewDefault = "addons://discover/";
 
 var gStrings = {};
 XPCOMUtils.defineLazyServiceGetter(gStrings, "bundleSvc",
                                    "@mozilla.org/intl/stringbundle;1",
                                    "nsIStringBundleService");
 
 XPCOMUtils.defineLazyGetter(gStrings, "brand", function brandLazyGetter() {
   return this.bundleSvc.createBundle("chrome://branding/locale/brand.properties");
@@ -119,16 +119,20 @@ function initialize(event) {
   });
   addonPage.addEventListener("drop", function(event) {
     gDragDrop.onDrop(event);
   });
   addonPage.addEventListener("keypress", function(event) {
     gHeader.onKeyPress(event);
   });
 
+  if (!isDiscoverEnabled()) {
+    gViewDefault = "addons://list/extension";
+  }
+
   gViewController.initialize();
   gCategories.initialize();
   gHeader.initialize();
   gEventManager.initialize();
   Services.obs.addObserver(sendEMPong, "EM-ping", false);
   Services.obs.notifyObservers(window, "EM-loaded", "");
 
   // If the initial view has already been selected (by a call to loadView from
@@ -636,22 +640,22 @@ var gViewController = {
       this.lastHistoryIndex = gHistory.index;
     }
     catch (e) {
       // The attempt to load the view failed, try moving further along history
       if (this.lastHistoryIndex > gHistory.index) {
         if (gHistory.canGoBack)
           gHistory.back();
         else
-          gViewController.replaceView(VIEW_DEFAULT);
+          gViewController.replaceView(gViewDefault);
       } else {
         if (gHistory.canGoForward)
           gHistory.forward();
         else
-          gViewController.replaceView(VIEW_DEFAULT);
+          gViewController.replaceView(gViewDefault);
       }
     }
   },
 
   parseViewId: function gVC_parseViewId(aViewId) {
     var matchRegex = /^addons:\/\/([^\/]+)\/(.*)$/;
     var [,viewType, viewParam] = aViewId.match(matchRegex) || [];
     return {type: viewType, param: decodeURIComponent(viewParam)};
@@ -1668,17 +1672,17 @@ var gCategories = {
     try {
       this.node.value = Services.prefs.getCharPref(PREF_UI_LASTCATEGORY);
     } catch (e) { }
 
     // If there was no last view or no existing category matched the last view
     // then the list will default to selecting the search category and we never
     // want to show that as the first view so switch to the default category
     if (!this.node.selectedItem || this.node.selectedItem == this._search)
-      this.node.value = VIEW_DEFAULT;
+      this.node.value = gViewDefault;
 
     var self = this;
     this.node.addEventListener("select", function node_onSelected() {
       self.maybeHideSearch();
       gViewController.loadView(self.node.selectedItem.value);
     }, false);
 
     this.node.addEventListener("click", function node_onClicked(aEvent) {
@@ -1736,17 +1740,17 @@ var gCategories = {
 
   _removeCategory: function gCategories_removeCategory(aId) {
     var category = document.getElementById("category-" + aId);
     if (!category)
       return;
 
     // If this category is currently selected then switch to the default view
     if (this.node.selectedItem == category)
-      gViewController.replaceView(VIEW_DEFAULT);
+      gViewController.replaceView(gViewDefault);
 
     this.node.removeChild(category);
   },
 
   onTypeAdded: function gCategories_onTypeAdded(aType) {
     // Ignore types that we don't have a view object for
     if (!(aType.viewType in gViewController.viewObjects))
       return;
@@ -1767,17 +1771,17 @@ var gCategories = {
       var self = this;
       gPendingInitializations++;
       getAddonsAndInstalls(aType.id, function onTypeAdded_getAddonsAndInstalls(aAddonsList, aInstallsList) {
         var hidden = (aAddonsList.length == 0 && aInstallsList.length == 0);
         var item = self.get(aViewId);
 
         // Don't load view that is becoming hidden
         if (hidden && aViewId == gViewController.currentViewId)
-          gViewController.loadView(VIEW_DEFAULT);
+          gViewController.loadView(gViewDefault);
 
         item.hidden = hidden;
         Services.prefs.setBoolPref(prefName, hidden);
 
         if (aAddonsList.length > 0 || aInstallsList.length > 0) {
           notifyInitialized();
           return;
         }
@@ -3006,17 +3010,17 @@ var gDetailView = {
         if (aAddonId in gCachedAddons) {
           self._updateView(gCachedAddons[aAddonId], true);
           return;
         }
 
         // This might happen due to session restore restoring us back to an
         // add-on that doesn't exist but otherwise shouldn't normally happen.
         // Either way just revert to the default view.
-        gViewController.replaceView(VIEW_DEFAULT);
+        gViewController.replaceView(gViewDefault);
       });
     });
   },
 
   hide: function gDetailView_hide() {
     AddonManager.removeManagerListener(this);
     this.clearLoading();
     if (this._addon) {
--- a/toolkit/mozapps/extensions/test/browser/browser_discovery.js
+++ b/toolkit/mozapps/extensions/test/browser/browser_discovery.js
@@ -615,8 +615,23 @@ add_test(function() {
   Services.prefs.setBoolPref(PREF_XPI_ENABLED, false);
   bug_601442_test_elements(false);
 });
 add_test(function() {
   Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, true);
   Services.prefs.setBoolPref(PREF_XPI_ENABLED, true);
   bug_601442_test_elements(true);
 });
+
+// Test for Bug 1132971 - if extensions.getAddons.showPane is false,
+// the extensions pane should show by default
+add_test(function() {
+  Services.prefs.clearUserPref(PREF_UI_LASTCATEGORY);
+  Services.prefs.setBoolPref(PREF_DISCOVER_ENABLED, false);
+
+  open_manager(null, function(aWindow) {
+    gManagerWindow = aWindow;
+    gCategoryUtilities = new CategoryUtilities(gManagerWindow);
+    is(gCategoryUtilities.selectedCategory, "extension", "Should be showing the extension view");
+    close_manager(gManagerWindow, run_next_test);
+    Services.prefs.clearUserPref(PREF_DISCOVER_ENABLED);
+  });
+});
--- a/toolkit/mozapps/extensions/test/browser/head.js
+++ b/toolkit/mozapps/extensions/test/browser/head.js
@@ -28,16 +28,17 @@ const TESTROOT = "http://example.com/" +
 const TESTROOT2 = "http://example.org/" + RELATIVE_DIR;
 const CHROMEROOT = pathParts.join("/") + "/";
 const PREF_DISCOVERURL = "extensions.webservice.discoverURL";
 const PREF_DISCOVER_ENABLED = "extensions.getAddons.showPane";
 const PREF_XPI_ENABLED = "xpinstall.enabled";
 const PREF_UPDATEURL = "extensions.update.url";
 const PREF_GETADDONS_CACHE_ENABLED = "extensions.getAddons.cache.enabled";
 const PREF_CUSTOM_XPINSTALL_CONFIRMATION_UI = "xpinstall.customConfirmationUI";
+const PREF_UI_LASTCATEGORY = "extensions.ui.lastCategory";
 
 const MANAGER_URI = "about:addons";
 const INSTALL_URI = "chrome://mozapps/content/xpinstall/xpinstallConfirm.xul";
 const PREF_LOGGING_ENABLED = "extensions.logging.enabled";
 const PREF_SEARCH_MAXRESULTS = "extensions.getAddons.maxResults";
 const PREF_STRICT_COMPAT = "extensions.strictCompatibility";
 
 var PREF_CHECK_COMPATIBILITY;