Bug 635688 - Update openAddonsMgr to take a add-on pane URI as argument and correctly open the add-ons Manager pane; r=Standard8
authorJim <squibblyflabbetydoo@gmail.com>
Thu, 24 Feb 2011 13:51:40 +0000
changeset 7218 268e2837835521c334a6ddf700761d12fc33a20e
parent 7217 aa25d31c8221123cf2408e33d85a4009c5f0ebd0
child 7219 e9817d0c0d024f2a8c9c4372e8ce41c8119ff243
push idunknown
push userunknown
push dateunknown
reviewersStandard8
bugs635688
Bug 635688 - Update openAddonsMgr to take a add-on pane URI as argument and correctly open the add-ons Manager pane; r=Standard8
mail/base/content/mailCore.js
mail/base/content/msgMail3PaneWindow.js
mail/test/mozmill/content-tabs/test-addons-mgr.js
--- a/mail/base/content/mailCore.js
+++ b/mail/base/content/mailCore.js
@@ -381,19 +381,57 @@ function openOptionsDialog(aPaneID, aTab
       // This is complicated because showPane is asynchronous (it could trigger a dynamic overlay)
       // so our tab element may not be accessible right away...
     }
   }
   else 
     openDialog("chrome://messenger/content/preferences/preferences.xul","Preferences", features, aPaneID, aTabID);
 }
 
-function openAddonsMgr(aPane)
+function openAddonsMgr(aView)
 {
+  if (aView) {
+    let emWindow;
+    let browserWindow;
+
+    function receivePong(aSubject, aTopic, aData) {
+      let browserWin = aSubject.QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIWebNavigation)
+        .QueryInterface(Components.interfaces.nsIDocShellTreeItem)
+        .rootTreeItem
+        .QueryInterface(Components.interfaces.nsIInterfaceRequestor)
+        .getInterface(Components.interfaces.nsIDOMWindow);
+      if (!emWindow || browserWin == window /* favor the current window */) {
+        emWindow = aSubject;
+        browserWindow = browserWin;
+      }
+    }
+    Services.obs.addObserver(receivePong, "EM-pong", false);
+    Services.obs.notifyObservers(null, "EM-ping", "");
+    Services.obs.removeObserver(receivePong, "EM-pong");
+
+    if (emWindow) {
+      emWindow.loadView(aView);
+      let tabmail = browserWindow.document.getElementById("tabmail");
+      tabmail.switchToTab(tabmail.getBrowserForDocument(emWindow));
+      emWindow.focus();
+      return;
+    }
+  }
+
   openContentTab("about:addons", "addons.mozilla.org");
+
+  if (aView) {
+    // This must be a new load, else the ping/pong would have
+    // found the window above.
+    Services.obs.addObserver(function (aSubject, aTopic, aData) {
+        Services.obs.removeObserver(arguments.callee, aTopic);
+        aSubject.loadView(aView);
+      }, "EM-loaded", false);
+  }
 }
 
 function openActivityMgr()
 {
   Components.classes['@mozilla.org/activity-manager-ui;1'].
     getService(Components.interfaces.nsIActivityManagerUI).show(window);
 }
 
--- a/mail/base/content/msgMail3PaneWindow.js
+++ b/mail/base/content/msgMail3PaneWindow.js
@@ -1386,17 +1386,17 @@ var LightWeightThemeWebInstaller = {
       callback: function () {
         LightWeightThemeWebInstaller._manager.forgetUsedTheme(newTheme.id);
         LightWeightThemeWebInstaller._manager.currentTheme = previousTheme;
       }
     }, {
       label: text("manageButton"),
       accessKey: text("manageButton.accesskey"),
       callback: function () {
-        openAddonsMgr("themes");
+        openAddonsMgr("addons://list/theme");
       }
     }];
 
     this._removePreviousNotifications();
 
     let notificationBox = this._getNotificationBox();
     let notificationBar =
       notificationBox.appendNotification(text("message"),
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/content-tabs/test-addons-mgr.js
@@ -0,0 +1,70 @@
+/* ***** BEGIN LICENSE BLOCK *****
+ * Version: MPL 1.1/GPL 2.0/LGPL 2.1
+ *
+ * The contents of this file are subject to the Mozilla Public License Version
+ * 1.1 (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ * http://www.mozilla.org/MPL/
+ *
+ * Software distributed under the License is distributed on an "AS IS" basis,
+ * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
+ * for the specific language governing rights and limitations under the
+ * License.
+ *
+ * The Original Code is mozilla.org code.
+ *
+ * The Initial Developer of the Original Code is
+ * the Mozilla Foundation.
+ * Portions created by the Initial Developer are Copyright (C) 2009
+ * the Initial Developer. All Rights Reserved.
+ *
+ * Contributor(s):
+ *   Jim Porter <squibblyflabbetydoo@gmail.com>
+ *
+ * Alternatively, the contents of this file may be used under the terms of
+ * either the GNU General Public License Version 2 or later (the "GPL"), or
+ * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
+ * in which case the provisions of the GPL or the LGPL are applicable instead
+ * of those above. If you wish to allow use of your version of this file only
+ * under the terms of either the GPL or the LGPL, and not to allow others to
+ * use your version of this file under the terms of the MPL, indicate your
+ * decision by deleting the provisions above and replace them with the notice
+ * and other provisions required by the GPL or the LGPL. If you do not delete
+ * the provisions above, a recipient may use your version of this file under
+ * the terms of any one of the MPL, the GPL or the LGPL.
+ *
+ * ***** END LICENSE BLOCK ***** */
+
+var MODULE_NAME = 'test-addons-pane';
+
+var RELATIVE_ROOT = '../shared-modules';
+var MODULE_REQUIRES = ['folder-display-helpers', 'content-tab-helpers'];
+
+var setupModule = function (module) {
+  let fdh = collector.getModule('folder-display-helpers');
+  fdh.installInto(module);
+  let cth = collector.getModule('content-tab-helpers');
+  cth.installInto(module);
+};
+
+function test_open_addons_with_url() {
+  mc.window.openAddonsMgr('addons://list/theme');
+  mc.sleep(0);
+
+  let tab = mc.tabmail.currentTabInfo;
+  wait_for_content_tab_load(tab);
+  assert_content_tab_has_url(tab, 'about:addons');
+  assert_true(content_tab_e(tab, 'category-themes').selected,
+              "Themes category should be selected!");
+
+  mc.tabmail.switchToTab(0); // switch to 3pane
+
+  mc.window.openAddonsMgr('addons://list/plugin');
+  mc.sleep(0);
+
+  tab = mc.tabmail.currentTabInfo;
+  wait_for_content_tab_load(tab);
+  assert_content_tab_has_url(tab, 'about:addons');
+  assert_true(content_tab_e(tab, 'category-plugins').selected,
+              "Plugins category should be selected!");
+}