Bug 1567341 - Add _TEST_CWD to xpcshell's head.js file. r=jmaher

This variable can be used by platforms to modify the current directory, useful
on Android as the process where the xpcshell test runs does not really have the
concept of CWD.

Differential Revision: https://phabricator.services.mozilla.com/D106207
This commit is contained in:
Agi Sferro 2021-03-24 20:19:59 +00:00
Родитель cc2c44abef
Коммит c553c5f3d3
1 изменённых файлов: 22 добавлений и 2 удалений

Просмотреть файл

@ -12,7 +12,7 @@
/* defined by the harness */
/* globals _HEAD_FILES, _HEAD_JS_PATH, _JSDEBUGGER_PORT, _JSCOV_DIR,
_MOZINFO_JS_PATH, _TEST_FILE, _TEST_NAME, _TESTING_MODULES_DIR:true,
_MOZINFO_JS_PATH, _TEST_FILE, _TEST_NAME, _TEST_CWD, _TESTING_MODULES_DIR:true,
_PREFS_FILE */
/* defined by XPCShellImpl.cpp */
@ -64,6 +64,8 @@ let _XPCOMUtils = ChromeUtils.import(
null
).XPCOMUtils;
let _OS = ChromeUtils.import("resource://gre/modules/osfile.jsm", null).OS;
// Support a common assertion library, Assert.jsm.
var AssertCls = ChromeUtils.import("resource://testing-common/Assert.jsm", null)
.Assert;
@ -503,6 +505,20 @@ function _initDebugging(port) {
}
function _execute_test() {
if (typeof _TEST_CWD != "undefined") {
let cwd_complete = false;
_OS.File.setCurrentDirectory(_TEST_CWD)
.then(_ => (cwd_complete = true))
.catch(e => {
_testLogger.error(_exception_message(e));
cwd_complete = true;
});
_Services.tm.spinEventLoopUntil(
"Test(xpcshell/head.js:setCurrentDirectory)",
() => cwd_complete
);
}
if (runningInParent && _AppConstants.platform == "android") {
_Services.obs.notifyObservers(null, "profile-after-change");
// Wake up GeckoViewStartup
@ -651,7 +667,7 @@ function _execute_test() {
.catch(reportCleanupError)
.then(() => (complete = true));
_Services.tm.spinEventLoopUntil(
"Test(xpcshel/head.js:_execute_test)",
"Test(xpcshell/head.js:_execute_test)",
() => complete
);
if (cleanupStartTime) {
@ -1368,6 +1384,10 @@ function do_load_child_test_harness() {
command += " const _JSCOV_DIR=" + uneval(_JSCOV_DIR) + ";";
}
if (typeof _TEST_CWD != "undefined") {
command += " const _TEST_CWD=" + uneval(_TEST_CWD) + ";";
}
if (_TESTING_MODULES_DIR) {
command +=
" const _TESTING_MODULES_DIR=" + uneval(_TESTING_MODULES_DIR) + ";";