Bumping manifests a=b2g-bump
[gecko.git] / testing / mochitest / browser-harness.xul
blob1f3369df136d394cd9928d83083a30e78255dbda
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <!-- This Source Code Form is subject to the terms of the Mozilla Public
4 - License, v. 2.0. If a copy of the MPL was not distributed with this
5 - file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
7 <window id="browserTestHarness"
8 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
9 onload="TestStart();"
10 title="Browser chrome tests"
11 width="1024">
12 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/>
13 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/LogController.js"/>
14 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/TestRunner.js"/>
15 <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"/>
16 <script type="application/javascript" src="chrome://mochikit/content/manifestLibrary.js" />
17 <script type="application/javascript" src="chrome://mochikit/content/chunkifyTests.js"/>
18 <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
19 #results {
20 margin: 5px;
21 background-color: window;
22 -moz-user-select: text;
25 #summary {
26 color: white;
27 border: 2px solid black;
30 #summary.success {
31 background-color: #0d0;
34 #summary.failure {
35 background-color: red;
38 #summary.todo {
39 background-color: orange;
42 .info {
43 color: grey;
46 .failed {
47 color: red;
48 font-weight: bold;
51 .testHeader {
52 margin-top: 1em;
55 p {
56 margin: 0.1em;
59 a {
60 color: blue;
61 text-decoration: underline;
63 ]]></style>
64 <script type="application/javascript;version=1.7"><![CDATA[
65 if (Cc === undefined) {
66 var Cc = Components.classes;
67 var Ci = Components.interfaces;
70 var gConfig;
72 var gDumper = {
73 get fileLogger() {
74 let logger = null;
75 if (gConfig.logFile) {
76 try {
77 logger = new MozillaFileLogger(gConfig.logFile)
78 } catch (ex) {
79 dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " +
80 "Error trying to log to " + gConfig.logFile + ": " + ex + "\n");
83 delete this.fileLogger;
84 return this.fileLogger = logger;
86 structuredLogger: new StructuredLogger(),
87 dump: function (str) {
88 this.structuredLogger.info(str);
90 if (this.fileLogger)
91 this.fileLogger.log(str);
94 done: function () {
95 if (this.fileLogger)
96 this.fileLogger.close();
100 function TestStart() {
101 gConfig = readConfig();
103 // If MochiTest was started with the --test-path flag specifying a subset
104 // of tests to run, put that path in the label of the "Run Tests" button
105 // so the tester knows which tests will run when they press that button.
106 if (gConfig.testPath)
107 document.getElementById("runTestsButton").label =
108 "Run " + gConfig.testPath + " tests";
110 // Similarly, update the title for --start-at and --end-at.
111 if (gConfig.startAt || gConfig.endAt)
112 document.getElementById("runTestsButton").label =
113 "Run subset of tests";
115 if (gConfig.autorun)
116 setTimeout(runTests, 0);
119 var gErrorCount = 0;
121 function browserTest(aTestFile) {
122 this.path = aTestFile;
123 this.dumper = gDumper;
124 this.results = [];
125 this.scope = null;
126 this.duration = 0;
127 this.unexpectedTimeouts = 0;
128 this.lastOutputTime = 0;
130 browserTest.prototype = {
131 get passCount() {
132 return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
134 get todoCount() {
135 return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
137 get failCount() {
138 return this.results.filter(function (t) !t.info && !t.pass).length;
141 addResult: function addResult(result) {
142 this.lastOutputTime = Date.now();
143 this.results.push(result);
145 if (result.info) {
146 if (result.msg) {
147 this.dumper.structuredLogger.info(result.msg);
149 return;
152 this.dumper.structuredLogger.testStatus(this.path,
153 result.name,
154 result.status,
155 result.expected,
156 result.msg);
159 setDuration: function setDuration(duration) {
160 this.duration = duration;
163 get htmlLog() {
164 let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"].
165 getService(Ci.mozITXTToHTMLConv);
166 function _entityEncode(str) {
167 return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
169 var path = _entityEncode(this.path);
170 var html = this.results.map(function (t) {
171 var classname = t.info ? "info" : "result " + (t.pass ? "passed" : "failed");
172 var text = t.result + " | " + path + " | " + _entityEncode(t.msg);
173 if (!t.info && !t.pass) {
174 return '<p class="' + classname + '" id=\"ERROR' + (gErrorCount++) + '">' +
175 text + " <a href=\"javascript:scrollTo('ERROR" + gErrorCount + "')\">NEXT ERROR</a></p>";
177 return '<p class="' + classname + '">' + text + "</p>";
178 }).join("\n");
179 if (this.duration) {
180 html += "<p class=\"info\">TEST-END | " + path + " | finished in " +
181 this.duration + " ms</p>";
183 return html;
187 // Returns an array of browserTest objects for all the selected tests
188 function runTests() {
189 gConfig.baseurl = "chrome://mochitests/content";
190 getTestList(gConfig, loadTestList);
193 function loadTestList(links) {
194 if (!links) {
195 createTester({});
196 return;
199 // load server.js in so we can share template functions
200 var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
201 getService(Ci.mozIJSSubScriptLoader);
202 var srvScope = {};
203 scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
204 srvScope);
206 var fileNames = [];
207 var fileNameRegexp = /browser_.+\.js$/;
208 srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
210 if (gConfig.startAt || gConfig.endAt) {
211 fileNames = skipTests(fileNames, gConfig.startAt, gConfig.endAt);
214 if (gConfig.totalChunks && gConfig.thisChunk) {
215 fileNames = chunkifyTests(fileNames, gConfig.totalChunks,
216 gConfig.thisChunk, gConfig.chunkByDir);
219 createTester(fileNames.map(function (f) { return new browserTest(f); }));
222 function setStatus(aStatusString) {
223 document.getElementById("status").value = aStatusString;
226 function createTester(links) {
227 var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
228 getService(Ci.nsIWindowMediator);
229 var winType = gConfig.testRoot == "browser" ? "navigator:browser" :
230 gConfig.testRoot == "metro" ? "navigator:browser" :
231 gConfig.testRoot == "webapprtChrome" ? "webapprt:webapp" :
232 null;
233 if (!winType) {
234 throw new Error("Unrecognized gConfig.testRoot: " + gConfig.testRoot);
236 var testWin = windowMediator.getMostRecentWindow(winType);
238 setStatus("Running...");
239 testWin.focus();
240 var Tester = new testWin.Tester(links, gDumper, testsFinished);
241 Tester.start();
244 function sum(a, b) {
245 return a + b;
248 function getHTMLLogFromTests(aTests) {
249 if (!aTests.length)
250 return "<div id=\"summary\" class=\"failure\">No tests to run." +
251 " Did you pass an invalid --test-path?</div>";
253 var log = "";
255 var passCount = aTests.map(function (f) f.passCount).reduce(sum);
256 var failCount = aTests.map(function (f) f.failCount).reduce(sum);
257 var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
258 log += "<div id=\"summary\" class=\"";
259 log += failCount != 0 ? "failure" :
260 passCount == 0 ? "todo" : "success";
261 log += "\">\n<p>Passed: " + passCount + "</p>\n" +
262 "<p>Failed: " + failCount;
263 if (failCount > 0)
264 log += " <a href=\"javascript:scrollTo('ERROR0')\">NEXT ERROR</a>";
265 log += "</p>\n" +
266 "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
268 return log + aTests.map(function (f) {
269 return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog;
270 }).join("\n") + "</div>";
273 function testsFinished(aTests) {
274 // Focus our window, to display the results
275 window.focus();
277 if (gConfig.closeWhenDone) {
278 let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
279 appStartup.quit(Ci.nsIAppStartup.eForceQuit);
280 return;
283 // UI
284 document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
285 setStatus("Done.");
288 function scrollTo(id) {
289 var line = document.getElementById(id);
290 if (!line)
291 return;
293 var boxObject = document.getElementById("results").parentNode.boxObject;
294 boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
295 boxObject.scrollToElement(line);
297 ]]></script>
298 <button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/>
299 <label id="status"/>
300 <scrollbox flex="1" style="overflow: auto" align="stretch">
301 <div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/>
302 </scrollbox>
303 </window>