fix offlineStoreLocking test failure, and turn test back on for windows, r+a=standard8, bug 697943
authorDavid Bienvenu <bienvenu@nventure.com>
Fri, 20 Jan 2012 07:27:18 -0800
changeset 10125 e9e9a97f4717f42a014ebae0469105f325ab22fc
parent 10124 1ce579a2554423acaa40725c723fb891f6feeee6
child 10126 c14dcbbdb4b21344d38aeada7b3750a597c1da99
push idunknown
push userunknown
push dateunknown
bugs697943
fix offlineStoreLocking test failure, and turn test back on for windows, r+a=standard8, bug 697943
mailnews/imap/test/unit/test_offlineStoreLocking.js
--- a/mailnews/imap/test/unit/test_offlineStoreLocking.js
+++ b/mailnews/imap/test/unit/test_offlineStoreLocking.js
@@ -52,73 +52,32 @@ var dummyMsgWindow =
                                          Ci.nsISupportsWeakReference])
 };
 
 function alert(aDialogTitle, aText) {
 //  do_check_eq(aText.indexOf("Connection to server Mail for  timed out."), 0);
   gGotAlert = true;
 }
 
-// Adds some messages directly to a mailbox (eg new mail)
-function addMessagesToServer(messages, mailbox)
-{
-  let ioService = Cc["@mozilla.org/network/io-service;1"]
-                    .getService(Ci.nsIIOService);
-  // For every message we have, we need to convert it to a file:/// URI
-  messages.forEach(function (message)
-  {
-    let URI = ioService.newFileURI(message.file).QueryInterface(Ci.nsIFileURL);
-    message.spec = URI.spec;
-  });
-
-  // Create the imapMessages and store them on the mailbox
-  messages.forEach(function (message)
-  {
-    mailbox.addMessage(new imapMessage(message.spec, mailbox.uidnext++, []));
-  });
-}
-
 function addGeneratedMessagesToServer(messages, mailbox)
 {
   let ioService = Cc["@mozilla.org/network/io-service;1"]
                     .getService(Ci.nsIIOService);
   // Create the imapMessages and store them on the mailbox
   messages.forEach(function (message)
   {
     let dataUri = ioService.newURI("data:text/plain;base64," +
                                     btoa(message.toMessageString()),
                                    null, null);
     mailbox.addMessage(new imapMessage(dataUri.spec, mailbox.uidnext++, []));
   });
 }
 
 var gStreamedHdr = null;
 
