Bug 802575 - AppMenu should get added to Chat tab automatically. feedback=florian, r=mkmelin, a=Standard8.
authorMike Conley <mconley@mozilla.com>
Wed, 24 Oct 2012 13:48:06 -0400
changeset 13505 40b0e18f5f7e18d44bb44f313e92a364be0daf0b
parent 13504 226f79ce0697f89eb6a2afbefb2d6bb4f03bbb75
child 13506 97dd0c4aadee02c20f8b22ccfef66442d1bc5e83
push idunknown
push userunknown
push dateunknown
reviewersmkmelin, Standard8
bugs802575
Bug 802575 - AppMenu should get added to Chat tab automatically. feedback=florian, r=mkmelin, a=Standard8.
mail/base/modules/mailMigrator.js
mail/test/mozmill/migration-to-rdf-ui-5/localstore.rdf
mail/test/mozmill/migration-to-rdf-ui-5/test-migrate-to-rdf-ui-5.js
--- a/mail/base/modules/mailMigrator.js
+++ b/mail/base/modules/mailMigrator.js
@@ -230,32 +230,41 @@ var MailMigrator = {
 
       // In UI version 5, we add the AppMenu button to the mail toolbar and
       // collapse the main menu by default if the user has no accounts
       // set up (and the override pref "mail.main_menu.collapse_by_default"
       // is set to true). Checking for 0 accounts is a hack, because we can't
       // think of any better way of determining whether this profile is new
       // or not.
       if (currentUIVersion < 5) {
-
-        // First, we'll add the button to the mail toolbar...
-        let barResource = this._rdf.GetResource(MESSENGER_DOCURL + "mail-bar3");
-        if (barResource !== null) {
-          let currentSetResource = this._rdf.GetResource("currentset");
-          let currentSet = this._getPersist(barResource, currentSetResource);
+        /**
+         * Helper function that attempts to add the AppMenu button to the
+         * end of a toolbar with ID aToolbarID. Fails silently if this is
+         * not possible, as is typical within our UI migration code.
+         *
+         * @param aToolbarID the ID of the toolbar to add the AppMenu to.
+         */
+        let addButtonToEnd = function(aToolbarID, aButtonID) {
+          let barResource = this._rdf.GetResource(MESSENGER_DOCURL +
+                                                  aToolbarID);
+          if (barResource) {
+            let currentSetResource = this._rdf.GetResource("currentset");
+            let currentSet = this._getPersist(barResource, currentSetResource);
 
-          if (currentSet
-              && currentSet.indexOf("button-appmenu") == -1) {
+            if (currentSet && currentSet.indexOf(aButtonID) == -1) {
+              // Put the AppMenu button at the end.
+              dirty = true;
+              currentSet = currentSet + "," + aButtonID;
+              this._setPersist(barResource, currentSetResource, currentSet);
+            }
+          }
+        }.bind(this);
 
-            dirty = true;
-            // Put the AppMenu button at the end.
-            currentSet = currentSet + ",button-appmenu";
-            this._setPersist(barResource, currentSetResource, currentSet);
-          }
-        }
+        addButtonToEnd("mail-bar3", "button-appmenu");
+        addButtonToEnd("chat-toobar", "button-chat-appmenu");
 
         if (Services.prefs.getBoolPref("mail.main_menu.collapse_by_default")
             && MailServices.accounts.accounts.Count() == 0) {
           let menuResource = this._rdf.GetResource(MESSENGER_DOCURL +
                                                    "mail-toolbar-menubar2");
           if (menuResource !== null) {
             let autohideResource = this._rdf.GetResource("autohide");
             dirty = true;
--- a/mail/test/mozmill/migration-to-rdf-ui-5/localstore.rdf
+++ b/mail/test/mozmill/migration-to-rdf-ui-5/localstore.rdf
@@ -23,26 +23,29 @@
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#mail-toolbar-menubar2"
                    mode="full"
                    iconsize="large"
                    currentset="menubar-items,spring,throbber-box" />
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#tabbar-toolbar"
                    currentset="qfb-show-filter-bar" />
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#mail-bar3"
                    currentset="button-getmsg,button-newmsg,button-chat,button-address,separator,button-tag,spring,separator,spring,spacer,gloda-search" />
+  <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#chat-toobar"
+                   currentset="button-add-buddy,button-chat-accounts,spacer,gloda-im-search" />
 
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul">
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#messengerWindow"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#messagepaneboxwrapper"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#header-view-toolbox"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#header-view-toolbar"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#attachment-view-toolbox"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#attachment-view-toolbar"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#abp-hooks"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#folderPaneBox"/>
     <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#mail-bar3"/>
+    <NC:persist RDF:resource="chrome://messenger/content/messenger.xul#chat-toobar"/>
   </RDF:Description>
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#folderPaneBox"
                    width="500"
                    collapsed="true" />
   <RDF:Description RDF:about="chrome://messenger/content/messenger.xul#abp-hooks"
                    currentVersion="2.0.2" />
 </RDF:RDF>
--- a/mail/test/mozmill/migration-to-rdf-ui-5/test-migrate-to-rdf-ui-5.js
+++ b/mail/test/mozmill/migration-to-rdf-ui-5/test-migrate-to-rdf-ui-5.js
@@ -6,38 +6,51 @@
  * When moving from ui-rdf 4 to 5, we ensure that we've added the App Menu
  * button to the mail toolbar, and that we've collapsed the main menu.
  */
 
 let MODULE_NAME = "test-migrate-to-rdf-ui-5";
 let RELATIVE_ROOT = "../shared-modules";
 let MODULE_REQUIRES = ["folder-display-helpers"];
 
+const kAppMenuButton = "button-appmenu";
+
 function setupModule(module) {
   collector.getModule("folder-display-helpers").installInto(module);
 }
 
 /**
+ * Ensures that the button with ID aButtonID exists at the end of a
+ * toolbar with ID aToolbarID.
+ *
+ * @param aToolbarID the ID of the toolbar to check.
+ * @param aButtonID the ID of the button to look for.
+ */
+function assert_button_at_end_of_toolbar(aToolbarID, aButtonID) {
+  let currentSet = mc.e(aToolbarID).currentSet;
+  assert_not_equals(-1, currentSet.indexOf(aButtonID),
+                   "We didn't find the button with ID " + aButtonID +
+                   "where we should have for the toolbar with ID " +
+                   aToolbarID);
+
+  let lastChars = currentSet.substring(currentSet.length -
+                                       aButtonID.length);
+  assert_equals(lastChars, aButtonID,
+                "We didn't find the button with ID " + aButtonID + " at the " +
+                "end of the toolbar with ID " + aToolbarID);
+}
+
+/**
  * Test that the App Menu button was added to the mail toolbar, and the main
  * menu is not collapsed (since this Mozmill test starts with a pre-existing
  * account).
  */
 function test_appmenu_button_added() {
-  const kAppMenuButton = "button-appmenu";
-
-  // Make sure that the App Menu button is in the mail toolbar.
-  let currentSet = mc.e("mail-bar3").currentSet;
-  assert_not_equals(-1, currentSet.indexOf(kAppMenuButton),
-                   "We didn't find the App Menu button where we should have.");
-
-  // We also expect App Menu button at the end of the currentSet.
-  let lastChars = currentSet.substring(currentSet.length - kAppMenuButton.length);
-  assert_equals(lastChars, kAppMenuButton,
-                "We didn't find the App Menu button at the end of the menu bar");
-
+  assert_button_at_end_of_toolbar("mail-bar3", "button-appmenu");
+  assert_button_at_end_of_toolbar("chat-toobar", "button-chat-appmenu");
   // Skip the next test for OSX, since it never exposes the main menu.
   if (!mc.mozmillModule.isMac) {
     // Since we started with a pre-existing account, the main menu should
     // NOT be collapsed.
     let mainMenu = mc.e("mail-toolbar-menubar2");
     assert_false(mainMenu.hasAttribute("autohide"),
                  "The main menu should not have the autohide attribute set.");
   }