Bug 1490639 - backed out changeset 8f55290ad6a2 for not having the desired effect. Mode switch is sync, no waiting required. a=backout
authorJorg K <jorgk@jorgk.com>
Tue, 02 Oct 2018 00:01:14 +0200
changeset 33280 064d247285aaf55f3dcbdd999d5c36ae7a809cbf
parent 33279 630fc01f8e33b9dc4fe8831c8038e534ade67314
child 33281 1d9d688d566980be56ad1c86b805c5675f9412fa
push id387
push userclokep@gmail.com
push dateMon, 10 Dec 2018 21:30:47 +0000
reviewersbackout
bugs1490639
Bug 1490639 - backed out changeset 8f55290ad6a2 for not having the desired effect. Mode switch is sync, no waiting required. a=backout
mail/base/content/folderPane.js
mail/test/mozmill/folder-display/test-deletion-from-virtual-folders.js
mail/test/mozmill/folder-pane/test-display-message-with-folder-modes.js
mail/test/mozmill/folder-pane/test-folder-names-in-recent-mode.js
mail/test/mozmill/folder-tree-modes/test-custom-folder-tree-mode.js
mail/test/mozmill/folder-tree-modes/test-custom-smart-folder.js
mail/test/mozmill/folder-tree-modes/test-mode-switching.js
mail/test/mozmill/folder-tree-modes/test-smart-folders.js
mail/test/mozmill/folder-tree-modes/test-unread-folders.js
mail/test/mozmill/shared-modules/test-folder-display-helpers.js
--- a/mail/base/content/folderPane.js
+++ b/mail/base/content/folderPane.js
@@ -1465,19 +1465,16 @@ var gFolderTreeView = {
     // restore selection.
     for (let folder of selectedFolders) {
       if (folder) {
         let index = this.getIndexOfFolder(folder);
         if (index != null)
           this.selection.toggleSelect(index);
       }
     }
-
-    this._treeElement.dispatchEvent(new Event("folder-tree-rebuilt",
-      { bubbles: true, cancelable: false }));
   },
 
   _sortedAccounts: function ftv_getSortedAccounts() {
     let accounts = allAccountsSorted(true);
 
     // Don't show deferred pop accounts.
     accounts = accounts.filter(function isNotDeferred(a) {
       let server = a.incomingServer;
--- a/mail/test/mozmill/folder-display/test-deletion-from-virtual-folders.js
+++ b/mail/test/mozmill/folder-display/test-deletion-from-virtual-folders.js
@@ -217,17 +217,17 @@ function test_delete_last_message_from_v
     throw new Error("We should be on the folder tab!");
 }
 
 /**
  * Open the first message in the smart inbox.
  */
 function test_open_first_message_in_smart_inbox() {
   // Switch to smart folders
-  set_folder_mode(mc.folderTreeView, "smart");
+  mc.folderTreeView.mode = "smart";
   // Select the smart inbox
   folder = get_smart_folder_named("Inbox");
   be_in_folder(folder);
   assert_messages_in_view(setNormal);
   // Open the first message
   _open_first_message();
 }
 
@@ -306,10 +306,10 @@ function test_delete_last_message_from_s
   if (mc.tabmail.currentTabInfo != tabFolder)
     throw new Error("We should be on the folder tab!");
 }
 
 /**
  * Switch back to the all folders mode for further tests.
  */
 function test_switch_back_to_all_folders_mode() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
 }
