Bug 462348: Make browser chrome test output less awful and more awesome, r=gavin
authorDave Townsend <dtownsend@oxymoronical.com>
Thu, 30 Oct 2008 16:13:24 +0000
changeset 21101 deed24924f5a3eb6cf282cc666ae48447ec09b0a
parent 21100 762df4556c17b1b64f2151f6a518f99cd6447e46
child 21102 80406c10f79550033c169b537db21669d3aef401
push id3313
push userdtownsend@mozilla.com
push dateThu, 30 Oct 2008 16:13:41 +0000
treeherdermozilla-central@deed24924f5a [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs462348
milestone1.9.1b2pre
Bug 462348: Make browser chrome test output less awful and more awesome, r=gavin
testing/mochitest/browser-harness.xul
--- a/testing/mochitest/browser-harness.xul
+++ b/testing/mochitest/browser-harness.xul
@@ -39,16 +39,48 @@
    - ***** END LICENSE BLOCK ***** -->
 
 <window id="browserTestHarness"
         xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
         onload="TestStart();"
         title="Browser chrome tests">
   <script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
   <script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
+  <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
+    #results {
+      margin: 5px;
+      background-color: window;
+      -moz-user-select: text;
+    }
+
+    #summary {
+      border: 2px solid black;
+    }
+
+    #summary.success {
+      background-color: green;
+    }
+
+    #summary.failure {
+      background-color: red;
+    }
+
+    .failed {
+      color: red;
+      font-weight: bold;
+    }
+
+    .testHeader {
+      margin-top: 1em;
+    }
+
+    p {
+      margin: 0.1em;
+    }
+  ]]></style>
   <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.
@@ -122,16 +154,25 @@
       get failCount() {
         return this.tests.filter(function (t) !t.pass).length;
       },
       get log() {
         var path = this.path;
         return this.tests.map(function (t) {
                                   return t.result + " | " + path + " | " + t.msg;
                               }).join("\n");
+      },
+      get htmlLog() {
+        var path = this.path;
+        return this.tests.map(function (t) {
+                                  var result = "<p class=\"result ";
+                                  result += t.pass ? "passed" : "failed";
+                                  result += "\">" + t.result + " | " + path + " | " + t.msg + "</p>";
+                                  return result;
+                              }).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"].
@@ -173,16 +214,34 @@
 
       setStatus("Running...");
       testWin.focus();
 
       var Tester = new testWin.Tester(listTests(), testsFinished);
       Tester.start();
     }
 
+    function getHTMLLogFromTests(aTests) {
+      var log = "";
+
+      function sum(a, b){ return a + b; }
+      var passCount = aTests.map(function (f) f.passCount).reduce(sum);
+      var failCount = aTests.map(function (f) f.failCount).reduce(sum);
+      var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
+      log += "<div id=\"summary\" class=\"";
+      log += failCount == 0 ? "success" : "failure";
+      log += "\">\n<p>Passed: " + passCount + "</p>\n" +
+             "<p>Failed: " + failCount + "</p>\n" +
+             "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
+
+      return log + aTests.map(function (f) {
+                                return "<p class=\"testHeader\">" + f.path + "</p>\n" + f.htmlLog;
+                              }).join("\n") + "</div>";
+    }
+
     function getLogFromTests(aTests) {
       if (!aTests.length)
         return "TEST-PASS | | No tests to run";
 
       var log = aTests.map(function (f) {
                              var output = f.path + "\n";
                              if (f.log)
                                output += f.log + "\n";
@@ -217,16 +276,18 @@
       }
 
       if (gConfig.closeWhenDone) {
         goQuitApplication();
         return;
       }
 
       // UI
-      document.getElementById("results").value = output;
+      document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
       setStatus("Done.");
     }
   ]]></script>
   <button id="runTestsButton" onclick="runAllTests();" label="Run All Tests"/>
   <label id="status"/>
-  <textbox flex="1" multiline="true" id="results"/>
+  <scrollbox flex="1" style="overflow: auto" align="stretch">
+    <div id="results" xmlns="http://www.w3.org/1999/xhtml"/>
+  </scrollbox>
 </window>