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['url'];
123 this.expected = aTestFile['expected'];
124 this.dumper = gDumper;
128 this.unexpectedTimeouts =
0;
129 this.lastOutputTime =
0;
131 browserTest.prototype = {
133 return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
136 return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
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);
148 this.dumper.structuredLogger.info(result.msg);
153 this.dumper.structuredLogger.testStatus(this.path,
160 setDuration: function setDuration(duration) {
161 this.duration = duration;
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-";
179 classname +=
"passed";
181 result +=
"KNOWN-FAIL";
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>";
198 html +=
"<p class=\"info\
">TEST-END | " + path +
" | finished in " +
199 this.duration +
" ms</p>";
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) {
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);
221 scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
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" :
252 throw new Error(
"Unrecognized gConfig.testRoot: " + gConfig.testRoot);
254 var testWin = windowMediator.getMostRecentWindow(winType);
256 setStatus(
"Running...");
258 var Tester = new testWin.Tester(links, gDumper, testsFinished);
266 function getHTMLLogFromTests(aTests) {
268 return
"<div id=\"summary\
" class=\"failure\
">No tests to run." +
269 " Did you pass an invalid --test-path?</div>";
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;
282 log +=
" <a href=\"javascript:scrollTo('ERROR0')\
">NEXT ERROR</a>";
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
295 if (gConfig.closeWhenDone) {
296 let appStartup = Cc[
"@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
297 appStartup.quit(Ci.nsIAppStartup.eForceQuit);
302 document.getElementById(
"results").innerHTML = getHTMLLogFromTests(aTests);
306 function scrollTo(id) {
307 var line = document.getElementById(id);
311 var boxObject = document.getElementById(
"results").parentNode.boxObject;
312 boxObject.scrollToElement(line);
315 <button id=
"runTestsButton" oncommand=
"runTests();" label=
"Run All Tests"/>
317 <scrollbox flex=
"1" style=
"overflow: auto" align=
"stretch">
318 <div id=
"results" xmlns=
"http://www.w3.org/1999/xhtml" flex=
"1"/>