Bug 1519628 - do not listen for folder events when we do not want to check them in test_nsIMsgFolderListener{IMAP|Local}.js. r=jorgk
authoraceman <acelists@atlas.sk>
Sat, 12 Jan 2019 09:12:00 +0100
changeset 33320 e01295953e4c
parent 33319 1275fb1bcae3
child 33321 041318b618cf
push id2368
push userclokep@gmail.com
push dateMon, 28 Jan 2019 21:12:50 +0000
treeherdercomm-beta@56d23c07d815 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjorgk
bugs1519628
Bug 1519628 - do not listen for folder events when we do not want to check them in test_nsIMsgFolderListener{IMAP|Local}.js. r=jorgk
mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
mailnews/test/resources/msgFolderListenerSetup.js
--- a/mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
+++ b/mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
@@ -303,21 +303,21 @@ var gTestArray =
   }
 ];
   // Folder structure should just be
   // Inbox
   // Trash
 
 function run_test()
 {
+  localAccountUtils.loadLocalMailAccount();
+
   // Add a listener.
   MailServices.mfn.addListener(gMFListener, allTestedEvents);
 
-  localAccountUtils.loadLocalMailAccount();
-
   // Load up some messages so that we can copy them in later.
   gMsgFile1 = do_get_file("../../../data/bugmail10");
   gMsgFile2 = do_get_file("../../../data/bugmail11");
   gMsgFile3 = do_get_file("../../../data/draft1");
 
   // "Trash" folder
   gRootFolder = localAccountUtils.incomingServer.rootMsgFolder;
   gLocalTrashFolder = gRootFolder.getChildNamed("Trash");
--- a/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
+++ b/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
@@ -186,18 +186,16 @@ var gTestArray =
   function testCopyMessages1() { copyMessages([gMsgHdrs[0].hdr, gMsgHdrs[1].hdr], false, gIMAPInbox, gIMAPFolder3) }
 ];
 
 function run_test()
 {
   // This is before any of the actual tests, so...
   gTest = 0;
 
-  // Add a listener.
-  MailServices.mfn.addListener(gMFListener, allTestedEvents);
   gIMAPDaemon = new imapDaemon();
   gServer = makeServer(gIMAPDaemon, "");
 
   gIMAPIncomingServer = createLocalIMAPServer(gServer.port);
 
   // Also make sure a local folders server is created, as that's what is used
   // for sent items
   localAccountUtils.loadLocalMailAccount();
@@ -221,16 +219,19 @@ function run_test()
   // Make sure no biff notifications happen
   Services.prefs.setBoolPref("mail.biff.play_sound", false);
   Services.prefs.setBoolPref("mail.biff.show_alert", false);
   Services.prefs.setBoolPref("mail.biff.show_tray_icon", false);
   Services.prefs.setBoolPref("mail.biff.animate_dock_icon", false);
   // We aren't interested in downloading messages automatically
   Services.prefs.setBoolPref("mail.server.server1.download_on_biff", false);
 
+  // Add a listener so that we can check all folder events from this point.
+  MailServices.mfn.addListener(gMFListener, allTestedEvents);
+
   // Get the server list...
   gIMAPIncomingServer.performExpand(null);
 
   // We get these notifications on initial discovery
   gRootFolder = gIMAPIncomingServer.rootFolder;
   gIMAPInbox = gRootFolder.getChildNamed("Inbox");
   gExpectedEvents = [[MailServices.mfn.folderAdded, gRootFolder, "Trash",
                      "gIMAPTrashFolder"]];
--- a/mailnews/test/resources/msgFolderListenerSetup.js
+++ b/mailnews/test/resources/msgFolderListenerSetup.js
@@ -13,17 +13,17 @@ var allTestedEvents =
   MailServices.mfn.itemEvent;
 
 var gCopyService = MailServices.copy;
 
 // Current test being executed
 var gTest = 1;
 
 // Which events are expected
-var gExpectedEvents;
+var gExpectedEvents = [];
 
 // The current status (what all has been done)
 var gCurrStatus = 0;
 var kStatus =
 {
   notificationsDone: 0x1,
   onStopCopyDone: 0x2,
   functionCallDone: 0x4,
@@ -264,17 +264,17 @@ function verify(event)
 
   switch (eventType)
   {
   case MailServices.mfn.msgAdded:
     // So for IMAP right now, we aren't able to get the actual nsIMsgDBHdr.
     // Instead, we'll match up message ids as a (poor?) substitute.
     if (expected[1].expectedMessageId)
     {
-      Assert.equal(event[1].messageId, expected[1].expectedMessageId);
+      Assert.equal(expected[1].expectedMessageId, event[1].messageId);
       break;
     }
     // If we do have a header, fall through to the case below
   case MailServices.mfn.msgsDeleted:
   case MailServices.mfn.folderDeleted:
     // Check: headers match/folder matches.
     hasExactlyElements(expected[1], event[1]);
     break;
@@ -301,17 +301,17 @@ function verify(event)
       hasExactlyElements(expected[1], event[1]);
     }
     // aJunkProcessed: was the message processed for junk?
     Assert.equal(expected[2], event[2]);
     // aTraitProcessed: was the message processed for traits?
     Assert.equal(expected[3], event[3]);
     break;
   case MailServices.mfn.msgKeyChanged:
-    Assert.equal(expected[1].messageId, event[2].expectedMessageId);
+    Assert.equal(expected[1].expectedMessageId, event[2].messageId);
     break;
   case MailServices.mfn.msgsMoveCopyCompleted:
   case MailServices.mfn.folderMoveCopyCompleted:
     // Check: Move or copy as expected.
     Assert.equal(expected[1], event[1]);
 
     // Check: headers match/folder matches.
     hasExactlyElements(expected[2], event[2]);
@@ -330,21 +330,21 @@ function verify(event)
     {
       let srcHdr = event[2].queryElementAt(iMsg, Ci.nsIMsgDBHdr);
       let destHdr = event[4].queryElementAt(iMsg, Ci.nsIMsgDBHdr);
       Assert.equal(srcHdr.messageId, destHdr.messageId);
     }
     break;
   case MailServices.mfn.folderAdded:
     // Check: parent folder matches
-    Assert.equal(event[1].parent, expected[1]);
+    Assert.equal(expected[1], event[1].parent);
 
     // Check: folder name matches
-    Assert.equal(event[1].prettyName, expected[2]);
-    Assert.equal(event[1].name, expected[2]);
+    Assert.equal(expected[2], event[1].prettyName);
+    Assert.equal(expected[2], event[1].name);
 
     // Not a check, but if we have to store this folder somewhere, do it
     if (expected[3])
       eval(expected[3] + "= event[1]");
     break;
   case MailServices.mfn.folderRenamed:
     // Check: source folder matches
     hasExactlyElements(expected[1], event[1]);