1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/testing/mochitest/tests/SimpleTest/setup.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,253 @@ 1.4 +/* -*- js-indent-level: 2; tab-width: 2; indent-tabs-mode: nil -*- */ 1.5 +/* vim:set ts=2 sw=2 sts=2 et: */ 1.6 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.7 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.8 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.9 + 1.10 +TestRunner.logEnabled = true; 1.11 +TestRunner.logger = LogController; 1.12 + 1.13 +/* Helper function */ 1.14 +parseQueryString = function(encodedString, useArrays) { 1.15 + // strip a leading '?' from the encoded string 1.16 + var qstr = (encodedString[0] == "?") ? encodedString.substring(1) : 1.17 + encodedString; 1.18 + var pairs = qstr.replace(/\+/g, "%20").split(/(\&\;|\&\#38\;|\&|\&)/); 1.19 + var o = {}; 1.20 + var decode; 1.21 + if (typeof(decodeURIComponent) != "undefined") { 1.22 + decode = decodeURIComponent; 1.23 + } else { 1.24 + decode = unescape; 1.25 + } 1.26 + if (useArrays) { 1.27 + for (var i = 0; i < pairs.length; i++) { 1.28 + var pair = pairs[i].split("="); 1.29 + if (pair.length !== 2) { 1.30 + continue; 1.31 + } 1.32 + var name = decode(pair[0]); 1.33 + var arr = o[name]; 1.34 + if (!(arr instanceof Array)) { 1.35 + arr = []; 1.36 + o[name] = arr; 1.37 + } 1.38 + arr.push(decode(pair[1])); 1.39 + } 1.40 + } else { 1.41 + for (i = 0; i < pairs.length; i++) { 1.42 + pair = pairs[i].split("="); 1.43 + if (pair.length !== 2) { 1.44 + continue; 1.45 + } 1.46 + o[decode(pair[0])] = decode(pair[1]); 1.47 + } 1.48 + } 1.49 + return o; 1.50 +}; 1.51 + 1.52 +// Check the query string for arguments 1.53 +var params = parseQueryString(location.search.substring(1), true); 1.54 + 1.55 +var config = {}; 1.56 +if (window.readConfig) { 1.57 + config = readConfig(); 1.58 +} 1.59 + 1.60 +if (config.testRoot == "chrome" || config.testRoot == "a11y") { 1.61 + for (p in params) { 1.62 + if (params[p] == 1) { 1.63 + config[p] = true; 1.64 + } else if (params[p] == 0) { 1.65 + config[p] = false; 1.66 + } else { 1.67 + config[p] = params[p]; 1.68 + } 1.69 + } 1.70 + params = config; 1.71 + params.baseurl = "chrome://mochitests/content"; 1.72 +} else { 1.73 + params.baseurl = ""; 1.74 +} 1.75 + 1.76 +if (params.testRoot == "browser") { 1.77 + params.testPrefix = "chrome://mochitests/content/browser/"; 1.78 +} else if (params.testRoot == "chrome") { 1.79 + params.testPrefix = "chrome://mochitests/content/chrome/"; 1.80 +} else if (params.testRoot == "a11y") { 1.81 + params.testPrefix = "chrome://mochitests/content/a11y/"; 1.82 +} else { 1.83 + params.testPrefix = "/tests/"; 1.84 +} 1.85 + 1.86 +// set the per-test timeout if specified in the query string 1.87 +if (params.timeout) { 1.88 + TestRunner.timeout = parseInt(params.timeout) * 1000; 1.89 +} 1.90 + 1.91 +// log levels for console and logfile 1.92 +var fileLevel = params.fileLevel || null; 1.93 +var consoleLevel = params.consoleLevel || null; 1.94 + 1.95 +// repeat tells us how many times to repeat the tests 1.96 +if (params.repeat) { 1.97 + TestRunner.repeat = params.repeat; 1.98 +} 1.99 + 1.100 +if (params.runUntilFailure) { 1.101 + TestRunner.runUntilFailure = true; 1.102 +} 1.103 + 1.104 +// closeWhenDone tells us to close the browser when complete 1.105 +if (params.closeWhenDone) { 1.106 + TestRunner.onComplete = SpecialPowers.quit; 1.107 +} 1.108 + 1.109 +if (params.failureFile) { 1.110 + TestRunner.setFailureFile(params.failureFile); 1.111 +} 1.112 + 1.113 +// Breaks execution and enters the JS debugger on a test failure 1.114 +if (params.debugOnFailure) { 1.115 + TestRunner.debugOnFailure = true; 1.116 +} 1.117 + 1.118 +// logFile to write our results 1.119 +if (params.logFile) { 1.120 + var spl = new SpecialPowersLogger(params.logFile); 1.121 + TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback()); 1.122 +} 1.123 + 1.124 +// A temporary hack for android 4.0 where Fennec utilizes the pandaboard so much it reboots 1.125 +if (params.runSlower) { 1.126 + TestRunner.runSlower = true; 1.127 +} 1.128 + 1.129 +if (params.dumpOutputDirectory) { 1.130 + TestRunner.dumpOutputDirectory = params.dumpOutputDirectory; 1.131 +} 1.132 + 1.133 +if (params.dumpAboutMemoryAfterTest) { 1.134 + TestRunner.dumpAboutMemoryAfterTest = true; 1.135 +} 1.136 + 1.137 +if (params.dumpDMDAfterTest) { 1.138 + TestRunner.dumpDMDAfterTest = true; 1.139 +} 1.140 + 1.141 +if (params.quiet) { 1.142 + TestRunner.quiet = true; 1.143 +} 1.144 + 1.145 +// Log things to the console if appropriate. 1.146 +TestRunner.logger.addListener("dumpListener", consoleLevel + "", function(msg) { 1.147 + dump(msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"); 1.148 +}); 1.149 + 1.150 +var gTestList = []; 1.151 +var RunSet = {} 1.152 +RunSet.runall = function(e) { 1.153 + // Filter tests to include|exclude tests based on data in params.filter. 1.154 + // This allows for including or excluding tests from the gTestList 1.155 + if (params.testManifest) { 1.156 + getTestManifest("http://mochi.test:8888/" + params.testManifest, params, function(filter) { gTestList = filterTests(filter, gTestList, params.runOnly); RunSet.runtests(); }); 1.157 + } else { 1.158 + RunSet.runtests(); 1.159 + } 1.160 +} 1.161 + 1.162 +RunSet.runtests = function(e) { 1.163 + // Which tests we're going to run 1.164 + var my_tests = gTestList; 1.165 + 1.166 + if (params.startAt || params.endAt) { 1.167 + my_tests = skipTests(my_tests, params.startAt, params.endAt); 1.168 + } 1.169 + 1.170 + if (params.totalChunks && params.thisChunk) { 1.171 + my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger); 1.172 + } 1.173 + 1.174 + if (params.shuffle) { 1.175 + for (var i = my_tests.length-1; i > 0; --i) { 1.176 + var j = Math.floor(Math.random() * i); 1.177 + var tmp = my_tests[j]; 1.178 + my_tests[j] = my_tests[i]; 1.179 + my_tests[i] = tmp; 1.180 + } 1.181 + } 1.182 + TestRunner.runTests(my_tests); 1.183 +} 1.184 + 1.185 +RunSet.reloadAndRunAll = function(e) { 1.186 + e.preventDefault(); 1.187 + //window.location.hash = ""; 1.188 + var addParam = ""; 1.189 + if (params.autorun) { 1.190 + window.location.search += ""; 1.191 + window.location.href = window.location.href; 1.192 + } else if (window.location.search) { 1.193 + window.location.href += "&autorun=1"; 1.194 + } else { 1.195 + window.location.href += "?autorun=1"; 1.196 + } 1.197 +}; 1.198 + 1.199 +// UI Stuff 1.200 +function toggleVisible(elem) { 1.201 + toggleElementClass("invisible", elem); 1.202 +} 1.203 + 1.204 +function makeVisible(elem) { 1.205 + removeElementClass(elem, "invisible"); 1.206 +} 1.207 + 1.208 +function makeInvisible(elem) { 1.209 + addElementClass(elem, "invisible"); 1.210 +} 1.211 + 1.212 +function isVisible(elem) { 1.213 + // you may also want to check for 1.214 + // getElement(elem).style.display == "none" 1.215 + return !hasElementClass(elem, "invisible"); 1.216 +}; 1.217 + 1.218 +function toggleNonTests (e) { 1.219 + e.preventDefault(); 1.220 + var elems = document.getElementsByClassName("non-test"); 1.221 + for (var i="0"; i<elems.length; i++) { 1.222 + toggleVisible(elems[i]); 1.223 + } 1.224 + if (isVisible(elems[0])) { 1.225 + $("toggleNonTests").innerHTML = "Hide Non-Tests"; 1.226 + } else { 1.227 + $("toggleNonTests").innerHTML = "Show Non-Tests"; 1.228 + } 1.229 +} 1.230 + 1.231 +// hook up our buttons 1.232 +function hookup() { 1.233 + if (params.manifestFile) { 1.234 + getTestManifest("http://mochi.test:8888/" + params.manifestFile, params, hookupTests); 1.235 + } else { 1.236 + hookupTests(gTestList); 1.237 + } 1.238 +} 1.239 + 1.240 +function hookupTests(testList) { 1.241 + if (testList.length > 0) { 1.242 + gTestList = testList; 1.243 + } else { 1.244 + gTestList = []; 1.245 + for (var obj in testList) { 1.246 + gTestList.push(obj); 1.247 + } 1.248 + } 1.249 + 1.250 + document.getElementById('runtests').onclick = RunSet.reloadAndRunAll; 1.251 + document.getElementById('toggleNonTests').onclick = toggleNonTests; 1.252 + // run automatically if autorun specified 1.253 + if (params.autorun) { 1.254 + RunSet.runall(); 1.255 + } 1.256 +}