2014-06-25 09:12:07 +04:00
|
|
|
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*- */
|
2010-08-24 21:29:34 +04:00
|
|
|
/* vim:set ts=2 sw=2 sts=2 et: */
|
2012-05-21 15:12:37 +04: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/. */
|
2010-08-24 21:29:34 +04:00
|
|
|
|
2019-01-17 21:18:31 +03:00
|
|
|
var { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
|
|
|
|
var { NetUtil } = ChromeUtils.import("resource://gre/modules/NetUtil.jsm");
|
2011-05-17 21:10:37 +04:00
|
|
|
|
2018-04-30 13:03:44 +03:00
|
|
|
/* import-globals-from manifestLibrary.js */
|
|
|
|
|
|
|
|
// Defined in browser-test.js
|
|
|
|
/* global gTestPath */
|
|
|
|
|
2010-08-24 21:29:34 +04:00
|
|
|
/*
|
|
|
|
* getChromeURI converts a URL to a URI
|
2014-07-17 11:02:00 +04:00
|
|
|
*
|
2010-08-24 21:29:34 +04:00
|
|
|
* url: string of a URL (http://mochi.test/test.html)
|
|
|
|
* returns: a nsiURI object representing the given URL
|
|
|
|
*
|
|
|
|
*/
|
|
|
|
function getChromeURI(url) {
|
2018-04-30 13:03:44 +03:00
|
|
|
return Services.io.newURI(url);
|
2010-08-24 21:29:34 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Convert a URL (string) into a nsIURI or NSIJARURI
|
2014-07-17 11:02:00 +04:00
|
|
|
* This is intended for URL's that are on a file system
|
2010-08-24 21:29:34 +04:00
|
|
|
* or in packaged up in an extension .jar file
|
|
|
|
*
|
|
|
|
* url: a string of a url on the local system(http://localhost/blah.html)
|
|
|
|
*/
|
|
|
|
function getResolvedURI(url) {
|
|
|
|
var chromeURI = getChromeURI(url);
|
2018-02-28 20:51:33 +03:00
|
|
|
var resolvedURI = Cc["@mozilla.org/chrome/chrome-registry;1"]
|
|
|
|
.getService(Ci.nsIChromeRegistry)
|
2010-08-24 21:29:34 +04:00
|
|
|
.convertChromeURL(chromeURI);
|
|
|
|
|
|
|
|
try {
|
2018-02-28 20:51:33 +03:00
|
|
|
resolvedURI = resolvedURI.QueryInterface(Ci.nsIJARURI);
|
2018-01-27 00:32:30 +03:00
|
|
|
} catch (ex) {} // not a jar file
|
2010-08-24 21:29:34 +04:00
|
|
|
|
|
|
|
return resolvedURI;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* getChromeDir is intended to be called after getResolvedURI and convert
|
2017-08-04 11:49:22 +03:00
|
|
|
* the input URI into a nsIFile (actually the directory containing the
|
2010-08-24 21:29:34 +04:00
|
|
|
* file). This can be used for copying or referencing the file or extra files
|
|
|
|
* required by the test. Usually we need to load a secondary html file or library
|
|
|
|
* and this will give us file system access to that.
|
|
|
|
*
|
|
|
|
* resolvedURI: nsIURI (from getResolvedURI) that points to a file:/// url
|
|
|
|
*/
|
|
|
|
function getChromeDir(resolvedURI) {
|
2018-02-28 20:51:33 +03:00
|
|
|
var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].getService(
|
|
|
|
Ci.nsIFileProtocolHandler
|
|
|
|
);
|
2010-08-24 21:29:34 +04:00
|
|
|
var chromeDir = fileHandler.getFileFromURLSpec(resolvedURI.spec);
|
2018-02-28 20:51:33 +03:00
|
|
|
return chromeDir.parent.QueryInterface(Ci.nsIFile);
|
2010-08-24 21:29:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// used by tests to determine their directory based off window.location.path
|
2010-08-24 21:29:34 +04:00
|
|
|
function getRootDirectory(path, chromeURI) {
|
2018-01-27 00:32:30 +03:00
|
|
|
if (chromeURI === undefined) {
|
2010-08-24 21:29:34 +04:00
|
|
|
chromeURI = getChromeURI(path);
|
|
|
|
}
|
2018-02-28 20:51:33 +03:00
|
|
|
var myURL = chromeURI.QueryInterface(Ci.nsIURL);
|
2010-10-01 04:10:19 +04:00
|
|
|
var mydir = myURL.directory;
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
if (mydir.match("/$") != "/") {
|
|
|
|
mydir += "/";
|
2010-10-01 04:10:19 +04:00
|
|
|
}
|
2010-08-24 21:29:34 +04:00
|
|
|
|
2010-10-01 04:10:19 +04:00
|
|
|
return chromeURI.prePath + mydir;
|
2010-08-24 21:29:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// used by tests to determine their directory based off window.location.path
|
2010-08-24 21:29:34 +04:00
|
|
|
function getChromePrePath(path, chromeURI) {
|
|
|
|
if (chromeURI === undefined) {
|
|
|
|
chromeURI = getChromeURI(path);
|
|
|
|
}
|
|
|
|
|
|
|
|
return chromeURI.prePath;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Given a URI, return nsIJARURI or null
|
|
|
|
*/
|
|
|
|
function getJar(uri) {
|
|
|
|
var resolvedURI = getResolvedURI(uri);
|
|
|
|
var jar = null;
|
|
|
|
try {
|
|
|
|
if (resolvedURI.JARFile) {
|
|
|
|
jar = resolvedURI;
|
|
|
|
}
|
|
|
|
} catch (ex) {}
|
|
|
|
return jar;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* input:
|
|
|
|
* jar: a nsIJARURI object with the jarfile and jarentry (path in jar file)
|
|
|
|
*
|
|
|
|
* output;
|
|
|
|
* all files and subdirectories inside jarentry will be extracted to TmpD/mochikit.tmp
|
|
|
|
* we will return the location of /TmpD/mochikit.tmp* so you can reference the files locally
|
|
|
|
*/
|
|
|
|
function extractJarToTmp(jar) {
|
2018-04-30 13:03:44 +03:00
|
|
|
var tmpdir = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2010-08-24 21:29:34 +04:00
|
|
|
tmpdir.append("mochikit.tmp");
|
2010-09-28 22:54:29 +04:00
|
|
|
// parseInt is used because octal escape sequences cause deprecation warnings
|
|
|
|
// in strict mode (which is turned on in debug builds)
|
2018-02-28 20:51:33 +03:00
|
|
|
tmpdir.createUnique(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0777", 8));
|
2010-08-24 21:29:34 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var zReader = Cc["@mozilla.org/libjar/zip-reader;1"].createInstance(
|
|
|
|
Ci.nsIZipReader
|
|
|
|
);
|
2010-08-24 21:29:34 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var fileHandler = Cc["@mozilla.org/network/protocol;1?name=file"].getService(
|
|
|
|
Ci.nsIFileProtocolHandler
|
|
|
|
);
|
2010-08-24 21:29:34 +04:00
|
|
|
|
|
|
|
var fileName = fileHandler.getFileFromURLSpec(jar.JARFile.spec);
|
|
|
|
zReader.open(fileName);
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// filepath represents the path in the jar file without the filename
|
2010-08-24 21:29:34 +04:00
|
|
|
var filepath = "";
|
2018-01-27 00:32:30 +03:00
|
|
|
var parts = jar.JAREntry.split("/");
|
|
|
|
for (var i = 0; i < parts.length - 1; i++) {
|
|
|
|
if (parts[i] != "") {
|
|
|
|
filepath += parts[i] + "/";
|
2010-08-24 21:29:34 +04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Create dir structure first, no guarantee about ordering of directories and
|
|
|
|
* files returned from findEntries.
|
|
|
|
*/
|
2018-08-25 02:22:40 +03:00
|
|
|
for (let dir of zReader.findEntries(filepath + "*/")) {
|
|
|
|
var targetDir = buildRelativePath(dir, tmpdir, filepath);
|
2010-09-28 22:54:29 +04:00
|
|
|
// parseInt is used because octal escape sequences cause deprecation warnings
|
|
|
|
// in strict mode (which is turned on in debug builds)
|
2013-10-17 22:27:23 +04:00
|
|
|
if (!targetDir.exists()) {
|
2018-02-28 20:51:33 +03:00
|
|
|
targetDir.create(Ci.nsIFile.DIRECTORY_TYPE, parseInt("0777", 8));
|
2013-10-17 22:27:23 +04:00
|
|
|
}
|
2010-08-24 21:29:34 +04:00
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
// now do the files
|
2018-08-25 02:22:40 +03:00
|
|
|
for (var fname of zReader.findEntries(filepath + "*")) {
|
2018-01-27 00:32:30 +03:00
|
|
|
if (fname.substr(-1) != "/") {
|
2010-08-24 21:29:34 +04:00
|
|
|
var targetFile = buildRelativePath(fname, tmpdir, filepath);
|
|
|
|
zReader.extract(fname, targetFile);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return tmpdir;
|
|
|
|
}
|
|
|
|
|
2013-10-17 22:27:23 +04:00
|
|
|
/*
|
|
|
|
* Take a relative path from the current mochitest file
|
|
|
|
* and returns the absolute path for the given test data file.
|
|
|
|
*/
|
|
|
|
function getTestFilePath(path) {
|
|
|
|
if (path[0] == "/") {
|
|
|
|
throw new Error("getTestFilePath only accepts relative path");
|
|
|
|
}
|
|
|
|
// Get the chrome/jar uri for the current mochitest file
|
|
|
|
// gTestPath being defined by the test harness in browser-chrome tests
|
|
|
|
// or window is being used for mochitest-browser
|
|
|
|
var baseURI = typeof gTestPath == "string" ? gTestPath : window.location.href;
|
|
|
|
var parentURI = getResolvedURI(getRootDirectory(baseURI));
|
|
|
|
var file;
|
|
|
|
if (parentURI.JARFile) {
|
|
|
|
// If it's a jar/zip, we have to extract it first
|
|
|
|
file = extractJarToTmp(parentURI);
|
|
|
|
} else {
|
|
|
|
// Otherwise, we can directly cast it to a file URI
|
2018-02-28 20:51:33 +03:00
|
|
|
var fileHandler = Cc[
|
|
|
|
"@mozilla.org/network/protocol;1?name=file"
|
|
|
|
].getService(Ci.nsIFileProtocolHandler);
|
2013-10-17 22:27:23 +04:00
|
|
|
file = fileHandler.getFileFromURLSpec(parentURI.spec);
|
|
|
|
}
|
|
|
|
// Then walk by the given relative path
|
2018-01-27 00:32:30 +03:00
|
|
|
path.split("/").forEach(function(p) {
|
2013-10-17 22:27:23 +04:00
|
|
|
if (p == "..") {
|
|
|
|
file = file.parent;
|
|
|
|
} else if (p != ".") {
|
|
|
|
file.append(p);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
return file.path;
|
|
|
|
}
|
|
|
|
|
2010-08-24 21:29:34 +04:00
|
|
|
/*
|
2014-07-17 11:02:00 +04:00
|
|
|
* Simple utility function to take the directory structure in jarentryname and
|
2017-08-04 11:49:22 +03:00
|
|
|
* translate that to a path of a nsIFile.
|
2010-08-24 21:29:34 +04:00
|
|
|
*/
|
2018-01-27 00:32:30 +03:00
|
|
|
function buildRelativePath(jarentryname, destdir, basepath) {
|
|
|
|
var baseParts = basepath.split("/");
|
|
|
|
if (baseParts[baseParts.length - 1] == "") {
|
2010-08-24 21:29:34 +04:00
|
|
|
baseParts.pop();
|
|
|
|
}
|
|
|
|
|
2018-01-27 00:32:30 +03:00
|
|
|
var parts = jarentryname.split("/");
|
2010-08-24 21:29:34 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var targetFile = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
|
2010-08-24 21:29:34 +04:00
|
|
|
targetFile.initWithFile(destdir);
|
|
|
|
|
|
|
|
for (var i = baseParts.length; i < parts.length; i++) {
|
|
|
|
targetFile.append(parts[i]);
|
|
|
|
}
|
|
|
|
|
|
|
|
return targetFile;
|
|
|
|
}
|
|
|
|
|
2013-08-02 16:48:06 +04:00
|
|
|
function readConfig(filename) {
|
|
|
|
filename = filename || "testConfig.js";
|
|
|
|
|
2018-04-30 13:03:44 +03:00
|
|
|
var configFile = Services.dirsvc.get("ProfD", Ci.nsIFile);
|
2013-08-02 16:48:06 +04:00
|
|
|
configFile.append(filename);
|
2011-05-17 21:10:37 +04:00
|
|
|
|
|
|
|
if (!configFile.exists()) {
|
2011-06-08 20:04:14 +04:00
|
|
|
return {};
|
2019-07-05 12:01:24 +03:00
|
|
|
}
|
2011-05-17 21:10:37 +04:00
|
|
|
|
2018-02-28 20:51:33 +03:00
|
|
|
var fileInStream = Cc[
|
|
|
|
"@mozilla.org/network/file-input-stream;1"
|
|
|
|
].createInstance(Ci.nsIFileInputStream);
|
2011-05-17 21:10:37 +04:00
|
|
|
fileInStream.init(configFile, -1, 0, 0);
|
|
|
|
|
|
|
|
var str = NetUtil.readInputStreamToString(
|
|
|
|
fileInStream,
|
|
|
|
fileInStream.available()
|
|
|
|
);
|
|
|
|
fileInStream.close();
|
|
|
|
return JSON.parse(str);
|
|
|
|
}
|
|
|
|
|
2013-08-02 16:48:06 +04:00
|
|
|
function getTestList(params, callback) {
|
2018-01-27 00:32:30 +03:00
|
|
|
var baseurl = "chrome://mochitests/content";
|
2011-05-17 21:10:37 +04:00
|
|
|
if (window.parseQueryString) {
|
2018-04-30 13:03:44 +03:00
|
|
|
params = window.parseQueryString(location.search.substring(1), true);
|
2011-05-17 21:10:37 +04:00
|
|
|
}
|
2013-08-02 16:48:06 +04:00
|
|
|
if (!params.baseurl) {
|
|
|
|
params.baseurl = baseurl;
|
|
|
|
}
|
2011-05-17 21:10:37 +04:00
|
|
|
|
|
|
|
var config = readConfig();
|
2013-11-04 15:02:38 +04:00
|
|
|
for (var p in params) {
|
2011-05-17 21:10:37 +04:00
|
|
|
if (params[p] == 1) {
|
|
|
|
config[p] = true;
|
|
|
|
} else if (params[p] == 0) {
|
|
|
|
config[p] = false;
|
|
|
|
} else {
|
|
|
|
config[p] = params[p];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
params = config;
|
2015-06-05 20:28:29 +03:00
|
|
|
getTestManifest(
|
|
|
|
"http://mochi.test:8888/" + params.manifestFile,
|
|
|
|
params,
|
|
|
|
callback
|
|
|
|
);
|
2011-05-17 21:10:37 +04:00
|
|
|
}
|