--- a/mail/test/mozmill/folder-pane/test-display-message-with-folder-modes.js
+++ b/mail/test/mozmill/folder-pane/test-display-message-with-folder-modes.js
@@ -61,17 +61,17 @@ function setupModule(module) {
  * the folder isn't present in the current folder mode.
  */
 function test_display_message_with_folder_not_present_in_current_folder_mode() {
   // Make sure the folder doesn't appear in the favorite folder mode just
   // because it was selected last before switching
   be_in_folder(inboxFolder);
 
   // Move to favorite folders. This folder isn't currently a favorite folder
-  set_folder_mode(mc.folderTreeView, "favorite");
+  mc.folderTreeView.mode = "favorite";
   assert_folder_not_visible(folder);
   assert_folder_not_visible(inboxFolder);
   assert_folder_not_visible(inbox2Folder);
 
   // Try displaying a message
   display_message_in_folder_tab(msgHdr);
 
   assert_folder_mode(mc.window.kDefaultMode);
@@ -91,17 +91,17 @@ function test_display_message_with_folde
   dummyFolder.flags |= Ci.nsMsgFolderFlags.Favorite;
 
   // Make sure the folder doesn't appear in the favorite folder mode just
   // because it was selected last before switching
   be_in_folder(inboxFolder);
 
   // Switch to favorite folders. Check that the folder is now in the view, as is
   // the dummy folder
-  set_folder_mode(mc.folderTreeView, "favorite");
+  mc.folderTreeView.mode = "favorite";
   assert_folder_visible(folder);
   assert_folder_visible(dummyFolder);
   // Also their parent folder should be visible.
   assert_folder_visible(inboxFolder);
   // But not a sibling of their parent, which is not Favorite.
   assert_folder_not_visible(inbox2Folder);
 
   // Try displaying a message
@@ -119,24 +119,24 @@ function test_display_message_with_folde
 /**
  * Test that displaying a message in smart folders mode causes the parent in the
  * view to expand.
  */
 function test_display_message_in_smart_folder_mode_works() {
   // Clear the message selection, otherwise msgHdr will still be displayed and
   // display_message_in_folder_tab(msgHdr) will be a no-op.
   select_none();
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
 
   // Switch to the dummy folder, otherwise msgHdr will be in the view and the
   // display message in folder tab logic will simply select the message without
   // bothering to expand any folders.
   be_in_folder(dummyFolder);
 
-  set_folder_mode(mc.folderTreeView, "smart");
+  mc.folderTreeView.mode = "smart";
 
   let rootFolder = folder.server.rootFolder;
   // Check that the folder is actually the child of the account root
   assert_folder_child_in_view(folder, rootFolder);
 
   // Collapse everything
   smartInboxFolder = get_smart_folder_named("Inbox");
   collapse_folder(smartInboxFolder);
@@ -186,17 +186,17 @@ function test_display_inbox_message_in_s
   assert_folder_selected_and_displayed(smartInboxFolder);
   assert_selected_and_displayed(inboxMsgHdr);
 }
 
 /**
  * Move back to the all folders mode.
  */
 function test_switch_to_all_folders() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
   assert_folder_tree_view_row_count(10);
 }
 
 function teardownModule() {
   // Remove our folders
   inboxFolder.propagateDelete(folder, true, null);
   inboxFolder.propagateDelete(dummyFolder, true, null);
   inboxFolder.server.rootFolder.propagateDelete(inbox2Folder, true, null);
--- a/mail/test/mozmill/folder-pane/test-folder-names-in-recent-mode.js
+++ b/mail/test/mozmill/folder-pane/test-folder-names-in-recent-mode.js
@@ -52,28 +52,28 @@ function test_folder_names_in_recent_vie
   assert_folder_tree_view_row_count(10);
 
   // Create some messages in the folders to make them modified.
   make_new_sets_in_folder(fUnique, [{count: 1}]);
   make_new_sets_in_folder(fDup1, [{count: 1}]);
   make_new_sets_in_folder(fDup2, [{count: 2}]);
   make_new_sets_in_folder(fDup3, [{count: 3}]);
 
-  set_folder_mode(mc.folderTreeView, "recent_compact");
+  mc.window.gFolderTreeView.mode = "recent_compact";
 
   // Check displayed folder names. In Recent mode the folders are sorted alphabetically
   assert_folder_at_index_as(0, "duplicatedName - Local Folders (1)");
   assert_folder_at_index_as(1, "duplicatedName - tinderbox@foo.invalid (3)");
   assert_folder_at_index_as(2, "duplicatedName - tinderbox@foo.invalid (2)");
   assert_folder_at_index_as(3, "uniqueName - Local Folders (1)");
   assert_folder_tree_view_row_count(4);
 
   // Remove our folders to clean up.
   rootFolder1.propagateDelete(fUnique, true, null);
   rootFolder1.propagateDelete(fDup1, true, null);
   rootFolder2.propagateDelete(fDup2, true, null);
   rootFolder2.propagateDelete(fDup3, true, null);
 }
 
 function teardownModule() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.window.gFolderTreeView.mode = "all";
   assert_folder_tree_view_row_count(7);
 }
