Bug 611048: Allow jumping to failures in the list of browser-chrome results. r=gavin
authorDave Townsend <dtownsend@oxymoronical.com>
Tue, 10 May 2011 10:27:11 -0700
changeset 69257 58663c18eb19ed6c716414dcdbbab8aafb5609ff
parent 69256 24bd5f86695cbb29e935a51550f554e3877985e4
child 69258 2a7aeaf22502810958a8d7a8a175e8ec1bb0ea28
push idunknown
push userunknown
push dateunknown
reviewersgavin
bugs611048
milestone6.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 611048: Allow jumping to failures in the list of browser-chrome results. r=gavin
testing/mochitest/browser-harness.xul
--- a/testing/mochitest/browser-harness.xul
+++ b/testing/mochitest/browser-harness.xul
@@ -82,16 +82,21 @@
 
     .testHeader {
       margin-top: 1em;
     }
 
     p {
       margin: 0.1em;
     }
+
+    a {
+      color: blue;
+      text-decoration: underline;
+    }
   ]]></style>
   <script type="application/javascript;version=1.7"><![CDATA[
     if (Cc === undefined) {
       var Cc = Components.classes;
       var Ci = Components.interfaces;
     }
     
     var gConfig;
@@ -163,16 +168,18 @@
       }
 
       sstream.close();
       fileInStream.close();
 
       return eval(config);
     }
 
+    var gErrorCount = 0;
+
     function browserTest(aTestFile) {
       this.path = aTestFile;
       this.dumper = gDumper;
       this.results = [];
       this.scope = null;
       this.duration = 0;
     }
     browserTest.prototype = {
@@ -200,18 +207,22 @@
         let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"].
                         getService(Ci.mozITXTToHTMLConv);
         function _entityEncode(str) {
           return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
         }
         var path = _entityEncode(this.path);
         var html = this.results.map(function (t) {
           var classname = t.info ? "info" : "result " + (t.pass ? "passed" : "failed");
-          return "<p class=\"" + classname + "\">" + t.result + " | " + path +
-                 " | " + _entityEncode(t.msg) + "</p>";
+          var text = t.result + " | " + path + " | " + _entityEncode(t.msg);
+          if (!t.info && !t.pass) {
+            return '<p class="' + classname + '" id=\"ERROR' + (gErrorCount++) + '">' +
+                   text + " <a href=\"javascript:scrollTo('ERROR" + gErrorCount + "')\">NEXT ERROR</a></p>";
+          }
+          return '<p class="' + classname + '">' + text + "</p>";
         }).join("\n");
         if (this.duration) {
           html += "<p class=\"info\">TEST-END | " + path + " | finished in " +
                   this.duration + " ms</p>";
         }
         return html;
       }
     };
@@ -278,17 +289,20 @@
 
       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 ? "failure" :
                passCount == 0 ? "todo" : "success";
       log += "\">\n<p>Passed: " + passCount + "</p>\n" +
-             "<p>Failed: " + failCount + "</p>\n" +
+             "<p>Failed: " + failCount;
+      if (failCount > 0)
+        log += " <a href=\"javascript:scrollTo('ERROR0')\">NEXT ERROR</a>";
+      log += "</p>\n" +
              "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
 
       return log + aTests.map(function (f) {
                                 return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog;
                               }).join("\n") + "</div>";
     }
 
     function testsFinished(aTests) {
@@ -299,15 +313,25 @@
         goQuitApplication();
         return;
       }
 
       // UI
       document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
       setStatus("Done.");
     }
+
+    function scrollTo(id) {
+      var line = document.getElementById(id);
+      if (!line)
+        return;
+
+      var boxObject = document.getElementById("results").parentNode.boxObject;
+      boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
+      boxObject.scrollToElement(line);
+    }
   ]]></script>
   <button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/>
   <label id="status"/>
   <scrollbox flex="1" style="overflow: auto" align="stretch">
     <div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/>
   </scrollbox>
 </window>