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 src=
"chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/>
13 <script src=
"chrome://mochikit/content/tests/SimpleTest/LogController.js"/>
14 <script src=
"chrome://mochikit/content/tests/SimpleTest/StructuredLog.jsm"/>
15 <script src=
"chrome://mochikit/content/tests/SimpleTest/TestRunner.js"/>
16 <script src=
"chrome://mochikit/content/chrome-harness.js"/>
17 <script src=
"chrome://mochikit/content/manifestLibrary.js" />
18 <script src=
"chrome://mochikit/content/chunkifyTests.js"/>
19 <style xmlns=
"http://www.w3.org/1999/xhtml"><![CDATA[
22 background-color: window;
28 border:
2px solid black;
32 background-color: #
0d0;
36 background-color: red;
40 background-color: orange;
62 text-decoration: underline;
65 <script type=
"application/javascript"><![CDATA[
71 if (gConfig.logFile) {
73 logger = new MozillaFileLogger(gConfig.logFile)
75 dump(
"TEST-UNEXPECTED-FAIL | (browser-harness.xhtml) | " +
76 "Error trying to log to " + gConfig.logFile +
": " + ex +
"\n");
79 delete this.fileLogger;
80 return this.fileLogger = logger;
82 structuredLogger: TestRunner.structuredLogger,
83 dump: function (str) {
84 this.structuredLogger.info(str);
87 this.fileLogger.log(str);
92 this.fileLogger.close();
96 function TestStart() {
97 gConfig = readConfig();
99 // Update the title for --start-at and --end-at.
100 if (gConfig.startAt || gConfig.endAt)
101 document.getElementById(
"runTestsButton").label =
102 "Run subset of tests";
105 setTimeout(runTests,
0);
110 function browserTest(aTestFile) {
111 this.path = aTestFile['url'];
112 this.expected = aTestFile['expected'];
113 this.https_first_disabled = aTestFile['https_first_disabled'] || false,
114 this.dumper = gDumper;
118 this.unexpectedTimeouts =
0;
119 this.lastOutputTime =
0;
121 browserTest.prototype = {
123 return this.results.filter(t =
> !t.info && !t.todo && t.pass).length;
126 return this.results.filter(t =
> !t.info && t.todo && t.pass).length;
129 return this.results.filter(t =
> !t.info && !t.pass).length;
131 get allowedFailureCount() {
132 return this.results.filter(t =
> t.allowedFailure).length;
135 addResult: function addResult(result) {
136 this.lastOutputTime = Date.now();
137 this.results.push(result);
141 ChromeUtils.addProfilerMarker(
"TEST-INFO", {category:
"Test"},
143 this.dumper.structuredLogger.info(result.msg);
148 this.dumper.structuredLogger.testStatus(this.path,
153 let markerName =
"TEST-";
155 markerName += result.todo ?
"KNOWN-FAIL" :
"PASS";
158 markerName +=
"UNEXPECTED-" + result.status;
160 let markerText = result.name;
162 markerText +=
" - " + result.msg;
164 ChromeUtils.addProfilerMarker(markerName, {category:
"Test"}, markerText);
167 setDuration: function setDuration(duration) {
168 this.duration = duration;
172 let txtToHTML = Cc[
"@mozilla.org/txttohtmlconv;1"].
173 getService(Ci.mozITXTToHTMLConv);
174 function _entityEncode(str) {
175 return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
177 var path = _entityEncode(this.path);
178 var html = this.results.map(function (t) {
179 var classname =
"result ";
180 var result =
"TEST-";
186 classname +=
"passed";
188 result +=
"KNOWN-FAIL";
193 classname +=
"failed";
194 result +=
"UNEXPECTED-" + t.status;
196 var message = t.name + (t.msg ?
" - " + t.msg :
"");
197 var text = result +
" | " + path +
" | " + _entityEncode(message);
198 if (!t.info && !t.pass) {
199 return '
<p class=
"' + classname + '" id=\
"ERROR' + (gErrorCount++) + '">' +
200 text +
" <a href=\"javascript:scrollTo('ERROR
" + gErrorCount + "')\
">NEXT ERROR</a></p>";
202 return '
<p class=
"' + classname + '">' + text +
"</p>";
205 html +=
"<p class=\"info\
">TEST-END | " + path +
" | finished in " +
206 this.duration +
" ms</p>";
212 // Returns an array of browserTest objects for all the selected tests
213 function runTests() {
214 gConfig.baseurl =
"chrome://mochitests/content";
215 getTestList(gConfig, loadTestList);
218 function loadTestList(links) {
224 // load server.js in so we can share template functions
225 var scriptLoader = Cc[
"@mozilla.org/moz/jssubscript-loader;1"].
226 getService(Ci.mozIJSSubScriptLoader);
228 scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
232 var fileNameRegexp = /browser_.+\.js$/;
233 srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
235 if (gConfig.startAt || gConfig.endAt) {
236 fileNames = skipTests(fileNames, gConfig.startAt, gConfig.endAt);
239 createTester(fileNames.map(function (f) { return new browserTest(f); }));
242 function setStatus(aStatusString) {
243 document.getElementById(
"status").value = aStatusString;
246 function createTester(links) {
247 var windowMediator = Cc['@mozilla.org/appshell/window-mediator;
1'].
248 getService(Ci.nsIWindowMediator);
250 if (gConfig.testRoot ==
"browser") {
251 const IS_THUNDERBIRD = Services.appinfo.ID ==
"{3550f703-e582-4d05-9a08-453d09bdfdc6}";
252 winType = IS_THUNDERBIRD ?
"mail:3pane" :
"navigator:browser";
255 throw new Error(
"Unrecognized gConfig.testRoot: " + gConfig.testRoot);
257 var testWin = windowMediator.getMostRecentWindow(winType);
259 setStatus(
"Running...");
261 // It's possible that the test harness window is not yet focused when this
262 // function runs (in which case testWin is already focused, and focusing it
263 // will be a no-op, and then the test harness window will steal focus later,
264 // which will mess up tests). So wait for the test harness window to be
265 // focused before trying to focus testWin.
267 // Focus the test window and start tests.
269 var Tester = new testWin.Tester(links, gDumper.structuredLogger, testsFinished);
275 function executeSoon(callback) {
276 let tm = Cc[
"@mozilla.org/thread-manager;1"].getService(Ci.nsIThreadManager);
277 tm.dispatchToMainThread(callback);
280 function waitForFocus(callback, win) {
281 // If
"win" is already focused, just call the callback.
282 let fm = Cc[
"@mozilla.org/focus-manager;1"].getService(Ci.nsIFocusManager);
283 if (fm.focusedWindow == win) {
284 executeSoon(callback);
288 // Otherwise focus it, and wait for the focus event.
289 win.addEventListener(
"focus", function listener() {
290 win.removeEventListener(
"focus", listener, true);
291 executeSoon(callback);
300 function getHTMLLogFromTests(aTests) {
302 return
"<div id=\"summary\
" class=\"failure\
">No tests to run." +
303 " Did you pass an invalid --test-path?</div>";
307 var passCount = aTests.map(f =
> f.passCount).reduce(sum);
308 var failCount = aTests.map(f =
> f.failCount).reduce(sum);
309 var todoCount = aTests.map(f =
> f.todoCount).reduce(sum);
310 log +=
"<div id=\"summary\
" class=\"";
311 log += failCount != 0 ? "failure
" :
312 passCount == 0 ? "todo
" : "success
";
313 log += "\
">\n<p>Passed: " + passCount +
"</p>\n" +
314 "<p>Failed: " + failCount;
316 log +=
" <a href=\"javascript:scrollTo('ERROR0')\
">NEXT ERROR</a>";
318 "<p>Todo: " + todoCount +
"</p>\n</div>\n<div id=\"log\
">\n";
320 return log + aTests.map(function (f) {
321 return
"<p class=\"testHeader\
">Running " + f.path +
"...</p>\n" + f.htmlLog;
322 }).join(
"\n") +
"</div>";
325 function testsFinished(aTests) {
326 if (gConfig.closeWhenDone) {
327 const {AppConstants} = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm");
329 !AppConstants.RELEASE_OR_BETA &&
330 !AppConstants.DEBUG &&
331 !AppConstants.MOZ_CODE_COVERAGE &&
332 !AppConstants.ASAN &&
335 Cu.exitIfInAutomation();
337 let appStartup = Cc[
"@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
338 appStartup.quit(Ci.nsIAppStartup.eForceQuit);
343 // Focus our window, to display the results
347 document.getElementById(
"results").innerHTML = getHTMLLogFromTests(aTests);
351 function scrollTo(id) {
352 var line = document.getElementById(id);
356 line.scrollIntoView();
359 <button id=
"runTestsButton" oncommand=
"runTests();" label=
"Run All Tests"/>
361 <scrollbox flex=
"1" style=
"overflow: auto" align=
"stretch">
362 <div id=
"results" xmlns=
"http://www.w3.org/1999/xhtml" flex=
"1"/>