Bug 470455 - test_database_sync_embed_visits.js leaks, r=sdwilsh
[wine-gecko.git] / testing / mochitest / browser-harness.xul
blob8a55f75a08d24512e6f18f20144e5f80ff9e3b71
1 <?xml version="1.0"?>
2 <?xml-stylesheet href="chrome://global/skin" type="text/css"?>
3 <!-- ***** BEGIN LICENSE BLOCK *****
4 - Version: MPL 1.1/GPL 2.0/LGPL 2.1
6 - The contents of this file are subject to the Mozilla Public License Version
7 - 1.1 (the "License"); you may not use this file except in compliance with
8 - the License. You may obtain a copy of the License at
9 - http://www.mozilla.org/MPL/
11 - Software distributed under the License is distributed on an "AS IS" basis,
12 - WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
13 - for the specific language governing rights and limitations under the
14 - License.
16 - The Original Code is Browser Test Harness.
18 - The Initial Developer of the Original Code is
19 - Mozilla Corporation.
21 - Portions created by the Initial Developer are Copyright (C) 2007
22 - the Initial Developer. All Rights Reserved.
24 - Contributor(s):
25 - Gavin Sharp <gavin@gavinsharp.com> (original author)
26 - Ehsan Akhgari <ehsan.akhgari@gmail.com>
28 - Alternatively, the contents of this file may be used under the terms of
29 - either the GNU General Public License Version 2 or later (the "GPL"), or
30 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
31 - in which case the provisions of the GPL or the LGPL are applicable instead
32 - of those above. If you wish to allow use of your version of this file only
33 - under the terms of either the GPL or the LGPL, and not to allow others to
34 - use your version of this file under the terms of the MPL, indicate your
35 - decision by deleting the provisions above and replace them with the notice
36 - and other provisions required by the LGPL or the GPL. If you do not delete
37 - the provisions above, a recipient may use your version of this file under
38 - the terms of any one of the MPL, the GPL or the LGPL.
40 - ***** END LICENSE BLOCK ***** -->
42 <window id="browserTestHarness"
43 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
44 onload="TestStart();"
45 title="Browser chrome tests">
46 <script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
47 <script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
48 <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
49 #results {
50 margin: 5px;
51 background-color: window;
52 -moz-user-select: text;
55 #summary {
56 border: 2px solid black;
59 #summary.success {
60 background-color: green;
63 #summary.failure {
64 background-color: red;
67 .failed {
68 color: red;
69 font-weight: bold;
72 .testHeader {
73 margin-top: 1em;
76 p {
77 margin: 0.1em;
79 ]]></style>
80 <script type="application/javascript;version=1.7"><![CDATA[
81 var gConfig;
82 function TestStart() {
83 gConfig = readConfig();
85 // If MochiTest was started with the --test-path flag specifying a subset
86 // of tests to run, put that path in the label of the "Run Tests" button
87 // so the tester knows which tests will run when they press that button.
88 if (gConfig.testPath)
89 document.getElementById("runTestsButton").label =
90 "Run " + gConfig.testPath + " Tests";
92 if (gConfig.autoRun)
93 setTimeout(runAllTests, 0);
96 function readConfig() {
97 var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
98 getService(Ci.nsIProperties);
99 var configFile = fileLocator.get("ProfD", Ci.nsIFile);
100 configFile.append("testConfig.js");
102 if (!configFile.exists())
103 return;
105 var fileInStream = Cc["@mozilla.org/network/file-input-stream;1"].
106 createInstance(Ci.nsIFileInputStream);
107 var sstream = Cc["@mozilla.org/scriptableinputstream;1"].
108 createInstance(Ci.nsIScriptableInputStream);
109 fileInStream.init(configFile, -1, 0, 0);
110 sstream.init(fileInStream);
112 var config = "";
113 var str = sstream.read(4096);
114 while (str.length > 0) {
115 config += str;
116 str = sstream.read(4096);
119 sstream.close();
120 fileInStream.close();
122 return eval(config);
125 function getChromeDir() {
126 const Cc = Components.classes; const Ci = Components.interfaces;
128 /** Find our chrome dir **/
129 var ios = Cc["@mozilla.org/network/io-service;1"].
130 getService(Ci.nsIIOService);
131 var chromeURI = ios.newURI("chrome://mochikit/content/",
132 null, null);
133 var resolvedURI = Cc["@mozilla.org/chrome/chrome-registry;1"].
134 getService(Ci.nsIChromeRegistry).
135 convertChromeURL(chromeURI);
136 var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].
137 getService(Ci.nsIFileProtocolHandler);
138 var chromeDir = fileHandler.getFileFromURLSpec(resolvedURI.spec);
140 return chromeDir.parent.QueryInterface(Ci.nsILocalFile);
143 function browserTestFile(aTestFile) {
144 this.path = aTestFile;
145 this.tests = [];
146 this.scope = null;
148 browserTestFile.prototype = {
149 get passCount() {
150 return this.tests.filter(function (t) !t.todo && t.pass).length;
152 get todoCount() {
153 return this.tests.filter(function (t) t.todo && t.pass).length;
155 get failCount() {
156 return this.tests.filter(function (t) !t.pass).length;
158 get log() {
159 var path = this.path;
160 return this.tests.map(function (t) {
161 return t.result + " | " + path + " | " + t.msg;
162 }).join("\n");
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 return this.tests.map(function (t) {
172 var result = "<p class=\"result ";
173 result += t.pass ? "passed" : "failed";
174 result += "\">" + t.result + " | " + path +
175 " | " + _entityEncode( t.msg ) + "</p>";
176 return result;
177 }).join("\n");
181 // Returns an array of chrome:// URLs to all the test files
182 function listTests() {
183 const Cc = Components.classes; const Ci = Components.interfaces;
185 var ioSvc = Cc["@mozilla.org/network/io-service;1"].
186 getService(Ci.nsIIOService);
188 var testsDir = getChromeDir();
189 testsDir.appendRelativePath("browser");
190 if (gConfig.testPath) {
191 var testsDirURI = ioSvc.newFileURI(testsDir);
192 testsDir = ioSvc.newURI(gConfig.testPath, null, testsDirURI)
193 .QueryInterface(Ci.nsIFileURL).file;
196 /** load server.js in so we can share template functions **/
197 var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
198 getService(Ci.mozIJSSubScriptLoader);
199 var srvScope = {};
200 scriptLoader.loadSubScript("chrome://mochikit/content/server.js", srvScope);
202 var requestPath = "chrome://mochikit/content/browser";
203 if (gConfig.testPath)
204 requestPath += "/" + gConfig.testPath;
206 var [links, count] = srvScope.list(requestPath, testsDir, true);
207 var fileNames = [];
208 srvScope.arrayOfTestFiles(links, fileNames, /browser_.+\.js$/);
210 return fileNames.map(function (f) new browserTestFile(f));;
213 function setStatus(aStatusString) {
214 document.getElementById("status").value = aStatusString;
217 function runAllTests() {
218 var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
219 getService(Ci.nsIWindowMediator);
220 var testWin = windowMediator.getMostRecentWindow("navigator:browser");
222 setStatus("Running...");
223 testWin.focus();
225 var Tester = new testWin.Tester(listTests(), testsFinished);
226 Tester.start();
229 function getHTMLLogFromTests(aTests) {
230 var log = "";
232 function sum(a, b){ return a + b; }
233 var passCount = aTests.map(function (f) f.passCount).reduce(sum);
234 var failCount = aTests.map(function (f) f.failCount).reduce(sum);
235 var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
236 log += "<div id=\"summary\" class=\"";
237 log += failCount == 0 ? "success" : "failure";
238 log += "\">\n<p>Passed: " + passCount + "</p>\n" +
239 "<p>Failed: " + failCount + "</p>\n" +
240 "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
242 return log + aTests.map(function (f) {
243 return "<p class=\"testHeader\">" + f.path + "</p>\n" + f.htmlLog;
244 }).join("\n") + "</div>";
247 function getLogFromTests(aTests) {
248 if (!aTests.length)
249 return "TEST-PASS | | No tests to run";
251 var log = aTests.map(function (f) {
252 var output = f.path + "\n";
253 if (f.log)
254 output += f.log + "\n";
255 return output;
256 }).join("");
257 log += "\nBrowser Chrome Test Summary\n";
258 function sum(a, b){ return a + b; }
259 var passCount = aTests.map(function (f) f.passCount).reduce(sum);
260 var failCount = aTests.map(function (f) f.failCount).reduce(sum);
261 var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
262 log += "\tPass: " + passCount + "\n\tFail: " + failCount + "\n\tTodo: " + todoCount + "\n";
264 return log;
267 function testsFinished(aTests) {
268 // Focus our window, to display the results
269 window.focus();
271 var start = "*** Start BrowserChrome Test Results ***\n";
272 var end = "\n*** End BrowserChrome Test Results ***\n";
273 var output = start + getLogFromTests(aTests) + end;
275 // Output to stdout
276 dump(output);
278 // Output to file
279 if (gConfig.logPath) {
280 MozillaFileLogger.init(gConfig.logPath);
281 MozillaFileLogger._foStream.write(output, output.length);
282 MozillaFileLogger.close();
285 if (gConfig.closeWhenDone) {
286 goQuitApplication();
287 return;
290 // UI
291 document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
292 setStatus("Done.");
294 ]]></script>
295 <button id="runTestsButton" onclick="runAllTests();" label="Run All Tests"/>
296 <label id="status"/>
297 <scrollbox flex="1" style="overflow: auto" align="stretch">
298 <div id="results" xmlns="http://www.w3.org/1999/xhtml"/>
299 </scrollbox>
300 </window>