Bug 1519712 - fix some Javascript errors in xpcshell tests. r=jorgk,jcranmer
authoraceman <acelists@atlas.sk>
Tue, 15 Jan 2019 10:38:00 +0100
changeset 34208 ee93a8e6c6322b2f5c54af5ffe96d18726183fd6
parent 34207 a77580b976188dbee9ba779c70fd44ef49389505
child 34209 279f3823f22354595e65d3327b39627ac838320d
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersjorgk, jcranmer
bugs1519712
Bug 1519712 - fix some Javascript errors in xpcshell tests. r=jorgk,jcranmer
mail/components/accountcreation/content/sanitizeDatatypes.js
mailnews/base/test/unit/test_autoconfigXML.js
mailnews/base/test/unit/test_bug428427.js
mailnews/base/test/unit/test_quarantineFilterMove.js
mailnews/base/test/unit/test_search.js
mailnews/base/test/unit/test_searchLocalizationStrings.js
mailnews/extensions/bayesian-spam-filter/test/unit/test_traits.js
mailnews/local/test/unit/test_pop3ServerBrokenCRAMFail.js
mailnews/mime/jsmime/jsmime.js
mailnews/mime/jsmime/test/test_header.js
mailnews/mime/test/unit/test_mimeStreaming.js
--- a/mail/components/accountcreation/content/sanitizeDatatypes.js
+++ b/mail/components/accountcreation/content/sanitizeDatatypes.js
@@ -192,15 +192,15 @@ var sanitize =
     return defaultValue;
   },
 };
 
 function MalformedException(msgID, uncheckedBadValue) {
   var stringBundle = getStringBundle(
       "chrome://messenger/locale/accountCreationUtil.properties");
   var msg = stringBundle.GetStringFromName(msgID);
-  if (kDebug)
+  if ((typeof(kDebug) != "undefined") && kDebug)
     msg += " (bad value: " + uncheckedBadValue + ")";
   Exception.call(this, msg);
 }
 MalformedException.prototype = Object.create(Exception.prototype);
 MalformedException.prototype.constructor = MalformedException;
 
--- a/mailnews/base/test/unit/test_autoconfigXML.js
+++ b/mailnews/base/test/unit/test_autoconfigXML.js
@@ -170,17 +170,17 @@ function test_readFromXML_config1()
 
   Assert.equal(config instanceof xmlReader.AccountConfig, true);
   Assert.equal("example.com", config.id);
   Assert.equal("Example", config.displayName);
   Assert.notEqual(-1, config.domains.indexOf("example.com"));
   // 1. incoming server skipped because of an unsupported protocol
   // 2. incoming server skipped because of an so-far unknown auth method
   // 3. incoming server is fine for us: IMAP, SSL, cleartext password
-  server = config.incoming;
+  let server = config.incoming;
   Assert.equal("imapmail.example.com", server.hostname);
   Assert.equal("imap", server.type);
   Assert.equal(2, server.socketType); // SSL
   Assert.equal(3, server.auth); // cleartext password
   // only one more supported incoming server
   Assert.equal(1, config.incomingAlternatives.length);
   // 4. incoming server skipped because of an so-far unknown socketType
   // 5. server: POP