--- a/mail/test/mozmill/folder-tree-modes/test-custom-folder-tree-mode.js
+++ b/mail/test/mozmill/folder-tree-modes/test-custom-folder-tree-mode.js
@@ -28,17 +28,17 @@ function setupModule(module) {
 
 // Provided by the extension in test-extension
 var kTestModeID = "testmode";
 
 /**
  * Switch to the mode and verify that it displays correctly.
  */
 function test_switch_to_test_mode() {
-  set_folder_mode(mc.folderTreeView, kTestModeID);
+  mc.folderTreeView.mode = kTestModeID;
   assert_folder_mode(kTestModeID);
   assert_folder_visible(gInbox);
 }
 
 /**
  * Open a new 3-pane window while the custom mode is selected, and make sure
  * that the mode displayed in the new window is the custom mode.
  */
@@ -56,10 +56,10 @@ function test_open_new_window_with_custo
 
   close_window(mc2);
 }
 
 /**
  * Switch back to all folders.
  */
 function test_switch_to_all_folders() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
 }
--- a/mail/test/mozmill/folder-tree-modes/test-custom-smart-folder.js
+++ b/mail/test/mozmill/folder-tree-modes/test-custom-smart-folder.js
@@ -59,17 +59,17 @@ function setupModule(module) {
   make_new_sets_in_folder(subfolderA, [{count: 1}]);
   make_new_sets_in_folder(subfolderB, [{count: 1}]);
 }
 
 /**
  * Switch to the smart folder mode, get the smart inbox.
  */
 function test_switch_to_smart_folder_mode() {
-  set_folder_mode(mc.folderTreeView, "smart");
+  mc.folderTreeView.mode = "smart";
   assert_folder_mode("smart");
 
   smartFolderA = get_smart_folder_named(smartParentNameA);
   mc.folderTreeView.selectFolder(smartFolderA);
 }
 
 
 function test_cache_property() {
@@ -159,16 +159,16 @@ function test_smart_subfolder() {
   assert_folder_visible(subfolderA);
 }
 
 /**
  * Switch back to all folders.
  */
 function test_return_to_all_folders() {
   assert_folder_mode("smart");
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
   assert_folder_mode("all");
 }
 
 function teardownModule() {
   inboxFolder.propagateDelete(subfolderA, true, null);
   inboxFolder.propagateDelete(subfolderB, true, null);
 }
--- a/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
+++ b/mail/test/mozmill/folder-tree-modes/test-mode-switching.js
@@ -11,16 +11,17 @@
 "use strict";
 
 var MODULE_NAME = "test-mode-switching";
 
 var RELATIVE_ROOT = "../shared-modules";
 var MODULE_REQUIRES = ["folder-display-helpers", "window-helpers"];
 
 var rootFolder;
+var inboxFolder;
 var unreadFolder;
 var favoriteFolder;
 var toggle_menu;
 var toggle_appmenu;
 var tree;
 var modeList_menu;
 var modeList_appmenu;
 var view_menu;
@@ -34,20 +35,21 @@ function setupModule(module) {
     collector.getModule(lib).installInto(module);
   }
 
   rootFolder = inboxFolder.server.rootFolder;
 
   // Create one folder with unread messages and one favorite folder.
   inboxFolder.createSubfolder("UnreadFolder", null);
   unreadFolder = inboxFolder.getChildNamed("UnreadFolder");
-  make_new_sets_in_folder(unreadFolder, [{count: 1}]);
 
   inboxFolder.createSubfolder("FavoriteFolder", null);
   favoriteFolder = inboxFolder.getChildNamed("FavoriteFolder");
+
+  make_new_sets_in_folder(unreadFolder, [{count: 1}]);
   favoriteFolder.flags |= Ci.nsMsgFolderFlags.Favorite;
 
   toggle_menu = mc.e("menu_compactFolderView");
   toggle_appmenu = mc.e("appmenu_compactFolderView");
 
   modeList_menu = mc.e("menu_FolderViewsPopup");
   modeList_appmenu = mc.e("appmenu_FolderViewsPopup");
 
@@ -129,131 +131,131 @@ function toggle_compact_in_menu() {
 }
 
 /**
  * Check the all folders mode.
  */
 function subtest_switch_to_all_folders(aViaMenu) {
   const mode = "all";
   if (aViaMenu)
-    set_folder_mode(tree, mode, select_mode_in_menu);
+    select_mode_in_menu(mode);
   else
-    set_folder_mode(tree, mode);
+    tree.mode = mode;
 
   assert_mode_selected(mode);
   assert_compact_state(false, true);
 
   // This mode should be rejected as it doesn't exist.
   tree.mode = mode + "_compact";
   assert_mode_selected(mode);
 }
 
 /**
  * Check the unread folder mode.
  */
 function subtest_switch_to_unread_folders(aViaMenu) {
   const mode = "unread";
   if (aViaMenu) {
-    set_folder_mode(tree, mode, select_mode_in_menu);
+    select_mode_in_menu(mode);
     // We came from "favorites_compact" so just toggling to "unread"
     // in UI produces "unread_compact".
     assert_mode_selected(mode + "_compact");
     // OK, now turn "compact" off.
-    set_folder_mode(tree, null, toggle_compact_in_menu);
+    toggle_compact_in_menu();
   } else {
-    set_folder_mode(tree, mode);
+    tree.mode = mode;
   }
 
   assert_mode_selected(mode);
   assert_compact_state(false, false);
 
   // Mode is hierarchical, parent folders are shown.
-  assert_folder_visible(rootFolder);
+  assert_folder_visible(inboxFolder.server.rootFolder);
   assert_folder_visible(inboxFolder);
   assert_folder_visible(unreadFolder);
   assert_folder_not_visible(favoriteFolder);
 
   if (aViaMenu)
-    set_folder_mode(tree, null, toggle_compact_in_menu);
+    toggle_compact_in_menu();
   else
-    set_folder_mode(tree, mode + "_compact");
+    tree.mode = mode + "_compact";
 
   assert_mode_selected(mode + "_compact");
   // In compact mode parent folders are not shown.
-  assert_folder_not_visible(rootFolder);
+  assert_folder_not_visible(inboxFolder.server.rootFolder);
   assert_folder_not_visible(inboxFolder);
   assert_folder_visible(unreadFolder);
   assert_folder_not_visible(favoriteFolder);
 }
 
 /**
  * Check the favorite folder mode.
  */
 function subtest_switch_to_favorite_folders(aViaMenu) {
   const mode = "favorite";
   if (aViaMenu) {
     select_mode_in_menu(mode);
     // We came from "unread_compact" so just toggling to "favorite"
     // in UI produces "favorite_compact".
     assert_mode_selected(mode + "_compact");
     // OK, now turn "compact" off.
-    set_folder_mode(tree, null, toggle_compact_in_menu);
+    toggle_compact_in_menu();
   } else {
-    set_folder_mode(tree, mode);
+    tree.mode = mode;
   }
 
   assert_mode_selected(mode);
   assert_compact_state(false, false);
 
   // Mode is hierarchical, parent folders are shown.
-  assert_folder_visible(rootFolder);
+  assert_folder_visible(inboxFolder.server.rootFolder);
   assert_folder_visible(inboxFolder);
   assert_folder_not_visible(unreadFolder);
   assert_folder_visible(favoriteFolder);
 
   if (aViaMenu)
-    set_folder_mode(tree, null, toggle_compact_in_menu);
+    toggle_compact_in_menu();
   else
-    set_folder_mode(tree, mode + "_compact");
+    tree.mode = mode + "_compact";
 
   assert_mode_selected(mode + "_compact");
   // In compact mode parent folders are not shown.
-  assert_folder_not_visible(rootFolder);
+  assert_folder_not_visible(inboxFolder.server.rootFolder);
   assert_folder_not_visible(inboxFolder);
   assert_folder_not_visible(unreadFolder);
   assert_folder_visible(favoriteFolder);
 }
 
 /**
  * Check the recent folder mode.
  */
 function subtest_switch_to_recent_folders(aViaMenu) {
   const mode = "recent_compact";
   if (aViaMenu)
-    set_folder_mode(tree, "recent", select_mode_in_menu);
+    select_mode_in_menu("recent");
   else
-    set_folder_mode(tree, mode);
+    tree.mode = mode;
 
   assert_mode_selected(mode);
   assert_compact_state(true, true);
 
   // This mode should be rejected as it doesn't exist.
   tree.mode = "recent";
   assert_mode_selected(mode);
 }
 
 /**
  * Check the smart folder mode.
  */
 function subtest_switch_to_smart_folders(aViaMenu) {
   const mode = "smart";
   if (aViaMenu)
-    set_folder_mode(tree, mode, select_mode_in_menu);
+    select_mode_in_menu(mode);
   else
-    set_folder_mode(tree, mode);
+    tree.mode = mode;
 
   assert_mode_selected(mode);
   assert_compact_state(false, true);
 
   // This mode should be rejected as it doesn't exist.
   tree.mode = mode + "_compact";
   assert_mode_selected(mode);
 }
@@ -273,13 +275,13 @@ function test_toggling_modes() {
   subtest_switch_to_favorite_folders(true);
   subtest_switch_to_recent_folders(true);
 
   subtest_switch_to_smart_folders(true);
   subtest_switch_to_all_folders(true);
 }
 
 function teardownModule() {
-  set_folder_mode(tree, "all");
+  tree.mode = "all";
   inboxFolder.propagateDelete(unreadFolder, true, null);
   inboxFolder.propagateDelete(favoriteFolder, true, null);
   toggle_main_menu(menu_state);
 }
--- a/mail/test/mozmill/folder-tree-modes/test-smart-folders.js
+++ b/mail/test/mozmill/folder-tree-modes/test-smart-folders.js
@@ -59,17 +59,17 @@ function assert_folder_for_msg_hdr(aMsgH
                     "in this view, but is actually contained in " +
                     actualFolder.URI);
 }
 
 /**
  * Switch to the smart folder mode.
  */
 function test_switch_to_smart_folders() {
-  set_folder_mode(mc.folderTreeView, "smart");
+  mc.folderTreeView.mode = "smart";
 
   // The smart inbox may not have been created at setupModule time, so get it
   // now
   smartInboxFolder = get_smart_folder_named("Inbox");
 }
 
 /**
  * Test the getParentOfFolder function.
@@ -231,16 +231,16 @@ function assert_uri_not_found(folderURI,
     throw new Error("scope " + scopeList + "contains " + folderURI +
                     " but shouldn't");
 }
 
 /**
  * Move back to the all folders mode.
  */
 function test_switch_to_all_folders() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
 }
 
 function teardownModule() {
   inboxFolder.propagateDelete(inboxSubfolder, true, null);
   delete_message_set(inboxSet);
   trashFolder.propagateDelete(trashSubfolder, true, null);
 }
