Bug 1493513 - clean up migration of UI features. r=jorgk,mkmelin
authoraceman <acelists@atlas.sk>
Wed, 26 Sep 2018 15:51:00 +0200
changeset 33238 60dfc2e2e18c5de53cd2ba530d817707a70c5ba6
parent 33237 8947f35b646399d97a4739ac4acd32f7388c81bb
child 33239 2bab51e3b5c282ca391161b0bd6ef50d9dcfd735
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersjorgk, mkmelin
bugs1493513
Bug 1493513 - clean up migration of UI features. r=jorgk,mkmelin
mail/app/profile/all-thunderbird.js
mail/base/modules/mailMigrator.js
mail/test/mozmill/content-tabs/test-addons-mgr.js
mail/test/mozmill/folder-tree-modes/test-mode-switching.js
mail/test/mozmill/folder-widget/test-message-filters.js
mail/test/mozmill/message-window/test-autohide-menubar.js
mail/test/mozmill/override-main-menu-collapse/wrapper.py
mail/test/mozmill/runtest.py
mail/test/mozmill/shared-modules/test-folder-display-helpers.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
@@ -254,16 +254,18 @@ pref("mail.close_message_window.on_delet
 
 // Number of lines of To/CC/BCC address headers to show before "more"
 // truncates the list.
 pref("mailnews.headers.show_n_lines_before_more", 1);
 
 // We want to keep track of what items are appropriate in
 // XULStore.json. We use versioning to scrub out the things
 // that have become obsolete.
+// The value will always be set by startup code and must not be changed
+// here. A value of 0 means a new profile.
 pref("mail.ui-rdf.version", 0);
 
 /////////////////////////////////////////////////////////////////
 // Overrides of the core mailnews.js and composer.js prefs
 /////////////////////////////////////////////////////////////////
 pref("mail.showCondensedAddresses", true); // show the friendly display name for people I know
 
 pref("mailnews.attachments.display.start_expanded", false);
--- a/mail/base/modules/mailMigrator.js
+++ b/mail/base/modules/mailMigrator.js
@@ -107,38 +107,34 @@ var MailMigrator = {
       currentUIVersion = Services.prefs.getIntPref(UI_VERSION_PREF);
     } catch(ex) {}
 
     if (currentUIVersion >= UI_VERSION)
       return;
 
     let xulStore = Services.xulStore;
 
+    let newProfile = (currentUIVersion == 0);
+    if (newProfile) {
+      // Collapse the main menu by default if the override pref
+      // "mail.main_menu.collapse_by_default" is set to true.
+      if (Services.prefs.getBoolPref("mail.main_menu.collapse_by_default")) {
+        xulStore.setValue(MESSENGER_DOCURL, "mail-toolbar-menubar2", "autohide", "true");
+      }
+
+      // Set to current version to skip all the migration below.
+      currentUIVersion = UI_VERSION;
+    }
+
     try {
       // UI versions below 5 could only exist in an old profile with localstore.rdf
       // file used for the XUL store. Since TB55 this file is no longer read.
       // Since UI version 5, the xulstore.json file is being used, so we only
       // support those version here, see bug 1371898.
 
-      // However, there's a tiny left-over. For new profiles (running the entire
-      // migration) we need to autohide the menubar.
-
-      // 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) {
-        if (Services.prefs.getBoolPref("mail.main_menu.collapse_by_default") &&
-            MailServices.accounts.accounts.length == 0) {
-          xulStore.setValue(MESSENGER_DOCURL, "mail-toolbar-menubar2", "autohide", "true");
-        }
-      }
-
       // In UI version 6, we move the otherActionsButton button to the
       // header-view-toolbar.
       if (currentUIVersion < 6) {
         let cs = xulStore.getValue(MESSENGER_DOCURL, "header-view-toolbar", "currentset");
         if (cs && !cs.includes("otherActionsButton")) {
           // Put the otherActionsButton button at the end.
           cs = cs + "," + "otherActionsButton";
           xulStore.setValue(MESSENGER_DOCURL, "header-view-toolbar", "currentset", cs);
@@ -181,18 +177,19 @@ var MailMigrator = {
               detector == "ruprob" ||
               detector == "ukprob")) {
           // If the encoding detector pref value is not reachable from the UI,
           // reset to default (varies by localization).
           Services.prefs.clearUserPref("intl.charset.detector");
         }
       }
 
+      // This one is needed also in all new profiles.
       // Add an expanded entry for All Address Books.
-      if (currentUIVersion < 10) {
+      if (currentUIVersion < 10 || newProfile) {
         const DIR_TREE_FILE = "directoryTree.json";
 
         // If the file exists, read its contents, prepend the "All ABs" URI
         // and save it, else, just write the "All ABs" URI to the file.
         let data = IOUtils.loadFileToString(DIR_TREE_FILE);
         if (!data || data == "[]") {
           data = "";
         } else if (data.length > 0) {
--- a/mail/test/mozmill/content-tabs/test-addons-mgr.js
+++ b/mail/test/mozmill/content-tabs/test-addons-mgr.js
@@ -46,18 +46,19 @@ function test_open_addons_with_url() {
 /**
  * Bug 1462923
  * Check if the "Tools->Add-on Options" menu item works and shows our add-on.
  * This relies on the MozMill extension having optionsURL defined in install.rdf,
  * however simplistic the preferences XUL document may be.
  */
 function test_addon_prefs() {
   // Open Add-on Options.
-  mc.click(mc.eid("tasksMenu"));
-  let popups = mc.click_menus_in_sequence(mc.e("taskPopup"), [ { id: "addonsManager_prefs" } ], true);
+  mc.click(mc.eid("button-appmenu"));
+  let popups = mc.click_menus_in_sequence(mc.e("appmenu-popup"), [ { id: "appmenu_addons" } ], true);
+
   let foundAddon = false;
   plan_for_modal_dialog("mozmill-prefs", function (controller) {
      // Add |mc.sleep(1000);| here to see the popup dialog.
     controller.window.close();
   });
 
   // MozMill add-on should be somewhere in the list. When found, click it.
   for (let item of popups[popups.length-1].children) {
@@ -69,10 +70,8 @@ function test_addon_prefs() {
     }
   }
   assert_true(foundAddon);
 
   // Wait for the options dialog to open and close.
   wait_for_modal_dialog();
   wait_for_window_close();
 }
-// The test operates the main menu which is not accessible from MozMill on Mac.
-test_addon_prefs.EXCLUDED_PLATFORMS = ["darwin"];
--- a/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
+++ b/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
@@ -23,16 +23,17 @@ var toggle_menu;
 var toggle_appmenu;
 var tree;
 var modeList_menu;
 var modeList_appmenu;
 var view_menu;
 var view_menupopup;
 var appmenu;
 var appmenu_popup;
+var menu_state;
 
 function setupModule(module) {
   for (let lib of MODULE_REQUIRES) {
     collector.getModule(lib).installInto(module);
   }
 
   rootFolder = inboxFolder.server.rootFolder;
 
@@ -55,16 +56,18 @@ function setupModule(module) {
   view_menu = mc.eid("menu_View");
   view_menupopup = mc.e("menu_View_Popup");
   appmenu = mc.eid("button-appmenu");
   appmenu_popup = mc.e("appmenu-popup");
 
   tree = mc.folderTreeView;
 
   select_no_folders();
+  // Main menu is needed for this whole test file.
+  menu_state = toggle_main_menu(true);
 }
 
 /**
  * Check if both "Compact view" checkboxes in menu are of the expected state.
  *
  * @param aChecked  Boolean whether checkbox should be checked or not.
  * @param aDisabled  Optional boolean whether the menuitem should be disabled..
  */
@@ -275,9 +278,10 @@ function test_toggling_modes() {
   subtest_switch_to_smart_folders(true);
   subtest_switch_to_all_folders(true);
 }
 
 function teardownModule() {
   tree.mode = "all";
   inboxFolder.propagateDelete(unreadFolder, true, null);
   inboxFolder.propagateDelete(favoriteFolder, true, null);
+  toggle_main_menu(menu_state);
 }
--- a/mail/test/mozmill/folder-widget/test-message-filters.js
+++ b/mail/test/mozmill/folder-widget/test-message-filters.js
@@ -85,28 +85,25 @@ function test_customize_toolbar_doesnt_d
 {
   be_in_folder(folderA);
 
   /**
    * Get the getAllNewMessages menu and check the number of items.
    */
   function check_getAllNewMsgMenu() {
     wait_for_window_focused(mc.window);
-    mc.click(mc.eid("menu_File"), 5, 5);
-    wait_for_popup_to_open(mc.e("menu_FilePopup"));
+    mc.click(mc.eid("button-appmenu"), 5, 5);
+    let popups = mc.click_menus_in_sequence(mc.e("appmenu-popup"),
+                                            [ { id: "appmenu_File" },
+                                              { id: "appmenu_getNewMsgFor" } ], true);
 
-    let menu = mc.eid("menu_getAllNewMsg");
-    mc.click(menu, 5, 5);
-    wait_for_popup_to_open(mc.e("menu_getAllNewMsgPopup"));
-
-    assert_equals(menu.node.itemCount, 5,
+    assert_equals(popups[popups.length - 1].children.length, 5,
                   "Incorrect number of items for GetNewMessages before customization");
 
-    close_popup(mc, mc.eid("menu_getAllNewMsgPopup"));
-    close_popup(mc, mc.eid("menu_FilePopup"));
+    mc.close_popup_sequence(popups);
   }
 
   check_getAllNewMsgMenu();
 
   plan_for_new_window("mailnews:customizeToolbar");
   // Open the customization dialog.
   mc.rightClick(mc.eid("mail-bar3"));
   mc.click(mc.eid("CustomizeMailToolbar"));
--- a/mail/test/mozmill/message-window/test-autohide-menubar.js
+++ b/mail/test/mozmill/message-window/test-autohide-menubar.js
@@ -12,31 +12,31 @@ var MODULE_NAME = "test-autohide-menubar
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "address-book-helpers",
                        "compose-helpers"];
 
 var elib = {};
 ChromeUtils.import("chrome://mozmill/content/modules/elementslib.js", elib);
 
 var menuFolder;
+var menuState;
 
 function setupModule(module) {
   let fdh = collector.getModule("folder-display-helpers");
   fdh.installInto(module);
   let abh = collector.getModule("address-book-helpers");
   abh.installInto(module);
   let ch = collector.getModule("compose-helpers");
   ch.installInto(module);
 
   menuFolder = create_folder("menuFolder");
   make_new_sets_in_folder(menuFolder, [{count: 1}]);
 
   // Make the menubar not autohide by default.
-  let menubar = mc.e("mail-toolbar-menubar2");
-  menubar.setAttribute("autohide", false);
+  menuState = toggle_main_menu(true);
 }
 
 /**
  * Set the autohide attribute of the menubar.
  *
  * @param controller the mozmill controller for the window
  * @param elem the element to click on (usually the menubar)
  * @param hide true to hide, false otherwise
@@ -105,8 +105,12 @@ test_autohidden_menubar_compose_window.E
 
 function test_autohidden_menubar_address_book() {
   let abc = open_address_book_window();
   let menubar = abc.e("addrbook-toolbar-menubar2");
 
   help_test_autohide(abc, menubar);
 }
 test_autohidden_menubar_address_book.EXCLUDED_PLATFORMS = ["darwin", "linux"];
+
+function teardownModule() {
+  toggle_main_menu(menuState);
+}
--- a/mail/test/mozmill/override-main-menu-collapse/wrapper.py
+++ b/mail/test/mozmill/override-main-menu-collapse/wrapper.py
@@ -7,16 +7,18 @@
 # any Mozmill tests.
 
 import os
 import shutil
 import sys
 
 # We don't want any accounts for these tests.
 NO_ACCOUNTS = True
+# Do not force enable main menu bar, we'll set our own value in prefs.js.
+DEFAULT_MENUBAR = True
 
 def on_profile_created(profiledir):
     """
     On profile creation, this copies prefs.js from the current folder to
     profile_dir as a user.js file. These user prefs is interpreted in addition
     to the standard prefs.js file.
     """
     # The pref file is in the same directory this script is in.
--- a/mail/test/mozmill/runtest.py
+++ b/mail/test/mozmill/runtest.py
@@ -125,16 +125,22 @@ class ThunderTestProfile(mozprofile.Thun
         # are still serviced; they just should not result in any matches.)
         'mailnews.database.global.logging.upstream': True,
         # Do not allow fonts to be upgraded
         'mail.font.windows.version': 2,
         # No, we don't want to be prompted about Telemetry
         'toolkit.telemetry.prompted': 999,
         }
 
+    menubar_preferences = {
+        # Many tests operate items in the main menu, so keep it shown
+        # until they are migrated to appmenu.
+        'mail.main_menu.collapse_by_default': False,
+    }
+
     # Dummied up local accounts to stop the account wizard
     account_preferences = {
         'mail.account.account1.server' :  "server1",
         'mail.account.account2.identities' :  "id1,id2",
         'mail.account.account2.server' :  "server2",
         'mail.account.account3.server' :  "server3",
         'mail.accountmanager.accounts' :  "account1,account2,account3",
         'mail.accountmanager.defaultaccount' :  "account2",
@@ -180,16 +186,22 @@ class ThunderTestProfile(mozprofile.Thun
         'messenger.accounts' :  "account1",
     }
 
     def __init__(self, *args, **kwargs):
         kwargs['profile'] = self.get_profile_dir()
         super(ThunderTestProfile, self).__init__(*args, **kwargs)
         self.set_preferences(self.preferences)
 
+        if (wrapper is not None and hasattr(wrapper, "DEFAULT_MENUBAR")
+            and wrapper.DEFAULT_MENUBAR):
+            pass
+        else:
+            self.set_preferences(self.menubar_preferences)
+
         if (wrapper is not None and hasattr(wrapper, "NO_ACCOUNTS")
             and wrapper.NO_ACCOUNTS):
             pass
         else:
             self.set_preferences(self.account_preferences)
 
 
     def get_profile_dir(self):
--- a/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
@@ -2870,16 +2870,29 @@ function assert_default_window_size() {
 
 /**
  * Restore window to nominal dimensions; saving the size was not working out.
  */
 function restore_default_window_size() {
   windowHelper.resize_to(mc, gDefaultWindowWidth, gDefaultWindowHeight);
 }
 
+/**
+ * Toggle visibility of the Main menu bar.
+ *
+ * @param aEnabled {boolean}  Whether the menu should be shown or not.
+ */
+function toggle_main_menu(aEnabled = true) {
+  let menubar = mc.e("mail-toolbar-menubar2");
+  let state = menubar.getAttribute("autohide") != "true";
+  menubar.setAttribute("autohide", !aEnabled);
+  mc.sleep(0);
+  return state;
+}
+
 /** exported from messageInjection */
 var make_new_sets_in_folders;
 var make_new_sets_in_folder;
 var add_sets_to_folders;
 var delete_message_set;
 var make_folder_with_sets;
 var make_virtual_folder;
 var SyntheticPartLeaf;
--- a/mail/test/mozmill/startup-firstrun/test-menubar-collapsed.js
+++ b/mail/test/mozmill/startup-firstrun/test-menubar-collapsed.js
@@ -27,17 +27,17 @@ function test_main_menu_collapsed() {
     observe: function(aSubject, aTopic, aData) {
       if (aTopic == "mail-startup-done") {
         done = true;
       }
     }
   };
   Services.obs.addObserver(observer, "mail-startup-done");
 
-  // Since no accounts were set up, and the account provisoner was disabled
+  // Since no accounts were set up, and the account provisioner was disabled
   // in prefs.js, the wizard will show up. Find it, and close it. This will
   // cause mail-startup-done to eventually be fired.
   let wizard = wait_for_existing_window("mail:autoconfig");
   close_window(wizard);
 
   // Spin the event loop until mail-startup-done is fired.
   mc.waitFor(() => done);
 
--- a/mail/test/mozmill/startup-firstrun/wrapper.py
+++ b/mail/test/mozmill/startup-firstrun/wrapper.py
@@ -7,16 +7,18 @@
 # any Mozmill tests.
 
 import os
 import shutil
 import sys
 
 # We don't want any accounts for these tests.
 NO_ACCOUNTS = True
+# Do not force enable main menu bar (keep the default).
+DEFAULT_MENUBAR = True
 
 def on_profile_created(profiledir):
     """
     On profile creation, this copies *-prefs.js from the current folder to
     profile_dir as a user.js file. These user prefs is interpreted in addition
     to the standard prefs.js file.
     """
     # The pref file is in the same directory this script is in