Bug 650702 - Message/Mark All Read doesn't get disabled when there are no (zero) unread messages/all messages are read; r=bwinton
authorJim Porter <squibblyflabbetydoo@gmail.com>
Mon, 02 May 2011 22:36:08 -0500
changeset 7673 05f56858101943bdc5d7c32b0356a1d4a23a8070
parent 7672 fa5918e6aff3ae03cee795c9466436a7e8ac7099
child 7674 8ecd228f3bd80d5f7ed0235187f4b61c269cc2a6
push idunknown
push userunknown
push dateunknown
reviewersbwinton
bugs650702
Bug 650702 - Message/Mark All Read doesn't get disabled when there are no (zero) unread messages/all messages are read; r=bwinton
mail/base/content/mail3PaneWindowCommands.js
mail/test/mozmill/folder-display/test-message-commands.js
--- a/mail/base/content/mail3PaneWindowCommands.js
+++ b/mail/base/content/mail3PaneWindowCommands.js
@@ -426,16 +426,18 @@ var DefaultController =
           enabled.value = gDBView.navigateStatus((command == "cmd_goBack" || command == "button_goBack") ? nsMsgNavigationType.back : nsMsgNavigationType.forward);
         return enabled.value;
       case "cmd_goStartPage":
         return document.getElementById("tabmail").selectedTab.mode.name == "folder" &&
                !IsMessagePaneCollapsed();
       case "cmd_undoCloseTab":
         return (document.getElementById("tabmail").recentlyClosedTabs.length > 0);               
       case "cmd_markAllRead":
+        return IsFolderSelected() && gDBView &&
+               gDBView.msgFolder.getNumUnread(false) > 0;
       case "cmd_markReadByDate":
         return IsFolderSelected();
       case "cmd_find":
       case "cmd_findAgain":
       case "cmd_findPrevious":
         // If we are a message tab, then we've got a message displayed, so
         // always allow searching in the message
         if (document.getElementById("tabmail").selectedTab.mode.name == "message")
--- a/mail/test/mozmill/folder-display/test-message-commands.js
+++ b/mail/test/mozmill/folder-display/test-message-commands.js
@@ -108,19 +108,25 @@ function check_read_menuitems(index, can
 }
 
 function enable_archiving(enabled) {
   Cc["@mozilla.org/preferences-service;1"]
    .getService(Ci.nsIPrefService).getBranch(null)
    .setBoolPref("mail.identity.default.archive_enabled", enabled);
 }
 
+/**
+ * Mark a message read or unread via the context menu
+ * @param index the row in the thread pane of the message to mark read/unread
+ * @param read true the message should be marked read, false otherwise
+ */
 function mark_read_via_menu(index, read) {
   let menuItem = read ? "mailContext-markRead" : "mailContext-markUnread";
   right_click_on_row(index);
+  wait_for_popup_to_open(mc.e("mailContext"));
   mc.click_menus_in_sequence(mc.e("mailContext"), [{id: "mailContext-mark"},
                                                    {id: menuItem}]);
   close_popup(mc, mc.eid("mailContext"));
 }
 
 function test_mark_one_read() {
   be_in_folder(unreadFolder);
   let curMessage = select_click_row(0);
@@ -250,16 +256,39 @@ function test_mark_menu_mixed() {
   let curMessages = select_shift_click_row(1);
 
   curMessages[0].markRead(false);
   curMessages[1].markRead(true);
 
   check_read_menuitems(0, true, true);
 }
 
+function test_mark_all_read() {
+  be_in_folder(unreadFolder);
+  let curMessage = select_click_row(0);
+  curMessage.markRead(false);
+
+  // Make sure we can mark all read with >0 messages unread.
+  right_click_on_row(0);
+  wait_for_popup_to_open(mc.e("mailContext"));
+  mc.click_menus_in_sequence(mc.e("mailContext"), [{id: "mailContext-mark"},
+                                                   {id: "mailContext-markAllRead"}]);
+  close_popup(mc, mc.eid("mailContext"));
+
+  assert_true(curMessage.isRead, "Message should have been marked read!");
+
+  // Make sure we can't mark all read, now that all messages are already read.
+  right_click_on_row(0);
+  wait_for_popup_to_open(mc.e("mailContext"));
+  mc.click_menus_in_sequence(mc.e("mailContext"), [{id: "mailContext-mark"}]);
+
+  let allReadDisabled = mc.e("mailContext-markAllRead").disabled;
+  assert_true(allReadDisabled, "Mark All Read menu item should be disabled!");
+}
+
 function test_yearly_archive() {
   yearly_archive(false);
 }
 
 function yearly_archive(keep_structure) {
   be_in_folder(archiveSrcFolder);
   make_display_unthreaded();
   mc.folderDisplay.view.sort(Ci.nsMsgViewSortType.byDate, Ci.nsMsgViewSortOrder.ascending);