Bug 1541508 - Use Services.env in toolkit/ r=Gijs,application-update-reviewers,nalexander

Differential Revision: https://phabricator.services.mozilla.com/D160149
This commit is contained in:
Barret Rennie 2022-11-25 19:09:11 +00:00
Родитель 15bea72588
Коммит 2ece2f0ce3
54 изменённых файлов: 124 добавлений и 283 удалений

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

@ -29,10 +29,10 @@ XPCOMUtils.defineLazyGetter(lazy, "log", () => {
// a transliteration of `register_modules_protocol_handler` from
// https://searchfox.org/mozilla-central/rev/f081504642a115cb8236bea4d8250e5cb0f39b02/testing/xpcshell/head.js#358-389.
function registerModulesProtocolHandler() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
let _TESTING_MODULES_URI = Services.env.get(
"XPCSHELL_TESTING_MODULES_URI",
""
);
let _TESTING_MODULES_URI = env.get("XPCSHELL_TESTING_MODULES_URI", "");
if (!_TESTING_MODULES_URI) {
return false;
}

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

@ -54,13 +54,12 @@ export var BackgroundTasksUtils = {
if (!this._defaultProfileInitialized) {
this._defaultProfileInitialized = true;
// This is all test-only.
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let defaultProfilePath = env.get(
let defaultProfilePath = Services.env.get(
"MOZ_BACKGROUNDTASKS_DEFAULT_PROFILE_PATH"
);
let noDefaultProfile = env.get("MOZ_BACKGROUNDTASKS_NO_DEFAULT_PROFILE");
let noDefaultProfile = Services.env.get(
"MOZ_BACKGROUNDTASKS_NO_DEFAULT_PROFILE"
);
if (defaultProfilePath) {
lazy.log.info(
`getDefaultProfile: using default profile path ${defaultProfilePath}`

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

@ -20,11 +20,8 @@ export async function runBackgroundTask(commandLine) {
);
// Get the temp dir.
var env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
var tmpd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
tmpd.initWithPath(env.get("XPCSHELL_TEST_TEMP_DIR"));
tmpd.initWithPath(Services.env.get("XPCSHELL_TEST_TEMP_DIR"));
// We need to call this or crash events go in an undefined location.
Services.appinfo.UpdateCrashEventsDir();

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

@ -4,11 +4,7 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
export async function runBackgroundTask(commandLine) {
var env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const get = env.get("MOZ_TEST_PROCESS_UPDATES");
const get = Services.env.get("MOZ_TEST_PROCESS_UPDATES");
let exitCode = 81;
if (get == "ShouldNotProcessUpdates(): OtherInstanceRunning") {
exitCode = 80;
@ -20,7 +16,7 @@ export async function runBackgroundTask(commandLine) {
exitCode = 78;
}
console.debug(`runBackgroundTask: shouldprocessupdates`, {
exists: env.exists("MOZ_TEST_PROCESS_UPDATES"),
exists: Services.env.exists("MOZ_TEST_PROCESS_UPDATES"),
get,
});
console.error(

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

@ -187,9 +187,7 @@ function getStackFromProfile(profile, stack, libs) {
add_task(async function test_xpcom_graph_wait() {
TestUtils.assertPackagedBuild();
let profilePath = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment)
.get("MOZ_UPLOAD_DIR");
let profilePath = Services.env.get("MOZ_UPLOAD_DIR");
profilePath =
profilePath ||
(await IOUtils.createUniqueDirectory(

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

@ -102,11 +102,8 @@ add_task(c, async function test_backgroundtask_cleans_up_stale_profiles() {
// Display logging for ease of debugging.
let moz_log = "BackgroundTasks:5";
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("MOZ_LOG")) {
moz_log += `,${env.get("MOZ_LOG")}`;
if (Services.env.exists("MOZ_LOG")) {
moz_log += `,${Services.env.get("MOZ_LOG")}`;
}
// Invoke the task.

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

@ -20,11 +20,8 @@ let tmp = do_get_profile();
tmp.append("Temp");
add_setup(() => {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("MOZ_LOG")) {
moz_log += `,${env.get("MOZ_LOG")}`;
if (Services.env.exists("MOZ_LOG")) {
moz_log += `,${Services.env.get("MOZ_LOG")}`;
}
tmp.createUnique(Ci.nsIFile.DIRECTORY_TYPE, 0o700);

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

@ -24,10 +24,7 @@ var gRunningProcesses = new Set();
* don't want to block shutdown waiting for it.
*/
async function maybeRunMinidumpAnalyzer(minidumpPath, allThreads) {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let shutdown = env.exists("MOZ_CRASHREPORTER_SHUTDOWN");
let shutdown = Services.env.exists("MOZ_CRASHREPORTER_SHUTDOWN");
if (gQuitting || shutdown) {
return;

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

@ -149,10 +149,7 @@ add_task(async function test_addCrash_shutdownOnCrash() {
await setup(crashId);
// Set the MOZ_CRASHREPORTER_SHUTDOWN environment variable
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_CRASHREPORTER_SHUTDOWN", "1");
Services.env.set("MOZ_CRASHREPORTER_SHUTDOWN", "1");
await addCrash(crashId);
@ -164,7 +161,7 @@ add_task(async function test_addCrash_shutdownOnCrash() {
"analyzer did not start.\n"
);
env.set("MOZ_CRASHREPORTER_SHUTDOWN", ""); // Unset the environment variable
Services.env.set("MOZ_CRASHREPORTER_SHUTDOWN", ""); // Unset the environment variable
await teardown();
});

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

@ -39,12 +39,6 @@ XPCOMUtils.defineLazyServiceGetter(
"@mozilla.org/toolkit/download-platform;1",
"mozIDownloadPlatform"
);
XPCOMUtils.defineLazyServiceGetter(
lazy,
"gEnvironment",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);
XPCOMUtils.defineLazyServiceGetter(
lazy,
"gMIMEService",
@ -282,7 +276,7 @@ export var DownloadIntegration = {
if (AppConstants.platform == "android") {
// Android doesn't have a $HOME directory, and by default we only have
// write access to /data/data/org.mozilla.{$APP} and /sdcard
this._downloadsDirectory = lazy.gEnvironment.get("DOWNLOADS_DIRECTORY");
this._downloadsDirectory = Services.env.get("DOWNLOADS_DIRECTORY");
if (!this._downloadsDirectory) {
throw new Components.Exception(
"DOWNLOADS_DIRECTORY is not set.",

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

@ -62,10 +62,7 @@ XPCOMUtils.defineLazyGetter(lazy, "log", () => {
});
});
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const isXpcshell = env.exists("XPCSHELL_TEST_PROFILE_DIR");
const isXpcshell = Services.env.exists("XPCSHELL_TEST_PROFILE_DIR");
// We're only testing for empty objects, not
// empty strings or empty arrays.

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

@ -5,10 +5,7 @@
"use strict";
XPCOMUtils.defineLazyGetter(this, "isXpcshell", function() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
return env.exists("XPCSHELL_TEST_PROFILE_DIR");
return Services.env.exists("XPCSHELL_TEST_PROFILE_DIR");
});
/**

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

@ -47,10 +47,7 @@ const ID = "native@tests.mozilla.org";
async function setupHosts(scripts) {
const PERMS = { unixMode: 0o755 };
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const pythonPath = await Subprocess.pathSearch(env.get("PYTHON"));
const pythonPath = await Subprocess.pathSearch(Services.env.get("PYTHON"));
async function writeManifest(script, scriptPath, path) {
let body = `#!${pythonPath} -u\n${script.script}`;

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

@ -9,10 +9,6 @@
* loads.
*/
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// Make sure media pre-loading is enabled on Android so that our <audio> and
// <video> elements trigger the expected requests.
Services.prefs.setIntPref("media.autoplay.default", Ci.nsIAutoplay.ALLOWED);
@ -1304,7 +1300,7 @@ add_task(async function test_contentscript_triggeringPrincipals() {
add_task(async function test_contentscript_csp() {
// TODO bug 1408193: We currently don't get the full set of CSP reports when
// running in network scheduling chaos mode. It's not entirely clear why.
let chaosMode = parseInt(env.get("MOZ_CHAOSMODE"), 16);
let chaosMode = parseInt(Services.env.get("MOZ_CHAOSMODE"), 16);
let checkCSPReports = !(chaosMode === 0 || chaosMode & 0x02);
gContentSecurityPolicy = `default-src 'none' 'report-sample'; script-src 'nonce-deadbeef' 'unsafe-eval' 'report-sample'; report-uri ${CSP_REPORT_PATH};`;
@ -1344,7 +1340,7 @@ add_task(async function test_extension_contentscript_csp() {
// TODO bug 1408193: We currently don't get the full set of CSP reports when
// running in network scheduling chaos mode. It's not entirely clear why.
let chaosMode = parseInt(env.get("MOZ_CHAOSMODE"), 16);
let chaosMode = parseInt(Services.env.get("MOZ_CHAOSMODE"), 16);
let checkCSPReports = !(chaosMode === 0 || chaosMode & 0x02);
gContentSecurityPolicy = `default-src 'none' 'report-sample'; script-src 'nonce-deadbeef' 'unsafe-eval' 'report-sample'; report-uri ${CSP_REPORT_PATH};`;

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

@ -88,11 +88,8 @@ let PYTHON;
add_task(async function setup() {
await Schemas.load(BASE_SCHEMA);
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
try {
PYTHON = await Subprocess.pathSearch(env.get("PYTHON"));
PYTHON = await Subprocess.pathSearch(Services.env.get("PYTHON"));
} catch (e) {
notEqual(
PYTHON,

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

@ -29,10 +29,7 @@ function getChainRootIdentifier() {
if (normandy_url.includes("dev.")) {
return Ci.nsIContentSignatureVerifier.ContentSignatureDevRoot;
}
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
if (Services.env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
return Ci.nsIX509CertDB.AppXPCShellRoot;
}
return Ci.nsIContentSignatureVerifier.ContentSignatureLocalRoot;

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

@ -13,15 +13,11 @@ const ProcessTools = Cc["@mozilla.org/processtools-service;1"].getService(
Ci.nsIProcessToolsService
);
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let PYTHON;
// Find Python.
add_task(async function setup() {
PYTHON = await Subprocess.pathSearch(env.get("PYTHON"));
PYTHON = await Subprocess.pathSearch(Services.env.get("PYTHON"));
});
// Ensure that killing a process... kills the process.

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

@ -21,10 +21,7 @@ var gTestScope;
export var SearchTestUtils = {
init(testScope) {
gTestScope = testScope;
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
this._isMochitest = !env.exists("XPCSHELL_TEST_PROFILE_DIR");
this._isMochitest = !Services.env.exists("XPCSHELL_TEST_PROFILE_DIR");
if (this._isMochitest) {
this._isMochitest = true;
lazy.AddonTestUtils.initMochitest(testScope);

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

@ -26,14 +26,10 @@ XPCOMUtils.defineLazyModuleGetters(this, {
sinon: "resource://testing-common/Sinon.jsm",
});
XPCOMUtils.defineLazyServiceGetters(this, {
gEnvironment: ["@mozilla.org/process/environment;1", "nsIEnvironment"],
});
XPCOMUtils.defineLazyGlobalGetters(this, ["fetch"]);
const GLOBAL_SCOPE = this;
const TEST_DEBUG = gEnvironment.get("TEST_DEBUG");
const TEST_DEBUG = Services.env.get("TEST_DEBUG");
const URLTYPE_SUGGEST_JSON = "application/x-suggestions+json";
const URLTYPE_SEARCH_HTML = "text/html";
@ -53,7 +49,7 @@ let engineSelector;
* against a remote server.
*/
async function maybeSetupConfig() {
const SEARCH_CONFIG = gEnvironment.get("SEARCH_CONFIG");
const SEARCH_CONFIG = Services.env.get("SEARCH_CONFIG");
if (SEARCH_CONFIG) {
if (!(SEARCH_CONFIG in SearchUtils.ENGINES_URLS)) {
throw new Error(`Invalid value for SEARCH_CONFIG`);

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

@ -3,9 +3,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
const gEnv = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const gDashboard = Cc["@mozilla.org/network/dashboard;1"].getService(
Ci.nsIDashboard
);
@ -66,7 +63,8 @@ function updateLogFile() {
let logPath = "";
// Try to get the environment variable for the log file
logPath = gEnv.get("MOZ_LOG_FILE") || gEnv.get("NSPR_LOG_FILE");
logPath =
Services.env.get("MOZ_LOG_FILE") || Services.env.get("NSPR_LOG_FILE");
let currentLogFile = document.getElementById("current-log-file");
let setLogFileButton = document.getElementById("set-log-file-button");
@ -109,9 +107,9 @@ function updateLogFile() {
function updateLogModules() {
// Try to get the environment variable for the log file
let logModules =
gEnv.get("MOZ_LOG") ||
gEnv.get("MOZ_LOG_MODULES") ||
gEnv.get("NSPR_LOG_MODULES");
Services.env.get("MOZ_LOG") ||
Services.env.get("MOZ_LOG_MODULES") ||
Services.env.get("NSPR_LOG_MODULES");
let currentLogModules = document.getElementById("current-log-modules");
let setLogModulesButton = document.getElementById("set-log-modules-button");
if (logModules.length) {

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

@ -7,9 +7,6 @@
const FileUtils = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
).FileUtils;
const gEnv = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const gDashboard = Cc["@mozilla.org/network/dashboard;1"].getService(
Ci.nsIDashboard
);

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

@ -644,14 +644,11 @@ var Debug = {
// Disable configure log modules if log modules are already set
// by environment variable.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let logModules =
env.get("MOZ_LOG") ||
env.get("MOZ_LOG_MODULES") ||
env.get("NSPR_LOG_MODULES");
Services.env.get("MOZ_LOG") ||
Services.env.get("MOZ_LOG_MODULES") ||
Services.env.get("NSPR_LOG_MODULES");
if (logModules.length) {
document.getElementById("set-log-modules").disabled = true;
@ -665,7 +662,8 @@ var Debug = {
// Disable set log file if log file is already set
// by environment variable.
let logFile = env.get("MOZ_LOG_FILE") || env.get("NSPR_LOG_FILE");
let logFile =
Services.env.get("MOZ_LOG_FILE") || Services.env.get("NSPR_LOG_FILE");
if (logFile.length) {
document.getElementById("set-log-file").disabled = true;
document.getElementById("log-file").value = logFile;

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

@ -24,10 +24,7 @@
const { AppConstants } = ChromeUtils.importESModule(
"resource://gre/modules/AppConstants.sys.mjs"
);
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const instrumentClasses = env.get("MOZ_INSTRUMENT_CUSTOM_ELEMENTS");
const instrumentClasses = Services.env.get("MOZ_INSTRUMENT_CUSTOM_ELEMENTS");
const instrumentedClasses = instrumentClasses ? new Set() : null;
const instrumentedBaseClasses = instrumentClasses ? new WeakSet() : null;

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

@ -212,9 +212,7 @@ Submitter.prototype = {
delete this.extraKeyVals.ServerURL;
// Override the submission URL from the environment
let envOverride = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment)
.get("MOZ_CRASHREPORTER_URL");
let envOverride = Services.env.get("MOZ_CRASHREPORTER_URL");
if (envOverride != "") {
serverURL = envOverride;
}

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

@ -2,11 +2,8 @@
var cwd = Services.dirsvc.get("CurWorkD", Ci.nsIFile);
// get the temp dir
var env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
var _tmpd = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
_tmpd.initWithPath(env.get("XPCSHELL_TEST_TEMP_DIR"));
_tmpd.initWithPath(Services.env.get("XPCSHELL_TEST_TEMP_DIR"));
// Allow `crashReporter` to be used as an alias in the tests.
var crashReporter = Services.appinfo;

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

@ -68,24 +68,20 @@ async function do_crash(setup, callback, canReturnZero) {
}
args.push("-f", tailfile.path);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let crashD = do_get_tempdir();
crashD.append("crash-events");
if (!crashD.exists()) {
crashD.create(crashD.DIRECTORY_TYPE, 0o700);
}
env.set("CRASHES_EVENTS_DIR", crashD.path);
Services.env.set("CRASHES_EVENTS_DIR", crashD.path);
try {
process.run(true, args, args.length);
} catch (ex) {
// on Windows we exit with a -1 status when crashing.
} finally {
env.set("CRASHES_EVENTS_DIR", "");
Services.env.set("CRASHES_EVENTS_DIR", "");
}
if (!canReturnZero) {
@ -307,17 +303,13 @@ async function do_backgroundtask_crash(
args.push(value);
}
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let crashD = do_get_tempdir();
crashD.append("crash-events");
if (!crashD.exists()) {
crashD.create(crashD.DIRECTORY_TYPE, 0o700);
}
env.set("CRASHES_EVENTS_DIR", crashD.path);
Services.env.set("CRASHES_EVENTS_DIR", crashD.path);
// Ensure `resource://testing-common` gets mapped.
let protocolHandler = Services.io
@ -328,15 +320,15 @@ async function do_backgroundtask_crash(
Assert.ok(uri, "resource://testing-common is not substituted");
// The equivalent of _TESTING_MODULES_DIR in xpcshell.
env.set("XPCSHELL_TESTING_MODULES_URI", uri.spec);
Services.env.set("XPCSHELL_TESTING_MODULES_URI", uri.spec);
try {
process.run(true, args, args.length);
} catch (ex) {
// on Windows we exit with a -1 status when crashing.
} finally {
env.set("CRASHES_EVENTS_DIR", "");
env.set("XPCSHELL_TESTING_MODULES_URI", "");
Services.env.set("CRASHES_EVENTS_DIR", "");
Services.env.set("XPCSHELL_TESTING_MODULES_URI", "");
}
if (!canReturnZero) {

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

@ -15,10 +15,7 @@ add_task(async function run_test() {
// Delay crashing so that the memory report has time to complete.
shouldDelay = true;
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let profd = env.get("XPCSHELL_TEST_PROFILE_DIR");
let profd = Services.env.get("XPCSHELL_TEST_PROFILE_DIR");
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(profd);

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

@ -85,10 +85,7 @@ export var ResetProfile = {
}
// Set the reset profile environment variable.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_RESET_PROFILE_RESTART", "1");
Services.env.set("MOZ_RESET_PROFILE_RESTART", "1");
Services.startup.quit(
Ci.nsIAppStartup.eForceQuit | Ci.nsIAppStartup.eRestart

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

@ -5,7 +5,6 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
import { AppConstants } from "resource://gre/modules/AppConstants.sys.mjs";
import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";
import {
BaseProcess,
PromiseWorker,
@ -13,15 +12,6 @@ import {
const { ctypes } = ChromeUtils.import("resource://gre/modules/ctypes.jsm");
const lazy = {};
XPCOMUtils.defineLazyServiceGetter(
lazy,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);
var obj = { ctypes };
Services.scriptloader.loadSubScript(
"resource://gre/modules/subprocess/subprocess_shared.js",
@ -50,7 +40,7 @@ class WinPromiseWorker extends PromiseWorker {
"win",
"6.2"
),
comspec: lazy.env.get("COMSPEC"),
comspec: Services.env.get("COMSPEC"),
signalEvent: String(
ctypes.cast(this.signalEvent, ctypes.uintptr_t).value
),

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

@ -5,10 +5,6 @@ const { setTimeout } = ChromeUtils.importESModule(
"resource://gre/modules/Timer.sys.mjs"
);
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const MAX_ROUND_TRIP_TIME_MS = AppConstants.DEBUG || AppConstants.ASAN ? 18 : 9;
const MAX_RETRIES = 5;
@ -35,7 +31,7 @@ let readAll = async function(pipe) {
};
add_task(async function setup() {
PYTHON = await Subprocess.pathSearch(env.get("PYTHON"));
PYTHON = await Subprocess.pathSearch(Services.env.get("PYTHON"));
PYTHON_BIN = PathUtils.filename(PYTHON);
PYTHON_DIR = PathUtils.parent(PYTHON);
@ -679,13 +675,13 @@ add_task(async function test_subprocess_environment() {
// PATH variables.
if (AppConstants.platform == "win") {
Object.assign(environment, {
PATH: env.get("PATH"),
PATHEXT: env.get("PATHEXT"),
SYSTEMROOT: env.get("SYSTEMROOT"),
PATH: Services.env.get("PATH"),
PATHEXT: Services.env.get("PATHEXT"),
SYSTEMROOT: Services.env.get("SYSTEMROOT"),
});
}
env.set("BAR", "BAZ");
Services.env.set("BAR", "BAZ");
let proc = await Subprocess.call({
command: PYTHON,
@ -709,9 +705,9 @@ add_task(async function test_subprocess_environment() {
});
add_task(async function test_subprocess_environmentAppend() {
env.set("VALUE_FROM_BASE_ENV", "untouched");
env.set("VALUE_FROM_BASE_ENV_EMPTY", "untouched");
env.set("VALUE_FROM_BASE_ENV_REMOVED", "untouched");
Services.env.set("VALUE_FROM_BASE_ENV", "untouched");
Services.env.set("VALUE_FROM_BASE_ENV_EMPTY", "untouched");
Services.env.set("VALUE_FROM_BASE_ENV_REMOVED", "untouched");
let proc = await Subprocess.call({
command: PYTHON,
@ -814,7 +810,7 @@ if (AppConstants.platform !== "win") {
equal(foo, val, "Got expected $FOO value");
env.set("FOO", "");
Services.env.set("FOO", "");
let { exitCode } = await proc.wait();

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

@ -1,18 +1,14 @@
"use strict";
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
add_task(async function test_getEnvironment() {
env.set("FOO", "BAR");
Services.env.set("FOO", "BAR");
let environment = Subprocess.getEnvironment();
equal(environment.FOO, "BAR");
equal(environment.PATH, env.get("PATH"));
equal(environment.PATH, Services.env.get("PATH"));
env.set("FOO", null);
Services.env.set("FOO", null);
environment = Subprocess.getEnvironment();
equal(environment.FOO || "", "");

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

@ -1,10 +1,6 @@
"use strict";
let envService = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const PYTHON = envService.get("PYTHON");
const PYTHON = Services.env.get("PYTHON");
const PYTHON_BIN = PathUtils.filename(PYTHON);
const PYTHON_DIR = PathUtils.parent(PYTHON);

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

@ -185,10 +185,7 @@ async function verifyGmpContentSignature(data, contentSignatureHeader) {
// See bug 1771992. In the future, this may need to handle staging and dev
// environments in addition to just production and testing.
let root = Ci.nsIContentSignatureVerifier.ContentSignatureProdRoot;
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
if (Services.env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
root = Ci.nsIX509CertDB.AppXPCShellRoot;
}

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

@ -46,12 +46,11 @@ const SITEPERMS_ADDON_ID_SUFFIX = "@siteperms.mozilla.org";
// used outside of tests.
let SALT;
export function generateSalt() {
//TODO: Use Services.env (See Bug 1541508).
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// Throw if we're not in test and SALT is already defined
if (typeof SALT !== "undefined" && !env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
if (
typeof SALT !== "undefined" &&
!Services.env.exists("XPCSHELL_TEST_PROFILE_DIR")
) {
throw new Error("This should only be called from XPCShell tests");
}
SALT = crypto.getRandomValues(new Uint8Array(12)).join("");

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

@ -56,10 +56,7 @@ export function isKnownPublicSuffix(siteOrigin) {
* @throws if not called from xpcshell test
*/
export function addGatedPermissionTypesForXpcShellTests(permissionTypes) {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (!env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
if (!Services.env.exists("XPCSHELL_TEST_PROFILE_DIR")) {
throw new Error("This should only be called from XPCShell tests");
}

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

@ -10,15 +10,12 @@ let global = this;
// if they include non-ascii characters (see bug 1428234 for an example of
// a past bug with such paths)
add_task(async function test_non_ascii_path() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
const PROFILE_VAR = "XPCSHELL_TEST_PROFILE_DIR";
let profileDir = PathUtils.join(
env.get(PROFILE_VAR),
Services.env.get(PROFILE_VAR),
"\u00ce \u00e5m \u00f1\u00f8t \u00e5s\u00e7ii"
);
env.set(PROFILE_VAR, profileDir);
Services.env.set(PROFILE_VAR, profileDir);
AddonTestUtils.init(global);
AddonTestUtils.overrideCertDB();

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

@ -127,10 +127,7 @@ const gUpdateElevationDialog = {
// If already in safe mode restart in safe mode (bug 327119)
if (Services.appinfo.inSafeMode) {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_SAFE_MODE_RESTART", "1");
Services.env.set("MOZ_SAFE_MODE_RESTART", "1");
}
// Restart the application

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

@ -8,7 +8,7 @@
// opened.
add_task(
async function aboutDialog_backgroundCheck_downloaded_stagingFailure() {
gEnv.set("MOZ_TEST_STAGING_ERROR", "1");
Services.env.set("MOZ_TEST_STAGING_ERROR", "1");
await SpecialPowers.pushPrefEnv({
set: [[PREF_APP_UPDATE_STAGING_ENABLED, true]],
});

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

@ -7,7 +7,7 @@
// with the update downloaded and staging has failed when the about:preferences
// is opened.
add_task(async function aboutPrefs_backgroundCheck_downloaded_stagingFailure() {
gEnv.set("MOZ_TEST_STAGING_ERROR", "1");
Services.env.set("MOZ_TEST_STAGING_ERROR", "1");
await SpecialPowers.pushPrefEnv({
set: [[PREF_APP_UPDATE_STAGING_ENABLED, true]],
});

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

@ -128,9 +128,9 @@ add_setup(async function setupTestCommon() {
*/
registerCleanupFunction(async () => {
AppMenuNotifications.removeNotification(/.*/);
gEnv.set("MOZ_TEST_SKIP_UPDATE_STAGE", "");
gEnv.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "");
gEnv.set("MOZ_TEST_STAGING_ERROR", "");
Services.env.set("MOZ_TEST_SKIP_UPDATE_STAGE", "");
Services.env.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "");
Services.env.set("MOZ_TEST_STAGING_ERROR", "");
UpdateListener.reset();
AppMenuNotifications.removeNotification(/.*/);
reloadUpdateManagerData(true);
@ -611,9 +611,9 @@ function runDoorhangerUpdateTest(params, steps) {
return (async function() {
if (params.slowStaging) {
gEnv.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
Services.env.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
} else {
gEnv.set("MOZ_TEST_SKIP_UPDATE_STAGE", "1");
Services.env.set("MOZ_TEST_SKIP_UPDATE_STAGE", "1");
}
await SpecialPowers.pushPrefEnv({
set: [
@ -856,7 +856,7 @@ function runAboutDialogUpdateTest(params, steps) {
}
return (async function() {
gEnv.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
Services.env.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
await SpecialPowers.pushPrefEnv({
set: [
[PREF_APP_UPDATE_DISABLEDFORTESTING, false],
@ -1145,7 +1145,7 @@ function runAboutPrefsUpdateTest(params, steps) {
}
return (async function() {
gEnv.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
Services.env.set("MOZ_TEST_SLOW_SKIP_UPDATE_STAGE", "1");
await SpecialPowers.pushPrefEnv({
set: [
[PREF_APP_UPDATE_DISABLEDFORTESTING, false],
@ -1251,7 +1251,7 @@ function removeUpdateSettingsIni() {
function runTelemetryUpdateTest(updateParams, event, stageFailure = false) {
return (async function() {
Services.telemetry.clearScalars();
gEnv.set("MOZ_TEST_SKIP_UPDATE_STAGE", "1");
Services.env.set("MOZ_TEST_SKIP_UPDATE_STAGE", "1");
await SpecialPowers.pushPrefEnv({
set: [[PREF_APP_UPDATE_DISABLEDFORTESTING, false]],
});

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

@ -147,13 +147,6 @@ XPCOMUtils.defineLazyGetter(this, "gPrefRoot", function test_gPR() {
return Services.prefs.getBranch(null);
});
XPCOMUtils.defineLazyServiceGetter(
this,
"gEnv",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);
/**
* Waits for the specified topic and (optionally) status.
*

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

@ -2018,7 +2018,7 @@ function runUpdate(
let pid = 0;
if (gPIDPersistProcess) {
pid = gPIDPersistProcess.pid;
gEnv.set("MOZ_TEST_SHORTER_WAIT_PID", "1");
Services.env.set("MOZ_TEST_SHORTER_WAIT_PID", "1");
}
let updateBin = copyTestUpdaterToBinDir();
@ -2074,7 +2074,7 @@ function runUpdate(
resetEnvironment();
if (gPIDPersistProcess) {
gEnv.set("MOZ_TEST_SHORTER_WAIT_PID", "");
Services.env.set("MOZ_TEST_SHORTER_WAIT_PID", "");
}
let status = readStatusFile();
@ -4706,7 +4706,7 @@ function setEnvironment() {
// set an environment variable and have the test updater set the current
// working directory than it is to set the current working directory in the
// test itself.
gEnv.set("CURWORKDIRPATH", getApplyDirFile().path);
Services.env.set("CURWORKDIRPATH", getApplyDirFile().path);
}
// Prevent setting the environment more than once.
@ -4718,28 +4718,28 @@ function setEnvironment() {
if (
AppConstants.platform == "win" &&
!gEnv.exists("XRE_NO_WINDOWS_CRASH_DIALOG")
!Services.env.exists("XRE_NO_WINDOWS_CRASH_DIALOG")
) {
gAddedEnvXRENoWindowsCrashDialog = true;
debugDump(
"setting the XRE_NO_WINDOWS_CRASH_DIALOG environment " +
"variable to 1... previously it didn't exist"
);
gEnv.set("XRE_NO_WINDOWS_CRASH_DIALOG", "1");
Services.env.set("XRE_NO_WINDOWS_CRASH_DIALOG", "1");
}
if (gEnv.exists("XPCOM_MEM_LEAK_LOG")) {
gEnvXPCOMMemLeakLog = gEnv.get("XPCOM_MEM_LEAK_LOG");
if (Services.env.exists("XPCOM_MEM_LEAK_LOG")) {
gEnvXPCOMMemLeakLog = Services.env.get("XPCOM_MEM_LEAK_LOG");
debugDump(
"removing the XPCOM_MEM_LEAK_LOG environment variable... " +
"previous value " +
gEnvXPCOMMemLeakLog
);
gEnv.set("XPCOM_MEM_LEAK_LOG", "");
Services.env.set("XPCOM_MEM_LEAK_LOG", "");
}
if (gEnv.exists("XPCOM_DEBUG_BREAK")) {
gEnvXPCOMDebugBreak = gEnv.get("XPCOM_DEBUG_BREAK");
if (Services.env.exists("XPCOM_DEBUG_BREAK")) {
gEnvXPCOMDebugBreak = Services.env.get("XPCOM_DEBUG_BREAK");
debugDump(
"setting the XPCOM_DEBUG_BREAK environment variable to " +
"warn... previous value " +
@ -4752,16 +4752,16 @@ function setEnvironment() {
);
}
gEnv.set("XPCOM_DEBUG_BREAK", "warn");
Services.env.set("XPCOM_DEBUG_BREAK", "warn");
if (gEnvForceServiceFallback) {
// This env variable forces the updater to use the service in an invalid
// way, so that it has to fall back to updating without the service.
debugDump("setting MOZ_FORCE_SERVICE_FALLBACK environment variable to 1");
gEnv.set("MOZ_FORCE_SERVICE_FALLBACK", "1");
Services.env.set("MOZ_FORCE_SERVICE_FALLBACK", "1");
} else if (gIsServiceTest) {
debugDump("setting MOZ_NO_SERVICE_FALLBACK environment variable to 1");
gEnv.set("MOZ_NO_SERVICE_FALLBACK", "1");
Services.env.set("MOZ_NO_SERVICE_FALLBACK", "1");
}
}
@ -4782,7 +4782,7 @@ function resetEnvironment() {
"setting the XPCOM_MEM_LEAK_LOG environment variable back to " +
gEnvXPCOMMemLeakLog
);
gEnv.set("XPCOM_MEM_LEAK_LOG", gEnvXPCOMMemLeakLog);
Services.env.set("XPCOM_MEM_LEAK_LOG", gEnvXPCOMMemLeakLog);
}
if (gEnvXPCOMDebugBreak) {
@ -4790,22 +4790,22 @@ function resetEnvironment() {
"setting the XPCOM_DEBUG_BREAK environment variable back to " +
gEnvXPCOMDebugBreak
);
gEnv.set("XPCOM_DEBUG_BREAK", gEnvXPCOMDebugBreak);
} else if (gEnv.exists("XPCOM_DEBUG_BREAK")) {
Services.env.set("XPCOM_DEBUG_BREAK", gEnvXPCOMDebugBreak);
} else if (Services.env.exists("XPCOM_DEBUG_BREAK")) {
debugDump("clearing the XPCOM_DEBUG_BREAK environment variable");
gEnv.set("XPCOM_DEBUG_BREAK", "");
Services.env.set("XPCOM_DEBUG_BREAK", "");
}
if (AppConstants.platform == "win" && gAddedEnvXRENoWindowsCrashDialog) {
debugDump("removing the XRE_NO_WINDOWS_CRASH_DIALOG environment variable");
gEnv.set("XRE_NO_WINDOWS_CRASH_DIALOG", "");
Services.env.set("XRE_NO_WINDOWS_CRASH_DIALOG", "");
}
if (gEnvForceServiceFallback) {
debugDump("removing MOZ_FORCE_SERVICE_FALLBACK environment variable");
gEnv.set("MOZ_FORCE_SERVICE_FALLBACK", "");
Services.env.set("MOZ_FORCE_SERVICE_FALLBACK", "");
} else if (gIsServiceTest) {
debugDump("removing MOZ_NO_SERVICE_FALLBACK environment variable");
gEnv.set("MOZ_NO_SERVICE_FALLBACK", "");
Services.env.set("MOZ_NO_SERVICE_FALLBACK", "");
}
}

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

@ -244,10 +244,7 @@ class TestNoWindowUpdateRestart(MarionetteTestCase):
await updateDownloadedPromise;
Services.obs.addObserver((aSubject, aTopic, aData) => {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
let silent_restart = env.get("MOZ_APP_SILENT_START") == 1 && env.get("MOZ_APP_RESTART") == 1;
let silent_restart = Services.env.get("MOZ_APP_SILENT_START") == 1 && Services.env.get("MOZ_APP_RESTART") == 1;
Services.prefs.setBoolPref("testing.no_window_update_restart.silent_restart_env", silent_restart);
}, "quit-application-granted");

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

@ -28,7 +28,7 @@ function run_test() {
);
// Bypass the manifest and run as invoker
gEnv.set("__COMPAT_LAYER", "RunAsInvoker");
Services.env.set("__COMPAT_LAYER", "RunAsInvoker");
let dummyInstallPath = "---";
let maintenanceServiceBinArgs = [

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

@ -64,19 +64,13 @@ ShellService.register();
let gIsLegacy = false;
function simulateSnapEnvironment() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("SNAP_INSTANCE_NAME", AppConstants.MOZ_APP_NAME);
Services.env.set("SNAP_INSTANCE_NAME", AppConstants.MOZ_APP_NAME);
gIsLegacy = true;
}
function enableLegacyProfiles() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("MOZ_LEGACY_PROFILES", "1");
Services.env.set("MOZ_LEGACY_PROFILES", "1");
gIsLegacy = true;
}

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

@ -32,11 +32,8 @@ add_task(async () => {
writeProfilesIni(profileData);
checkProfileService(profileData);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("XRE_PROFILE_PATH", dir.path);
env.set("XRE_PROFILE_LOCAL_PATH", dir.path);
Services.env.set("XRE_PROFILE_PATH", dir.path);
Services.env.set("XRE_PROFILE_LOCAL_PATH", dir.path);
let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
checkStartupReason("restart");

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

@ -34,11 +34,8 @@ add_task(async () => {
writeProfilesIni(profileData);
checkProfileService(profileData);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("XRE_PROFILE_PATH", root.path);
env.set("XRE_PROFILE_LOCAL_PATH", local.path);
Services.env.set("XRE_PROFILE_PATH", root.path);
Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
let { rootDir, localDir, profile, didCreate } = selectStartupProfile([
"-P",

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

@ -45,11 +45,8 @@ add_task(async () => {
writeProfilesIni(profileData);
checkProfileService(profileData);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("XRE_PROFILE_PATH", root.path);
env.set("XRE_PROFILE_LOCAL_PATH", local.path);
Services.env.set("XRE_PROFILE_PATH", root.path);
Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
checkStartupReason("restart-skipped-default");

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

@ -44,11 +44,8 @@ add_task(async () => {
writeProfilesIni(profileData);
checkProfileService(profileData);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("XRE_PROFILE_PATH", root.path);
env.set("XRE_PROFILE_LOCAL_PATH", local.path);
Services.env.set("XRE_PROFILE_PATH", root.path);
Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
checkStartupReason("restart-claimed-default");

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

@ -46,11 +46,8 @@ add_task(async () => {
writeProfilesIni(profileData);
checkProfileService(profileData);
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
env.set("XRE_PROFILE_PATH", root.path);
env.set("XRE_PROFILE_LOCAL_PATH", local.path);
Services.env.set("XRE_PROFILE_PATH", root.path);
Services.env.set("XRE_PROFILE_LOCAL_PATH", local.path);
let { rootDir, localDir, profile, didCreate } = selectStartupProfile();
checkStartupReason("restart-claimed-default");

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

@ -134,8 +134,7 @@ class TestFissionAutostart(MarionetteTestCase):
// We're running in a function, in a sandbox, that inherits from an
// X-ray wrapped window. Anything we want to be globally available
// needs to be defined on that window.
window.env = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
window.env = Services.env;
"""
)

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

@ -142,8 +142,7 @@ class TestWin32kAutostart(MarionetteTestCase):
// We're running in a function, in a sandbox, that inherits from an
// X-ray wrapped window. Anything we want to be globally available
// needs to be defined on that window.
window.env = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
window.env = Services.env;
"""
)

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

@ -142,8 +142,7 @@ class TestWin32kAutostart(MarionetteTestCase):
// We're running in a function, in a sandbox, that inherits from an
// X-ray wrapped window. Anything we want to be globally available
// needs to be defined on that window.
window.env = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment);
window.env = Services.env;
"""
)

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

@ -18,20 +18,17 @@ const TRY_COUNT = 50;
// newVals AND return value is an array of { key: "", value: "" }
function setEnvironmentVariables(newVals) {
let oldVals = [];
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
for (let i = 0; i < newVals.length; ++i) {
let key = newVals[i].key;
let value = newVals[i].value;
let oldObj = { key };
if (env.exists(key)) {
oldObj.value = env.get(key);
if (Services.env.exists(key)) {
oldObj.value = Services.env.get(key);
} else {
oldObj.value = null;
}
env.set(key, value);
Services.env.set(key, value);
oldVals.push(oldObj);
}
return oldVals;