--- a/mail/test/mozmill/folder-tree-modes/test-unread-folders.js
+++ b/mail/test/mozmill/folder-tree-modes/test-unread-folders.js
@@ -43,25 +43,25 @@ function setupModule(module) {
   [ inboxSet ] = make_new_sets_in_folder(inboxFolder, [{count: 1}]);
   make_new_sets_in_folder(inboxSubfolder, [{count: 1}]);
 }
 
 /**
  * Switch to the all folders mode.
  */
 function test_switch_to_all_folders() {
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
   be_in_folder(inboxFolder);
 }
 
 /**
  * Switch to the unread folder mode.
  */
 function test_switch_to_unread_folders() {
-  set_folder_mode(mc.folderTreeView, "unread");
+  mc.folderTreeView.mode = "unread";
 }
 
 /**
  * Test that inbox and inboxSubfolder are in view
  */
 function test_folder_population() {
   assert_folder_visible(inboxFolder);
   assert_folder_visible(inboxSubfolder);
--- a/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
@@ -359,17 +359,17 @@ function teardownImporter(customTeardown
     // At this point we should have exactly one window open.
     // - Close all tabs other than the first one.
     mc.tabmail.closeOtherTabs(mc.tabmail.tabInfo[0]);
 
     // - Set the mode to All Folders.
     if (mc.folderTreeView.mode != "all") {
       mark_action("fdh", "teardown",
                   ["resetting folderTreeView mode", mc.folderTreeView.mode]);
-      set_folder_mode(mc.folderTreeView, "all");
+      mc.folderTreeView.mode = "all";
     }
 
     // - Make sure the message pane is visible.
     if (mc.window.IsMessagePaneCollapsed()) {
       mark_action("fdh", "teardown", ["toggling message pane on again"]);
       mc.window.MsgToggleMessagePane();
     }
   };
@@ -389,27 +389,27 @@ function teardownImporter(customTeardown
 
 /**
  * Create a folder and rebuild the folder tree view.
  * @param aFolderName  A folder name with no support for hierarchy at this time.
  * @param aSpecialFlags An optional list of nsMsgFolderFlags bits to set.
  */
 function create_folder(aFolderName, aSpecialFlags) {
   let folder = testHelperModule.make_empty_folder(aFolderName, aSpecialFlags);
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
   return folder;
 }
 
 /**
  * Create a virtual folder by deferring to |make_virtual_folder| and making
  *  sure to rebuild the folder tree afterwards.
  */
 function create_virtual_folder(...aArgs) {
   let folder = testHelperModule.make_virtual_folder(...aArgs);
-  set_folder_mode(mc.folderTreeView, "all");
+  mc.folderTreeView.mode = "all";
   return folder;
 }
 
 /**
  * Get special folder having a folder flag under Local Folders.
  * This function clears the contents of the folder by default.
  *
  * @param aFolderFlag  Folder flag of the required folder.
@@ -2883,34 +2883,16 @@ function restore_default_window_size() {
 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;
 }
 
-/**
- * Switches the folder mode in the folder tree view.
- *
- * @param aTree      The folder tree view object
- * @param aMode      Mode name to switch to
- * @param aFunction  (optional) Function to use for the mode switching instead of aTree.mode
- */
-function set_folder_mode(aTree, aMode, aFunction) {
-  let foldersRebuilt = false;
-  aTree._treeElement.addEventListener("folder-tree-rebuilt", () => foldersRebuilt = true,
-                                      { once: true });
-  if (aFunction)
-    aFunction(aMode);
-  else
-    aTree.mode = aMode;
-  mc.waitFor(() => foldersRebuilt);
-}
-
 /** 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;