2007-07-09 20:24:15 +04:00
|
|
|
<?xml version="1.0"?>
|
|
|
|
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
|
2012-05-21 15:12:37 +04:00
|
|
|
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
2007-07-09 20:24:15 +04:00
|
|
|
|
|
|
|
<window id="browserTestHarness"
|
|
|
|
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
|
|
|
|
onload="TestStart();"
|
2009-01-16 22:19:25 +03:00
|
|
|
title="Browser chrome tests"
|
|
|
|
width="1024">
|
2013-01-12 04:40:28 +04:00
|
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/>
|
|
|
|
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/LogController.js"/>
|
|
|
|
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"/>
|
2008-10-30 19:13:24 +03:00
|
|
|
<style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[
|
|
|
|
#results {
|
|
|
|
margin: 5px;
|
|
|
|
background-color: window;
|
|
|
|
-moz-user-select: text;
|
|
|
|
}
|
|
|
|
|
|
|
|
#summary {
|
2009-01-16 22:19:25 +03:00
|
|
|
color: white;
|
2008-10-30 19:13:24 +03:00
|
|
|
border: 2px solid black;
|
|
|
|
}
|
|
|
|
|
|
|
|
#summary.success {
|
2009-05-16 03:14:13 +04:00
|
|
|
background-color: #0d0;
|
2008-10-30 19:13:24 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
#summary.failure {
|
|
|
|
background-color: red;
|
|
|
|
}
|
|
|
|
|
2009-05-16 03:14:13 +04:00
|
|
|
#summary.todo {
|
|
|
|
background-color: orange;
|
|
|
|
}
|
|
|
|
|
2009-07-03 11:22:31 +04:00
|
|
|
.info {
|
|
|
|
color: grey;
|
|
|
|
}
|
|
|
|
|
2008-10-30 19:13:24 +03:00
|
|
|
.failed {
|
|
|
|
color: red;
|
|
|
|
font-weight: bold;
|
|
|
|
}
|
|
|
|
|
|
|
|
.testHeader {
|
|
|
|
margin-top: 1em;
|
|
|
|
}
|
|
|
|
|
|
|
|
p {
|
|
|
|
margin: 0.1em;
|
|
|
|
}
|
2011-05-10 21:27:11 +04:00
|
|
|
|
|
|
|
a {
|
|
|
|
color: blue;
|
|
|
|
text-decoration: underline;
|
|
|
|
}
|
2008-10-30 19:13:24 +03:00
|
|
|
]]></style>
|
2007-07-09 20:24:15 +04:00
|
|
|
<script type="application/javascript;version=1.7"><![CDATA[
|
2010-09-10 21:20:38 +04:00
|
|
|
if (Cc === undefined) {
|
|
|
|
var Cc = Components.classes;
|
|
|
|
var Ci = Components.interfaces;
|
|
|
|
}
|
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
var gConfig;
|
2009-06-11 21:47:37 +04:00
|
|
|
|
|
|
|
var gDumper = {
|
|
|
|
get fileLogger() {
|
|
|
|
let logger = null;
|
2011-05-17 21:10:37 +04:00
|
|
|
if (gConfig.logFile) {
|
2009-06-11 21:47:37 +04:00
|
|
|
try {
|
2011-07-19 06:10:29 +04:00
|
|
|
logger = new MozillaFileLogger(gConfig.logFile)
|
2009-06-11 21:47:37 +04:00
|
|
|
} catch (ex) {
|
|
|
|
dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " +
|
2011-05-17 21:10:37 +04:00
|
|
|
"Error trying to log to " + gConfig.logFile + ": " + ex + "\n");
|
2009-06-11 21:47:37 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
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 20:24:15 +04:00
|
|
|
function TestStart() {
|
|
|
|
gConfig = readConfig();
|
|
|
|
|
2007-09-28 02:11:05 +04: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 22:19:25 +03:00
|
|
|
"Run " + gConfig.testPath + " tests";
|
2007-09-28 02:11:05 +04:00
|
|
|
|
2011-05-17 21:10:37 +04:00
|
|
|
if (gConfig.autorun)
|
2009-06-11 21:47:37 +04:00
|
|
|
setTimeout(runTests, 0);
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
|
2011-05-10 21:27:11 +04:00
|
|
|
var gErrorCount = 0;
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
function browserTest(aTestFile) {
|
2007-07-09 20:24:15 +04:00
|
|
|
this.path = aTestFile;
|
2009-06-11 21:47:37 +04:00
|
|
|
this.dumper = gDumper;
|
|
|
|
this.results = [];
|
2007-07-09 20:24:15 +04:00
|
|
|
this.scope = null;
|
2010-10-19 23:20:49 +04:00
|
|
|
this.duration = 0;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
2009-06-11 21:47:37 +04:00
|
|
|
browserTest.prototype = {
|
2007-07-12 18:29:33 +04:00
|
|
|
get passCount() {
|
2009-07-03 11:22:31 +04:00
|
|
|
return this.results.filter(function (t) !t.info && !t.todo && t.pass).length;
|
2007-07-12 18:29:33 +04:00
|
|
|
},
|
|
|
|
get todoCount() {
|
2009-07-03 11:22:31 +04:00
|
|
|
return this.results.filter(function (t) !t.info && t.todo && t.pass).length;
|
2007-07-12 18:29:33 +04:00
|
|
|
},
|
|
|
|
get failCount() {
|
2009-07-03 11:22:31 +04:00
|
|
|
return this.results.filter(function (t) !t.info && !t.pass).length;
|
2007-07-09 20:24:15 +04:00
|
|
|
},
|
2009-06-11 21:47:37 +04:00
|
|
|
|
|
|
|
addResult: function addResult(result) {
|
|
|
|
this.results.push(result);
|
|
|
|
|
|
|
|
this.dumper.dump(result.result + " | " + this.path + " | " + result.msg + "\n");
|
2008-10-30 19:13:24 +03:00
|
|
|
},
|
2009-06-11 21:47:37 +04:00
|
|
|
|
2010-10-19 23:20:49 +04:00
|
|
|
setDuration: function setDuration(duration) {
|
|
|
|
this.duration = duration;
|
|
|
|
},
|
|
|
|
|
2008-10-30 19:13:24 +03:00
|
|
|
get htmlLog() {
|
2008-11-02 21:59:16 +03:00
|
|
|
let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"].
|
|
|
|
getService(Ci.mozITXTToHTMLConv);
|
|
|
|
function _entityEncode(str) {
|
|
|
|
return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities);
|
|
|
|
}
|
2009-06-11 21:47:37 +04:00
|
|
|
var path = _entityEncode(this.path);
|
2010-10-19 23:20:49 +04:00
|
|
|
var html = this.results.map(function (t) {
|
2011-01-23 04:46:22 +03:00
|
|
|
var classname = t.info ? "info" : "result " + (t.pass ? "passed" : "failed");
|
2011-05-10 21:27:11 +04:00
|
|
|
var text = t.result + " | " + path + " | " + _entityEncode(t.msg);
|
|
|
|
if (!t.info && !t.pass) {
|
|
|
|
return '<p class="' + classname + '" id=\"ERROR' + (gErrorCount++) + '">' +
|
|
|
|
text + " <a href=\"javascript:scrollTo('ERROR" + gErrorCount + "')\">NEXT ERROR</a></p>";
|
|
|
|
}
|
|
|
|
return '<p class="' + classname + '">' + text + "</p>";
|
2009-07-03 11:22:31 +04:00
|
|
|
}).join("\n");
|
2010-10-19 23:20:49 +04:00
|
|
|
if (this.duration) {
|
|
|
|
html += "<p class=\"info\">TEST-END | " + path + " | finished in " +
|
2010-10-21 00:35:22 +04:00
|
|
|
this.duration + " ms</p>";
|
2010-10-19 23:20:49 +04:00
|
|
|
}
|
|
|
|
return html;
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
// Returns an array of browserTest objects for all the selected tests
|
2007-07-09 20:24:15 +04:00
|
|
|
function listTests() {
|
2011-05-17 21:10:37 +04:00
|
|
|
[links, singleTestPath] = getTestList();
|
2011-05-20 19:54:01 +04:00
|
|
|
if (!links)
|
|
|
|
return [];
|
2007-07-09 20:24:15 +04:00
|
|
|
|
2009-01-16 22:19:25 +03:00
|
|
|
// load server.js in so we can share template functions
|
2007-07-09 20:24:15 +04:00
|
|
|
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
|
2011-05-17 21:10:37 +04:00
|
|
|
getService(Ci.mozIJSSubScriptLoader);
|
2007-07-09 20:24:15 +04:00
|
|
|
var srvScope = {};
|
2011-05-17 21:10:37 +04:00
|
|
|
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
|
|
|
|
srvScope);
|
2007-07-09 20:24:15 +04:00
|
|
|
|
|
|
|
var fileNames = [];
|
2010-09-10 21:20:38 +04:00
|
|
|
var fileNameRegexp = /browser_.+\.js$/;
|
2009-01-16 22:19:25 +03:00
|
|
|
srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp);
|
2009-06-11 21:47:37 +04:00
|
|
|
return fileNames.map(function (f) new browserTest(f));
|
2007-07-09 20:24:15 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
function setStatus(aStatusString) {
|
|
|
|
document.getElementById("status").value = aStatusString;
|
|
|
|
}
|
|
|
|
|
2009-06-11 21:47:37 +04:00
|
|
|
function runTests() {
|
2007-07-09 20:24:15 +04:00
|
|
|
var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1'].
|
|
|
|
getService(Ci.nsIWindowMediator);
|
2012-06-30 02:52:43 +04:00
|
|
|
var winType = gConfig.testRoot == "browser" ? "navigator:browser" :
|
2013-02-13 00:51:24 +04:00
|
|
|
gConfig.testRoot == "metro" ? "navigator:browser" :
|
2012-06-30 02:52:43 +04:00
|
|
|
gConfig.testRoot == "webapprtChrome" ? "webapprt:webapp" :
|
|
|
|
null;
|
|
|
|
if (!winType) {
|
|
|
|
throw new Error("Unrecognized gConfig.testRoot: " + gConfig.testRoot);
|
|
|
|
}
|
|
|
|
var testWin = windowMediator.getMostRecentWindow(winType);
|
2007-07-09 20:24:15 +04:00
|
|
|
|
|
|
|
setStatus("Running...");
|
|
|
|
testWin.focus();
|
2009-06-11 21:47:37 +04:00
|
|
|
var Tester = new testWin.Tester(listTests(), gDumper, testsFinished);
|
2007-07-09 20:24:15 +04:00
|
|
|
Tester.start();
|
|
|
|
}
|
|
|
|
|
2009-01-16 22:19:25 +03:00
|
|
|
function sum(a, b) {
|
|
|
|
return a + b;
|
|
|
|
}
|
|
|
|
|
2008-10-30 19:13:24 +03:00
|
|
|
function getHTMLLogFromTests(aTests) {
|
2009-01-16 22:19:25 +03:00
|
|
|
if (!aTests.length)
|
2009-05-16 03:14:13 +04:00
|
|
|
return "<div id=\"summary\" class=\"failure\">No tests to run." +
|
|
|
|
" Did you pass an invalid --test-path?</div>";
|
2009-01-16 22:19:25 +03:00
|
|
|
|
2008-10-30 19:13:24 +03: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-16 03:14:13 +04:00
|
|
|
log += failCount != 0 ? "failure" :
|
|
|
|
passCount == 0 ? "todo" : "success";
|
2008-10-30 19:13:24 +03:00
|
|
|
log += "\">\n<p>Passed: " + passCount + "</p>\n" +
|
2011-05-10 21:27:11 +04:00
|
|
|
"<p>Failed: " + failCount;
|
|
|
|
if (failCount > 0)
|
|
|
|
log += " <a href=\"javascript:scrollTo('ERROR0')\">NEXT ERROR</a>";
|
|
|
|
log += "</p>\n" +
|
2008-10-30 19:13:24 +03:00
|
|
|
"<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n";
|
|
|
|
|
|
|
|
return log + aTests.map(function (f) {
|
2009-05-16 03:14:13 +04:00
|
|
|
return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog;
|
2008-10-30 19:13:24 +03:00
|
|
|
}).join("\n") + "</div>";
|
|
|
|
}
|
|
|
|
|
2007-07-09 20:24:15 +04:00
|
|
|
function testsFinished(aTests) {
|
|
|
|
// Focus our window, to display the results
|
|
|
|
window.focus();
|
|
|
|
|
|
|
|
if (gConfig.closeWhenDone) {
|
2011-10-14 15:52:02 +04:00
|
|
|
let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup);
|
|
|
|
appStartup.quit(Ci.nsIAppStartup.eForceQuit);
|
2007-07-09 20:24:15 +04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// UI
|
2008-10-30 19:13:24 +03:00
|
|
|
document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests);
|
2007-07-09 20:24:15 +04:00
|
|
|
setStatus("Done.");
|
|
|
|
}
|
2011-05-10 21:27:11 +04:00
|
|
|
|
|
|
|
function scrollTo(id) {
|
|
|
|
var line = document.getElementById(id);
|
|
|
|
if (!line)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var boxObject = document.getElementById("results").parentNode.boxObject;
|
|
|
|
boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject);
|
|
|
|
boxObject.scrollToElement(line);
|
|
|
|
}
|
2007-07-09 20:24:15 +04:00
|
|
|
]]></script>
|
2009-07-07 14:40:49 +04:00
|
|
|
<button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/>
|
2007-07-09 20:24:15 +04:00
|
|
|
<label id="status"/>
|
2008-10-30 19:13:24 +03:00
|
|
|
<scrollbox flex="1" style="overflow: auto" align="stretch">
|
2009-01-16 22:19:25 +03:00
|
|
|
<div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/>
|
2008-10-30 19:13:24 +03:00
|
|
|
</scrollbox>
|
2007-07-09 20:24:15 +04:00
|
|
|
</window>
|