2014-03-05 17:39:46 +00:00
|
|
|
/* -*- js-indent-level: 2; tab-width: 2; indent-tabs-mode: nil -*- */
|
2007-01-26 18:44:58 +00:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 11:12:37 +00: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-01-26 18:44:58 +00:00
|
|
|
|
|
|
|
TestRunner.logEnabled = true;
|
2011-08-12 16:21:35 +00:00
|
|
|
TestRunner.logger = LogController;
|
|
|
|
|
|
|
|
/* Helper function */
|
|
|
|
parseQueryString = function(encodedString, useArrays) {
|
|
|
|
// strip a leading '?' from the encoded string
|
|
|
|
var qstr = (encodedString[0] == "?") ? encodedString.substring(1) :
|
|
|
|
encodedString;
|
|
|
|
var pairs = qstr.replace(/\+/g, "%20").split(/(\&\;|\&\#38\;|\&|\&)/);
|
|
|
|
var o = {};
|
|
|
|
var decode;
|
|
|
|
if (typeof(decodeURIComponent) != "undefined") {
|
|
|
|
decode = decodeURIComponent;
|
|
|
|
} else {
|
|
|
|
decode = unescape;
|
|
|
|
}
|
|
|
|
if (useArrays) {
|
|
|
|
for (var i = 0; i < pairs.length; i++) {
|
|
|
|
var pair = pairs[i].split("=");
|
|
|
|
if (pair.length !== 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
var name = decode(pair[0]);
|
|
|
|
var arr = o[name];
|
|
|
|
if (!(arr instanceof Array)) {
|
|
|
|
arr = [];
|
|
|
|
o[name] = arr;
|
|
|
|
}
|
|
|
|
arr.push(decode(pair[1]));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
for (i = 0; i < pairs.length; i++) {
|
|
|
|
pair = pairs[i].split("=");
|
|
|
|
if (pair.length !== 2) {
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
o[decode(pair[0])] = decode(pair[1]);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return o;
|
|
|
|
};
|
2007-01-26 18:44:58 +00:00
|
|
|
|
|
|
|
// Check the query string for arguments
|
|
|
|
var params = parseQueryString(location.search.substring(1), true);
|
|
|
|
|
2011-05-17 17:10:37 +00:00
|
|
|
var config = {};
|
|
|
|
if (window.readConfig) {
|
|
|
|
config = readConfig();
|
|
|
|
}
|
|
|
|
|
|
|
|
if (config.testRoot == "chrome" || config.testRoot == "a11y") {
|
|
|
|
for (p in params) {
|
|
|
|
if (params[p] == 1) {
|
|
|
|
config[p] = true;
|
|
|
|
} else if (params[p] == 0) {
|
|
|
|
config[p] = false;
|
|
|
|
} else {
|
|
|
|
config[p] = params[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params = config;
|
2013-08-02 12:48:06 +00:00
|
|
|
params.baseurl = "chrome://mochitests/content";
|
|
|
|
} else {
|
|
|
|
params.baseurl = "";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.testRoot == "browser") {
|
|
|
|
params.testPrefix = "chrome://mochitests/content/browser/";
|
|
|
|
} else if (params.testRoot == "chrome") {
|
|
|
|
params.testPrefix = "chrome://mochitests/content/chrome/";
|
|
|
|
} else if (params.testRoot == "a11y") {
|
|
|
|
params.testPrefix = "chrome://mochitests/content/a11y/";
|
|
|
|
} else {
|
|
|
|
params.testPrefix = "/tests/";
|
2011-05-17 17:10:37 +00:00
|
|
|
}
|
|
|
|
|
2009-10-16 20:23:30 +00:00
|
|
|
// set the per-test timeout if specified in the query string
|
|
|
|
if (params.timeout) {
|
|
|
|
TestRunner.timeout = parseInt(params.timeout) * 1000;
|
|
|
|
}
|
|
|
|
|
2007-01-26 18:44:58 +00:00
|
|
|
// log levels for console and logfile
|
|
|
|
var fileLevel = params.fileLevel || null;
|
|
|
|
var consoleLevel = params.consoleLevel || null;
|
|
|
|
|
2013-05-24 19:03:50 +00:00
|
|
|
// repeat tells us how many times to repeat the tests
|
2011-08-29 20:14:33 +00:00
|
|
|
if (params.repeat) {
|
|
|
|
TestRunner.repeat = params.repeat;
|
2011-07-14 21:39:17 +00:00
|
|
|
}
|
|
|
|
|
2013-05-24 19:03:50 +00:00
|
|
|
if (params.runUntilFailure) {
|
|
|
|
TestRunner.runUntilFailure = true;
|
|
|
|
}
|
|
|
|
|
2011-10-14 11:52:02 +00:00
|
|
|
// closeWhenDone tells us to close the browser when complete
|
2007-01-26 18:44:58 +00:00
|
|
|
if (params.closeWhenDone) {
|
2011-10-14 11:52:02 +00:00
|
|
|
TestRunner.onComplete = SpecialPowers.quit;
|
2007-01-26 18:44:58 +00:00
|
|
|
}
|
|
|
|
|
2012-02-20 14:59:04 +00:00
|
|
|
if (params.failureFile) {
|
2012-08-16 22:20:29 +00:00
|
|
|
TestRunner.setFailureFile(params.failureFile);
|
2012-02-20 14:59:04 +00:00
|
|
|
}
|
|
|
|
|
2013-11-01 19:23:34 +00:00
|
|
|
// Breaks execution and enters the JS debugger on a test failure
|
|
|
|
if (params.debugOnFailure) {
|
|
|
|
TestRunner.debugOnFailure = true;
|
|
|
|
}
|
|
|
|
|
2007-01-26 18:44:58 +00:00
|
|
|
// logFile to write our results
|
|
|
|
if (params.logFile) {
|
2012-08-16 22:20:29 +00:00
|
|
|
var spl = new SpecialPowersLogger(params.logFile);
|
2011-07-19 02:10:29 +00:00
|
|
|
TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback());
|
2007-01-26 18:44:58 +00:00
|
|
|
}
|
|
|
|
|
2012-11-28 15:23:11 +00:00
|
|
|
// A temporary hack for android 4.0 where Fennec utilizes the pandaboard so much it reboots
|
|
|
|
if (params.runSlower) {
|
|
|
|
TestRunner.runSlower = true;
|
|
|
|
}
|
|
|
|
|
2013-11-21 18:02:56 +00:00
|
|
|
if (params.dumpOutputDirectory) {
|
|
|
|
TestRunner.dumpOutputDirectory = params.dumpOutputDirectory;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.dumpAboutMemoryAfterTest) {
|
|
|
|
TestRunner.dumpAboutMemoryAfterTest = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
if (params.dumpDMDAfterTest) {
|
|
|
|
TestRunner.dumpDMDAfterTest = true;
|
|
|
|
}
|
|
|
|
|
2014-03-05 17:39:46 +00:00
|
|
|
// Log things to the console if appropriate.
|
|
|
|
TestRunner.logger.addListener("dumpListener", consoleLevel + "", function(msg) {
|
|
|
|
dump(msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n");
|
|
|
|
});
|
|
|
|
|
2007-01-26 18:44:58 +00:00
|
|
|
var gTestList = [];
|
|
|
|
var RunSet = {}
|
|
|
|
RunSet.runall = function(e) {
|
2011-09-26 11:41:17 +00:00
|
|
|
// Filter tests to include|exclude tests based on data in params.filter.
|
|
|
|
// This allows for including or excluding tests from the gTestList
|
2013-08-02 12:48:06 +00:00
|
|
|
if (params.testManifest) {
|
|
|
|
getTestManifest("http://mochi.test:8888/" + params.testManifest, params, function(filter) { gTestList = filterTests(filter, gTestList, params.runOnly); RunSet.runtests(); });
|
|
|
|
} else {
|
|
|
|
RunSet.runtests();
|
|
|
|
}
|
|
|
|
}
|
2011-09-26 11:41:17 +00:00
|
|
|
|
2013-08-02 12:48:06 +00:00
|
|
|
RunSet.runtests = function(e) {
|
2009-09-22 13:12:58 +00:00
|
|
|
// Which tests we're going to run
|
|
|
|
var my_tests = gTestList;
|
|
|
|
|
2013-10-28 19:24:55 +00:00
|
|
|
if (params.startAt || params.endAt) {
|
|
|
|
my_tests = skipTests(my_tests, params.startAt, params.endAt);
|
|
|
|
}
|
|
|
|
|
2009-09-22 13:12:58 +00:00
|
|
|
if (params.totalChunks && params.thisChunk) {
|
2013-06-16 15:19:47 +00:00
|
|
|
my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger);
|
2009-09-22 13:12:58 +00:00
|
|
|
}
|
2013-06-16 15:19:47 +00:00
|
|
|
|
2009-09-22 13:12:58 +00:00
|
|
|
if (params.shuffle) {
|
|
|
|
for (var i = my_tests.length-1; i > 0; --i) {
|
|
|
|
var j = Math.floor(Math.random() * i);
|
|
|
|
var tmp = my_tests[j];
|
|
|
|
my_tests[j] = my_tests[i];
|
|
|
|
my_tests[i] = tmp;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
TestRunner.runTests(my_tests);
|
2007-01-26 18:44:58 +00:00
|
|
|
}
|
2011-07-14 21:39:17 +00:00
|
|
|
|
2007-01-26 18:44:58 +00:00
|
|
|
RunSet.reloadAndRunAll = function(e) {
|
|
|
|
e.preventDefault();
|
|
|
|
//window.location.hash = "";
|
|
|
|
var addParam = "";
|
|
|
|
if (params.autorun) {
|
|
|
|
window.location.search += "";
|
|
|
|
window.location.href = window.location.href;
|
|
|
|
} else if (window.location.search) {
|
|
|
|
window.location.href += "&autorun=1";
|
|
|
|
} else {
|
|
|
|
window.location.href += "?autorun=1";
|
2011-07-14 21:39:17 +00:00
|
|
|
}
|
2007-01-26 18:44:58 +00:00
|
|
|
};
|
2011-09-26 11:41:17 +00:00
|
|
|
|
2007-01-26 18:44:58 +00:00
|
|
|
// UI Stuff
|
|
|
|
function toggleVisible(elem) {
|
|
|
|
toggleElementClass("invisible", elem);
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeVisible(elem) {
|
|
|
|
removeElementClass(elem, "invisible");
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeInvisible(elem) {
|
|
|
|
addElementClass(elem, "invisible");
|
|
|
|
}
|
|
|
|
|
|
|
|
function isVisible(elem) {
|
|
|
|
// you may also want to check for
|
|
|
|
// getElement(elem).style.display == "none"
|
|
|
|
return !hasElementClass(elem, "invisible");
|
|
|
|
};
|
|
|
|
|
|
|
|
function toggleNonTests (e) {
|
|
|
|
e.preventDefault();
|
2012-11-27 19:02:08 +00:00
|
|
|
var elems = document.getElementsByClassName("non-test");
|
2007-01-26 18:44:58 +00:00
|
|
|
for (var i="0"; i<elems.length; i++) {
|
|
|
|
toggleVisible(elems[i]);
|
|
|
|
}
|
|
|
|
if (isVisible(elems[0])) {
|
|
|
|
$("toggleNonTests").innerHTML = "Hide Non-Tests";
|
|
|
|
} else {
|
|
|
|
$("toggleNonTests").innerHTML = "Show Non-Tests";
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// hook up our buttons
|
|
|
|
function hookup() {
|
2013-08-02 12:48:06 +00:00
|
|
|
if (params.manifestFile) {
|
|
|
|
getTestManifest("http://mochi.test:8888/" + params.manifestFile, params, hookupTests);
|
|
|
|
} else {
|
|
|
|
hookupTests(gTestList);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function hookupTests(testList) {
|
|
|
|
if (testList.length > 0) {
|
|
|
|
gTestList = testList;
|
|
|
|
} else {
|
|
|
|
gTestList = [];
|
|
|
|
for (var obj in testList) {
|
|
|
|
gTestList.push(obj);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-08-12 16:21:35 +00:00
|
|
|
document.getElementById('runtests').onclick = RunSet.reloadAndRunAll;
|
|
|
|
document.getElementById('toggleNonTests').onclick = toggleNonTests;
|
2011-07-14 21:39:17 +00:00
|
|
|
// run automatically if autorun specified
|
2007-01-26 18:44:58 +00:00
|
|
|
if (params.autorun) {
|
|
|
|
RunSet.runall();
|
|
|
|
}
|
|
|
|
}
|