add unit test for copying a message to a local folder whose db is out of date/invalid, r=standard8, bug 670159
authorDavid Bienvenu <bienvenu@nventure.com>
Wed, 27 Jul 2011 11:48:44 -0700
changeset 8644 a4811dffa2705f1dde06fb72b07db5498ad2da8f
parent 8643 55e6502234617e9afa227177d51b1d33549acb63
child 8645 5e361c76f4e53bf1d566394272cb9a74708dc33c
push id158
push userbugzilla@standard8.plus.com
push dateTue, 27 Sep 2011 19:18:14 +0000
treeherdercomm-beta@e47b99c61e4d [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersstandard8, bug
bugs670159
add unit test for copying a message to a local folder whose db is out of date/invalid, r=standard8, bug 670159
mailnews/base/test/unit/test_copyToInvalidDB.js
mailnews/base/test/unit/xpcshell.ini
new file mode 100644
--- /dev/null
+++ b/mailnews/base/test/unit/test_copyToInvalidDB.js
@@ -0,0 +1,73 @@
+/*
+ * Simple tests for copying local messages to a folder whose db is missing
+ * or invalid
+ */
+
+load("../../../resources/logHelper.js");
+load("../../../resources/asyncTestUtils.js");
+
+load("../../../resources/messageGenerator.js");
+load("../../../resources/messageModifier.js");
+load("../../../resources/messageInjection.js");
+
+Components.utils.import("resource:///modules/mailServices.js");
+
+var gMsg1;
+var gMessages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+var gCurTestNum;
+var gMsgId1;
+
+var gTestFolder, gTestFolder2;
+
+function setup_globals(aNextFunc) {
+  var messageGenerator = new MessageGenerator();
+  gMsg1 = messageGenerator.makeMessage();
+  let msg2 = messageGenerator.makeMessage({inReplyTo: gMsg1});
+
+  let messages = [];
+  messages = messages.concat([gMsg1, msg2]);
+  let msgSet = new SyntheticMessageSet(messages);
+
+  gTestFolder = make_empty_folder();
+  gTestFolder2 = make_empty_folder();
+  yield add_sets_to_folders(gTestFolder, [msgSet]);
+  let msg3 = messageGenerator.makeMessage();
+  messages = [msg3];
+  msgSet = new SyntheticMessageSet(messages);
+  yield add_sets_to_folders(gTestFolder2, [msgSet]);
+}
+
+function run_test() {
+  configure_message_injection({mode: "local"});
+  do_test_pending();
+  async_run({func: actually_run_test});
+}
+
+function actually_run_test() {
+  yield async_run({func: setup_globals});
+  gTestFolder2.msgDatabase.summaryValid = false;
+  gTestFolder2.msgDatabase = null;
+  gTestFolder2.ForceDBClosed();
+  let dbPath = gTestFolder2.filePath;
+  dbPath.leafName = dbPath.leafName + ".msf";
+  dbPath.remove(false);
+  gTestFolder2.msgDatabase = null;
+
+  let msgHdr = firstMsgHdr(gTestFolder);
+  let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
+  gMsgId1 = msgHdr.messageId;
+  messages.appendElement(msgHdr, false);
+  MailServices.copy.CopyMessages(gTestFolder, messages, gTestFolder2, true,
+                           asyncCopyListener, null, false);
+  yield false;
+  try {
+    gTestFolder2.getDatabaseWithReparse(asyncUrlListener, null);
+  } catch (ex) {
+    do_check_true(ex.result == Cr.NS_ERROR_NOT_INITIALIZED);
+  }
+  yield false;
+  let msgRestored = gTestFolder2.msgDatabase.getMsgHdrForMessageID(gMsgId1);
+  let msg = loadMessageToString(gTestFolder2, msgRestored);
+  do_check_eq(msg, gMsg1.toMboxString());
+  do_test_finished();
+}
--- a/mailnews/base/test/unit/xpcshell.ini
+++ b/mailnews/base/test/unit/xpcshell.ini
@@ -13,16 +13,17 @@ tail = tail_base.js
 [test_bug404489.js]
 [test_bug428427.js]
 [test_bug434810.js]
 [test_bug465805.js]
 [test_bug471682.js]
 [test_bug514945.js]
 [test_copyChaining.js]
 [test_copyThenMoveManual.js]
+[test_copyToInvalidDB.js]
 [test_detachToFile.js]
 [test_emptyTrash.js]
 [test_fix_deferred_accounts.js]
 [test_folderCompact.js]
 [test_getMsgTextFromStream.js]
 [test_imapPump.js]
 [test_inheritedFolderProperties.js]
 [test_iteratorUtils.js]