--- a/mailnews/base/test/unit/test_bug428427.js
+++ b/mailnews/base/test/unit/test_bug428427.js
@@ -188,17 +188,17 @@ function CreateVirtualFolder(newName, pa
   // set the original folder name as well.
   dbFolderInfo.setCharProperty("searchStr", searchTermString);
   dbFolderInfo.setCharProperty("searchFolderUri", searchFolderURIs);
   dbFolderInfo.setBooleanProperty("searchOnline", searchOnline);
   // This fails because the folder doesn't exist - why were we doing it?
   //  vfdb.summaryValid = true;
   vfdb.Close(true);
   // use acctMgr to setup the virtual folder listener
-  acctMgr = MailServices.accounts.QueryInterface(Ci.nsIFolderListener);
+  var acctMgr = MailServices.accounts.QueryInterface(Ci.nsIFolderListener);
   //print(acctMgr);
   acctMgr.OnItemAdded(null, newFolder);
   return newFolder;
 }
 
 function getSearchTermString(term)
 {
   var condition = "";
--- a/mailnews/base/test/unit/test_quarantineFilterMove.js
+++ b/mailnews/base/test/unit/test_quarantineFilterMove.js
@@ -46,17 +46,17 @@ var gTestArray =
     // the local inbox folder should now be empty, since the second
     // operation was a move
     Assert.equal(folderCount(localAccountUtils.inboxFolder), 0);
 
     let enumerator = gMoveFolder.msgDatabase.EnumerateMessages();
     let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     let secondMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     // Check that the messages have content
-    messageContent = getContentFromMessage(firstMsgHdr);
+    let messageContent = getContentFromMessage(firstMsgHdr);
     Assert.ok(messageContent.includes("Some User <bugmail@example.org> changed"));
     messageContent = getContentFromMessage(secondMsgHdr);
     Assert.ok(messageContent.includes("https://bugzilla.mozilla.org/show_bug.cgi?id=436880"));
   },
   async function copyMovedMessages() {
     let messages = Cc["@mozilla.org/array;1"].createInstance(Ci.nsIMutableArray);
     let enumerator = gMoveFolder.msgDatabase.EnumerateMessages();
     let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
@@ -72,17 +72,17 @@ var gTestArray =
   },
   function verifyFolders2() {
     Assert.equal(folderCount(gMoveFolder2), 2);
 
     let enumerator = gMoveFolder2.msgDatabase.EnumerateMessages();
     let firstMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     let secondMsgHdr = enumerator.getNext().QueryInterface(Ci.nsIMsgDBHdr);
     // Check that the messages have content
-    messageContent = getContentFromMessage(firstMsgHdr);
+    let messageContent = getContentFromMessage(firstMsgHdr);
     Assert.ok(messageContent.includes("Some User <bugmail@example.org> changed"));
     messageContent = getContentFromMessage(secondMsgHdr);
     Assert.ok(messageContent.includes("https://bugzilla.mozilla.org/show_bug.cgi?id=436880"));
   },
   function endTest() {
     dump("Exiting mail tests\n");
     gPOP3Pump = null;
   }
