Bug 435739 Poor performance of Firefox 3 with no X RENDER extension
[wine-gecko.git] / testing / mochitest / browser-harness.xul
blob2e3823063509085765500cb717bef2b526f77f01
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)
27 - Alternatively, the contents of this file may be used under the terms of
28 - either the GNU General Public License Version 2 or later (the "GPL"), or
29 - the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
30 - in which case the provisions of the GPL or the LGPL are applicable instead
31 - of those above. If you wish to allow use of your version of this file only
32 - under the terms of either the GPL or the LGPL, and not to allow others to
33 - use your version of this file under the terms of the MPL, indicate your
34 - decision by deleting the provisions above and replace them with the notice
35 - and other provisions required by the LGPL or the GPL. If you do not delete
36 - the provisions above, a recipient may use your version of this file under
37 - the terms of any one of the MPL, the GPL or the LGPL.
39 - ***** END LICENSE BLOCK ***** -->
41 <window id="browserTestHarness"
42 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
43 onload="TestStart();"
44 title="Browser chrome tests">
45 <script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
46 <script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
47 <script type="application/javascript;version=1.7"><![CDATA[
48 var gConfig;
49 function TestStart() {
50 gConfig = readConfig();
52 // If MochiTest was started with the --test-path flag specifying a subset
53 // of tests to run, put that path in the label of the "Run Tests" button
54 // so the tester knows which tests will run when they press that button.
55 if (gConfig.testPath)
56 document.getElementById("runTestsButton").label =
57 "Run " + gConfig.testPath + " Tests";
59 if (gConfig.autoRun)
60 setTimeout(runAllTests, 0);
63 function readConfig() {
64 var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
65 getService(Ci.nsIProperties);
66 var configFile = fileLocator.get("ProfD", Ci.nsIFile);
67 configFile.append("testConfig.js");
69 if (!configFile.exists())
70 return;
72 var fileInStream = Cc["@mozilla.org/network/file-input-stream;1"].
73 createInstance(Ci.nsIFileInputStream);
74 var sstream = Cc["@mozilla.org/scriptableinputstream;1"].
75 createInstance(Ci.nsIScriptableInputStream);
76 fileInStream.init(configFile, -1, 0, 0);
77 sstream.init(fileInStream);
79 var config = "";
80 var str = sstream.read(4096);
81 while (str.length > 0) {
82 config += str;
83 str = sstream.read(4096);
86 sstream.close();
87 fileInStream.close();
89 return eval(config);
92 function getChromeDir() {
93 const Cc = Components.classes; const Ci = Components.interfaces;
95 /** Find our chrome dir **/
96 var ios = Cc["@mozilla.org/network/io-service;1"].
97 getService(Ci.nsIIOService);
98 var chromeURI = ios.newURI("chrome://mochikit/content/",
99 null, null);
100 var resolvedURI = Cc["@mozilla.org/chrome/chrome-registry;1"].
101 getService(Ci.nsIChromeRegistry).
102 convertChromeURL(chromeURI);
103 var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].
104 getService(Ci.nsIFileProtocolHandler);
105 var chromeDir = fileHandler.getFileFromURLSpec(resolvedURI.spec);
107 return chromeDir.parent.QueryInterface(Ci.nsILocalFile);
110 function browserTestFile(aTestFile) {
111 this.path = aTestFile;
112 this.tests = [];
113 this.scope = null;
115 browserTestFile.prototype = {
116 get passCount() {
117 return this.tests.filter(function (t) !t.todo && t.pass).length;
119 get todoCount() {
120 return this.tests.filter(function (t) t.todo && t.pass).length;
122 get failCount() {
123 return this.tests.filter(function (t) !t.pass).length;
125 get log() {
126 var path = this.path;
127 return this.tests.map(function (t) {
128 if (!t.pass)
129 return t.msg + " - " + path;
130 return t.msg;
131 }).join("\n");
135 // Returns an array of chrome:// URLs to all the test files
136 function listTests() {
137 const Cc = Components.classes; const Ci = Components.interfaces;
139 var ioSvc = Cc["@mozilla.org/network/io-service;1"].
140 getService(Ci.nsIIOService);
142 var testsDir = getChromeDir();
143 testsDir.appendRelativePath("browser");
144 if (gConfig.testPath) {
145 var testsDirURI = ioSvc.newFileURI(testsDir);
146 testsDir = ioSvc.newURI(gConfig.testPath, null, testsDirURI)
147 .QueryInterface(Ci.nsIFileURL).file;
150 /** load server.js in so we can share template functions **/
151 var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
152 getService(Ci.mozIJSSubScriptLoader);
153 var srvScope = {};
154 scriptLoader.loadSubScript("chrome://mochikit/content/server.js", srvScope);
156 var requestPath = "chrome://mochikit/content/browser";
157 if (gConfig.testPath)
158 requestPath += "/" + gConfig.testPath;
160 var [links, count] = srvScope.list(requestPath, testsDir, true);
161 var fileNames = [];
162 srvScope.arrayOfTestFiles(links, fileNames, /browser_.+\.js$/);
164 return fileNames.map(function (f) new browserTestFile(f));;
167 function setStatus(aStatusString) {
168 document.getElementById("status").value = aStatusString;
171 function runAllTests() {
172 var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
173 getService(Ci.nsIWindowMediator);
174 var testWin = windowMediator.getMostRecentWindow("navigator:browser");
176 setStatus("Running...");
177 testWin.focus();
179 var Tester = new testWin.Tester(listTests(), testsFinished);
180 Tester.start();
183 function getLogFromTests(aTests) {
184 if (!aTests.length)
185 return "PASS - No tests to run";
187 var log = aTests.map(function (f) {
188 var output = f.path + "\n";
189 if (f.log)
190 output += f.log + "\n";
191 return output;
192 }).join("");
193 log += "\nBrowser Chrome Test Summary\n";
194 function sum(a, b){ return a + b; }
195 var passCount = aTests.map(function (f) f.passCount).reduce(sum);
196 var failCount = aTests.map(function (f) f.failCount).reduce(sum);
197 var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
198 log += "\tPass: " + passCount + "\n\tFail: " + failCount + "\n\tTodo: " + todoCount + "\n";
200 return log;
203 function testsFinished(aTests) {
204 // Focus our window, to display the results
205 window.focus();
207 var start = "*** Start BrowserChrome Test Results ***\n";
208 var end = "\n*** End BrowserChrome Test Results ***\n";
209 var output = start + getLogFromTests(aTests) + end;
211 // Output to stdout
212 dump(output);
214 // Output to file
215 if (gConfig.logPath) {
216 MozillaFileLogger.init(gConfig.logPath);
217 MozillaFileLogger._foStream.write(output, output.length);
218 MozillaFileLogger.close();
221 if (gConfig.closeWhenDone) {
222 goQuitApplication();
223 return;
226 // UI
227 document.getElementById("results").value = output;
228 setStatus("Done.");
230 ]]></script>
231 <button id="runTestsButton" onclick="runAllTests();" label="Run All Tests"/>
232 <label id="status"/>
233 <textbox flex="1" multiline="true" id="results"/>
234 </window>