Bug 791311 - Don't auto-collapse the menubar by default unless we're creating a new profile. r=bwinton.
authorMike Conley <mconley@mozilla.com>
Thu, 20 Sep 2012 13:52:54 -0400
changeset 11095 5241f7deed342324aa59086ac13ecf03840b78ef
parent 11094 410b8317fa4eed449e65e63e871babacbbab18a1
child 11096 dbd153b0fa9c449a30d5095a755b9b224bbc337b
push id8323
push usermconley@mozilla.com
push dateThu, 20 Sep 2012 17:53:27 +0000
treeherdercomm-central@5241f7deed34 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersbwinton
bugs791311
Bug 791311 - Don't auto-collapse the menubar by default unless we're creating a new profile. r=bwinton.
mail/app/profile/all-thunderbird.js
mail/base/modules/mailMigrator.js
mail/test/mozmill/migration-to-rdf-ui-5/test-migrate-to-rdf-ui-5.js
mail/test/mozmill/mozmilltests.list
mail/test/mozmill/override-main-menu-collapse/prefs.js
mail/test/mozmill/override-main-menu-collapse/test-override-mainmenu-collapse.js
mail/test/mozmill/override-main-menu-collapse/wrapper.py
mail/test/mozmill/startup-firstrun/prefs.js
mail/test/mozmill/startup-firstrun/test-menubar-collapsed.js
mail/test/mozmill/startup-firstrun/wrapper.py
--- a/mail/app/profile/all-thunderbird.js
+++ b/mail/app/profile/all-thunderbird.js
@@ -825,8 +825,12 @@ pref("privacy.cpd.cache", true);
 // 1 - Last Hour
 // 2 - Last 2 Hours
 // 3 - Last 4 Hours
 // 4 - Today
 pref("privacy.sanitize.timeSpan", 1);
 
 // PgpMime Proxy
 pref("mail.pgpmime.addon_url", "https://addons.mozilla.org/thunderbird/addon/enigmail/");
+
+// If set to true, Thunderbird will collapse the main menu for new profiles
+// (or, more precisely, profiles that start with no accounts created).
+pref("mail.main_menu.collapse_by_default", true);
--- a/mail/base/modules/mailMigrator.js
+++ b/mail/base/modules/mailMigrator.js
@@ -12,16 +12,17 @@
 var EXPORTED_SYMBOLS = ["MailMigrator"];
 
 const Cc = Components.classes;
 const Ci = Components.interfaces;
 const Cu = Components.utils;
 
 Cu.import("resource://gre/modules/XPCOMUtils.jsm");
 Cu.import("resource://gre/modules/Services.jsm");
+Cu.import("resource:///modules/mailServices.js");
 
 var MailMigrator = {
   /**
    * Switch the given fonts to the given encodings, but only if the current fonts
    * are defaults.
    */
   _switchDefaultFonts: function MailMigrator__switchDefaultFonts(aFonts,
                                                                  aEncodings) {
@@ -223,17 +224,21 @@ var MailMigrator = {
               currentSet = currentSet + ",button-chat";
             }
             this._setPersist(barResource, currentSetResource, currentSet);
           }
         }
       }
 
       // In UI version 5, we add the AppMenu button to the mail toolbar and
-      // collapse the main menu by default.
+      // 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);
 
@@ -242,23 +247,25 @@ var MailMigrator = {
 
             dirty = true;
             // Put the AppMenu button at the end.
             currentSet = currentSet + ",button-appmenu";
             this._setPersist(barResource, currentSetResource, currentSet);
           }
         }
 
