2007-03-22 10:30:00 -07:00
|
|
|
/* -*- Mode: Java; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 04:12:37 -07: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-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// Note that the server script itself already defines Cc, Ci, and Cr for us,
|
|
|
|
// and because they're constants it's not safe to redefine them. Scope leakage
|
|
|
|
// sucks.
|
|
|
|
|
2009-01-12 21:52:00 -08:00
|
|
|
// Disable automatic network detection, so tests work correctly when
|
|
|
|
// not connected to a network.
|
|
|
|
let (ios = Cc["@mozilla.org/network/io-service;1"]
|
|
|
|
.getService(Ci.nsIIOService2)) {
|
|
|
|
ios.manageOfflineStatus = false;
|
|
|
|
ios.offline = false;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
var server; // for use in the shutdown handler, if necessary
|
|
|
|
|
|
|
|
//
|
|
|
|
// HTML GENERATION
|
|
|
|
//
|
|
|
|
var tags = ['A', 'ABBR', 'ACRONYM', 'ADDRESS', 'APPLET', 'AREA', 'B', 'BASE',
|
|
|
|
'BASEFONT', 'BDO', 'BIG', 'BLOCKQUOTE', 'BODY', 'BR', 'BUTTON',
|
|
|
|
'CAPTION', 'CENTER', 'CITE', 'CODE', 'COL', 'COLGROUP', 'DD',
|
|
|
|
'DEL', 'DFN', 'DIR', 'DIV', 'DL', 'DT', 'EM', 'FIELDSET', 'FONT',
|
|
|
|
'FORM', 'FRAME', 'FRAMESET', 'H1', 'H2', 'H3', 'H4', 'H5', 'H6',
|
|
|
|
'HEAD', 'HR', 'HTML', 'I', 'IFRAME', 'IMG', 'INPUT', 'INS',
|
|
|
|
'ISINDEX', 'KBD', 'LABEL', 'LEGEND', 'LI', 'LINK', 'MAP', 'MENU',
|
|
|
|
'META', 'NOFRAMES', 'NOSCRIPT', 'OBJECT', 'OL', 'OPTGROUP',
|
|
|
|
'OPTION', 'P', 'PARAM', 'PRE', 'Q', 'S', 'SAMP', 'SCRIPT',
|
|
|
|
'SELECT', 'SMALL', 'SPAN', 'STRIKE', 'STRONG', 'STYLE', 'SUB',
|
|
|
|
'SUP', 'TABLE', 'TBODY', 'TD', 'TEXTAREA', 'TFOOT', 'TH', 'THEAD',
|
|
|
|
'TITLE', 'TR', 'TT', 'U', 'UL', 'VAR'];
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Below, we'll use makeTagFunc to create a function for each of the
|
|
|
|
* strings in 'tags'. This will allow us to use s-expression like syntax
|
|
|
|
* to create HTML.
|
|
|
|
*/
|
|
|
|
function makeTagFunc(tagName)
|
|
|
|
{
|
|
|
|
return function (attrs /* rest... */)
|
|
|
|
{
|
|
|
|
var startChildren = 0;
|
|
|
|
var response = "";
|
|
|
|
|
|
|
|
// write the start tag and attributes
|
|
|
|
response += "<" + tagName;
|
|
|
|
// if attr is an object, write attributes
|
|
|
|
if (attrs && typeof attrs == 'object') {
|
|
|
|
startChildren = 1;
|
|
|
|
for (var [key,value] in attrs) {
|
|
|
|
var val = "" + value;
|
|
|
|
response += " " + key + '="' + val.replace('"','"') + '"';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
response += ">";
|
|
|
|
|
|
|
|
// iterate through the rest of the args
|
|
|
|
for (var i = startChildren; i < arguments.length; i++) {
|
|
|
|
if (typeof arguments[i] == 'function') {
|
|
|
|
response += arguments[i]();
|
|
|
|
} else {
|
|
|
|
response += arguments[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// write the close tag
|
|
|
|
response += "</" + tagName + ">\n";
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
function makeTags() {
|
|
|
|
// map our global HTML generation functions
|
2008-01-28 19:48:34 -08:00
|
|
|
for each (var tag in tags) {
|
|
|
|
this[tag] = makeTagFunc(tag.toLowerCase());
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2009-04-15 13:19:35 -07:00
|
|
|
var _quitting = false;
|
|
|
|
|
|
|
|
/** Quit when all activity has completed. */
|
|
|
|
function serverStopped()
|
|
|
|
{
|
|
|
|
_quitting = true;
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// only run the "main" section if httpd.js was loaded ahead of us
|
|
|
|
if (this["nsHttpServer"]) {
|
|
|
|
//
|
|
|
|
// SCRIPT CODE
|
|
|
|
//
|
|
|
|
runServer();
|
|
|
|
|
2009-04-15 13:19:35 -07:00
|
|
|
// We can only have gotten here if the /server/shutdown path was requested.
|
|
|
|
if (_quitting)
|
|
|
|
{
|
|
|
|
dumpn("HTTP server stopped, all pending requests complete");
|
|
|
|
quit(0);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Impossible as the stop callback should have been called, but to be safe...
|
|
|
|
dumpn("TEST-UNEXPECTED-FAIL | failure to correctly shut down HTTP server");
|
|
|
|
quit(1);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
var serverBasePath;
|
2012-09-18 16:28:39 -07:00
|
|
|
var displayResults = true;
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
//
|
|
|
|
// SERVER SETUP
|
|
|
|
//
|
|
|
|
function runServer()
|
|
|
|
{
|
2009-02-09 10:57:27 -08:00
|
|
|
serverBasePath = __LOCATION__.parent;
|
2008-06-06 23:43:15 -07:00
|
|
|
server = createMochitestServer(serverBasePath);
|
2010-03-12 13:53:36 -08:00
|
|
|
|
|
|
|
//verify server address
|
|
|
|
//if a.b.c.d or 'localhost'
|
|
|
|
if (typeof(_SERVER_ADDR) != "undefined") {
|
|
|
|
if (_SERVER_ADDR == "localhost") {
|
|
|
|
gServerAddress = _SERVER_ADDR;
|
|
|
|
} else {
|
|
|
|
var quads = _SERVER_ADDR.split('.');
|
|
|
|
if (quads.length == 4) {
|
|
|
|
var invalid = false;
|
|
|
|
for (var i=0; i < 4; i++) {
|
|
|
|
if (quads[i] < 0 || quads[i] > 255)
|
|
|
|
invalid = true;
|
|
|
|
}
|
|
|
|
if (!invalid)
|
|
|
|
gServerAddress = _SERVER_ADDR;
|
|
|
|
else
|
2010-03-13 09:56:24 -08:00
|
|
|
throw "invalid _SERVER_ADDR, please specify a valid IP Address";
|
2010-03-12 13:53:36 -08:00
|
|
|
}
|
|
|
|
}
|
2010-03-13 09:56:24 -08:00
|
|
|
} else {
|
|
|
|
throw "please defined _SERVER_ADDR (as an ip address) before running server.js";
|
|
|
|
}
|
|
|
|
|
|
|
|
if (typeof(_SERVER_PORT) != "undefined") {
|
2011-02-23 11:39:01 -08:00
|
|
|
if (parseInt(_SERVER_PORT) > 0 && parseInt(_SERVER_PORT) < 65536)
|
2010-03-13 09:56:24 -08:00
|
|
|
SERVER_PORT = _SERVER_PORT;
|
|
|
|
} else {
|
|
|
|
throw "please define _SERVER_PORT (as a port number) before running server.js";
|
2010-03-12 13:53:36 -08:00
|
|
|
}
|
|
|
|
|
2012-09-18 16:28:39 -07:00
|
|
|
// If DISPLAY_RESULTS is not specified, it defaults to true
|
|
|
|
if (typeof(_DISPLAY_RESULTS) != "undefined") {
|
|
|
|
displayResults = _DISPLAY_RESULTS;
|
|
|
|
}
|
|
|
|
|
2010-03-12 13:53:36 -08:00
|
|
|
server._start(SERVER_PORT, gServerAddress);
|
2007-07-12 17:58:25 -07:00
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// touch a file in the profile directory to indicate we're alive
|
|
|
|
var foStream = Cc["@mozilla.org/network/file-output-stream;1"]
|
|
|
|
.createInstance(Ci.nsIFileOutputStream);
|
|
|
|
var serverAlive = Cc["@mozilla.org/file/local;1"]
|
|
|
|
.createInstance(Ci.nsILocalFile);
|
2010-03-13 09:56:24 -08:00
|
|
|
|
|
|
|
if (typeof(_PROFILE_PATH) == "undefined") {
|
|
|
|
serverAlive.initWithFile(serverBasePath);
|
|
|
|
serverAlive.append("mochitesttestingprofile");
|
|
|
|
} else {
|
|
|
|
serverAlive.initWithPath(_PROFILE_PATH);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
// If we're running outside of the test harness, there might
|
|
|
|
// not be a test profile directory present
|
|
|
|
if (serverAlive.exists()) {
|
|
|
|
serverAlive.append("server_alive.txt");
|
|
|
|
foStream.init(serverAlive,
|
2011-06-08 09:04:14 -07:00
|
|
|
0x02 | 0x08 | 0x20, 436, 0); // write, create, truncate
|
2007-03-22 10:30:00 -07:00
|
|
|
data = "It's alive!";
|
|
|
|
foStream.write(data, data.length);
|
|
|
|
foStream.close();
|
|
|
|
}
|
|
|
|
|
|
|
|
makeTags();
|
|
|
|
|
|
|
|
//
|
|
|
|
// The following is threading magic to spin an event loop -- this has to
|
|
|
|
// happen manually in xpcshell for the server to actually work.
|
|
|
|
//
|
|
|
|
var thread = Cc["@mozilla.org/thread-manager;1"]
|
|
|
|
.getService()
|
|
|
|
.currentThread;
|
|
|
|
while (!server.isStopped())
|
|
|
|
thread.processNextEvent(true);
|
|
|
|
|
|
|
|
// Server stopped by /server/shutdown handler -- go through pending events
|
|
|
|
// and return.
|
|
|
|
|
|
|
|
// get rid of any pending requests
|
|
|
|
while (thread.hasPendingEvents())
|
|
|
|
thread.processNextEvent(true);
|
|
|
|
}
|
|
|
|
|
2008-06-06 23:43:15 -07:00
|
|
|
/** Creates and returns an HTTP server configured to serve Mochitests. */
|
|
|
|
function createMochitestServer(serverBasePath)
|
|
|
|
{
|
|
|
|
var server = new nsHttpServer();
|
|
|
|
|
|
|
|
server.registerDirectory("/", serverBasePath);
|
|
|
|
server.registerPathHandler("/server/shutdown", serverShutdown);
|
2010-02-09 14:07:33 -08:00
|
|
|
server.registerPathHandler("/server/debug", serverDebug);
|
2008-06-06 23:43:15 -07:00
|
|
|
server.registerContentType("sjs", "sjs"); // .sjs == CGI-like functionality
|
2009-01-21 14:50:28 -08:00
|
|
|
server.registerContentType("jar", "application/x-jar");
|
2009-06-26 00:45:08 -07:00
|
|
|
server.registerContentType("ogg", "application/ogg");
|
2012-03-21 19:25:06 -07:00
|
|
|
server.registerContentType("pdf", "application/pdf");
|
2009-06-26 00:45:08 -07:00
|
|
|
server.registerContentType("ogv", "video/ogg");
|
|
|
|
server.registerContentType("oga", "audio/ogg");
|
2012-05-01 17:29:42 -07:00
|
|
|
server.registerContentType("opus", "audio/ogg; codecs=opus");
|
2010-09-01 04:41:12 -07:00
|
|
|
server.registerContentType("dat", "text/plain; charset=utf-8");
|
2011-05-20 14:50:53 -07:00
|
|
|
server.registerContentType("frag", "text/plain"); // .frag == WebGL fragment shader
|
|
|
|
server.registerContentType("vert", "text/plain"); // .vert == WebGL vertex shader
|
2008-06-06 23:43:15 -07:00
|
|
|
server.setIndexHandler(defaultDirHandler);
|
|
|
|
|
2010-02-02 17:28:46 -08:00
|
|
|
var serverRoot =
|
|
|
|
{
|
|
|
|
getFile: function getFile(path)
|
|
|
|
{
|
|
|
|
var file = serverBasePath.clone().QueryInterface(Ci.nsILocalFile);
|
2010-02-23 18:04:35 -08:00
|
|
|
path.split("/").forEach(function(p) {
|
|
|
|
file.appendRelativePath(p);
|
|
|
|
});
|
2010-02-02 17:28:46 -08:00
|
|
|
return file;
|
|
|
|
},
|
|
|
|
QueryInterface: function(aIID) { return this; }
|
|
|
|
};
|
|
|
|
|
|
|
|
server.setObjectState("SERVER_ROOT", serverRoot);
|
|
|
|
|
2008-06-06 23:43:15 -07:00
|
|
|
processLocations(server);
|
|
|
|
|
|
|
|
return server;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Notifies the HTTP server about all the locations at which it might receive
|
|
|
|
* requests, so that it can properly respond to requests on any of the hosts it
|
|
|
|
* serves.
|
|
|
|
*/
|
|
|
|
function processLocations(server)
|
|
|
|
{
|
|
|
|
var serverLocations = serverBasePath.clone();
|
|
|
|
serverLocations.append("server-locations.txt");
|
|
|
|
|
|
|
|
const PR_RDONLY = 0x01;
|
2011-06-08 09:04:14 -07:00
|
|
|
var fis = new FileInputStream(serverLocations, PR_RDONLY, 292 /* 0444 */,
|
2008-06-06 23:43:15 -07:00
|
|
|
Ci.nsIFileInputStream.CLOSE_ON_EOF);
|
|
|
|
|
|
|
|
var lis = new ConverterInputStream(fis, "UTF-8", 1024, 0x0);
|
|
|
|
lis.QueryInterface(Ci.nsIUnicharLineInputStream);
|
|
|
|
|
|
|
|
const LINE_REGEXP =
|
|
|
|
new RegExp("^([a-z][-a-z0-9+.]*)" +
|
|
|
|
"://" +
|
|
|
|
"(" +
|
|
|
|
"\\d+\\.\\d+\\.\\d+\\.\\d+" +
|
|
|
|
"|" +
|
|
|
|
"(?:[a-z0-9](?:[-a-z0-9]*[a-z0-9])?\\.)*" +
|
|
|
|
"[a-z](?:[-a-z0-9]*[a-z0-9])?" +
|
|
|
|
")" +
|
|
|
|
":" +
|
|
|
|
"(\\d+)" +
|
|
|
|
"(?:" +
|
|
|
|
"\\s+" +
|
2008-09-05 06:35:58 -07:00
|
|
|
"(\\S+(?:,\\S+)*)" +
|
2008-06-06 23:43:15 -07:00
|
|
|
")?$");
|
|
|
|
|
|
|
|
var line = {};
|
|
|
|
var lineno = 0;
|
|
|
|
var seenPrimary = false;
|
|
|
|
do
|
|
|
|
{
|
|
|
|
var more = lis.readLine(line);
|
|
|
|
lineno++;
|
|
|
|
|
|
|
|
var lineValue = line.value;
|
|
|
|
if (lineValue.charAt(0) == "#" || lineValue == "")
|
|
|
|
continue;
|
|
|
|
|
|
|
|
var match = LINE_REGEXP.exec(lineValue);
|
|
|
|
if (!match)
|
|
|
|
throw "Syntax error in server-locations.txt, line " + lineno;
|
|
|
|
|
|
|
|
var [, scheme, host, port, options] = match;
|
|
|
|
if (options)
|
|
|
|
{
|
|
|
|
if (options.split(",").indexOf("primary") >= 0)
|
|
|
|
{
|
|
|
|
if (seenPrimary)
|
|
|
|
{
|
|
|
|
throw "Multiple primary locations in server-locations.txt, " +
|
|
|
|
"line " + lineno;
|
|
|
|
}
|
|
|
|
|
|
|
|
server.identity.setPrimary(scheme, host, port);
|
|
|
|
seenPrimary = true;
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
server.identity.add(scheme, host, port);
|
|
|
|
}
|
|
|
|
while (more);
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
// PATH HANDLERS
|
|
|
|
|
|
|
|
// /server/shutdown
|
|
|
|
function serverShutdown(metadata, response)
|
|
|
|
{
|
|
|
|
response.setStatusLine("1.1", 200, "OK");
|
2008-03-18 10:42:39 -07:00
|
|
|
response.setHeader("Content-type", "text/plain", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
var body = "Server shut down.";
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
|
2009-04-15 13:19:35 -07:00
|
|
|
dumpn("Server shutting down now...");
|
|
|
|
server.stop(serverStopped);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
2010-02-09 14:07:33 -08:00
|
|
|
// /server/debug?[012]
|
|
|
|
function serverDebug(metadata, response)
|
|
|
|
{
|
|
|
|
response.setStatusLine(metadata.httpVersion, 400, "Bad debugging level");
|
|
|
|
if (metadata.queryString.length !== 1)
|
|
|
|
return;
|
|
|
|
|
|
|
|
var mode;
|
|
|
|
if (metadata.queryString === "0") {
|
|
|
|
// do this now so it gets logged with the old mode
|
|
|
|
dumpn("Server debug logs disabled.");
|
|
|
|
DEBUG = false;
|
|
|
|
DEBUG_TIMESTAMP = false;
|
|
|
|
mode = "disabled";
|
|
|
|
} else if (metadata.queryString === "1") {
|
|
|
|
DEBUG = true;
|
|
|
|
DEBUG_TIMESTAMP = false;
|
|
|
|
mode = "enabled";
|
|
|
|
} else if (metadata.queryString === "2") {
|
|
|
|
DEBUG = true;
|
|
|
|
DEBUG_TIMESTAMP = true;
|
|
|
|
mode = "enabled, with timestamps";
|
|
|
|
} else {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
response.setStatusLine(metadata.httpVersion, 200, "OK");
|
|
|
|
response.setHeader("Content-type", "text/plain", false);
|
|
|
|
var body = "Server debug logs " + mode + ".";
|
|
|
|
response.bodyOutputStream.write(body, body.length);
|
|
|
|
dumpn(body);
|
|
|
|
}
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
//
|
|
|
|
// DIRECTORY LISTINGS
|
|
|
|
//
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Creates a generator that iterates over the contents of
|
|
|
|
* an nsIFile directory.
|
|
|
|
*/
|
|
|
|
function dirIter(dir)
|
|
|
|
{
|
2008-05-03 18:19:16 -07:00
|
|
|
var en = dir.directoryEntries;
|
|
|
|
while (en.hasMoreElements()) {
|
|
|
|
var file = en.getNext();
|
2007-03-22 10:30:00 -07:00
|
|
|
yield file.QueryInterface(Ci.nsILocalFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Builds an optionally nested object containing links to the
|
|
|
|
* files and directories within dir.
|
|
|
|
*/
|
|
|
|
function list(requestPath, directory, recurse)
|
|
|
|
{
|
|
|
|
var count = 0;
|
|
|
|
var path = requestPath;
|
|
|
|
if (path.charAt(path.length - 1) != "/") {
|
|
|
|
path += "/";
|
|
|
|
}
|
|
|
|
|
|
|
|
var dir = directory.QueryInterface(Ci.nsIFile);
|
|
|
|
var links = {};
|
|
|
|
|
|
|
|
// The SimpleTest directory is hidden
|
|
|
|
var files = [file for (file in dirIter(dir))
|
2008-03-14 18:12:05 -07:00
|
|
|
if (file.exists() && file.path.indexOf("SimpleTest") == -1)];
|
2007-03-22 10:30:00 -07:00
|
|
|
|
2007-06-21 13:21:30 -07:00
|
|
|
// Sort files by name, so that tests can be run in a pre-defined order inside
|
|
|
|
// a given directory (see bug 384823)
|
|
|
|
function leafNameComparator(first, second) {
|
|
|
|
if (first.leafName < second.leafName)
|
|
|
|
return -1;
|
|
|
|
if (first.leafName > second.leafName)
|
|
|
|
return 1;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
files.sort(leafNameComparator);
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
count = files.length;
|
|
|
|
for each (var file in files) {
|
2007-06-14 22:42:06 -07:00
|
|
|
var key = path + file.leafName;
|
2007-03-22 10:30:00 -07:00
|
|
|
var childCount = 0;
|
|
|
|
if (file.isDirectory()) {
|
|
|
|
key += "/";
|
|
|
|
}
|
|
|
|
if (recurse && file.isDirectory()) {
|
|
|
|
[links[key], childCount] = list(key, file, recurse);
|
|
|
|
count += childCount;
|
|
|
|
} else {
|
2007-04-27 09:48:53 -07:00
|
|
|
if (file.leafName.charAt(0) != '.') {
|
|
|
|
links[key] = true;
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return [links, count];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Heuristic function that determines whether a given path
|
|
|
|
* is a test case to be executed in the harness, or just
|
|
|
|
* a supporting file.
|
|
|
|
*/
|
2007-07-09 09:24:15 -07:00
|
|
|
function isTest(filename, pattern)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
2007-07-09 09:24:15 -07:00
|
|
|
if (pattern)
|
|
|
|
return pattern.test(filename);
|
|
|
|
|
2010-09-30 17:10:19 -07:00
|
|
|
// File name is a URL style path to a test file, make sure that we check for
|
2012-06-29 15:52:43 -07:00
|
|
|
// tests that start with the appropriate prefix.
|
|
|
|
var testPrefix = typeof(_TEST_PREFIX) == "string" ? _TEST_PREFIX : "test_";
|
|
|
|
var testPattern = new RegExp("^" + testPrefix);
|
|
|
|
|
2010-09-30 17:10:19 -07:00
|
|
|
pathPieces = filename.split('/');
|
|
|
|
|
|
|
|
return testPattern.test(pathPieces[pathPieces.length - 1]) &&
|
2007-07-09 09:24:15 -07:00
|
|
|
filename.indexOf(".js") == -1 &&
|
2007-11-11 09:44:50 -08:00
|
|
|
filename.indexOf(".css") == -1 &&
|
2007-11-12 08:55:48 -08:00
|
|
|
!/\^headers\^$/.test(filename);
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform nested hashtables of paths to nested HTML lists.
|
|
|
|
*/
|
|
|
|
function linksToListItems(links)
|
|
|
|
{
|
|
|
|
var response = "";
|
|
|
|
var children = "";
|
|
|
|
for (var [link, value] in links) {
|
|
|
|
var classVal = (!isTest(link) && !(value instanceof Object))
|
|
|
|
? "non-test invisible"
|
|
|
|
: "test";
|
|
|
|
if (value instanceof Object) {
|
|
|
|
children = UL({class: "testdir"}, linksToListItems(value));
|
|
|
|
} else {
|
|
|
|
children = "";
|
|
|
|
}
|
2007-06-17 04:51:35 -07:00
|
|
|
|
|
|
|
var bug_title = link.match(/test_bug\S+/);
|
|
|
|
var bug_num = null;
|
|
|
|
if (bug_title != null) {
|
|
|
|
bug_num = bug_title[0].match(/\d+/);
|
|
|
|
}
|
|
|
|
|
|
|
|
if ((bug_title == null) || (bug_num == null)) {
|
|
|
|
response += LI({class: classVal}, A({href: link}, link), children);
|
|
|
|
} else {
|
2007-07-12 16:33:51 -07:00
|
|
|
var bug_url = "https://bugzilla.mozilla.org/show_bug.cgi?id="+bug_num;
|
2007-06-17 04:51:35 -07:00
|
|
|
response += LI({class: classVal}, A({href: link}, link), " - ", A({href: bug_url}, "Bug "+bug_num), children);
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Transform nested hashtables of paths to a flat table rows.
|
|
|
|
*/
|
2009-04-21 04:25:22 -07:00
|
|
|
function linksToTableRows(links, recursionLevel)
|
2007-03-22 10:30:00 -07:00
|
|
|
{
|
|
|
|
var response = "";
|
|
|
|
for (var [link, value] in links) {
|
|
|
|
var classVal = (!isTest(link) && !(value instanceof Object))
|
|
|
|
? "non-test invisible"
|
|
|
|
: "";
|
2009-04-21 04:25:22 -07:00
|
|
|
|
|
|
|
spacer = "padding-left: " + (10 * recursionLevel) + "px";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
if (value instanceof Object) {
|
|
|
|
response += TR({class: "dir", id: "tr-" + link },
|
2009-04-21 04:25:22 -07:00
|
|
|
TD({colspan: "3"}, " "),
|
|
|
|
TD({style: spacer},
|
|
|
|
A({href: link}, link)));
|
|
|
|
response += linksToTableRows(value, recursionLevel + 1);
|
2007-03-22 10:30:00 -07:00
|
|
|
} else {
|
2009-04-21 04:25:22 -07:00
|
|
|
var bug_title = link.match(/test_bug\S+/);
|
|
|
|
var bug_num = null;
|
|
|
|
if (bug_title != null) {
|
|
|
|
bug_num = bug_title[0].match(/\d+/);
|
|
|
|
}
|
|
|
|
if ((bug_title == null) || (bug_num == null)) {
|
|
|
|
response += TR({class: classVal, id: "tr-" + link },
|
|
|
|
TD("0"),
|
|
|
|
TD("0"),
|
|
|
|
TD("0"),
|
|
|
|
TD({style: spacer},
|
|
|
|
A({href: link}, link)));
|
|
|
|
} else {
|
|
|
|
var bug_url = "https://bugzilla.mozilla.org/show_bug.cgi?id=" + bug_num;
|
|
|
|
response += TR({class: classVal, id: "tr-" + link },
|
|
|
|
TD("0"),
|
|
|
|
TD("0"),
|
|
|
|
TD("0"),
|
|
|
|
TD({style: spacer},
|
|
|
|
A({href: link}, link), " - ",
|
|
|
|
A({href: bug_url}, "Bug " + bug_num)));
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return response;
|
|
|
|
}
|
|
|
|
|
2007-07-09 09:24:15 -07:00
|
|
|
function arrayOfTestFiles(linkArray, fileArray, testPattern) {
|
2010-12-05 05:38:29 -08:00
|
|
|
for (var [link, value] in Iterator(linkArray)) {
|
2007-07-09 09:24:15 -07:00
|
|
|
if (value instanceof Object) {
|
|
|
|
arrayOfTestFiles(value, fileArray, testPattern);
|
|
|
|
} else if (isTest(link, testPattern)) {
|
|
|
|
fileArray.push(link)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2007-03-22 10:30:00 -07:00
|
|
|
/**
|
|
|
|
* Produce a flat array of test file paths to be executed in the harness.
|
|
|
|
*/
|
|
|
|
function jsonArrayOfTestFiles(links)
|
|
|
|
{
|
|
|
|
var testFiles = [];
|
2007-07-09 09:24:15 -07:00
|
|
|
arrayOfTestFiles(links, testFiles);
|
|
|
|
testFiles = ['"' + file + '"' for each(file in testFiles)];
|
2007-03-22 10:30:00 -07:00
|
|
|
return "[" + testFiles.join(",\n") + "]";
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produce a normal directory listing.
|
|
|
|
*/
|
|
|
|
function regularListing(metadata, response)
|
|
|
|
{
|
|
|
|
var [links, count] = list(metadata.path,
|
|
|
|
metadata.getProperty("directory"),
|
|
|
|
false);
|
|
|
|
response.write(
|
|
|
|
HTML(
|
|
|
|
HEAD(
|
|
|
|
TITLE("mochitest index ", metadata.path)
|
|
|
|
),
|
|
|
|
BODY(
|
|
|
|
BR(),
|
|
|
|
A({href: ".."}, "Up a level"),
|
|
|
|
UL(linksToListItems(links))
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Produce a test harness page containing all the test cases
|
|
|
|
* below it, recursively.
|
|
|
|
*/
|
|
|
|
function testListing(metadata, response)
|
|
|
|
{
|
2013-08-02 05:48:06 -07:00
|
|
|
var links = {};
|
|
|
|
var count = 0;
|
|
|
|
if (metadata.queryString.indexOf('manifestFile') == -1) {
|
|
|
|
[links, count] = list(metadata.path,
|
|
|
|
metadata.getProperty("directory"),
|
|
|
|
true);
|
|
|
|
}
|
2011-07-26 16:13:20 -07:00
|
|
|
var table_class = metadata.queryString.indexOf("hideResultsTable=1") > -1 ? "invisible": "";
|
|
|
|
|
2013-05-24 12:03:49 -07:00
|
|
|
let testname = (metadata.queryString.indexOf("testname=") > -1)
|
|
|
|
? metadata.queryString.match(/testname=([^&]+)/)[1]
|
|
|
|
: "";
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
dumpn("count: " + count);
|
2013-05-24 12:03:49 -07:00
|
|
|
var tests = testname
|
|
|
|
? "['/" + testname + "']"
|
|
|
|
: jsonArrayOfTestFiles(links);
|
2007-03-22 10:30:00 -07:00
|
|
|
response.write(
|
|
|
|
HTML(
|
|
|
|
HEAD(
|
|
|
|
TITLE("MochiTest | ", metadata.path),
|
|
|
|
LINK({rel: "stylesheet",
|
|
|
|
type: "text/css", href: "/static/harness.css"}
|
|
|
|
),
|
2011-08-12 09:21:35 -07:00
|
|
|
SCRIPT({type: "text/javascript",
|
|
|
|
src: "/tests/SimpleTest/LogController.js"}),
|
2007-03-22 10:30:00 -07:00
|
|
|
SCRIPT({type: "text/javascript",
|
|
|
|
src: "/tests/SimpleTest/TestRunner.js"}),
|
|
|
|
SCRIPT({type: "text/javascript",
|
2011-07-18 19:10:29 -07:00
|
|
|
src: "/tests/SimpleTest/MozillaLogger.js"}),
|
2013-06-16 08:19:47 -07:00
|
|
|
SCRIPT({type: "text/javascript",
|
|
|
|
src: "/chunkifyTests.js"}),
|
2013-08-02 05:48:06 -07:00
|
|
|
SCRIPT({type: "text/javascript",
|
|
|
|
src: "/manifestLibrary.js"}),
|
2007-03-22 10:30:00 -07:00
|
|
|
SCRIPT({type: "text/javascript",
|
|
|
|
src: "/tests/SimpleTest/setup.js"}),
|
|
|
|
SCRIPT({type: "text/javascript"},
|
2011-08-12 09:21:35 -07:00
|
|
|
"window.onload = hookup; gTestList=" + tests + ";"
|
2007-03-22 10:30:00 -07:00
|
|
|
)
|
|
|
|
),
|
|
|
|
BODY(
|
|
|
|
DIV({class: "container"},
|
|
|
|
H2("--> ", A({href: "#", id: "runtests"}, "Run Tests"), " <--"),
|
|
|
|
P({style: "float: right;"},
|
|
|
|
SMALL(
|
|
|
|
"Based on the ",
|
|
|
|
A({href:"http://www.mochikit.com/"}, "MochiKit"),
|
|
|
|
" unit tests."
|
|
|
|
)
|
|
|
|
),
|
|
|
|
DIV({class: "status"},
|
|
|
|
H1({id: "indicator"}, "Status"),
|
|
|
|
H2({id: "pass"}, "Passed: ", SPAN({id: "pass-count"},"0")),
|
|
|
|
H2({id: "fail"}, "Failed: ", SPAN({id: "fail-count"},"0")),
|
|
|
|
H2({id: "fail"}, "Todo: ", SPAN({id: "todo-count"},"0"))
|
|
|
|
),
|
|
|
|
DIV({class: "clear"}),
|
|
|
|
DIV({id: "current-test"},
|
|
|
|
B("Currently Executing: ",
|
|
|
|
SPAN({id: "current-test-path"}, "_")
|
|
|
|
)
|
|
|
|
),
|
|
|
|
DIV({class: "clear"}),
|
|
|
|
DIV({class: "frameholder"},
|
2008-04-01 14:21:54 -07:00
|
|
|
IFRAME({scrolling: "no", id: "testframe", width: "500", height: "300"})
|
2007-03-22 10:30:00 -07:00
|
|
|
),
|
|
|
|
DIV({class: "clear"}),
|
|
|
|
DIV({class: "toggle"},
|
|
|
|
A({href: "#", id: "toggleNonTests"}, "Show Non-Tests"),
|
|
|
|
BR()
|
|
|
|
),
|
2012-09-18 16:28:39 -07:00
|
|
|
|
|
|
|
(
|
|
|
|
displayResults ?
|
|
|
|
TABLE({cellpadding: 0, cellspacing: 0, class: table_class, id: "test-table"},
|
|
|
|
TR(TD("Passed"), TD("Failed"), TD("Todo"), TD("Test Files")),
|
|
|
|
linksToTableRows(links, 0)
|
|
|
|
) : ""
|
2007-03-22 10:30:00 -07:00
|
|
|
),
|
2011-07-14 14:39:17 -07:00
|
|
|
|
|
|
|
BR(),
|
|
|
|
TABLE({cellpadding: 0, cellspacing: 0, border: 1, bordercolor: "red", id: "fail-table"}
|
|
|
|
),
|
|
|
|
|
2007-03-22 10:30:00 -07:00
|
|
|
DIV({class: "clear"})
|
|
|
|
)
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Respond to requests that match a file system directory.
|
|
|
|
* Under the tests/ directory, return a test harness page.
|
|
|
|
*/
|
|
|
|
function defaultDirHandler(metadata, response)
|
|
|
|
{
|
|
|
|
response.setStatusLine("1.1", 200, "OK");
|
2013-02-22 13:23:28 -08:00
|
|
|
response.setHeader("Content-type", "text/html", false);
|
2007-03-22 10:30:00 -07:00
|
|
|
try {
|
|
|
|
if (metadata.path.indexOf("/tests") != 0) {
|
|
|
|
regularListing(metadata, response);
|
|
|
|
} else {
|
|
|
|
testListing(metadata, response);
|
|
|
|
}
|
|
|
|
} catch (ex) {
|
|
|
|
response.write(ex);
|
|
|
|
}
|
|
|
|
}
|