Bumping manifests a=b2g-bump
[gecko.git] / testing / mochitest / browser-harness.xul
blob42443fb51a76c6348c8d49aadde0943ec5724006
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['url'];
123 this.expected = aTestFile['expected'];
124 this.dumper = gDumper;
125 this.results = [];
126 this.scope = null;
127 this.duration = 0;
128 this.unexpectedTimeouts = 0;
129 this.lastOutputTime = 0;
131 browserTest.prototype = {
132 get passCount() {
133 return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
135 get todoCount() {
136 return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
138 get failCount() {
139 return this.results.filter(function (t) !t.info && !t.pass).length;
142 addResult: function addResult(result) {
143 this.lastOutputTime = Date.now();
144 this.results.push(result);
146 if (result.info) {
147 if (result.msg) {
148 this.dumper.structuredLogger.info(result.msg);
150 return;
153 this.dumper.structuredLogger.testStatus(this.path,
154 result.name,
155 result.status,
156 result.expected,
157 result.msg);
160 setDuration: function setDuration(duration) {
161 this.duration = duration;
164 get htmlLog() {
165 let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"].
166 getService(Ci.mozITXTToHTMLConv);
167 function _entityEncode(str) {
168 return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
170 var path = _entityEncode(this.path);
171 var html = this.results.map(function (t) {
172 var classname = "result ";
173 var result = "TEST-";
174 if (t.info) {
175 classname = "info";
176 result += "INFO";
178 else if (t.pass) {
179 classname += "passed";
180 if (t.todo)
181 result += "KNOWN-FAIL";
182 else
183 result += "PASS";
185 else {
186 classname += "failed";
187 result += "UNEXPECTED-" + t.status;
189 var message = t.name + (t.msg ? " - " + t.msg : "");
190 var text = result + " | " + path + " | " + _entityEncode(message);
191 if (!t.info && !t.pass) {
192 return '<p class="' + classname + '" id=\"ERROR' + (gErrorCount++) + '">' +
193 text + " <a href=\"javascript:scrollTo('ERROR" + gErrorCount + "')\">NEXT ERROR</a></p>";
195 return '<p class="' + classname + '">' + text + "</p>";
196 }).join("\n");
197 if (this.duration) {
198 html += "<p class=\"info\">TEST-END | " + path + " | finished in " +
199 this.duration + " ms</p>";
201 return html;
205 // Returns an array of browserTest objects for all the selected tests
206 function runTests() {
207 gConfig.baseurl = "chrome://mochitests/content";
208 getTestList(gConfig, loadTestList);
211 function loadTestList(links) {
212 if (!links) {
213 createTester({});
214 return;
217 // load server.js in so we can share template functions
218 var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
219 getService(Ci.mozIJSSubScriptLoader);
220 var srvScope = {};
221 scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
222 srvScope);
224 var fileNames = [];
225 var fileNameRegexp = /browser_.+\.js$/;
226 srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
228 if (gConfig.startAt || gConfig.endAt) {
229 fileNames = skipTests(fileNames, gConfig.startAt, gConfig.endAt);
232 if (gConfig.totalChunks && gConfig.thisChunk) {
233 fileNames = chunkifyTests(fileNames, gConfig.totalChunks,
234 gConfig.thisChunk, gConfig.chunkByDir);
237 createTester(fileNames.map(function (f) { return new browserTest(f); }));
240 function setStatus(aStatusString) {
241 document.getElementById("status").value = aStatusString;
244 function createTester(links) {
245 var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
246 getService(Ci.nsIWindowMediator);
247 var winType = gConfig.testRoot == "browser" ? "navigator:browser" :
248 gConfig.testRoot == "metro" ? "navigator:browser" :
249 gConfig.testRoot == "webapprtChrome" ? "webapprt:webapp" :
250 null;
251 if (!winType) {
252 throw new Error("Unrecognized gConfig.testRoot: " + gConfig.testRoot);
254 var testWin = windowMediator.getMostRecentWindow(winType);
256 setStatus("Running...");
257 testWin.focus();
258 var Tester = new testWin.Tester(links, gDumper, testsFinished);
259 Tester.start();
262 function sum(a, b) {
263 return a + b;
266 function getHTMLLogFromTests(aTests) {
267 if (!aTests.length)
268 return "<div id=\"summary\" class=\"failure\">No tests to run." +
269 " Did you pass an invalid --test-path?</div>";
271 var log = "";
273 var passCount = aTests.map(function (f) f.passCount).reduce(sum);
274 var failCount = aTests.map(function (f) f.failCount).reduce(sum);
275 var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
276 log += "<div id=\"summary\" class=\"";
277 log += failCount != 0 ? "failure" :
278 passCount == 0 ? "todo" : "success";
279 log += "\">\n<p>Passed: " + passCount + "</p>\n" +
280 "<p>Failed: " + failCount;
281 if (failCount > 0)
282 log += " <a href=\"javascript:scrollTo('ERROR0')\">NEXT ERROR</a>";
283 log += "</p>\n" +
284 "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
286 return log + aTests.map(function (f) {
287 return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog;
288 }).join("\n") + "</div>";
291 function testsFinished(aTests) {
292 // Focus our window, to display the results
293 window.focus();
295 if (gConfig.closeWhenDone) {
296 let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
297 appStartup.quit(Ci.nsIAppStartup.eForceQuit);
298 return;
301 // UI
302 document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
303 setStatus("Done.");
306 function scrollTo(id) {
307 var line = document.getElementById(id);
308 if (!line)
309 return;
311 var boxObject = document.getElementById("results").parentNode.boxObject;
312 boxObject.scrollToElement(line);
314 ]]></script>
315 <button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/>
316 <label id="status"/>
317 <scrollbox flex="1" style="overflow: auto" align="stretch">
318 <div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/>
319 </scrollbox>
320 </window>