--- a/mailnews/base/test/unit/test_search.js
+++ b/mailnews/base/test/unit/test_search.js
@@ -451,18 +451,18 @@ function run_test()
 var testObject;
 function testSearch()
 {
   var test = Tests.shift();
   if (test && test.dbHeader)
   {
     //  test of a custom db header
     dump("testing dbHeader " + test.dbHeader + "\n");
-    customValue = mailTestUtils.firstMsgHdr(localAccountUtils.inboxFolder)
-                               .getProperty(test.dbHeader);
+    let customValue = mailTestUtils.firstMsgHdr(localAccountUtils.inboxFolder)
+                                   .getProperty(test.dbHeader);
     Assert.equal(customValue, test.testString);
     do_timeout(0, testSearch);
   }
   else if (test)
   {
     dump("testing for string '" + test.testString + "'\n");
     testObject = new TestSearch(localAccountUtils.inboxFolder,
                          test.testString,
--- a/mailnews/base/test/unit/test_searchLocalizationStrings.js
+++ b/mailnews/base/test/unit/test_searchLocalizationStrings.js
@@ -36,16 +36,17 @@ function run_test()
     let scope = kValidScopes[index];
     let table = gValidityManager.getTable(scope);
     let attributes = table.getAvailableAttributes({});
     let attribute;
     while ((attribute = attributes.pop()) && attribute)
     {
       let property = gValidityManager.getAttributeProperty(attribute);
       let valid = false;
+      let localizedString;
       try
       {
         localizedString = gStringBundle.GetStringFromName(property);
         valid = true;
       }
       catch (e)
       {
         dump("\n" + e);
--- a/mailnews/extensions/bayesian-spam-filter/test/unit/test_traits.js
+++ b/mailnews/extensions/bayesian-spam-filter/test/unit/test_traits.js
@@ -153,17 +153,18 @@ var listener =
             " Token " + aTokenString[i]);
       Assert.ok(aTokenString[i] in gTest.percents);
 
       Assert.equal(gTest.percents[aTokenString[i]], aTokenPercents[i]);
       Assert.equal(gTest.runnings[i], aRunningPercents[i]);
       delete gTest.percents[aTokenString[i]];
     }
     Assert.equal(Object.keys(gTest.percents).length, 0);
-    gTest.currentIndex++;
+    if (gTest.command == kClass)
+      gTest.currentIndex++;
     startCommand();
   }
 };
 
 // start the next test command
 function startCommand()
 {
   if (!tests.length)       // Do we have more commands?
--- a/mailnews/local/test/unit/test_pop3ServerBrokenCRAMFail.js
+++ b/mailnews/local/test/unit/test_pop3ServerBrokenCRAMFail.js
@@ -5,16 +5,18 @@
  */
 
 var server;
 var daemon;
 var incomingServer;
 test = "Server which advertises CRAM-MD5, but fails when it's tried";
 var expectedTransaction = ["AUTH", "CAPA", "AUTH CRAM-MD5", "AUTH PLAIN", "STAT"];
 
+const kStateAuthNeeded = 1; // the same value as in pop3d.js
+
 var urlListener = {
   OnStartRunningUrl(url) {
   },
   OnStopRunningUrl(url, result) {
     try {
       Assert.equal(result, 0);
 
       var transaction = server.playTransaction();
--- a/mailnews/mime/jsmime/jsmime.js
+++ b/mailnews/mime/jsmime/jsmime.js
@@ -943,17 +943,17 @@ function parseAddressingHeader(header, d
           commentClosed = false;
         } else {
           localPart += spacedToken;
         }
       }
 
       // We need space for the next token if we aren't some kind of comment or
       // . delimiter.
-      needsSpace = token.toString()[0] != '.';
+      needsSpace = (token.toString().length > 0) && (token.toString()[0] != '.');
       // The fall-through case after this resets needsSpace to false, and we
       // don't want that!
       continue;
     }
 
     // If we just parsed a delimiter, we don't need any space for the next
     // token.
     needsSpace = false;
@@ -1091,17 +1091,17 @@ function parseParameterHeader(headerValu
       // When the string ends in *, we need to charset decoding.
       // Note that the star is only meaningful for the *0*= case.
       let lastStar = name[name.length - 1] == '*';
       let number = name.substring(star + 1, name.length - (lastStar ? 1 : 0));
       if (number == '0')
         entry.hasCharset = lastStar;
 
       // Is the continuation number illegal?
-      else if ((number[0] == '0' && number != '0') ||
+      else if (number.length == 0 || (number[0] == '0' && number != '0') ||
           !(/^[0-9]+$/.test(number))) {
         entry.valid = false;
         continue;
       }
       // Normalize to an integer
       number = parseInt(number, 10);
 
       // Is this a repeat? If so, bail.
@@ -1137,17 +1137,17 @@ function parseParameterHeader(headerValu
       // entry, stop there.
       let valid = true;
       for (var i = 0; valid && i < entry.length; i++)
         if (entry[i] === undefined)
           valid = false;
 
       // Concatenate as many parameters as are valid. If we need to decode thec
       // charset, do so now.
-      var value = entry.slice(0, i).join('');
+      let value = entry.slice(0, i).join('');
       if (entry.hasCharset) {
         try {
           value = decode2231Value(value);
         } catch (e) {
           // Bad charset, don't add anything.
           continue;
         }
       }
--- a/mailnews/mime/jsmime/test/test_header.js
+++ b/mailnews/mime/jsmime/test/test_header.js
@@ -693,15 +693,15 @@ suite('headerparser', function () {
       ["=?UTF-8?Q?=c3?= \xa8", "\ufffd \ufffd", "UTF-8"],
       ["=?UTF-8?Q?=c3?= \xa8", "\ufffd \u00a8", "ISO-8859-1"],
       ["\xc3 =?UTF-8?Q?=a8?=", "\ufffd \ufffd", "UTF-8"],
       ["\xc3 =?UTF-8?Q?=a8?=", "\u00c3 \ufffd", "ISO-8859-1"],
     ];
     header_tests.forEach(function (data) {
       arrayTest(data, function () {
         assert.deepEqual(headerparser.decodeRFC2047Words(
-          headerparser.convert8BitHeader(data[0], data[2])), data[1]);
+          headerparser.convert8BitHeader(data[0], (data.length > 2 ? data[2] : null))), data[1]);
       });
     });
   });
 });
 
 });
--- a/mailnews/mime/test/unit/test_mimeStreaming.js
+++ b/mailnews/mime/test/unit/test_mimeStreaming.js
@@ -51,17 +51,17 @@ function streamMsg(msgHdr)
     null,
     gUrlListener,
     true, // have them create the converter
     // additional uri payload, note that "header=" is prepended automatically
     "filter",
     true);
 }
 
-gStreamListener = {
+var gStreamListener = {
   QueryInterface: ChromeUtils.generateQI([Ci.nsIStreamListener]),
   _stream : null,
   // nsIRequestObserver part
   onStartRequest: function (aRequest, aContext) {
   },
   onStopRequest: function (aRequest, aContext, aStatusCode) {
     doNextTest();
   },