michael@0: /* -*- js-indent-level: 2; tab-width: 2; indent-tabs-mode: nil -*- */ michael@0: /* vim:set ts=2 sw=2 sts=2 et: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: TestRunner.logEnabled = true; michael@0: TestRunner.logger = LogController; michael@0: michael@0: /* Helper function */ michael@0: parseQueryString = function(encodedString, useArrays) { michael@0: // strip a leading '?' from the encoded string michael@0: var qstr = (encodedString[0] == "?") ? encodedString.substring(1) : michael@0: encodedString; michael@0: var pairs = qstr.replace(/\+/g, "%20").split(/(\&\;|\&\#38\;|\&|\&)/); michael@0: var o = {}; michael@0: var decode; michael@0: if (typeof(decodeURIComponent) != "undefined") { michael@0: decode = decodeURIComponent; michael@0: } else { michael@0: decode = unescape; michael@0: } michael@0: if (useArrays) { michael@0: for (var i = 0; i < pairs.length; i++) { michael@0: var pair = pairs[i].split("="); michael@0: if (pair.length !== 2) { michael@0: continue; michael@0: } michael@0: var name = decode(pair[0]); michael@0: var arr = o[name]; michael@0: if (!(arr instanceof Array)) { michael@0: arr = []; michael@0: o[name] = arr; michael@0: } michael@0: arr.push(decode(pair[1])); michael@0: } michael@0: } else { michael@0: for (i = 0; i < pairs.length; i++) { michael@0: pair = pairs[i].split("="); michael@0: if (pair.length !== 2) { michael@0: continue; michael@0: } michael@0: o[decode(pair[0])] = decode(pair[1]); michael@0: } michael@0: } michael@0: return o; michael@0: }; michael@0: michael@0: // Check the query string for arguments michael@0: var params = parseQueryString(location.search.substring(1), true); michael@0: michael@0: var config = {}; michael@0: if (window.readConfig) { michael@0: config = readConfig(); michael@0: } michael@0: michael@0: if (config.testRoot == "chrome" || config.testRoot == "a11y") { michael@0: for (p in params) { michael@0: if (params[p] == 1) { michael@0: config[p] = true; michael@0: } else if (params[p] == 0) { michael@0: config[p] = false; michael@0: } else { michael@0: config[p] = params[p]; michael@0: } michael@0: } michael@0: params = config; michael@0: params.baseurl = "chrome://mochitests/content"; michael@0: } else { michael@0: params.baseurl = ""; michael@0: } michael@0: michael@0: if (params.testRoot == "browser") { michael@0: params.testPrefix = "chrome://mochitests/content/browser/"; michael@0: } else if (params.testRoot == "chrome") { michael@0: params.testPrefix = "chrome://mochitests/content/chrome/"; michael@0: } else if (params.testRoot == "a11y") { michael@0: params.testPrefix = "chrome://mochitests/content/a11y/"; michael@0: } else { michael@0: params.testPrefix = "/tests/"; michael@0: } michael@0: michael@0: // set the per-test timeout if specified in the query string michael@0: if (params.timeout) { michael@0: TestRunner.timeout = parseInt(params.timeout) * 1000; michael@0: } michael@0: michael@0: // log levels for console and logfile michael@0: var fileLevel = params.fileLevel || null; michael@0: var consoleLevel = params.consoleLevel || null; michael@0: michael@0: // repeat tells us how many times to repeat the tests michael@0: if (params.repeat) { michael@0: TestRunner.repeat = params.repeat; michael@0: } michael@0: michael@0: if (params.runUntilFailure) { michael@0: TestRunner.runUntilFailure = true; michael@0: } michael@0: michael@0: // closeWhenDone tells us to close the browser when complete michael@0: if (params.closeWhenDone) { michael@0: TestRunner.onComplete = SpecialPowers.quit; michael@0: } michael@0: michael@0: if (params.failureFile) { michael@0: TestRunner.setFailureFile(params.failureFile); michael@0: } michael@0: michael@0: // Breaks execution and enters the JS debugger on a test failure michael@0: if (params.debugOnFailure) { michael@0: TestRunner.debugOnFailure = true; michael@0: } michael@0: michael@0: // logFile to write our results michael@0: if (params.logFile) { michael@0: var spl = new SpecialPowersLogger(params.logFile); michael@0: TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback()); michael@0: } michael@0: michael@0: // A temporary hack for android 4.0 where Fennec utilizes the pandaboard so much it reboots michael@0: if (params.runSlower) { michael@0: TestRunner.runSlower = true; michael@0: } michael@0: michael@0: if (params.dumpOutputDirectory) { michael@0: TestRunner.dumpOutputDirectory = params.dumpOutputDirectory; michael@0: } michael@0: michael@0: if (params.dumpAboutMemoryAfterTest) { michael@0: TestRunner.dumpAboutMemoryAfterTest = true; michael@0: } michael@0: michael@0: if (params.dumpDMDAfterTest) { michael@0: TestRunner.dumpDMDAfterTest = true; michael@0: } michael@0: michael@0: if (params.quiet) { michael@0: TestRunner.quiet = true; michael@0: } michael@0: michael@0: // Log things to the console if appropriate. michael@0: TestRunner.logger.addListener("dumpListener", consoleLevel + "", function(msg) { michael@0: dump(msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"); michael@0: }); michael@0: michael@0: var gTestList = []; michael@0: var RunSet = {} michael@0: RunSet.runall = function(e) { michael@0: // Filter tests to include|exclude tests based on data in params.filter. michael@0: // This allows for including or excluding tests from the gTestList michael@0: if (params.testManifest) { michael@0: getTestManifest("http://mochi.test:8888/" + params.testManifest, params, function(filter) { gTestList = filterTests(filter, gTestList, params.runOnly); RunSet.runtests(); }); michael@0: } else { michael@0: RunSet.runtests(); michael@0: } michael@0: } michael@0: michael@0: RunSet.runtests = function(e) { michael@0: // Which tests we're going to run michael@0: var my_tests = gTestList; michael@0: michael@0: if (params.startAt || params.endAt) { michael@0: my_tests = skipTests(my_tests, params.startAt, params.endAt); michael@0: } michael@0: michael@0: if (params.totalChunks && params.thisChunk) { michael@0: my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger); michael@0: } michael@0: michael@0: if (params.shuffle) { michael@0: for (var i = my_tests.length-1; i > 0; --i) { michael@0: var j = Math.floor(Math.random() * i); michael@0: var tmp = my_tests[j]; michael@0: my_tests[j] = my_tests[i]; michael@0: my_tests[i] = tmp; michael@0: } michael@0: } michael@0: TestRunner.runTests(my_tests); michael@0: } michael@0: michael@0: RunSet.reloadAndRunAll = function(e) { michael@0: e.preventDefault(); michael@0: //window.location.hash = ""; michael@0: var addParam = ""; michael@0: if (params.autorun) { michael@0: window.location.search += ""; michael@0: window.location.href = window.location.href; michael@0: } else if (window.location.search) { michael@0: window.location.href += "&autorun=1"; michael@0: } else { michael@0: window.location.href += "?autorun=1"; michael@0: } michael@0: }; michael@0: michael@0: // UI Stuff michael@0: function toggleVisible(elem) { michael@0: toggleElementClass("invisible", elem); michael@0: } michael@0: michael@0: function makeVisible(elem) { michael@0: removeElementClass(elem, "invisible"); michael@0: } michael@0: michael@0: function makeInvisible(elem) { michael@0: addElementClass(elem, "invisible"); michael@0: } michael@0: michael@0: function isVisible(elem) { michael@0: // you may also want to check for michael@0: // getElement(elem).style.display == "none" michael@0: return !hasElementClass(elem, "invisible"); michael@0: }; michael@0: michael@0: function toggleNonTests (e) { michael@0: e.preventDefault(); michael@0: var elems = document.getElementsByClassName("non-test"); michael@0: for (var i="0"; i 0) { michael@0: gTestList = testList; michael@0: } else { michael@0: gTestList = []; michael@0: for (var obj in testList) { michael@0: gTestList.push(obj); michael@0: } michael@0: } michael@0: michael@0: document.getElementById('runtests').onclick = RunSet.reloadAndRunAll; michael@0: document.getElementById('toggleNonTests').onclick = toggleNonTests; michael@0: // run automatically if autorun specified michael@0: if (params.autorun) { michael@0: RunSet.runall(); michael@0: } michael@0: }