Bug 682028 - Rename the Mochitest 'loops' feature to be 'repeat'. r=jmaher
authorMalini Das <mdas@mozilla.com>
Mon, 29 Aug 2011 16:14:33 -0400
changeset 76196 98d6d376f1402fc73b5f85c4f1a6bc953aeaed7f
parent 76195 4ce9a64d1ddfe3ef353130e4d310039c898f846e
child 76197 b9905024a884f2d58ea69b0a79209178c0692cc3
push id3
push userfelipc@gmail.com
push dateFri, 30 Sep 2011 20:09:13 +0000
reviewersjmaher
bugs682028
milestone9.0a1
Bug 682028 - Rename the Mochitest 'loops' feature to be 'repeat'. r=jmaher
testing/mochitest/browser-test.js
testing/mochitest/runtests.py
testing/mochitest/tests/SimpleTest/TestRunner.js
testing/mochitest/tests/SimpleTest/setup.js
--- a/testing/mochitest/browser-test.js
+++ b/testing/mochitest/browser-test.js
@@ -51,32 +51,32 @@ function Tester(aTests, aDumper, aCallba
   this._scriptLoader.loadSubScript("chrome://mochikit/content/tests/SimpleTest/SimpleTest.js", simpleTestScope);
   this._scriptLoader.loadSubScript("chrome://mochikit/content/chrome-harness.js", simpleTestScope);
   this.SimpleTest = simpleTestScope.SimpleTest;
 }
 Tester.prototype = {
   EventUtils: {},
   SimpleTest: {},
 
-  loops: 0,
+  repeat: 0,
   checker: null,
   currentTestIndex: -1,
   lastStartTime: null,
   get currentTest() {
     return this.tests[this.currentTestIndex];
   },
   get done() {
     return this.currentTestIndex == this.tests.length - 1;
   },
 
   start: function Tester_start() {
     //if testOnLoad was not called, then gConfig is not defined
     if(!gConfig)
       gConfig = readConfig();
-    this.loops = gConfig.loops;
+    this.repeat = gConfig.repeat;
     this.dumper.dump("*** Start BrowserChrome Test Results ***\n");
     this._cs.registerListener(this);
 
     if (this.tests.length)
       this.nextTest();
     else
       this.finish();
   },
@@ -122,18 +122,18 @@ Tester.prototype = {
       }
     }
 
     // Make sure the window is raised before each test.
     this.SimpleTest.waitForFocus(aCallback);
   },
 
   finish: function Tester_finish(aSkipSummary) {
-    if(this.loops > 0){
-      --this.loops;
+    if (this.repeat > 0) {
+      --this.repeat;
       this.currentTestIndex = -1;
       this.nextTest();
     }
     else{
       this._cs.unregisterListener(this);
   
       this.dumper.dump("\nINFO TEST-START | Shutdown\n");
       if (this.tests.length) {
--- a/testing/mochitest/runtests.py
+++ b/testing/mochitest/runtests.py
@@ -227,22 +227,22 @@ class MochitestOptions(optparse.OptionPa
     defaults["profilePath"] = tempfile.mkdtemp()
 
     self.add_option("--use-vmware-recording",
                     action = "store_true", dest = "vmwareRecording",
                     help = "enables recording while the application is running "
                            "inside a VMware Workstation 7.0 or later VM")
     defaults["vmwareRecording"] = False
 
-    self.add_option("--loops",
+    self.add_option("--repeat",
                     action = "store", type = "int",
-                    dest = "loops", metavar = "LOOPS",
-                    help = "repeats the test or set of tests the given number of times "
-                           "without restarting the browser (given number > 0)")
-    defaults["loops"] = 0
+                    dest = "repeat", metavar = "REPEAT",
+                    help = "repeats the test or set of tests the given number of times, ie: repeat=1 will run the test twice.")
+                   
+    defaults["repeat"] = 0
 
     # -h, --help are automatically handled by OptionParser
 
     self.set_defaults(**defaults)
 
     usage = """\
 Usage instructions for runtests.py.
 All arguments are optional.
@@ -436,17 +436,17 @@ class Mochitest(object):
   def getFullPath(self, path):
     " Get an absolute path relative to self.oldcwd."
     return os.path.normpath(os.path.join(self.oldcwd, os.path.expanduser(path)))
 
   def buildTestPath(self, options):
     """ Build the url path to the specific test harness and test file or directory """
     testHost = "http://mochi.test:8888"
     testURL = ("/").join([testHost, self.TEST_PATH, options.testPath])
-    if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.loops > 0:
+    if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.repeat > 0:
        testURL = ("/").join([testHost, self.PLAIN_LOOP_PATH])
     if options.chrome or options.a11y:
        testURL = ("/").join([testHost, self.CHROME_PATH])
     elif options.browserChrome:
       testURL = "about:blank"
     elif options.ipcplugins:
       testURL = ("/").join([testHost, self.TEST_PATH, "dom/plugins/test"])
     return testURL
@@ -543,17 +543,17 @@ class Mochitest(object):
 
         autorun -- kick off tests automatically
         closeWhenDone -- runs quit.js after tests
         hideResultsTable -- hides the table of individual test results
         logFile -- logs test run to an absolute path
         totalChunks -- how many chunks to split tests into
         thisChunk -- which chunk to run
         timeout -- per-test timeout in seconds
-        loops -- How many times to run the test
+        repeat -- How many times to repeat the test, ie: repeat=1 will run the test twice.
     """
   
     # allow relative paths for logFile
     if options.logFile:
       options.logFile = self.getLogFilePath(options.logFile)
     if options.browserChrome or options.chrome or options.a11y:
       self.makeTestConfig(options)
     else:
@@ -572,19 +572,19 @@ class Mochitest(object):
         self.urlOpts.append("totalChunks=%d" % options.totalChunks)
         self.urlOpts.append("thisChunk=%d" % options.thisChunk)
       if options.chunkByDir:
         self.urlOpts.append("chunkByDir=%d" % options.chunkByDir)
       if options.shuffle:
         self.urlOpts.append("shuffle=1")
       if "MOZ_HIDE_RESULTS_TABLE" in env and env["MOZ_HIDE_RESULTS_TABLE"] == "1":
         self.urlOpts.append("hideResultsTable=1")
-      if options.loops:
-        self.urlOpts.append("loops=%d" % options.loops)
-      if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.loops > 0:
+      if options.repeat:
+        self.urlOpts.append("repeat=%d" % options.repeat)
+      if os.path.isfile(os.path.join(self.oldcwd, os.path.dirname(__file__), self.TEST_PATH, options.testPath)) and options.repeat > 0:
         self.urlOpts.append("testname=%s" % ("/").join([self.TEST_PATH, options.testPath]))
 
   def cleanup(self, manifest, options):
     """ remove temporary files and profile """
     os.remove(manifest)
     shutil.rmtree(options.profilePath)
 
   def startVMwareRecording(self, options):
--- a/testing/mochitest/tests/SimpleTest/TestRunner.js
+++ b/testing/mochitest/tests/SimpleTest/TestRunner.js
@@ -124,17 +124,17 @@ TestRunner._checkForHangs = function() {
 
 TestRunner.requestLongerTimeout = function(factor) {
     TestRunner._timeoutFactor = factor;
 }
 
 /**
  * This is used to loop tests
 **/
-TestRunner.loops = 0;
+TestRunner.repeat = 0;
 TestRunner._currentLoop = 0;
 
 /**
  * This function is called after generating the summary.
 **/
 TestRunner.onComplete = null;
 
 /**
@@ -241,28 +241,28 @@ TestRunner.resetTests = function(listURL
 }
 
 /*
  * Used to run a single test in a loop and update the UI with the results
  */
 TestRunner.loopTest = function(testPath) {
   //must set the following line so that TestHarness.updateUI finds the right div to update
   document.getElementById("current-test-path").innerHTML = testPath;
-  var numLoops = TestRunner.loops;
+  var numLoops = TestRunner.repeat;
   var completed = 0; // keep track of how many tests have finished
 
   // function to kick off the test and to check when the test is complete
   function checkComplete() {
     var testWindow = window.open(testPath, 'test window'); // kick off the test or find the active window
     if (testWindow.document.readyState == "complete") {
       // the test is complete -> mark as complete
       TestRunner.currentTestURL = testPath;
       TestRunner.updateUI(testWindow.SimpleTest._tests);
       testWindow.close();
-      if (TestRunner.loops == completed  && TestRunner.onComplete) {
+      if (TestRunner.repeat == completed  && TestRunner.onComplete) {
         TestRunner.onComplete();
       }
       completed++;
     }
     else {
       // wait and check later
       setTimeout(checkComplete, 1000);
     }
@@ -311,24 +311,25 @@ TestRunner.runNextTest = function() {
           indicator.style.backgroundColor = "red";
         }
 
         TestRunner.log("TEST-START | Shutdown"); // used by automation.py
         TestRunner.log("Passed: " + $("pass-count").innerHTML);
         TestRunner.log("Failed: " + $("fail-count").innerHTML);
         TestRunner.log("Todo:   " + $("todo-count").innerHTML);
         // If we are looping, don't send this cause it closes the log file
-        if (TestRunner.loops == 0)
+        if (TestRunner.repeat == 0) {
           TestRunner.log("SimpleTest FINISHED");
+        }
 
-        if (TestRunner.loops == 0 && TestRunner.onComplete) {
+        if (TestRunner.repeat == 0 && TestRunner.onComplete) {
              TestRunner.onComplete();
          }
  
-        if (TestRunner._currentLoop < TestRunner.loops){
+        if (TestRunner._currentLoop < TestRunner.repeat) {
           TestRunner._currentLoop++;
           TestRunner.resetTests(TestRunner._urls);
         } else {
           // Loops are finished
           if (TestRunner.logEnabled) {
             TestRunner.log("TEST-INFO | Ran " + TestRunner._currentLoop + " Loops");
             TestRunner.log("SimpleTest FINISHED");
           }
@@ -477,12 +478,12 @@ TestRunner.updateUI = function(tests) {
   tds[0].style.backgroundColor = "#0d0";
   tds[0].innerHTML = parseInt(tds[0].innerHTML) + parseInt(results.OK);
   tds[1].style.backgroundColor = results.notOK > 0 ? "red" : "#0d0";
   tds[1].innerHTML = parseInt(tds[1].innerHTML) + parseInt(results.notOK);
   tds[2].style.backgroundColor = results.todo > 0 ? "orange" : "#0d0";
   tds[2].innerHTML = parseInt(tds[2].innerHTML) + parseInt(results.todo);
 
   //if we ran in a loop, display any found errors
-  if(TestRunner.loops > 0){
+  if (TestRunner.repeat > 0) {
     TestRunner.displayLoopErrors('fail-table', tests);
   }
 }
--- a/testing/mochitest/tests/SimpleTest/setup.js
+++ b/testing/mochitest/tests/SimpleTest/setup.js
@@ -104,18 +104,18 @@ if (params.timeout) {
   TestRunner.timeout = parseInt(params.timeout) * 1000;
 }
 
 // log levels for console and logfile
 var fileLevel =  params.fileLevel || null;
 var consoleLevel = params.consoleLevel || null;
 
 // loop tells us how many times to run the tests
-if (params.loops) {
-  TestRunner.loops = params.loops;
+if (params.repeat) {
+  TestRunner.repeat = params.repeat;
 } 
 
 // closeWhenDone tells us to call quit.js when complete
 if (params.closeWhenDone) {
   TestRunner.onComplete = goQuitApplication;
 }
 
 // logFile to write our results