Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
michael@0 | 1 | /* -*- js-indent-level: 2; tab-width: 2; indent-tabs-mode: nil -*- */ |
michael@0 | 2 | /* vim:set ts=2 sw=2 sts=2 et: */ |
michael@0 | 3 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 4 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 5 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 6 | |
michael@0 | 7 | TestRunner.logEnabled = true; |
michael@0 | 8 | TestRunner.logger = LogController; |
michael@0 | 9 | |
michael@0 | 10 | /* Helper function */ |
michael@0 | 11 | parseQueryString = function(encodedString, useArrays) { |
michael@0 | 12 | // strip a leading '?' from the encoded string |
michael@0 | 13 | var qstr = (encodedString[0] == "?") ? encodedString.substring(1) : |
michael@0 | 14 | encodedString; |
michael@0 | 15 | var pairs = qstr.replace(/\+/g, "%20").split(/(\&\;|\&\#38\;|\&|\&)/); |
michael@0 | 16 | var o = {}; |
michael@0 | 17 | var decode; |
michael@0 | 18 | if (typeof(decodeURIComponent) != "undefined") { |
michael@0 | 19 | decode = decodeURIComponent; |
michael@0 | 20 | } else { |
michael@0 | 21 | decode = unescape; |
michael@0 | 22 | } |
michael@0 | 23 | if (useArrays) { |
michael@0 | 24 | for (var i = 0; i < pairs.length; i++) { |
michael@0 | 25 | var pair = pairs[i].split("="); |
michael@0 | 26 | if (pair.length !== 2) { |
michael@0 | 27 | continue; |
michael@0 | 28 | } |
michael@0 | 29 | var name = decode(pair[0]); |
michael@0 | 30 | var arr = o[name]; |
michael@0 | 31 | if (!(arr instanceof Array)) { |
michael@0 | 32 | arr = []; |
michael@0 | 33 | o[name] = arr; |
michael@0 | 34 | } |
michael@0 | 35 | arr.push(decode(pair[1])); |
michael@0 | 36 | } |
michael@0 | 37 | } else { |
michael@0 | 38 | for (i = 0; i < pairs.length; i++) { |
michael@0 | 39 | pair = pairs[i].split("="); |
michael@0 | 40 | if (pair.length !== 2) { |
michael@0 | 41 | continue; |
michael@0 | 42 | } |
michael@0 | 43 | o[decode(pair[0])] = decode(pair[1]); |
michael@0 | 44 | } |
michael@0 | 45 | } |
michael@0 | 46 | return o; |
michael@0 | 47 | }; |
michael@0 | 48 | |
michael@0 | 49 | // Check the query string for arguments |
michael@0 | 50 | var params = parseQueryString(location.search.substring(1), true); |
michael@0 | 51 | |
michael@0 | 52 | var config = {}; |
michael@0 | 53 | if (window.readConfig) { |
michael@0 | 54 | config = readConfig(); |
michael@0 | 55 | } |
michael@0 | 56 | |
michael@0 | 57 | if (config.testRoot == "chrome" || config.testRoot == "a11y") { |
michael@0 | 58 | for (p in params) { |
michael@0 | 59 | if (params[p] == 1) { |
michael@0 | 60 | config[p] = true; |
michael@0 | 61 | } else if (params[p] == 0) { |
michael@0 | 62 | config[p] = false; |
michael@0 | 63 | } else { |
michael@0 | 64 | config[p] = params[p]; |
michael@0 | 65 | } |
michael@0 | 66 | } |
michael@0 | 67 | params = config; |
michael@0 | 68 | params.baseurl = "chrome://mochitests/content"; |
michael@0 | 69 | } else { |
michael@0 | 70 | params.baseurl = ""; |
michael@0 | 71 | } |
michael@0 | 72 | |
michael@0 | 73 | if (params.testRoot == "browser") { |
michael@0 | 74 | params.testPrefix = "chrome://mochitests/content/browser/"; |
michael@0 | 75 | } else if (params.testRoot == "chrome") { |
michael@0 | 76 | params.testPrefix = "chrome://mochitests/content/chrome/"; |
michael@0 | 77 | } else if (params.testRoot == "a11y") { |
michael@0 | 78 | params.testPrefix = "chrome://mochitests/content/a11y/"; |
michael@0 | 79 | } else { |
michael@0 | 80 | params.testPrefix = "/tests/"; |
michael@0 | 81 | } |
michael@0 | 82 | |
michael@0 | 83 | // set the per-test timeout if specified in the query string |
michael@0 | 84 | if (params.timeout) { |
michael@0 | 85 | TestRunner.timeout = parseInt(params.timeout) * 1000; |
michael@0 | 86 | } |
michael@0 | 87 | |
michael@0 | 88 | // log levels for console and logfile |
michael@0 | 89 | var fileLevel = params.fileLevel || null; |
michael@0 | 90 | var consoleLevel = params.consoleLevel || null; |
michael@0 | 91 | |
michael@0 | 92 | // repeat tells us how many times to repeat the tests |
michael@0 | 93 | if (params.repeat) { |
michael@0 | 94 | TestRunner.repeat = params.repeat; |
michael@0 | 95 | } |
michael@0 | 96 | |
michael@0 | 97 | if (params.runUntilFailure) { |
michael@0 | 98 | TestRunner.runUntilFailure = true; |
michael@0 | 99 | } |
michael@0 | 100 | |
michael@0 | 101 | // closeWhenDone tells us to close the browser when complete |
michael@0 | 102 | if (params.closeWhenDone) { |
michael@0 | 103 | TestRunner.onComplete = SpecialPowers.quit; |
michael@0 | 104 | } |
michael@0 | 105 | |
michael@0 | 106 | if (params.failureFile) { |
michael@0 | 107 | TestRunner.setFailureFile(params.failureFile); |
michael@0 | 108 | } |
michael@0 | 109 | |
michael@0 | 110 | // Breaks execution and enters the JS debugger on a test failure |
michael@0 | 111 | if (params.debugOnFailure) { |
michael@0 | 112 | TestRunner.debugOnFailure = true; |
michael@0 | 113 | } |
michael@0 | 114 | |
michael@0 | 115 | // logFile to write our results |
michael@0 | 116 | if (params.logFile) { |
michael@0 | 117 | var spl = new SpecialPowersLogger(params.logFile); |
michael@0 | 118 | TestRunner.logger.addListener("mozLogger", fileLevel + "", spl.getLogCallback()); |
michael@0 | 119 | } |
michael@0 | 120 | |
michael@0 | 121 | // A temporary hack for android 4.0 where Fennec utilizes the pandaboard so much it reboots |
michael@0 | 122 | if (params.runSlower) { |
michael@0 | 123 | TestRunner.runSlower = true; |
michael@0 | 124 | } |
michael@0 | 125 | |
michael@0 | 126 | if (params.dumpOutputDirectory) { |
michael@0 | 127 | TestRunner.dumpOutputDirectory = params.dumpOutputDirectory; |
michael@0 | 128 | } |
michael@0 | 129 | |
michael@0 | 130 | if (params.dumpAboutMemoryAfterTest) { |
michael@0 | 131 | TestRunner.dumpAboutMemoryAfterTest = true; |
michael@0 | 132 | } |
michael@0 | 133 | |
michael@0 | 134 | if (params.dumpDMDAfterTest) { |
michael@0 | 135 | TestRunner.dumpDMDAfterTest = true; |
michael@0 | 136 | } |
michael@0 | 137 | |
michael@0 | 138 | if (params.quiet) { |
michael@0 | 139 | TestRunner.quiet = true; |
michael@0 | 140 | } |
michael@0 | 141 | |
michael@0 | 142 | // Log things to the console if appropriate. |
michael@0 | 143 | TestRunner.logger.addListener("dumpListener", consoleLevel + "", function(msg) { |
michael@0 | 144 | dump(msg.num + " " + msg.level + " " + msg.info.join(' ') + "\n"); |
michael@0 | 145 | }); |
michael@0 | 146 | |
michael@0 | 147 | var gTestList = []; |
michael@0 | 148 | var RunSet = {} |
michael@0 | 149 | RunSet.runall = function(e) { |
michael@0 | 150 | // Filter tests to include|exclude tests based on data in params.filter. |
michael@0 | 151 | // This allows for including or excluding tests from the gTestList |
michael@0 | 152 | if (params.testManifest) { |
michael@0 | 153 | getTestManifest("http://mochi.test:8888/" + params.testManifest, params, function(filter) { gTestList = filterTests(filter, gTestList, params.runOnly); RunSet.runtests(); }); |
michael@0 | 154 | } else { |
michael@0 | 155 | RunSet.runtests(); |
michael@0 | 156 | } |
michael@0 | 157 | } |
michael@0 | 158 | |
michael@0 | 159 | RunSet.runtests = function(e) { |
michael@0 | 160 | // Which tests we're going to run |
michael@0 | 161 | var my_tests = gTestList; |
michael@0 | 162 | |
michael@0 | 163 | if (params.startAt || params.endAt) { |
michael@0 | 164 | my_tests = skipTests(my_tests, params.startAt, params.endAt); |
michael@0 | 165 | } |
michael@0 | 166 | |
michael@0 | 167 | if (params.totalChunks && params.thisChunk) { |
michael@0 | 168 | my_tests = chunkifyTests(my_tests, params.totalChunks, params.thisChunk, params.chunkByDir, TestRunner.logger); |
michael@0 | 169 | } |
michael@0 | 170 | |
michael@0 | 171 | if (params.shuffle) { |
michael@0 | 172 | for (var i = my_tests.length-1; i > 0; --i) { |
michael@0 | 173 | var j = Math.floor(Math.random() * i); |
michael@0 | 174 | var tmp = my_tests[j]; |
michael@0 | 175 | my_tests[j] = my_tests[i]; |
michael@0 | 176 | my_tests[i] = tmp; |
michael@0 | 177 | } |
michael@0 | 178 | } |
michael@0 | 179 | TestRunner.runTests(my_tests); |
michael@0 | 180 | } |
michael@0 | 181 | |
michael@0 | 182 | RunSet.reloadAndRunAll = function(e) { |
michael@0 | 183 | e.preventDefault(); |
michael@0 | 184 | //window.location.hash = ""; |
michael@0 | 185 | var addParam = ""; |
michael@0 | 186 | if (params.autorun) { |
michael@0 | 187 | window.location.search += ""; |
michael@0 | 188 | window.location.href = window.location.href; |
michael@0 | 189 | } else if (window.location.search) { |
michael@0 | 190 | window.location.href += "&autorun=1"; |
michael@0 | 191 | } else { |
michael@0 | 192 | window.location.href += "?autorun=1"; |
michael@0 | 193 | } |
michael@0 | 194 | }; |
michael@0 | 195 | |
michael@0 | 196 | // UI Stuff |
michael@0 | 197 | function toggleVisible(elem) { |
michael@0 | 198 | toggleElementClass("invisible", elem); |
michael@0 | 199 | } |
michael@0 | 200 | |
michael@0 | 201 | function makeVisible(elem) { |
michael@0 | 202 | removeElementClass(elem, "invisible"); |
michael@0 | 203 | } |
michael@0 | 204 | |
michael@0 | 205 | function makeInvisible(elem) { |
michael@0 | 206 | addElementClass(elem, "invisible"); |
michael@0 | 207 | } |
michael@0 | 208 | |
michael@0 | 209 | function isVisible(elem) { |
michael@0 | 210 | // you may also want to check for |
michael@0 | 211 | // getElement(elem).style.display == "none" |
michael@0 | 212 | return !hasElementClass(elem, "invisible"); |
michael@0 | 213 | }; |
michael@0 | 214 | |
michael@0 | 215 | function toggleNonTests (e) { |
michael@0 | 216 | e.preventDefault(); |
michael@0 | 217 | var elems = document.getElementsByClassName("non-test"); |
michael@0 | 218 | for (var i="0"; i<elems.length; i++) { |
michael@0 | 219 | toggleVisible(elems[i]); |
michael@0 | 220 | } |
michael@0 | 221 | if (isVisible(elems[0])) { |
michael@0 | 222 | $("toggleNonTests").innerHTML = "Hide Non-Tests"; |
michael@0 | 223 | } else { |
michael@0 | 224 | $("toggleNonTests").innerHTML = "Show Non-Tests"; |
michael@0 | 225 | } |
michael@0 | 226 | } |
michael@0 | 227 | |
michael@0 | 228 | // hook up our buttons |
michael@0 | 229 | function hookup() { |
michael@0 | 230 | if (params.manifestFile) { |
michael@0 | 231 | getTestManifest("http://mochi.test:8888/" + params.manifestFile, params, hookupTests); |
michael@0 | 232 | } else { |
michael@0 | 233 | hookupTests(gTestList); |
michael@0 | 234 | } |
michael@0 | 235 | } |
michael@0 | 236 | |
michael@0 | 237 | function hookupTests(testList) { |
michael@0 | 238 | if (testList.length > 0) { |
michael@0 | 239 | gTestList = testList; |
michael@0 | 240 | } else { |
michael@0 | 241 | gTestList = []; |
michael@0 | 242 | for (var obj in testList) { |
michael@0 | 243 | gTestList.push(obj); |
michael@0 | 244 | } |
michael@0 | 245 | } |
michael@0 | 246 | |
michael@0 | 247 | document.getElementById('runtests').onclick = RunSet.reloadAndRunAll; |
michael@0 | 248 | document.getElementById('toggleNonTests').onclick = toggleNonTests; |
michael@0 | 249 | // run automatically if autorun specified |
michael@0 | 250 | if (params.autorun) { |
michael@0 | 251 | RunSet.runall(); |
michael@0 | 252 | } |
michael@0 | 253 | } |