Testcase for bug 457168. r=bienvenu
authorMark Banner <bugzilla@standard8.plus.com>
Mon, 29 Sep 2008 15:11:46 +0100
changeset 461 f95b15892209021649676464b167fe4192c86014
parent 460 4e502622d8b1bbbc5f03842812e0914c30a58ccc
child 462 71e7cad5c95abd53f03c35ed720d7cacc27d2631
push idunknown
push userunknown
push dateunknown
reviewersbienvenu
bugs457168
Testcase for bug 457168. r=bienvenu
mailnews/local/test/unit/data/message2.eml
mailnews/local/test/unit/data/message3.eml
mailnews/local/test/unit/test_bug457168.js
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/data/message2.eml
@@ -0,0 +1,8 @@
+From: from@invalid.com
+To: to@invalid.com
+cc: dupemail@test.com
+Subject: test mail
+
+this email is in dos format because that is what the interface requires
+
+test message
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/data/message3.eml
@@ -0,0 +1,7 @@
+From: from@invalid.com
+To: to@invalid.com
+Subject: test mail 2
+
+this email is in dos format because that is what the interface requires
+
+test message 2
new file mode 100644
--- /dev/null
+++ b/mailnews/local/test/unit/test_bug457168.js
@@ -0,0 +1,169 @@
+/* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
+/**
+ * Protocol tests for POP3.
+ */
+var type = null;
+var test = null;
+var server;
+var daemon;
+var incomingServer;
+var pop3Service;
+var firstTest = true;
+var thisTest;
+
+// The fake server doesn't support AUTH and CAPA (not part of RFC 1939),
+// but mailnews correctly tries anyway.
+var tests = [
+  { title: "Get New Mail, One Message",
+    messages: [ "message2.eml", "message2.eml", "message3.eml" ],
+    transaction: [ "AUTH", "CAPA", "USER fake", "PASS server", "STAT", "LIST",
+                   "UIDL", "XTND XLST Message-Id",
+                   "RETR 1", "DELE 1", "RETR 2", "DELE 2", "RETR 3", "DELE 3" ] }
+];
+
+var urlListener =
+{
+  OnStartRunningUrl: function (url) {
+  },
+  OnStopRunningUrl: function (url, result) {
+    try {
+      var transaction = server.playTransaction();
+
+      do_check_transaction(transaction, thisTest.transaction);
+
+      do_check_eq(gLocalInboxFolder.getTotalMessages(false), 2);
+      do_check_eq(gLocalInboxFolder.getNumUnread(false), 1);
+
+      do_check_eq(result, 0);
+    }
+    catch (e) {
+      // If we have an error, clean up nicely before we throw it.
+      server.stop();
+
+      var thread = gThreadManager.currentThread;
+      while (thread.hasPendingEvents())
+        thread.processNextEvent(true);
+
+      do_throw(e);
+    }
+
+    // Let OnStopRunningUrl return cleanly before doing anything else.
+    do_timeout(0, "checkBusy();");
+  }
+};
+
+function checkBusy() {
+  if (tests.length == 0) {
+    incomingServer.closeCachedConnections();
+
+    // No more tests, let everything finish
+    server.stop();
+
+    var thread = gThreadManager.currentThread;
+    while (thread.hasPendingEvents())
+      thread.processNextEvent(true);
+
+    do_test_finished();
+    return;
+  }
+
+  // If the server hasn't quite finished, just delay a little longer.
+  if (incomingServer.serverBusy ||
+      (incomingServer instanceof Ci.nsIPop3IncomingServer &&
+       incomingServer.runningProtocol)) {
+    do_timeout(20, "checkBusy();");
+    return;
+  }
+
+  testNext();
+}
+
+function testNext() {
+  thisTest = tests.shift();
+
+  // Handle the server in a try/catch/finally loop so that we always will stop
+  // the server if something fails.
+  try {
+    if (firstTest) {
+      firstTest = false;
+
+      // Start the fake POP3 server
+      server.start(POP3_PORT);
+    }
+    else
+      server.resetTest();
+
+    // Set up the test
+    test = thisTest.title;
+
+    daemon.setMessages(thisTest.messages);
+
+    // Now get the mail
+    pop3Service.GetNewMail(null, urlListener, gLocalInboxFolder,
+                           incomingServer);
+
+    server.performTest();
+  } catch (e) {
+    server.stop();
+
+    do_throw(e);
+  } finally {
+    var thread = gThreadManager.currentThread;
+    while (thread.hasPendingEvents())
+      thread.processNextEvent(true);
+  }
+}
+
+function run_test() {
+  // Disable new mail notifications
+  var prefSvc = Components.classes["@mozilla.org/preferences-service;1"]
+    .getService(Components.interfaces.nsIPrefBranch);
+
+  prefSvc.setBoolPref("mail.biff.play_sound", false);
+  prefSvc.setBoolPref("mail.biff.show_alert", false);
+  prefSvc.setBoolPref("mail.biff.show_tray_icon", false);
+  prefSvc.setBoolPref("mail.biff.animate_dock_icon", false);
+  prefSvc.setIntPref("mail.server.default.dup_action", 2);
+
+  server = setupServerDaemon();
+  daemon = server[0];
+  server = server[1];
+
+  type = "RFC 1939";
+
+  // Set up the basic accounts and folders
+  incomingServer = createPop3ServerAndLocalFolders();
+
+  // Create a cc filter
+  var filters = incomingServer.getFilterList(null);
+
+  var filter = filters.createFilter("cc dup test");
+  filter.filterType = Ci.nsMsgFilterType.Incoming;
+  var searchTerm = filter.createTerm();
+  searchTerm.attrib = Ci.nsMsgSearchAttrib.CC;
+  searchTerm.op = Ci.nsMsgSearchOp.Contains;
+  var oldValue = searchTerm.value;
+  oldValue.attrib = Ci.nsMsgSearchAttrib.CC;
+  oldValue.str = "dupemail";
+  searchTerm.value = oldValue;
+  filter.appendTerm(searchTerm);
+  var filterAction = filter.createAction();
+  filterAction.type = Ci.nsMsgFilterAction.MarkRead;
+  filter.appendAction(filterAction);
+  filter.enabled = true;
+
+  filters.insertFilterAt(0, filter);
+
+  incomingServer.setFilterList(filters);
+
+  // Check that we haven't got any messages in the folder, if we have its a test
+  // setup issue.
+  do_check_eq(gLocalInboxFolder.getTotalMessages(false), 0);
+
+  pop3Service = Cc["@mozilla.org/messenger/popservice;1"]
+                      .getService(Ci.nsIPop3Service);
+
+  do_test_pending();
+
+  testNext();
+}