2007-07-09 09:24:15 -07:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
|
|
|
<!-- ***** BEGIN LICENSE BLOCK *****
|
|
|
|
- Version: MPL 1.1/GPL 2.0/LGPL 2.1
|
|
|
|
-
|
|
|
|
- The contents of this file are subject to the Mozilla Public License Version
|
|
|
|
- 1.1 (the "License"); you may not use this file except in compliance with
|
|
|
|
- the License. You may obtain a copy of the License at
|
|
|
|
- http://www.mozilla.org/MPL/
|
|
|
|
-
|
|
|
|
- Software distributed under the License is distributed on an "AS IS" basis,
|
|
|
|
- WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
|
|
|
|
- for the specific language governing rights and limitations under the
|
|
|
|
- License.
|
|
|
|
-
|
|
|
|
- The Original Code is Browser Test Harness.
|
|
|
|
-
|
|
|
|
- The Initial Developer of the Original Code is
|
|
|
|
- Mozilla Corporation.
|
|
|
|
-
|
|
|
|
- Portions created by the Initial Developer are Copyright (C) 2007
|
|
|
|
- the Initial Developer. All Rights Reserved.
|
|
|
|
-
|
|
|
|
- Contributor(s):
|
|
|
|
- Gavin Sharp <gavin@gavinsharp.com> (original author)
|
2008-11-02 10:59:16 -08:00
|
|
|
- Ehsan Akhgari <ehsan.akhgari@gmail.com>
|
2007-07-09 09:24:15 -07:00
|
|
|
-
|
|
|
|
- Alternatively, the contents of this file may be used under the terms of
|
|
|
|
- either the GNU General Public License Version 2 or later (the "GPL"), or
|
|
|
|
- the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
|
|
|
|
- in which case the provisions of the GPL or the LGPL are applicable instead
|
|
|
|
- of those above. If you wish to allow use of your version of this file only
|
|
|
|
- under the terms of either the GPL or the LGPL, and not to allow others to
|
|
|
|
- use your version of this file under the terms of the MPL, indicate your
|
|
|
|
- decision by deleting the provisions above and replace them with the notice
|
|
|
|
- and other provisions required by the LGPL or the GPL. If you do not delete
|
|
|
|
- the provisions above, a recipient may use your version of this file under
|
|
|
|
- the terms of any one of the MPL, the GPL or the LGPL.
|
|
|
|
-
|
|
|
|
- ***** END LICENSE BLOCK ***** -->
|
|
|
|
|
|
|
|
<window id="browserTestHarness"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="TestStart();"
|
2009-01-16 11:19:25 -08:00
|
|
|
title="Browser chrome tests"
|
|
|
|
width="1024">
|
2007-07-09 09:24:15 -07:00
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
|
|
|
|
<script src="chrome://mochikit/content/tests/SimpleTest/quit.js"/>
|
2010-09-10 10:20:38 -07:00
|
|
|
<script src="chrome://mochikit/content/chrome-harness.js"/>
|
2008-10-30 09:13:24 -07:00
|
|
|
<style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
|
|
|
|
#results {
|
|
|
|
margin: 5px;
|
|
|
|
background-color: window;
|
|
|
|
-moz-user-select: text;
|
|
|
|
}
|
|
|
|
|
|
|
|
#summary {
|
2009-01-16 11:19:25 -08:00
|
|
|
color: white;
|
2008-10-30 09:13:24 -07:00
|
|
|
border: 2px solid black;
|
|
|
|
}
|
|
|
|
|
|
|
|
#summary.success {
|
2009-05-15 16:14:13 -07:00
|
|
|
background-color: #0d0;
|
2008-10-30 09:13:24 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
#summary.failure {
|
|
|
|
background-color: red;
|
|
|
|
}
|
|
|
|
|
2009-05-15 16:14:13 -07:00
|
|
|
#summary.todo {
|
|
|
|
background-color: orange;
|
|
|
|
}
|
|
|
|
|
2009-07-03 00:22:31 -07:00
|
|
|
.info {
|
|
|
|
color: grey;
|
|
|
|
}
|
|
|
|
|
2008-10-30 09:13:24 -07:00
|
|
|
.failed {
|
|
|
|
color: red;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.testHeader {
|
|
|
|
margin-top: 1em;
|
|
|
|
}
|
|
|
|
|
|
|
|
p {
|
|
|
|
margin: 0.1em;
|
|
|
|
}
|
|
|
|
]]></style>
|
2007-07-09 09:24:15 -07:00
|
|
|
<script type="application/javascript;version=1.7"><![CDATA[
|
2010-09-10 10:20:38 -07:00
|
|
|
if (Cc === undefined) {
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
}
|
|
|
|
|
2007-07-09 09:24:15 -07:00
|
|
|
var gConfig;
|
2009-06-11 10:47:37 -07:00
|
|
|
|
|
|
|
var gDumper = {
|
|
|
|
get fileLogger() {
|
|
|
|
let logger = null;
|
|
|
|
if (gConfig.logPath) {
|
|
|
|
try {
|
|
|
|
MozillaFileLogger.init(gConfig.logPath);
|
|
|
|
logger = MozillaFileLogger;
|
|
|
|
} catch (ex) {
|
|
|
|
dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " +
|
|
|
|
"Error trying to log to " + gConfig.logPath + ": " + ex + "\n");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
delete this.fileLogger;
|
|
|
|
return this.fileLogger = logger;
|
|
|
|
},
|
|
|
|
|
|
|
|
dump: function (str) {
|
|
|
|
dump(str);
|
|
|
|
|
|
|
|
if (this.fileLogger)
|
|
|
|
this.fileLogger._foStream.write(str, str.length);
|
|
|
|
},
|
|
|
|
|
|
|
|
done: function () {
|
|
|
|
if (this.fileLogger)
|
|
|
|
this.fileLogger.close();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2007-07-09 09:24:15 -07:00
|
|
|
function TestStart() {
|
|
|
|
gConfig = readConfig();
|
|
|
|
|
2007-09-27 15:11:05 -07:00
|
|
|
// If MochiTest was started with the --test-path flag specifying a subset
|
|
|
|
// of tests to run, put that path in the label of the "Run Tests" button
|
|
|
|
// so the tester knows which tests will run when they press that button.
|
|
|
|
if (gConfig.testPath)
|
|
|
|
document.getElementById("runTestsButton").label =
|
2009-01-16 11:19:25 -08:00
|
|
|
"Run " + gConfig.testPath + " tests";
|
2007-09-27 15:11:05 -07:00
|
|
|
|
2007-07-09 09:24:15 -07:00
|
|
|
if (gConfig.autoRun)
|
2009-06-11 10:47:37 -07:00
|
|
|
setTimeout(runTests, 0);
|
2007-07-09 09:24:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function readConfig() {
|
|
|
|
var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
|
|
|
|
getService(Ci.nsIProperties);
|
|
|
|
var configFile = fileLocator.get("ProfD", Ci.nsIFile);
|
|
|
|
configFile.append("testConfig.js");
|
|
|
|
|
|
|
|
if (!configFile.exists())
|
|
|
|
return;
|
|
|
|
|
|
|
|
var fileInStream = Cc["@mozilla.org/network/file-input-stream;1"].
|
|
|
|
createInstance(Ci.nsIFileInputStream);
|
|
|
|
var sstream = Cc["@mozilla.org/scriptableinputstream;1"].
|
|
|
|
createInstance(Ci.nsIScriptableInputStream);
|
|
|
|
fileInStream.init(configFile, -1, 0, 0);
|
|
|
|
sstream.init(fileInStream);
|
|
|
|
|
|
|
|
var config = "";
|
|
|
|
var str = sstream.read(4096);
|
|
|
|
while (str.length > 0) {
|
|
|
|
config += str;
|
|
|
|
str = sstream.read(4096);
|
|
|
|
}
|
|
|
|
|
|
|
|
sstream.close();
|
|
|
|
fileInStream.close();
|
|
|
|
|
|
|
|
return eval(config);
|
|
|
|
}
|
|
|
|
|
2009-06-11 10:47:37 -07:00
|
|
|
function browserTest(aTestFile) {
|
2007-07-09 09:24:15 -07:00
|
|
|
this.path = aTestFile;
|
2009-06-11 10:47:37 -07:00
|
|
|
this.dumper = gDumper;
|
|
|
|
this.results = [];
|
2007-07-09 09:24:15 -07:00
|
|
|
this.scope = null;
|
2010-10-19 12:20:49 -07:00
|
|
|
this.duration = 0;
|
2007-07-09 09:24:15 -07:00
|
|
|
}
|
2009-06-11 10:47:37 -07:00
|
|
|
browserTest.prototype = {
|
2007-07-12 07:29:33 -07:00
|
|
|
get passCount() {
|
2009-07-03 00:22:31 -07:00
|
|
|
return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
|
2007-07-12 07:29:33 -07:00
|
|
|
},
|
|
|
|
get todoCount() {
|
2009-07-03 00:22:31 -07:00
|
|
|
return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
|
2007-07-12 07:29:33 -07:00
|
|
|
},
|
|
|
|
get failCount() {
|
2009-07-03 00:22:31 -07:00
|
|
|
return this.results.filter(function (t) !t.info && !t.pass).length;
|
2007-07-09 09:24:15 -07:00
|
|
|
},
|
2009-06-11 10:47:37 -07:00
|
|
|
|
|
|
|
addResult: function addResult(result) {
|
|
|
|
this.results.push(result);
|
|
|
|
|
|
|
|
this.dumper.dump(result.result + " | " + this.path + " | " + result.msg + "\n");
|
2008-10-30 09:13:24 -07:00
|
|
|
},
|
2009-06-11 10:47:37 -07:00
|
|
|
|
2010-10-19 12:20:49 -07:00
|
|
|
setDuration: function setDuration(duration) {
|
|
|
|
this.duration = duration;
|
|
|
|
},
|
|
|
|
|
2008-10-30 09:13:24 -07:00
|
|
|
get htmlLog() {
|
2008-11-02 10:59:16 -08:00
|
|
|
let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"].
|
|
|
|
getService(Ci.mozITXTToHTMLConv);
|
|
|
|
function _entityEncode(str) {
|
|
|
|
return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
|
|
|
|
}
|
2009-06-11 10:47:37 -07:00
|
|
|
var path = _entityEncode(this.path);
|
2010-10-19 12:20:49 -07:00
|
|
|
var html = this.results.map(function (t) {
|
2009-07-03 00:22:31 -07:00
|
|
|
var class = t.info ? "info" : "result " + (t.pass ? "passed" : "failed");
|
|
|
|
return "<p class=\"" + class + "\">" + t.result + " | " + path +
|
|
|
|
" | " + _entityEncode(t.msg) + "</p>";
|
|
|
|
}).join("\n");
|
2010-10-19 12:20:49 -07:00
|
|
|
if (this.duration) {
|
|
|
|
html += "<p class=\"info\">TEST-END | " + path + " | finished in " +
|
2010-10-20 13:35:22 -07:00
|
|
|
this.duration + " ms</p>";
|
2010-10-19 12:20:49 -07:00
|
|
|
}
|
|
|
|
return html;
|
2007-07-09 09:24:15 -07:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-11 10:47:37 -07:00
|
|
|
// Returns an array of browserTest objects for all the selected tests
|
2007-07-09 09:24:15 -07:00
|
|
|
function listTests() {
|
2010-09-30 17:10:19 -07:00
|
|
|
var baseURL = 'chrome://mochitests/content';
|
|
|
|
var testsURI = Components.classes["@mozilla.org/file/directory_service;1"]
|
|
|
|
.getService(Components.interfaces.nsIProperties)
|
|
|
|
.get("ProfD", Components.interfaces.nsILocalFile);
|
|
|
|
testsURI.append("tests.manifest");
|
|
|
|
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"].
|
|
|
|
getService(Components.interfaces.nsIIOService);
|
|
|
|
var manifestFile = ioSvc.newFileURI(testsURI)
|
|
|
|
.QueryInterface(Components.interfaces.nsIFileURL).file;
|
|
|
|
|
|
|
|
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
|
|
|
|
autoRegister(manifestFile);
|
2007-07-09 09:24:15 -07:00
|
|
|
|
2009-01-16 11:19:25 -08:00
|
|
|
// load server.js in so we can share template functions
|
2007-07-09 09:24:15 -07:00
|
|
|
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
|
|
|
getService(Ci.mozIJSSubScriptLoader);
|
|
|
|
var srvScope = {};
|
2010-09-10 10:20:38 -07:00
|
|
|
scriptLoader.loadSubScript('chrome://mochikit/content/server.js', srvScope);
|
|
|
|
|
2010-09-30 17:10:19 -07:00
|
|
|
var jar = getJar(baseURL);
|
|
|
|
if (jar != null) {
|
|
|
|
var [links, singleTestPath] = getMochitestJarListing(baseURL, gConfig.testPath, "browser");
|
|
|
|
} else {
|
|
|
|
var [links, singleTestPath] = getFileListing(baseURL, gConfig.testPath, "browser", srvScope);
|
|
|
|
}
|
2007-07-09 09:24:15 -07:00
|
|
|
|
|
|
|
var fileNames = [];
|
2010-09-10 10:20:38 -07:00
|
|
|
var fileNameRegexp = /browser_.+\.js$/;
|
2009-01-16 11:19:25 -08:00
|
|
|
srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
|
2009-06-11 10:47:37 -07:00
|
|
|
return fileNames.map(function (f) new browserTest(f));
|
2007-07-09 09:24:15 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function setStatus(aStatusString) {
|
|
|
|
document.getElementById("status").value = aStatusString;
|
|
|
|
}
|
|
|
|
|
2009-06-11 10:47:37 -07:00
|
|
|
function runTests() {
|
2007-07-09 09:24:15 -07:00
|
|
|
var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
|
|
|
var testWin = windowMediator.getMostRecentWindow("navigator:browser");
|
|
|
|
|
|
|
|
setStatus("Running...");
|
|
|
|
testWin.focus();
|
2009-06-11 10:47:37 -07:00
|
|
|
var Tester = new testWin.Tester(listTests(), gDumper, testsFinished);
|
2007-07-09 09:24:15 -07:00
|
|
|
Tester.start();
|
|
|
|
}
|
|
|
|
|
2009-01-16 11:19:25 -08:00
|
|
|
function sum(a, b) {
|
|
|
|
return a + b;
|
|
|
|
}
|
|
|
|
|
2008-10-30 09:13:24 -07:00
|
|
|
function getHTMLLogFromTests(aTests) {
|
2009-01-16 11:19:25 -08:00
|
|
|
if (!aTests.length)
|
2009-05-15 16:14:13 -07:00
|
|
|
return "<div id=\"summary\" class=\"failure\">No tests to run." +
|
|
|
|
" Did you pass an invalid --test-path?</div>";
|
2009-01-16 11:19:25 -08:00
|
|
|
|
2008-10-30 09:13:24 -07:00
|
|
|
var log = "";
|
|
|
|
|
|
|
|
var passCount = aTests.map(function (f) f.passCount).reduce(sum);
|
|
|
|
var failCount = aTests.map(function (f) f.failCount).reduce(sum);
|
|
|
|
var todoCount = aTests.map(function (f) f.todoCount).reduce(sum);
|
|
|
|
log += "<div id=\"summary\" class=\"";
|
2009-05-15 16:14:13 -07:00
|
|
|
log += failCount != 0 ? "failure" :
|
|
|
|
passCount == 0 ? "todo" : "success";
|
2008-10-30 09:13:24 -07:00
|
|
|
log += "\">\n<p>Passed: " + passCount + "</p>\n" +
|
|
|
|
"<p>Failed: " + failCount + "</p>\n" +
|
|
|
|
"<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
|
|
|
|
|
|
|
|
return log + aTests.map(function (f) {
|
2009-05-15 16:14:13 -07:00
|
|
|
return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog;
|
2008-10-30 09:13:24 -07:00
|
|
|
}).join("\n") + "</div>";
|
|
|
|
}
|
|
|
|
|
2007-07-09 09:24:15 -07:00
|
|
|
function testsFinished(aTests) {
|
|
|
|
// Focus our window, to display the results
|
|
|
|
window.focus();
|
|
|
|
|
|
|
|
if (gConfig.closeWhenDone) {
|
|
|
|
goQuitApplication();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UI
|
2008-10-30 09:13:24 -07:00
|
|
|
document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
|
2007-07-09 09:24:15 -07:00
|
|
|
setStatus("Done.");
|
|
|
|
}
|
|
|
|
]]></script>
|
2009-07-07 03:40:49 -07:00
|
|
|
<button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/>
|
2007-07-09 09:24:15 -07:00
|
|
|
<label id="status"/>
|
2008-10-30 09:13:24 -07:00
|
|
|
<scrollbox flex="1" style="overflow: auto" align="stretch">
|
2009-01-16 11:19:25 -08:00
|
|
|
<div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/>
|
2008-10-30 09:13:24 -07:00
|
|
|
</scrollbox>
|
2007-07-09 09:24:15 -07:00
|
|
|
</window>
|