forked from mirrors/gecko-dev
There are some complications here to handle unpackaged and packaged builds. In addition, there could be a difference between App prefs and GRE prefs. Since the underlying backgroundtasks code is built as part of Gecko (i.e., `toolkit/...` rather than `browser/...`) I have favoured GRE prefs. I think, however, that what is written will work for App-specific prefs, but I'm not concerned with that detail at this time. This also add tests for backgroundtask-specific prefs, which are structured as both xpcshell and mochitest-chrome tests because locally, the former tests unpackaged builds and the latter can accommodate testing packaged builds. We could use mochitest-chrome for both, but this has been pleasant to work with locally. Differential Revision: https://phabricator.services.mozilla.com/D97510
66 lines
1.9 KiB
JavaScript
66 lines
1.9 KiB
JavaScript
/* -*- indent-tabs-mode: nil; js-indent-level: 2 -*-
|
|
* vim: sw=4 ts=4 sts=4 et
|
|
* 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/. */
|
|
|
|
"use strict";
|
|
|
|
async function do_backgroundtask(
|
|
task,
|
|
options = { extraArgs: [], extraEnv: {} }
|
|
) {
|
|
options = Object.assign({}, options);
|
|
options.extraArgs = options.extraArgs || [];
|
|
options.extraEnv = options.extraEnv || {};
|
|
|
|
let command = Services.dirsvc.get("XREExeF", Ci.nsIFile).path;
|
|
let args = ["--backgroundtask", task];
|
|
args.push(...options.extraArgs);
|
|
|
|
// Ensure `resource://testing-common` gets mapped.
|
|
let protocolHandler = Services.io
|
|
.getProtocolHandler("resource")
|
|
.QueryInterface(Ci.nsIResProtocolHandler);
|
|
|
|
let uri = protocolHandler.getSubstitution("testing-common");
|
|
Assert.ok(uri, "resource://testing-common is not substituted");
|
|
|
|
// The equivalent of _TESTING_MODULES_DIR in xpcshell.
|
|
options.extraEnv.XPCSHELL_TESTING_MODULES_URI = uri.spec;
|
|
|
|
// Now we can actually invoke the process.
|
|
info(
|
|
`launching child process ${command} with args: ${args} and extra environment: ${JSON.stringify(
|
|
options.extraEnv
|
|
)}`
|
|
);
|
|
|
|
const { Subprocess } = ChromeUtils.import(
|
|
"resource://gre/modules/Subprocess.jsm"
|
|
);
|
|
let proc = await Subprocess.call({
|
|
command,
|
|
arguments: args,
|
|
environment: options.extraEnv,
|
|
environmentAppend: true,
|
|
stderr: "stdout",
|
|
}).then(p => {
|
|
p.stdin.close();
|
|
const dumpPipe = async pipe => {
|
|
let data = await pipe.readString();
|
|
while (data) {
|
|
for (let line of data.split(/\r\n|\r|\n/).slice(0, -1)) {
|
|
dump("> " + line + "\n");
|
|
}
|
|
data = await pipe.readString();
|
|
}
|
|
};
|
|
dumpPipe(p.stdout);
|
|
|
|
return p;
|
|
});
|
|
|
|
let { exitCode } = await proc.wait();
|
|
return exitCode;
|
|
}
|