bug 390539: honor the --test-path option for browser chrome tests as well; r=gavin
authormyk@mozilla.org
Thu, 27 Sep 2007 15:11:05 -0700
changeset 6373 986307d758e9ed190bafe6fdbe03512e44352585
parent 6372 76170d5871b5e1b03fb92598c50dca9610b8a94a
child 6374 6a1985fbb74f9ed9d00840f9dbecfc8cceb13c54
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs390539
milestone1.9a9pre
bug 390539: honor the --test-path option for browser chrome tests as well; r=gavin
testing/mochitest/browser-harness.xul
testing/mochitest/runtests.pl.in
--- a/testing/mochitest/browser-harness.xul
+++ b/testing/mochitest/browser-harness.xul
@@ -44,16 +44,23 @@
         title="Browser chrome tests">
   <script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
   <script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
   <script type="application/javascript;version=1.7"><![CDATA[
     var gConfig;
     function TestStart() {
       gConfig = readConfig();
 
+      // If MochiTest was started with the --test-path flag specifying a subset
+      // of tests to run, put that path in the label of the "Run Tests" button
+      // so the tester knows which tests will run when they press that button.
+      if (gConfig.testPath)
+        document.getElementById("runTestsButton").label =
+          "Run " + gConfig.testPath + " Tests";
+
       if (gConfig.autoRun)
         setTimeout(runAllTests, 0);
     }
 
     function readConfig() {
       var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
                         getService(Ci.nsIProperties);
       var configFile = fileLocator.get("ProfD", Ci.nsIFile);
@@ -124,27 +131,38 @@
                               }).join("\n");
       }
     };
 
     // Returns an array of chrome:// URLs to all the test files
     function listTests() {
       const Cc = Components.classes; const Ci = Components.interfaces;
 
+      var ioSvc = Cc["@mozilla.org/network/io-service;1"].
+                  getService(Ci.nsIIOService);
+
       var testsDir = getChromeDir();
       testsDir.appendRelativePath("browser");
+      if (gConfig.testPath) {
+        var testsDirURI = ioSvc.newFileURI(testsDir);
+        testsDir = ioSvc.newURI(gConfig.testPath, null, testsDirURI)
+                        .QueryInterface(Ci.nsIFileURL).file;
+      }
 
       /** load server.js in so we can share template functions **/
       var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
                          getService(Ci.mozIJSSubScriptLoader);
       var srvScope = {};
       scriptLoader.loadSubScript("chrome://mochikit/content/server.js", srvScope);
 
-      var [links, count] = srvScope.list("chrome://mochikit/content/browser/",
-                                         testsDir, true);
+      var requestPath = "chrome://mochikit/content/browser";
+      if (gConfig.testPath)
+        requestPath += "/" + gConfig.testPath;
+
+      var [links, count] = srvScope.list(requestPath, testsDir, true);
       var fileNames = [];
       srvScope.arrayOfTestFiles(links, fileNames, /browser_.+\.js$/);
 
       return fileNames.map(function (f) new browserTestFile(f));;
     }
 
     function setStatus(aStatusString) {
       document.getElementById("status").value = aStatusString;
@@ -205,12 +223,12 @@
         return;
       }
 
       // UI
       document.getElementById("results").value = output;
       setStatus("Done.");
     }
   ]]></script>
-  <button onclick="runAllTests();" label="Run All Tests"/>
+  <button id="runTestsButton" onclick="runAllTests();" label="Run All Tests"/>
   <label id="status"/>
   <textbox flex="1" multiline="true" id="results"/>
 </window>
--- a/testing/mochitest/runtests.pl.in
+++ b/testing/mochitest/runtests.pl.in
@@ -197,24 +197,25 @@ sub main {
     # execution.  If we fail, we try to kill the server and exit with an error.
     wait_for_server_startup($serverPid, SERVER_STARTUP_TIMEOUT);
   }
 
   my $url;
   if ($do_chrome) {
    $url = CHROMETESTS_URL . ($test_path ? $test_path : "") . "?";
   } elsif ($do_browser_chrome) {
-   # Tests will run from an overlay, no need to load any URL
+   # Tests will run from an overlay, no need to load any URL.  We'll include
+   # the test path in the config file so the browser chrome harness can use it.
    $url = "about:blank";
   } else {
    $url = TESTS_URL . ($test_path ? $test_path : "") . "?";
   }
 
   if ($do_browser_chrome) {
-    generate_test_config($autorun, $close_when_done, $log_path);
+    generate_test_config($autorun, $close_when_done, $log_path, $test_path);
   } else {
     if ($autorun) {
       $url .= "&autorun=1";
     }
     if ($close_when_done) {
       $url .= "&closeWhenDone=1";
     }
     if ($log_path) {
@@ -362,27 +363,30 @@ sub startServer {
 }
 
 
  ##############
  # TEST SETUP #
  ##############
 
 sub generate_test_config {
-  my ($autorun, $close_when_done, $log_path) = @_;
+  my ($autorun, $close_when_done, $log_path, $test_path) = @_;
   $autorun = $autorun || 0;
   $close_when_done = $close_when_done || 0;
   $log_path = $log_path || "";
-  $log_path =~ s/\\/\\\\/;
+  $log_path =~ s/\\/\\\\/g;
+  $test_path = $test_path || "";
+  $test_path =~ s/\\/\\\\/g;
 
   my $config_content = <<CONFIGEND;
 ({
   autoRun: $autorun,
   closeWhenDone: $close_when_done,
-  logPath: "$log_path"
+  logPath: "$log_path",
+  testPath: "$test_path"
 })
 CONFIGEND
 
   open(CONFIGOUTFILE, ">$profile_dir/testConfig.js") ||
     die("Could not open testConfig.js file $!");
   print CONFIGOUTFILE ($config_content);
   close(CONFIGOUTFILE);
 }