Part of bug 540110 - Fix a failure related to deleting no junk messages by expecting a timeout. r?asuth
☠☠ backed out by de590cc07beb ☠ ☠
authorSiddharth Agarwal <sid.bugzilla@gmail.com>
Sun, 04 Apr 2010 23:51:51 +0530
changeset 5413 6cb656f5dc98196aeb929f4b09ab303c7e60a9ba
parent 5412 a75909d4b0b10214ab53fc788e4a211d39604016
child 5414 de590cc07bebf0287cf9866a888f979bc84ac958
push idunknown
push userunknown
push dateunknown
reviewersasuth
bugs540110
Part of bug 540110 - Fix a failure related to deleting no junk messages by expecting a timeout. r?asuth Part of bug 540110 - Fix a failure related to deleting no junk messages by expecting a timeout. r=asuth sr=bienvenu
mail/test/mozmill/junk-commands/test-junk-commands.js
mail/test/mozmill/shared-modules/test-folder-display-helpers.js
mail/test/mozmill/shared-modules/test-junk-helpers.js
--- a/mail/test/mozmill/junk-commands/test-junk-commands.js
+++ b/mail/test/mozmill/junk-commands/test-junk-commands.js
@@ -74,33 +74,34 @@ function _assert_folder_total_messages(a
 
 /**
  * Test deleting junk messages with no messages marked as junk.
  */
 function test_delete_no_junk_messages() {
   let initialNumMessages = folder.getTotalMessages(false);
   be_in_folder(folder);
   select_none();
-  delete_mail_marked_as_junk();
+  // Don't expect deletes
+  delete_mail_marked_as_junk(false);
   // Check if we still have the same number of messages
   _assert_folder_total_messages(folder, initialNumMessages);
 }
 
 /**
  * Test deleting junk messages with some messages marked as junk.
  */
 function test_delete_junk_messages() {
   let initialNumMessages = folder.getTotalMessages(false);
   be_in_folder(folder);
   select_click_row(1);
   let selectedMessages = select_shift_click_row(NUM_MESSAGES_TO_JUNK);
   // Mark these messages as junk
   mark_selected_messages_as_junk();
   // Now delete junk mail
-  delete_mail_marked_as_junk();
+  delete_mail_marked_as_junk(true);
   // Check that we have the right number of messages left
   _assert_folder_total_messages(folder,
                                 initialNumMessages - NUM_MESSAGES_TO_JUNK);
   // Check that none of the message keys exist any more
   let db = folder.getDBFolderInfoAndDB({});
   for each (let [, msgHdr] in Iterator(selectedMessages)) {
     let key = msgHdr.messageKey;
     if (db.ContainsKey(key))
--- a/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-folder-display-helpers.js
@@ -1397,37 +1397,52 @@ var FolderListener = {
     mailSession.AddFolderListener(this,
                                   Ci.nsIFolderListener.event);
 
     this._inited = true;
   },
 
   sawEvents: false,
   watchingFor: null,
+  eventSeen: null,
   planToWaitFor: function FolderListener_planToWaitFor() {
     this.sawEvents = false;
     this.watchingFor = [];
     for (let i = 0; i < arguments.length; i++)
       this.watchingFor[i] = arguments[i];
   },
-  waitForEvents: function FolderListener_waitForEvents() {
-    if (this.sawEvents)
+  waitForEvents: function FolderListener_waitForEvents(aDontReallyExpectEvents) {
+    if (this.sawEvents) {
+      if (aDontReallyExpectEvents)
+        mark_failure(["Seen event", this.eventSeen,
+                      "when we weren't expecting it"]);
       return;
-    if (!controller.waitForEval('subject.sawEvents', NORMAL_TIMEOUT,
-                                FAST_INTERVAL, this))
+    }
+
+    // A timeout here is expected if aReallyExpectEvents is false
+    controller.waitForEval('subject.sawEvents', NORMAL_TIMEOUT,
+                           FAST_INTERVAL, this);
+    // this.sawEvents being false is equivalent to the above waitForEval timing
+    // out
+    if (!aDontReallyExpectEvents && !this.sawEvents)
       mark_failure(["Timeout waiting for events:", this.watchingFor]);
+    if (aDontReallyExpectEvents && this.sawEvents)
+      mark_failure(["Seen event", this.eventSeen,
+                    "when we weren't expecting any"]);
   },
 
   OnItemEvent: function FolderNotificationHelper_OnItemEvent(
       aFolder, aEvent) {
     if (!this.watchingFor)
       return;
-    if (this.watchingFor.indexOf(aEvent.toString()) != -1) {
+    let eventStr = aEvent.toString();
+    if (this.watchingFor.indexOf(eventStr) != -1) {
       this.watchingFor = null;
       this.sawEvents = true;
+      this.eventSeen = eventStr;
     }
   },
 };
 
 /**
  * Plan to wait for an nsIFolderListener.OnItemEvent matching one of the
  *  provided strings.  Call this before you do the thing that triggers the
  *  event, then call |wait_for_folder_events| after the event.  This ensures
@@ -1439,18 +1454,30 @@ var FolderListener = {
  * The waiting is currently un-scoped, so the event happening on any folder
  *  triggers us.  It is expected that you won't try and have multiple events
  *  in-flight or will augment us when the time comes to have to deal with that.
  */
 function plan_to_wait_for_folder_events() {
   FolderListener.ensureInited();
   FolderListener.planToWaitFor.apply(FolderListener, arguments);
 }
-function wait_for_folder_events() {
-  FolderListener.waitForEvents();
+
+/**
+ * Wait for folder events. This needs a plan_to_wait_for_folder_events call
+ * before it works, and it must be called if plan_to_wait_for_folder_events is
+ * called.
+ *
+ * @param [aDontReallyExpectEvents] Usually you'll expect a particular event to
+ *     happen (and want to fail if the event doesn't happen), but sometimes
+ *     you'll expect that a particular event does not happen (and want to fail
+ *     if the event does happen). This should be set to true for those
+ *     times. Defaults to false.
+ */
+function wait_for_folder_events(aDontReallyExpectEvents) {
+  FolderListener.waitForEvents(aDontReallyExpectEvents);
 }
 
 /**
  * Assert that the given synthetic message sets are present in the folder
  *  display.
  *
  * @param aSynSets Either a single SyntheticMessageSet or a list of them.
  * @param aController Optional controller, which we get the folderDisplay
--- a/mail/test/mozmill/shared-modules/test-junk-helpers.js
+++ b/mail/test/mozmill/shared-modules/test-junk-helpers.js
@@ -79,21 +79,24 @@ function mark_selected_messages_as_junk(
   aController.keypress(aController == mc ? mc.eThreadTree : null,
                        "j", {});
 }
 
 /**
  * Delete all mail marked as junk in the selected folder. This is done by
  * activating the menu option from the Tools menu.
  *
+ * @param aExpectDeletes Whether this call is expected to delete junk messages.
  * @param aController The controller in whose context to do this, defaults to
  *     |mc| if omitted.
  */
-function delete_mail_marked_as_junk(aController) {
+function delete_mail_marked_as_junk(aExpectDeletes, aController) {
   if (aController === undefined)
     aController = mc;
   // if something is loading, make sure it finishes loading...
   folderDisplayHelper.wait_for_message_display_completion(aController);
   folderDisplayHelper.plan_to_wait_for_folder_events(
       "DeleteOrMoveMsgCompleted", "DeleteOrMoveMsgFailed");
   aController.click(new elib.Elem(aController.menus.tasksMenu.deleteJunk));
-  folderDisplayHelper.wait_for_folder_events();
+  // Expecting messages to be deleted implies that we should receive folder
+  // events
+  folderDisplayHelper.wait_for_folder_events(!aExpectDeletes);
 }