Bug 654461 - cleanup chrome and a11y harnesses to simplify code. r=ted, a=test-only

This commit is contained in:
Joel Maher 2011-05-17 13:10:37 -04:00
parent 6c39859dae
commit d3b8ce217f
11 changed files with 168 additions and 146 deletions

View File

@ -86,7 +86,6 @@ _SERV_FILES = \
$(topsrcdir)/build/mobile/remoteautomation.py \
gen_template.pl \
server.js \
harness-a11y.xul \
harness-overlay.xul \
harness.xul \
browser-test-overlay.xul \
@ -95,7 +94,6 @@ _SERV_FILES = \
ipc-overlay.xul \
ipc.js \
browser-harness.xul \
redirect-a11y.html \
redirect.html \
redirect.js \
$(topsrcdir)/build/pgo/server-locations.txt \

View File

@ -104,13 +104,13 @@
var gDumper = {
get fileLogger() {
let logger = null;
if (gConfig.logPath) {
if (gConfig.logFile) {
try {
MozillaFileLogger.init(gConfig.logPath);
MozillaFileLogger.init(gConfig.logFile);
logger = MozillaFileLogger;
} catch (ex) {
dump("TEST-UNEXPECTED-FAIL | (browser-harness.xul) | " +
"Error trying to log to " + gConfig.logPath + ": " + ex + "\n");
"Error trying to log to " + gConfig.logFile + ": " + ex + "\n");
}
}
delete this.fileLogger;
@ -140,39 +140,10 @@
document.getElementById("runTestsButton").label =
"Run " + gConfig.testPath + " tests";
if (gConfig.autoRun)
if (gConfig.autorun)
setTimeout(runTests, 0);
}
function readConfig() {
var fileLocator = Cc["@mozilla.org/file/directory_service;1"].
getService(Ci.nsIProperties);
var configFile = fileLocator.get("ProfD", Ci.nsIFile);
configFile.append("testConfig.js");
if (!configFile.exists())
return;
var fileInStream = Cc["@mozilla.org/network/file-input-stream;1"].
createInstance(Ci.nsIFileInputStream);
var sstream = Cc["@mozilla.org/scriptableinputstream;1"].
createInstance(Ci.nsIScriptableInputStream);
fileInStream.init(configFile, -1, 0, 0);
sstream.init(fileInStream);
var config = "";
var str = sstream.read(4096);
while (str.length > 0) {
config += str;
str = sstream.read(4096);
}
sstream.close();
fileInStream.close();
return eval(config);
}
var gErrorCount = 0;
function browserTest(aTestFile) {
@ -229,31 +200,14 @@
// Returns an array of browserTest objects for all the selected tests
function listTests() {
var baseURL = 'chrome://mochitests/content';
var testsURI = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
testsURI.append("tests.manifest");
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var manifestFile = ioSvc.newFileURI(testsURI)
.QueryInterface(Components.interfaces.nsIFileURL).file;
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
autoRegister(manifestFile);
[links, singleTestPath] = getTestList();
// load server.js in so we can share template functions
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
getService(Ci.mozIJSSubScriptLoader);
var srvScope = {};
scriptLoader.loadSubScript('chrome://mochikit/content/server.js', srvScope);
var jar = getJar(baseURL);
if (jar != null) {
var [links, singleTestPath] = getMochitestJarListing(baseURL, gConfig.testPath, "browser");
} else {
var [links, singleTestPath] = getFileListing(baseURL, gConfig.testPath, "browser", srvScope);
}
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
srvScope);
var fileNames = [];
var fileNameRegexp = /browser_.+\.js$/;

View File

@ -40,5 +40,6 @@
<overlay id="browserTestOverlay"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/chrome-harness.js"/>
<script type="application/javascript" src="chrome://mochikit/content/browser-test.js"/>
</overlay>

View File

@ -17,15 +17,18 @@ function testOnLoad() {
return;
prefs.setBoolPref("testing.browserTestHarness.running", true);
gConfig = readConfig();
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
var sstring = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
sstring.data = location.search;
if (gConfig.testRoot == "browser") {
var ww = Cc["@mozilla.org/embedcomp/window-watcher;1"].
getService(Ci.nsIWindowWatcher);
var sstring = Cc["@mozilla.org/supports-string;1"].
createInstance(Ci.nsISupportsString);
sstring.data = location.search;
ww.openWindow(window, "chrome://mochikit/content/browser-harness.xul", "browserTest",
"chrome,centerscreen,dialog=no,resizable,titlebar,toolbar=no,width=800,height=600", sstring);
ww.openWindow(window, "chrome://mochikit/content/browser-harness.xul", "browserTest",
"chrome,centerscreen,dialog=no,resizable,titlebar,toolbar=no,width=800,height=600", sstring);
}
}
function Tester(aTests, aDumper, aCallback) {

View File

@ -38,6 +38,8 @@
* ***** END LICENSE BLOCK ***** */
Components.utils.import("resource://gre/modules/NetUtil.jsm");
/*
* getChromeURI converts a URL to a URI
*
@ -353,3 +355,68 @@ function buildRelativePath(jarentryname, destdir, basepath)
return targetFile;
}
function readConfig() {
var fileLocator = Components.classes["@mozilla.org/file/directory_service;1"].
getService(Components.interfaces.nsIProperties);
var configFile = fileLocator.get("ProfD", Components.interfaces.nsIFile);
configFile.append("testConfig.js");
if (!configFile.exists())
return;
var fileInStream = Components.classes["@mozilla.org/network/file-input-stream;1"].
createInstance(Components.interfaces.nsIFileInputStream);
fileInStream.init(configFile, -1, 0, 0);
var str = NetUtil.readInputStreamToString(fileInStream, fileInStream.available());
fileInStream.close();
return JSON.parse(str);
}
function getTestList() {
var params = {};
if (window.parseQueryString) {
params = parseQueryString(location.search.substring(1), true);
}
var config = readConfig();
for (p in params) {
if (params[p] == 1) {
config[p] = true;
} else if (params[p] == 0) {
config[p] = false;
} else {
config[p] = params[p];
}
}
params = config;
var baseurl = 'chrome://mochitests/content';
var testsURI = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
testsURI.append("tests.manifest");
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var manifestFile = ioSvc.newFileURI(testsURI)
.QueryInterface(Components.interfaces.nsIFileURL).file;
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
autoRegister(manifestFile);
// load server.js in so we can share template functions
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
getService(Ci.mozIJSSubScriptLoader);
var srvScope = {};
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
srvScope);
var singleTestPath;
var links;
if (getResolvedURI(baseurl).JARFile) {
[links, singleTestPath] = getMochitestJarListing(baseurl, params.testPath, params.testRoot);
} else {
[links, singleTestPath] = getFileListing(baseurl, params.testPath, params.testRoot, srvScope);
}
return [links, singleTestPath];
}

View File

@ -1,11 +0,0 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/static/harness.css"
type="text/css"?>
<?xul-overlay href="chrome://mochikit/content/harness-overlay.xul"?>
<window xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
title="Accessibility Chrome Test Harness"
directory="a11y">
</window>

View File

@ -1,7 +1,9 @@
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/static/harness.css"
type="text/css"?>
<overlay id="browserTestOverlay"
<overlay id="chromeTestOverlay"
xmlns:html="http://www.w3.org/1999/xhtml"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
@ -15,30 +17,21 @@
src="chrome://mochikit/content/tests/SimpleTest/MozillaFileLogger.js"/>
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/quit.js" />
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/setup.js" />
<script type="application/javascript"
src="chrome://mochikit/content/chrome-harness.js" />
<script type="text/javascript"
src="chrome://mochikit/content/tests/SimpleTest/setup.js" />
<script type="application/javascript;version=1.7"><![CDATA[
if (Cc === undefined) {
var Cc = Components.classes;
var Ci = Components.interfaces;
}
function loadTests()
{
window.removeEventListener("load", loadTests, false);
var baseurl = 'chrome://mochitests/content';
var testsURI = Components.classes["@mozilla.org/file/directory_service;1"]
.getService(Components.interfaces.nsIProperties)
.get("ProfD", Components.interfaces.nsILocalFile);
testsURI.append("tests.manifest");
var ioSvc = Components.classes["@mozilla.org/network/io-service;1"].
getService(Components.interfaces.nsIIOService);
var manifestFile = ioSvc.newFileURI(testsURI)
.QueryInterface(Components.interfaces.nsIFileURL).file;
Components.manager.QueryInterface(Components.interfaces.nsIComponentRegistrar).
autoRegister(manifestFile);
var dir = document.documentElement.getAttribute('directory');
[links, singleTestPath] = getTestList();
// load server.js in so we can share template functions
var scriptLoader = Cc["@mozilla.org/moz/jssubscript-loader;1"].
@ -46,18 +39,9 @@ function loadTests()
var srvScope = {};
scriptLoader.loadSubScript('chrome://mochikit/content/server.js',
srvScope);
// generate our test list
srvScope.makeTags();
var singleTestPath;
var links;
if (getResolvedURI(baseurl).JARFile) {
[links, singleTestPath] = getMochitestJarListing(baseurl, params.testPath, dir);
} else {
[links, singleTestPath] = getFileListing(baseurl, params.testPath, dir, srvScope);
}
var tableContent = srvScope.linksToTableRows(links, 0);
function populate() {

View File

@ -4,13 +4,11 @@ mochikit.jar:
content/browser-test.js (browser-test.js)
content/browser-test-overlay.xul (browser-test-overlay.xul)
content/chrome-harness.js (chrome-harness.js)
content/harness-a11y.xul (harness-a11y.xul)
content/harness-overlay.xul (harness-overlay.xul)
content/harness.xul (harness.xul)
content/ipc.js (ipc.js)
content/ipc-overlay.xul (ipc-overlay.xul)
content/mozprefs.js (mozprefs.js)
content/redirect-a11y.html (redirect-a11y.html)
content/redirect.html (redirect.html)
content/redirect.js (redirect.js)
content/server.js (server.js)

View File

@ -1,14 +0,0 @@
<html>
<head>
<title>redirecting...</title>
<script type="text/javascript" src="redirect.js"></script>
<script type="text/javascript">
redirect("chrome://mochikit/content/harness-a11y.xul");
</script>
</head>
<body>
redirecting...
</body>
</html>

View File

@ -405,7 +405,6 @@ class Mochitest(object):
# Path to the test script on the server
TEST_PATH = "/tests/"
CHROME_PATH = "/redirect.html";
A11Y_PATH = "/redirect-a11y.html"
urlOpts = []
runSSLTunnel = True
vmwareHelper = None
@ -434,14 +433,8 @@ class Mochitest(object):
""" Build the url path to the specific test harness and test file or directory """
testHost = "http://mochi.test:8888"
testURL = testHost + self.TEST_PATH + options.testPath
if options.chrome:
testURL = testHost + self.CHROME_PATH
if options.testPath:
self.urlOpts.append("testPath=" + encodeURIComponent(options.testPath))
elif options.a11y:
testURL = testHost + self.A11Y_PATH
if options.testPath:
self.urlOpts.append("testPath=" + encodeURIComponent(options.testPath))
if options.chrome or options.a11y:
testURL = testHost + self.CHROME_PATH
elif options.browserChrome:
testURL = "about:blank"
elif options.ipcplugins:
@ -554,7 +547,7 @@ class Mochitest(object):
# allow relative paths for logFile
if options.logFile:
options.logFile = self.getLogFilePath(options.logFile)
if options.browserChrome:
if options.browserChrome or options.chrome or options.a11y:
self.makeTestConfig(options)
else:
if options.autorun:
@ -679,23 +672,54 @@ class Mochitest(object):
def makeTestConfig(self, options):
"Creates a test configuration file for customizing test execution."
def boolString(b):
if b:
return "true"
return "false"
def jsonString(val):
if isinstance(val, bool):
if val:
return "true"
return "false"
elif val is None:
return '""'
elif isinstance(val, basestring):
return '"%s"' % (val.replace('\\', '\\\\'))
elif isinstance(val, int):
return '%s' % (val)
elif isinstance(val, list):
content = '['
first = True
for item in val:
if first:
first = False
else:
content += ", "
content += jsonString(item)
content += ']'
return content
else:
print "unknown type: %s: %s" % (opt, val)
sys.exit(1)
logFile = options.logFile.replace("\\", "\\\\")
testPath = options.testPath.replace("\\", "\\\\")
content = """\
({
autoRun: %(autorun)s,
closeWhenDone: %(closeWhenDone)s,
logPath: "%(logPath)s",
testPath: "%(testPath)s"
})""" % {"autorun": boolString(options.autorun),
"closeWhenDone": boolString(options.closeWhenDone),
"logPath": logFile,
"testPath": testPath}
options.logFile = options.logFile.replace("\\", "\\\\")
options.testPath = options.testPath.replace("\\", "\\\\")
testRoot = 'chrome'
if (options.browserChrome):
testRoot = 'browser'
elif (options.a11y):
testRoot = 'a11y'
#TODO: when we upgrade to python 2.6, just use json.dumps(options.__dict__)
content = "{"
content += '"testRoot": "%s", ' % (testRoot)
first = True
for opt in options.__dict__.keys():
val = options.__dict__[opt]
if first:
first = False
else:
content += ", "
content += '"' + opt + '": '
content += jsonString(val)
content += "}"
with open(os.path.join(options.profilePath, "testConfig.js"), "w") as config:
config.write(content)
@ -742,12 +766,12 @@ toolbar#nav-bar {
# Support Firefox (browser) and SeaMonkey (navigator).
chrome = ""
if options.browserChrome:
if options.browserChrome or options.chrome or options.a11y:
chrome += """
overlay chrome://browser/content/browser.xul chrome://mochikit/content/browser-test-overlay.xul
overlay chrome://navigator/content/navigator.xul chrome://mochikit/content/browser-test-overlay.xul
"""
elif (options.chrome == False) and (options.a11y == False):
else:
#only do the ipc-overlay.xul for mochitest-plain.
#Currently there are focus issues in chrome tests and issues with new windows and dialogs when using ipc
chrome += """

View File

@ -42,6 +42,24 @@ TestRunner.logger = new Logger();
// Check the query string for arguments
var params = parseQueryString(location.search.substring(1), true);
var config = {};
if (window.readConfig) {
config = readConfig();
}
if (config.testRoot == "chrome" || config.testRoot == "a11y") {
for (p in params) {
if (params[p] == 1) {
config[p] = true;
} else if (params[p] == 0) {
config[p] = false;
} else {
config[p] = params[p];
}
}
params = config;
}
// set the per-test timeout if specified in the query string
if (params.timeout) {
TestRunner.timeout = parseInt(params.timeout) * 1000;