-gStreamListener = {
-  QueryInterface : XPCOMUtils.generateQI([Ci.nsIStreamListener]),
-  _stream : null,
-  _data : null,
-  onStartRequest : function (aRequest, aContext) {
-    this._data = "";
-  },
-  onStopRequest : function (aRequest, aContext, aStatusCode) {
-    // Because we're streaming the message while compaction is going on,
-    // we should not have stored it for offline use.
-    do_check_false(gStreamedHdr.flags & Ci.nsMsgMessageFlags.Offline);
-    do_timeout(0, function(){doTest(++gCurTestNum)});
-  },
-  onDataAvailable : function (aRequest, aContext, aInputStream, aOff, aCount) {
-    if (this._stream == null) {
-      this._stream = Cc["@mozilla.org/scriptableinputstream;1"].createInstance(Ci.nsIScriptableInputStream);
-      this._stream.init(aInputStream);
-    }
-    this._data += this._stream.read(aCount);
-  },
-};
-
 function checkOfflineStore(prevOfflineStoreSize) {
   dump("checking offline store\n");
   let offset = new Object;
   let size = new Object;
   let enumerator = gIMAPInbox.msgDatabase.EnumerateMessages();
   if (enumerator)
   {
     while (enumerator.hasMoreElements())
@@ -162,17 +121,19 @@ const gTestArray =
     gIMAPInbox.msgDatabase.MarkOffline(msgHdr.messageKey, false, null);
     let msgURI = msgHdr.folder.getUriForMsg(msgHdr);
     let messenger = Cc["@mozilla.org/messenger;1"].createInstance(Ci.nsIMessenger);
     let msgServ = messenger.messageServiceFromURI(msgURI);
     // UrlListener will get called when both expunge and offline store
     // compaction are finished. dummyMsgWindow is required to make the backend
     // compact the offline store.
     gIMAPInbox.compact(UrlListener, dummyMsgWindow);
-    msgServ.streamMessage(msgURI, gStreamListener, null, null, false, "", false);
+    // Stream the message w/o a stream listener in an attempt to get the url
+    // started more quickly, while the compact is still going on.
+    msgServ.streamMessage(msgURI, null, null, UrlListener2, false, "", false);
     // We can't know which will finish first (compact or streaming), so we'll
     // have a dummy test. There's a chance that the stream won't start until
     // after the compact is finished, because the stream will get queued after
     // the expunge, which will hide failures. However, that's not happening
     // here.
   },
   function dummyTest() {
   },
@@ -220,22 +181,16 @@ const gTestArray =
     do_check_false(movedMsg.flags & Ci.nsMsgMessageFlags.Offline);
     do_timeout(0, function(){doTest(++gCurTestNum)});
     } catch (ex) {dump(ex);}
   }
 ];
 
 function run_test()
 {
-  // XXX Disable on windows for now as it is failing there.
-  if ("@mozilla.org/windows-registry-key;1" in Cc) {
-    dump("Disabled on windows due to permanent failures\n");
-    return;
-  }
-
   // Add a listener.
   gIMAPDaemon = new imapDaemon();
   gServer = makeServer(gIMAPDaemon, "");
 
   gIMAPIncomingServer = createLocalIMAPServer();
 
   loadLocalMailAccount();
 
@@ -278,18 +233,22 @@ function run_test()
   // running initial folder discovery, and adding the folder bails
   // out before we set it as verified online, so we bail out, and
   // then remove the INBOX folder since it's not verified.
   gMsgImapInboxFolder.hierarchyDelimiter = '/';
   gMsgImapInboxFolder.verifiedAsOnlineFolder = true;
 
   let messageGenerator = new MessageGenerator();
   let messages = [];
+  let bodyString = "";
+  for (i = 0; i < 100; i++)
+    bodyString += "1234567890123456789012345678901234567890123456789012345678901234567890123456789012345678901234567890\r\n";
+
   for (let i = 0; i < 50; i++)
-    messages = messages.concat(messageGenerator.makeMessage());
+    messages = messages.concat(messageGenerator.makeMessage({body: {body: bodyString, contentType: "text/plain"}}));
 
   addGeneratedMessagesToServer(messages, gIMAPDaemon.getMailbox("INBOX"));
 
   // "Master" do_test_pending(), paired with a do_test_finished() at the end of
   // all the operations.
   do_test_pending();
   //start first test
   doTest(1);
@@ -366,8 +325,23 @@ var UrlListener =
     do_check_eq(aExitCode, 0);
     // Ugly hack: make sure we don't get stuck in a JS->C++->JS->C++... call stack
     // This can happen with a bunch of synchronous functions grouped together, and
     // can even cause tests to fail because they're still waiting for the listener
     // to return
     do_timeout(0, function(){doTest(++gCurTestNum)});
   }
 };
+
+var UrlListener2 = 
+{
+  OnStartRunningUrl: function(url) { },
+
+  OnStopRunningUrl: function (aUrl, aExitCode) {
+    // Check: message successfully copied.
+    do_check_eq(aExitCode, 0);
+    // Because we're streaming the message while compaction is going on,
+    // we should not have stored it for offline use.
+    dump("finished streaming " + gStreamedHdr.messageKey + "\n");
+    do_check_false(gStreamedHdr.flags & Ci.nsMsgMessageFlags.Offline);
+    do_timeout(0, function(){doTest(++gCurTestNum)});
+  }
+};