-        // ... and now we'll collapse the main menu.
-        let menuResource = this._rdf.GetResource(MESSENGER_DOCURL +
-                                                 "mail-toolbar-menubar2");
-        if (menuResource !== null) {
-          let autohideResource = this._rdf.GetResource("autohide");
-          dirty = true;
-          this._setPersist(menuResource, autohideResource, "true");
+        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;
+            this._setPersist(menuResource, autohideResource, "true");
+          }
         }
       }
 
       // Update the migration version.
       Services.prefs.setIntPref(UI_VERSION_PREF, UI_VERSION);
 
     } catch(e) {
       Cu.reportError("Migrating from UI version " + currentUIVersion + " to "
--- 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
@@ -12,31 +12,33 @@ let RELATIVE_ROOT = "../shared-modules";
 let MODULE_REQUIRES = ["folder-display-helpers"];
 
 function setupModule(module) {
   collector.getModule("folder-display-helpers").installInto(module);
 }
 
 /**
  * Test that the App Menu button was added to the mail toolbar, and the main
- * menu is collapsed by default.
+ * 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");
 
-  // Skip the next test for OSX, since it never exposed the menubar.
+  // Skip the next test for OSX, since it never exposes the main menu.
   if (!mc.mozmillModule.isMac) {
-    // Now also make sure that the menubar is collapsed.
-    let menuBar = mc.e("mail-toolbar-menubar2");
-    assert_equals(menuBar.getAttribute("autohide"), "true",
-                  "The main menu should have autohide set to true.");
+    // 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.");
   }
 }
--- a/mail/test/mozmill/mozmilltests.list
+++ b/mail/test/mozmill/mozmilltests.list
@@ -17,14 +17,16 @@ keyboard
 message-header
 message-window
 migration-to-rdf-ui-2
 migration-to-rdf-ui-3
 migration-to-rdf-ui-5
 multiple-identities
 newmailaccount
 notification
+override-main-menu-collapse
 pref-window
 quick-filter-bar
 search-window
 session-store
+startup-firstrun
 tabmail
 utils
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/override-main-menu-collapse/prefs.js
@@ -0,0 +1,2 @@
+pref("mail.provider.enabled", false);
+pref("mail.main_menu.collapse_by_default", false);
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/override-main-menu-collapse/test-override-mainmenu-collapse.js
@@ -0,0 +1,24 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Tests that the main menu will NOT be collapsed by default if Thunderbird
+ * starts with no accounts created, and mail.main_menu.collapse_by_default set
+ * to false.
+ */
+
+let MODULE_NAME = "test-override-main-menu-collapse";
+let RELATIVE_ROOT = "../shared-modules";
+let MODULE_REQUIRES = ["folder-display-helpers"];
+
+function setupModule(module) {
+  collector.getModule("folder-display-helpers").installInto(module);
+}
+
+function test_main_menu_not_collapsed() {
+  let mainMenu = mc.e("mail-toolbar-menubar2");
+  assert_false(mainMenu.hasAttribute("autohide"),
+               "The main menu should not have the autohide attribute.");
+}
+test_main_menu_not_collapsed.EXCLUDED_PLATFORMS = ["Darwin"];
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/override-main-menu-collapse/wrapper.py
@@ -0,0 +1,32 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# For these tests, we need to disable the account provisioner, or
+# else it will spawn immediately and block before we have a chance to run
+# any Mozmill tests.
+
+import os
+import shutil
+import sys
+
+# We don't want any accounts for these tests.
+NO_ACCOUNTS = True
+
+def on_profile_created(profiledir):
+    """
+    On profile creation, this copies prefs.js from the current folder to
+    profile_dir/preferences. This is a somewhat undocumented feature -- anything
+    in profile_dir/preferences gets treated as a default pref, which is what we
+    want here.
+    """
+    prefdir = os.path.join(profiledir, "preferences")
+    # This needs to be a directory, so if it's a file, raise an exception
+    if os.path.isfile(prefdir):
+        raise Exception("%s needs to be a directory, but is a file" % prefdir)
+    if not os.path.exists(prefdir):
+        os.mkdir(prefdir)
+    # The pref file is in the same directory this script is in
+    # Fallback to Linux prefs for anything not in the dictionary.
+    preffile = os.path.join(os.path.dirname(__file__), "prefs.js")
+    shutil.copy(preffile, prefdir)
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/startup-firstrun/prefs.js
@@ -0,0 +1,1 @@
+pref("mail.provider.enabled", false);
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/startup-firstrun/test-menubar-collapsed.js
@@ -0,0 +1,23 @@
+/* This Source Code Form is subject to the terms of the Mozilla Public
+ * License, v. 2.0. If a copy of the MPL was not distributed with this
+ * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
+
+/**
+ * Tests that the main menu will be collapsed by default if Thunderbird starts
+ * with no accounts created.
+ */
+
+let MODULE_NAME = "test-main-menu-collapsed";
+let RELATIVE_ROOT = "../shared-modules";
+let MODULE_REQUIRES = ["folder-display-helpers"];
+
+function setupModule(module) {
+  collector.getModule("folder-display-helpers").installInto(module);
+}
+
+function test_main_menu_collapsed() {
+  let mainMenu = mc.e("mail-toolbar-menubar2");
+  assert_equals(mainMenu.getAttribute("autohide"), "true",
+                "The main menu should have the autohide attribute set to true.");
+}
+test_main_menu_collapsed.EXCLUDED_PLATFORMS = ["Darwin"];
new file mode 100644
--- /dev/null
+++ b/mail/test/mozmill/startup-firstrun/wrapper.py
@@ -0,0 +1,32 @@
+# This Source Code Form is subject to the terms of the Mozilla Public
+# License, v. 2.0. If a copy of the MPL was not distributed with this
+# file, You can obtain one at http://mozilla.org/MPL/2.0/.
+
+# For these tests, we need to disable the account provisioner, or
+# else it will spawn immediately and block before we have a chance to run
+# any Mozmill tests.
+
+import os
+import shutil
+import sys
+
+# We don't want any accounts for these tests.
+NO_ACCOUNTS = True
+
+def on_profile_created(profiledir):
+    """
+    On profile creation, this copies prefs.js from the current folder to
+    profile_dir/preferences. This is a somewhat undocumented feature -- anything
+    in profile_dir/preferences gets treated as a default pref, which is what we
+    want here.
+    """
+    prefdir = os.path.join(profiledir, "preferences")
+    # This needs to be a directory, so if it's a file, raise an exception
+    if os.path.isfile(prefdir):
+        raise Exception("%s needs to be a directory, but is a file" % prefdir)
+    if not os.path.exists(prefdir):
+        os.mkdir(prefdir)
+    # The pref file is in the same directory this script is in
+    # Fallback to Linux prefs for anything not in the dictionary.
+    preffile = os.path.join(os.path.dirname(__file__), "prefs.js")
+    shutil.copy(preffile, prefdir)