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"
10 title=
"Browser chrome tests"
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[
21 background-color: window;
22 -moz-user-select: text;
27 border:
2px solid black;
31 background-color: #
0d0;
35 background-color: red;
39 background-color: orange;
61 text-decoration: underline;
64 <script type=
"application/javascript;version=1.7"><![CDATA[
65 if (Cc === undefined) {
66 var Cc = Components.classes;
67 var Ci = Components.interfaces;
75 if (gConfig.logFile) {
77 logger = new MozillaFileLogger(gConfig.logFile)
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);
91 this.fileLogger.log(str);
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";
116 setTimeout(runTests,
0);
121 function browserTest(aTestFile) {
122 this.path = aTestFile;
123 this.dumper = gDumper;
127 this.unexpectedTimeouts =
0;
128 this.lastOutputTime =
0;
130 browserTest.prototype = {
132 return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
135 return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
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);
147 this.dumper.structuredLogger.info(result.msg);
152 this.dumper.structuredLogger.testStatus(this.path,
159 setDuration: function setDuration(duration) {
160 this.duration = duration;
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>";
180 html +=
"<p class=\"info\
">TEST-END | " + path +
" | finished in " +
181 this.duration +
" ms</p>";
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) {
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);
203 scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
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" :
234 throw new Error(
"Unrecognized gConfig.testRoot: " + gConfig.testRoot);
236 var testWin = windowMediator.getMostRecentWindow(winType);
238 setStatus(
"Running...");
240 var Tester = new testWin.Tester(links, gDumper, testsFinished);
248 function getHTMLLogFromTests(aTests) {
250 return
"<div id=\"summary\
" class=\"failure\
">No tests to run." +
251 " Did you pass an invalid --test-path?</div>";
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;
264 log +=
" <a href=\"javascript:scrollTo('ERROR0')\
">NEXT ERROR</a>";
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
277 if (gConfig.closeWhenDone) {
278 let appStartup = Cc[
"@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
279 appStartup.quit(Ci.nsIAppStartup.eForceQuit);
284 document.getElementById(
"results").innerHTML = getHTMLLogFromTests(aTests);
288 function scrollTo(id) {
289 var line = document.getElementById(id);
293 var boxObject = document.getElementById(
"results").parentNode.boxObject;
294 boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
295 boxObject.scrollToElement(line);
298 <button id=
"runTestsButton" oncommand=
"runTests();" label=
"Run All Tests"/>
300 <scrollbox flex=
"1" style=
"overflow: auto" align=
"stretch">
301 <div id=
"results" xmlns=
"http://www.w3.org/1999/xhtml" flex=
"1"/>