Bug 1522608 - remove most uses of eval() in C-C tests. r=darktrojan
authoraceman <acelists@atlas.sk>
Sun, 27 Jan 2019 16:30:00 +0100
changeset 34309 3728fc9ecdc3cc4bb09349bd0b7d713bbbbc1381
parent 34308 63b3267ac3badda658156ebce1dbeb194c3ae875
child 34310 79eb92913221762b56402ea04150ed32fedbb008
push id389
push userclokep@gmail.com
push dateMon, 18 Mar 2019 19:01:53 +0000
reviewersdarktrojan
bugs1522608
Bug 1522608 - remove most uses of eval() in C-C tests. r=darktrojan
mail/test/mozmill/message-header/test-message-header.js
mail/test/resources/mozmill/mozmill/extension/content/modules/controller.js
mail/test/resources/mozmill/mozmill/extension/content/modules/utils.js
mailnews/base/content/newFolderDialog.js
mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
mailnews/test/resources/msgFolderListenerSetup.js
--- a/mail/test/mozmill/message-header/test-message-header.js
+++ b/mail/test/mozmill/message-header/test-message-header.js
@@ -154,20 +154,20 @@ function test_add_tag_with_really_long_l
   // with the normal value rather than "taaaaaaaags"
   tagsLabel.value = oldTagsValue;
   mc.keypress(mc.eid("expandedHeadersNameColumn"), "1", {});
   mc.keypress(mc.eid("expandedHeadersNameColumn"), "1", {});
 }
 
 /**
  * @param headerName used for pretty-printing in exceptions
- * @param headerValueElement code to be eval()ed returning the DOM element
- *        with the data.
- * @param expectedName code to be eval()ed returning the expected value of
- *                     nsIAccessible.name for the DOM element in question
+ * @param headerValueElement  Function returning the DOM element
+ *                            with the data.
+ * @param expectedName  Function returning the expected value of
+ *                      nsIAccessible.name for the DOM element in question
  * @param expectedRole the expected value for nsIAccessible.role
  */
 let headersToTest = [
 {
   headerName: "Subject",
   headerValueElement: function(mc) {
                       return mc.e("expandedsubjectBox", {class: "headerValue"}); },
   expectedName: function(mc, headerValueElement) {
--- a/mail/test/resources/mozmill/mozmill/extension/content/modules/controller.js
+++ b/mail/test/resources/mozmill/mozmill/extension/content/modules/controller.js
@@ -33,17 +33,17 @@
 // use your version of this file under the terms of the MPL, indicate your
 // decision by deleting the provisions above and replace them with the notice
 // and other provisions required by the GPL or the LGPL. If you do not delete
 // the provisions above, a recipient may use your version of this file under
 // the terms of any one of the MPL, the GPL or the LGPL.
 //
 // ***** END LICENSE BLOCK *****
 
-var EXPORTED_SYMBOLS = ["MozMillController", "waitForEval", "MozMillAsyncTest",
+var EXPORTED_SYMBOLS = ["MozMillController", "MozMillAsyncTest",
                         "globalEventRegistry", "sleep", "windowMap"];
 
 var EventUtils = {}; ChromeUtils.import("chrome://mozmill/content/stdlib/EventUtils.js", EventUtils);
 
 var events = {}; ChromeUtils.import("chrome://mozmill/content/modules/events.js", events);
 var utils = {}; ChromeUtils.import("chrome://mozmill/content/modules/utils.js", utils);
 var elementslib = {}; ChromeUtils.import("chrome://mozmill/content/modules/elementslib.js", elementslib);
 var frame = {}; ChromeUtils.import("chrome://mozmill/content/modules/frame.js", frame);
@@ -89,18 +89,16 @@ var windowMap = {
   }
 }
 
 
 // Declare most used utils functions in the controller namespace
 var sleep = utils.sleep;
 var assert = utils.assert;
 var waitFor = utils.waitFor;
-var waitForEval = utils.waitForEval;
-
 
 var waitForEvents = function() {}
 
 waitForEvents.prototype = {
   /**
    *  Initialize list of events for given node
    */
   init : function waitForEvents_init(node, events) {
@@ -684,24 +682,16 @@ MozMillController.prototype.isLoaded = f
 
 MozMillController.prototype.waitFor = function(callback, message, timeout,
                                                interval, thisObject) {
   utils.waitFor(callback, message, timeout, interval, thisObject);
 
   frame.events.pass({'function':'controller.waitFor()'});
 }
 
-MozMillController.prototype.waitForEval = function(expression, timeout, interval, subject) {
-  waitFor(function() {
-    return eval(expression);
-  }, "controller.waitForEval: Timeout exceeded for '" + expression + "'", timeout, interval);
-
-  frame.events.pass({'function':'controller.waitForEval()'});
-}
-
 MozMillController.prototype.waitForElement = function(elem, timeout, interval) {
   this.waitFor(function() {
     return elem.exists();
   }, "Timeout exceeded for waitForElement " + elem.getInfo(), timeout, interval);
 
   frame.events.pass({'function':'Controller.waitForElement()'});
 }
 
--- a/mail/test/resources/mozmill/mozmill/extension/content/modules/utils.js
+++ b/mail/test/resources/mozmill/mozmill/extension/content/modules/utils.js
@@ -36,17 +36,17 @@
 // the terms of any one of the MPL, the GPL or the LGPL.
 //
 // ***** END LICENSE BLOCK *****
 
 var EXPORTED_SYMBOLS = ["openFile", "saveFile", "saveAsFile", "genBoiler",
                         "getFile", "Copy", "getChromeWindow", "getWindows", "runEditor",
                         "runFile", "getWindowByTitle", "getWindowByType", "getWindowId",
                         "tempfile", "getMethodInWindows", "getPreference", "setPreference",
-                        "sleep", "assert", "unwrapNode", "TimeoutError", "waitFor", "waitForEval"];
+                        "sleep", "assert", "unwrapNode", "TimeoutError", "waitFor"];
 
 var hwindow = Cc["@mozilla.org/appshell/appShellService;1"]
               .getService(Ci.nsIAppShellService)
               .hiddenDOMWindow;
 
 var uuidgen = Cc["@mozilla.org/uuid-generator;1"]
     .getService(Ci.nsIUUIDGenerator);
 
@@ -450,27 +450,16 @@ function waitFor(callback, message, time
     }
 
     throw new TimeoutError(messageText);
   }
 
   return true;
 }
 
-/**
- * Waits until the expression evaluates to true
- */
-function waitForEval(expression, timeout, interval, subject) {
-  waitFor(function() {
-    return eval(expression);
-  }, "waitForEval: Timeout exceeded for '" + expression + "'", timeout, interval);
-
-  return true;
-}
-
 
  //
  // //Function to start the running of jsTests
  // var jsTests = function (paramObj) {
  //     //Setup needed variables
  //     mozmill.jsTest.actions.loadActions();
  //     var wm = mozmill.jsTest.actions;
  //     var testFiles = paramObj.files;
--- a/mailnews/base/content/newFolderDialog.js
+++ b/mailnews/base/content/newFolderDialog.js
@@ -34,18 +34,17 @@ function onLoad()
   if (windowArgs.dualUseFolders) {
     dialog.folderType = FOLDERS | MESSAGES;
 
     // hide the section when folder contain both folders and messages.
     var newFolderTypeBox = document.getElementById("newFolderTypeBox");
     newFolderTypeBox.setAttribute("hidden", "true");
   } else {
     // set our folder type by calling the default selected type's oncommand
-    var selectedFolderType = document.getElementById("folderGroup").selectedItem;
-    eval(selectedFolderType.getAttribute("oncommand"));
+    document.getElementById("folderGroup").selectedItem.doCommand();
   }
 
   doEnabling();
 }
 
 function onFolderSelect(event) {
   dialog.folder = event.target._folder;
   document.getElementById("msgNewFolderPicker")
--- a/mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
+++ b/mailnews/base/test/unit/test_nsIMsgFolderListenerLocal.js
@@ -165,19 +165,23 @@ function compactFolder(folder)
  * TESTS
  */
 
 // Beware before commenting out a test -- later tests might just depend on earlier ones
 var gTestArray =
 [
   // Adding folders
   // Create another folder to move and copy messages around, and force initialization.
-  function addFolder1() { addFolder(gRootFolder, "folder2", "gLocalFolder2"); },
+  function addFolder1() {
+    addFolder(gRootFolder, "folder2", function(folder) { gLocalFolder2 = folder; });
+  },
   // Create a third folder for more testing.
-  function addFolder2() { addFolder(gRootFolder, "folder3", "gLocalFolder3"); },
+  function addFolder2() {
+    addFolder(gRootFolder, "folder3", function(folder) { gLocalFolder3 = folder; });
+  },
   // Folder structure is now
   // Inbox
   // Trash
   // folder2
   // folder3
 
   // Copying messages from files
   function testCopyFileMessage1() {
--- a/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
+++ b/mailnews/imap/test/unit/test_nsIMsgFolderListenerIMAP.js
@@ -148,18 +148,22 @@ function copyMessages(messages, isMove, 
   if (gCurrStatus == kStatus.everythingDone)
     resetStatusAndProceed();
 }
 
 var gTestArray =
 [
   // Adding folders
   // Create another folder to move and copy messages around, and force initialization.
-  function testAddFolder1() { addFolder(gRootFolder, "folder2", "gIMAPFolder2") },
-  function testAddFolder2() { addFolder(gRootFolder, "folder3", "gIMAPFolder3") },
+  function testAddFolder1() {
+    addFolder(gRootFolder, "folder2", function(folder) { gIMAPFolder2 = folder; });
+   },
+  function testAddFolder2() {
+    addFolder(gRootFolder, "folder3", function(folder) { gIMAPFolder3 = folder; });
+  },
 
   // Adding messages to folders
   function testCopyFileMessage1()
   {
     // Make sure the offline flag is not set for any of the folders
     [gIMAPInbox, gIMAPFolder2, gIMAPFolder3].forEach(function (folder)
     {
       folder.clearFlag(Ci.nsMsgFolderFlags.Offline);
@@ -229,17 +233,17 @@ function run_test()
 
   // 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"]];
+                      function(folder) { gIMAPTrashFolder = folder; } ]];
   gCurrStatus |= kStatus.onStopCopyDone | kStatus.functionCallDone;
 
   gServer.performTest("SUBSCRIBE");
 
   // "Master" do_test_pending(), paired with a do_test_finished() at the end of
   // all the operations.
   do_test_pending();
 }
--- a/mailnews/test/resources/msgFolderListenerSetup.js
+++ b/mailnews/test/resources/msgFolderListenerSetup.js
@@ -336,19 +336,20 @@ function verify(event)
   case MailServices.mfn.folderAdded:
     // Check: parent folder matches
     Assert.equal(expected[1].URI, event[1].parent.URI);
 
     // Check: folder name matches
     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
+    // Not a check, but call the passed in callback with the new folder,
+    // used e.g. to store this folder somewhere.
     if (expected[3])
-      eval(expected[3] + "= event[1]");
+      expected[3](event[1]);
     break;
   case MailServices.mfn.folderRenamed:
     // Check: source folder matches
     hasExactlyElements(expected[1], event[1]);
 
     // Check: destination folder name matches
     Assert.equal(expected[2], event[2].prettyName);
     break;