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 | <?xml version="1.0"?> |
michael@0 | 2 | <?xml-stylesheet href="chrome://global/skin" type="text/css"?> |
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 | <window id="browserTestHarness" |
michael@0 | 8 | xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul" |
michael@0 | 9 | onload="TestStart();" |
michael@0 | 10 | title="Browser chrome tests" |
michael@0 | 11 | width="1024"> |
michael@0 | 12 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/MozillaLogger.js"/> |
michael@0 | 13 | <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/LogController.js"/> |
michael@0 | 14 | <script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"/> |
michael@0 | 15 | <script type="application/javascript" src="chrome://mochikit/content/manifestLibrary.js" /> |
michael@0 | 16 | <script type="application/javascript" src="chrome://mochikit/content/chunkifyTests.js"/> |
michael@0 | 17 | <style xmlns="http://www.w3.org/1999/xhtml"><![CDATA[ |
michael@0 | 18 | #results { |
michael@0 | 19 | margin: 5px; |
michael@0 | 20 | background-color: window; |
michael@0 | 21 | -moz-user-select: text; |
michael@0 | 22 | } |
michael@0 | 23 | |
michael@0 | 24 | #summary { |
michael@0 | 25 | color: white; |
michael@0 | 26 | border: 2px solid black; |
michael@0 | 27 | } |
michael@0 | 28 | |
michael@0 | 29 | #summary.success { |
michael@0 | 30 | background-color: #0d0; |
michael@0 | 31 | } |
michael@0 | 32 | |
michael@0 | 33 | #summary.failure { |
michael@0 | 34 | background-color: red; |
michael@0 | 35 | } |
michael@0 | 36 | |
michael@0 | 37 | #summary.todo { |
michael@0 | 38 | background-color: orange; |
michael@0 | 39 | } |
michael@0 | 40 | |
michael@0 | 41 | .info { |
michael@0 | 42 | color: grey; |
michael@0 | 43 | } |
michael@0 | 44 | |
michael@0 | 45 | .failed { |
michael@0 | 46 | color: red; |
michael@0 | 47 | font-weight: bold; |
michael@0 | 48 | } |
michael@0 | 49 | |
michael@0 | 50 | .testHeader { |
michael@0 | 51 | margin-top: 1em; |
michael@0 | 52 | } |
michael@0 | 53 | |
michael@0 | 54 | p { |
michael@0 | 55 | margin: 0.1em; |
michael@0 | 56 | } |
michael@0 | 57 | |
michael@0 | 58 | a { |
michael@0 | 59 | color: blue; |
michael@0 | 60 | text-decoration: underline; |
michael@0 | 61 | } |
michael@0 | 62 | ]]></style> |
michael@0 | 63 | <script type="application/javascript;version=1.7"><![CDATA[ |
michael@0 | 64 | if (Cc === undefined) { |
michael@0 | 65 | var Cc = Components.classes; |
michael@0 | 66 | var Ci = Components.interfaces; |
michael@0 | 67 | } |
michael@0 | 68 | |
michael@0 | 69 | var gConfig; |
michael@0 | 70 | |
michael@0 | 71 | var gDumper = { |
michael@0 | 72 | get fileLogger() { |
michael@0 | 73 | let logger = null; |
michael@0 | 74 | if (gConfig.logFile) { |
michael@0 | 75 | try { |
michael@0 | 76 | logger = new MozillaFileLogger(gConfig.logFile) |
michael@0 | 77 | } catch (ex) { |
michael@0 | 78 | dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " + |
michael@0 | 79 | "Error trying to log to " + gConfig.logFile + ": " + ex + "\n"); |
michael@0 | 80 | } |
michael@0 | 81 | } |
michael@0 | 82 | delete this.fileLogger; |
michael@0 | 83 | return this.fileLogger = logger; |
michael@0 | 84 | }, |
michael@0 | 85 | |
michael@0 | 86 | dump: function (str) { |
michael@0 | 87 | dump(str); |
michael@0 | 88 | |
michael@0 | 89 | if (this.fileLogger) |
michael@0 | 90 | this.fileLogger._foStream.write(str, str.length); |
michael@0 | 91 | }, |
michael@0 | 92 | |
michael@0 | 93 | done: function () { |
michael@0 | 94 | if (this.fileLogger) |
michael@0 | 95 | this.fileLogger.close(); |
michael@0 | 96 | } |
michael@0 | 97 | } |
michael@0 | 98 | |
michael@0 | 99 | function TestStart() { |
michael@0 | 100 | gConfig = readConfig(); |
michael@0 | 101 | |
michael@0 | 102 | // If MochiTest was started with the --test-path flag specifying a subset |
michael@0 | 103 | // of tests to run, put that path in the label of the "Run Tests" button |
michael@0 | 104 | // so the tester knows which tests will run when they press that button. |
michael@0 | 105 | if (gConfig.testPath) |
michael@0 | 106 | document.getElementById("runTestsButton").label = |
michael@0 | 107 | "Run " + gConfig.testPath + " tests"; |
michael@0 | 108 | |
michael@0 | 109 | // Similarly, update the title for --start-at and --end-at. |
michael@0 | 110 | if (gConfig.startAt || gConfig.endAt) |
michael@0 | 111 | document.getElementById("runTestsButton").label = |
michael@0 | 112 | "Run subset of tests"; |
michael@0 | 113 | |
michael@0 | 114 | if (gConfig.autorun) |
michael@0 | 115 | setTimeout(runTests, 0); |
michael@0 | 116 | } |
michael@0 | 117 | |
michael@0 | 118 | var gErrorCount = 0; |
michael@0 | 119 | |
michael@0 | 120 | function browserTest(aTestFile) { |
michael@0 | 121 | this.path = aTestFile; |
michael@0 | 122 | this.dumper = gDumper; |
michael@0 | 123 | this.results = []; |
michael@0 | 124 | this.scope = null; |
michael@0 | 125 | this.duration = 0; |
michael@0 | 126 | this.unexpectedTimeouts = 0; |
michael@0 | 127 | this.lastOutputTime = 0; |
michael@0 | 128 | } |
michael@0 | 129 | browserTest.prototype = { |
michael@0 | 130 | get passCount() { |
michael@0 | 131 | return this.results.filter(function (t) !t.info && !t.todo && t.pass).length; |
michael@0 | 132 | }, |
michael@0 | 133 | get todoCount() { |
michael@0 | 134 | return this.results.filter(function (t) !t.info && t.todo && t.pass).length; |
michael@0 | 135 | }, |
michael@0 | 136 | get failCount() { |
michael@0 | 137 | return this.results.filter(function (t) !t.info && !t.pass).length; |
michael@0 | 138 | }, |
michael@0 | 139 | |
michael@0 | 140 | addResult: function addResult(result) { |
michael@0 | 141 | this.lastOutputTime = Date.now(); |
michael@0 | 142 | this.results.push(result); |
michael@0 | 143 | |
michael@0 | 144 | this.dumper.dump(result.result + " | " + this.path + " | " + result.msg + "\n"); |
michael@0 | 145 | }, |
michael@0 | 146 | |
michael@0 | 147 | setDuration: function setDuration(duration) { |
michael@0 | 148 | this.duration = duration; |
michael@0 | 149 | }, |
michael@0 | 150 | |
michael@0 | 151 | get htmlLog() { |
michael@0 | 152 | let txtToHTML = Cc["@mozilla.org/txttohtmlconv;1"]. |
michael@0 | 153 | getService(Ci.mozITXTToHTMLConv); |
michael@0 | 154 | function _entityEncode(str) { |
michael@0 | 155 | return txtToHTML.scanTXT(str, Ci.mozITXTToHTMLConv.kEntities); |
michael@0 | 156 | } |
michael@0 | 157 | var path = _entityEncode(this.path); |
michael@0 | 158 | var html = this.results.map(function (t) { |
michael@0 | 159 | var classname = t.info ? "info" : "result " + (t.pass ? "passed" : "failed"); |
michael@0 | 160 | var text = t.result + " | " + path + " | " + _entityEncode(t.msg); |
michael@0 | 161 | if (!t.info && !t.pass) { |
michael@0 | 162 | return '<p class="' + classname + '" id=\"ERROR' + (gErrorCount++) + '">' + |
michael@0 | 163 | text + " <a href=\"javascript:scrollTo('ERROR" + gErrorCount + "')\">NEXT ERROR</a></p>"; |
michael@0 | 164 | } |
michael@0 | 165 | return '<p class="' + classname + '">' + text + "</p>"; |
michael@0 | 166 | }).join("\n"); |
michael@0 | 167 | if (this.duration) { |
michael@0 | 168 | html += "<p class=\"info\">TEST-END | " + path + " | finished in " + |
michael@0 | 169 | this.duration + " ms</p>"; |
michael@0 | 170 | } |
michael@0 | 171 | return html; |
michael@0 | 172 | } |
michael@0 | 173 | }; |
michael@0 | 174 | |
michael@0 | 175 | // Returns an array of browserTest objects for all the selected tests |
michael@0 | 176 | function runTests() { |
michael@0 | 177 | gConfig.baseurl = "chrome://mochitests/content"; |
michael@0 | 178 | getTestList(gConfig, loadTestList); |
michael@0 | 179 | } |
michael@0 | 180 | |
michael@0 | 181 | function loadTestList(links) { |
michael@0 | 182 | if (!links) { |
michael@0 | 183 | createTester({}); |
michael@0 | 184 | return; |
michael@0 | 185 | } |
michael@0 | 186 | |
michael@0 | 187 | // load server.js in so we can share template functions |
michael@0 | 188 | var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"]. |
michael@0 | 189 | getService(Ci.mozIJSSubScriptLoader); |
michael@0 | 190 | var srvScope = {}; |
michael@0 | 191 | scriptLoader.loadSubScript('chrome://mochikit/content/server.js', |
michael@0 | 192 | srvScope); |
michael@0 | 193 | |
michael@0 | 194 | var fileNames = []; |
michael@0 | 195 | var fileNameRegexp = /browser_.+\.js$/; |
michael@0 | 196 | srvScope.arrayOfTestFiles(links, fileNames, fileNameRegexp); |
michael@0 | 197 | |
michael@0 | 198 | if (gConfig.startAt || gConfig.endAt) { |
michael@0 | 199 | fileNames = skipTests(fileNames, gConfig.startAt, gConfig.endAt); |
michael@0 | 200 | } |
michael@0 | 201 | |
michael@0 | 202 | if (gConfig.totalChunks && gConfig.thisChunk) { |
michael@0 | 203 | fileNames = chunkifyTests(fileNames, gConfig.totalChunks, |
michael@0 | 204 | gConfig.thisChunk, gConfig.chunkByDir); |
michael@0 | 205 | } |
michael@0 | 206 | |
michael@0 | 207 | createTester(fileNames.map(function (f) { return new browserTest(f); })); |
michael@0 | 208 | } |
michael@0 | 209 | |
michael@0 | 210 | function setStatus(aStatusString) { |
michael@0 | 211 | document.getElementById("status").value = aStatusString; |
michael@0 | 212 | } |
michael@0 | 213 | |
michael@0 | 214 | function createTester(links) { |
michael@0 | 215 | var windowMediator = Cc['@mozilla.org/appshell/window-mediator;1']. |
michael@0 | 216 | getService(Ci.nsIWindowMediator); |
michael@0 | 217 | var winType = gConfig.testRoot == "browser" ? "navigator:browser" : |
michael@0 | 218 | gConfig.testRoot == "metro" ? "navigator:browser" : |
michael@0 | 219 | gConfig.testRoot == "webapprtChrome" ? "webapprt:webapp" : |
michael@0 | 220 | null; |
michael@0 | 221 | if (!winType) { |
michael@0 | 222 | throw new Error("Unrecognized gConfig.testRoot: " + gConfig.testRoot); |
michael@0 | 223 | } |
michael@0 | 224 | var testWin = windowMediator.getMostRecentWindow(winType); |
michael@0 | 225 | |
michael@0 | 226 | setStatus("Running..."); |
michael@0 | 227 | testWin.focus(); |
michael@0 | 228 | var Tester = new testWin.Tester(links, gDumper, testsFinished); |
michael@0 | 229 | Tester.start(); |
michael@0 | 230 | } |
michael@0 | 231 | |
michael@0 | 232 | function sum(a, b) { |
michael@0 | 233 | return a + b; |
michael@0 | 234 | } |
michael@0 | 235 | |
michael@0 | 236 | function getHTMLLogFromTests(aTests) { |
michael@0 | 237 | if (!aTests.length) |
michael@0 | 238 | return "<div id=\"summary\" class=\"failure\">No tests to run." + |
michael@0 | 239 | " Did you pass an invalid --test-path?</div>"; |
michael@0 | 240 | |
michael@0 | 241 | var log = ""; |
michael@0 | 242 | |
michael@0 | 243 | var passCount = aTests.map(function (f) f.passCount).reduce(sum); |
michael@0 | 244 | var failCount = aTests.map(function (f) f.failCount).reduce(sum); |
michael@0 | 245 | var todoCount = aTests.map(function (f) f.todoCount).reduce(sum); |
michael@0 | 246 | log += "<div id=\"summary\" class=\""; |
michael@0 | 247 | log += failCount != 0 ? "failure" : |
michael@0 | 248 | passCount == 0 ? "todo" : "success"; |
michael@0 | 249 | log += "\">\n<p>Passed: " + passCount + "</p>\n" + |
michael@0 | 250 | "<p>Failed: " + failCount; |
michael@0 | 251 | if (failCount > 0) |
michael@0 | 252 | log += " <a href=\"javascript:scrollTo('ERROR0')\">NEXT ERROR</a>"; |
michael@0 | 253 | log += "</p>\n" + |
michael@0 | 254 | "<p>Todo: " + todoCount + "</p>\n</div>\n<div id=\"log\">\n"; |
michael@0 | 255 | |
michael@0 | 256 | return log + aTests.map(function (f) { |
michael@0 | 257 | return "<p class=\"testHeader\">Running " + f.path + "...</p>\n" + f.htmlLog; |
michael@0 | 258 | }).join("\n") + "</div>"; |
michael@0 | 259 | } |
michael@0 | 260 | |
michael@0 | 261 | function testsFinished(aTests) { |
michael@0 | 262 | // Focus our window, to display the results |
michael@0 | 263 | window.focus(); |
michael@0 | 264 | |
michael@0 | 265 | if (gConfig.closeWhenDone) { |
michael@0 | 266 | let appStartup = Cc["@mozilla.org/toolkit/app-startup;1"].getService(Ci.nsIAppStartup); |
michael@0 | 267 | appStartup.quit(Ci.nsIAppStartup.eForceQuit); |
michael@0 | 268 | return; |
michael@0 | 269 | } |
michael@0 | 270 | |
michael@0 | 271 | // UI |
michael@0 | 272 | document.getElementById("results").innerHTML = getHTMLLogFromTests(aTests); |
michael@0 | 273 | setStatus("Done."); |
michael@0 | 274 | } |
michael@0 | 275 | |
michael@0 | 276 | function scrollTo(id) { |
michael@0 | 277 | var line = document.getElementById(id); |
michael@0 | 278 | if (!line) |
michael@0 | 279 | return; |
michael@0 | 280 | |
michael@0 | 281 | var boxObject = document.getElementById("results").parentNode.boxObject; |
michael@0 | 282 | boxObject.QueryInterface(Components.interfaces.nsIScrollBoxObject); |
michael@0 | 283 | boxObject.scrollToElement(line); |
michael@0 | 284 | } |
michael@0 | 285 | ]]></script> |
michael@0 | 286 | <button id="runTestsButton" oncommand="runTests();" label="Run All Tests"/> |
michael@0 | 287 | <label id="status"/> |
michael@0 | 288 | <scrollbox flex="1" style="overflow: auto" align="stretch"> |
michael@0 | 289 | <div id="results" xmlns="http://www.w3.org/1999/xhtml" flex="1"/> |
michael@0 | 290 | </scrollbox> |
michael@0 | 291 | </window> |