Bug 1541508 - Use Services.env in testing/ r=jmaher,perftest-reviewers,sparky

Differential Revision: https://phabricator.services.mozilla.com/D160147
This commit is contained in:
Barret Rennie 2022-11-25 19:09:10 +00:00
parent 0e792b5f3c
commit 15bea72588
10 changed files with 24 additions and 79 deletions

View File

@ -333,9 +333,7 @@
) {
let filename =
Services.profiler.IsActive() &&
Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment)
.get("MOZ_PROFILER_SHUTDOWN");
Services.env.get("MOZ_PROFILER_SHUTDOWN");
if (!filename) {
Cu.exitIfInAutomation();
}

View File

@ -262,12 +262,8 @@ function Tester(aTests, structuredLogger, aCallback) {
),
});
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// ensure the mouse is reset before each test run
if (env.exists("MOZ_AUTOMATION")) {
if (Services.env.exists("MOZ_AUTOMATION")) {
this.EventUtils.synthesizeNativeMouseEvent({
type: "mousemove",
screenX: 1000,
@ -578,10 +574,7 @@ Tester.prototype = {
async ensureVsyncDisabled() {
// The WebExtension process keeps vsync enabled forever in headless mode.
// See bug 1782541.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.get("MOZ_HEADLESS")) {
if (Services.env.get("MOZ_HEADLESS")) {
return;
}
@ -857,18 +850,15 @@ Tester.prototype = {
// See if we should upload a profile of a failing test.
if (this.currentTest.failCount) {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// If MOZ_PROFILER_SHUTDOWN is set, the profiler got started from --profiler
// and a profile will be shown even if there's no test failure.
if (
env.exists("MOZ_UPLOAD_DIR") &&
!env.exists("MOZ_PROFILER_SHUTDOWN") &&
Services.env.exists("MOZ_UPLOAD_DIR") &&
!Services.env.exists("MOZ_PROFILER_SHUTDOWN") &&
Services.profiler.IsActive()
) {
let filename = `profile_${name}.json`;
let path = env.get("MOZ_UPLOAD_DIR");
let path = Services.env.get("MOZ_UPLOAD_DIR");
let profilePath = PathUtils.join(path, filename);
try {
let profileData = await Services.profiler.getProfileDataAsGzippedArrayBuffer();

View File

@ -721,9 +721,7 @@ export class SpecialPowersParent extends JSWindowActorParent {
!AppConstants.TSAN
) {
if (Services.profiler.IsActive()) {
let filename = Cc["@mozilla.org/process/environment;1"]
.getService(Ci.nsIEnvironment)
.get("MOZ_PROFILER_SHUTDOWN");
let filename = Services.env.get("MOZ_PROFILER_SHUTDOWN");
if (filename) {
await Services.profiler.dumpProfileToFileAsync(filename);
await Services.profiler.StopProfiler();

View File

@ -50,13 +50,6 @@ XPCOMUtils.defineLazyServiceGetter(
"amIAddonManagerStartup"
);
XPCOMUtils.defineLazyServiceGetter(
this,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);
async function talosStart() {
// Tests are driven from pageloader.xhtml. We need to be careful to open
// pageloader.xhtml before dismissing the default browser window or we
@ -112,7 +105,7 @@ this.pageloader = class extends ExtensionAPI {
["content", "pageloader", "chrome/"],
]);
if (env.exists("MOZ_USE_PAGELOADER")) {
if (Services.env.exists("MOZ_USE_PAGELOADER")) {
// TalosPowers is a separate WebExtension that may or may not already have
// finished loading. tryLoad is used to wait for TalosPowers to be around
// before continuing.

View File

@ -150,12 +150,8 @@ async function plInit() {
// for pageloader tests the profiling info is found in an env variable
// because it is not available early enough to set it as a browser pref
var env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("TPPROFILINGINFO")) {
profilingInfo = env.get("TPPROFILINGINFO");
if (Services.env.exists("TPPROFILINGINFO")) {
profilingInfo = Services.env.get("TPPROFILINGINFO");
if (profilingInfo !== null) {
TalosParentProfiler.initFromObject(JSON.parse(profilingInfo));
}

View File

@ -57,12 +57,8 @@ this.startup_about_home_paint = class extends ExtensionAPI {
dump("__start_report" + measurement + "__end_report\n\n");
dump("__startTimestamp" + win.performance.now() + "__endTimestamp\n");
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.exists("TPPROFILINGINFO")) {
let profilingInfo = env.get("TPPROFILINGINFO");
if (Services.env.exists("TPPROFILINGINFO")) {
let profilingInfo = Services.env.get("TPPROFILINGINFO");
if (profilingInfo !== null) {
TalosParentProfiler.initFromObject(JSON.parse(profilingInfo));
await TalosParentProfiler.finishStartupProfiling();

View File

@ -13,16 +13,12 @@ const { AddonManager } = require("resource://gre/modules/AddonManager.jsm");
const DampLoadParentModule = require("damp-test/actors/DampLoadParent.jsm");
const DAMP_TESTS = require("damp-test/damp-tests.js");
const env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// Record allocation count in new subtests if DEBUG_DEVTOOLS_ALLOCATIONS is set to
// "normal". Print allocation sites to stdout if DEBUG_DEVTOOLS_ALLOCATIONS is set to
// "verbose".
const DEBUG_ALLOCATIONS = env.get("DEBUG_DEVTOOLS_ALLOCATIONS");
const DEBUG_ALLOCATIONS = Services.env.get("DEBUG_DEVTOOLS_ALLOCATIONS");
const DEBUG_SCREENSHOTS = env.get("DEBUG_DEVTOOLS_SCREENSHOTS");
const DEBUG_SCREENSHOTS = Services.env.get("DEBUG_DEVTOOLS_SCREENSHOTS");
// Maximum time spent in one test, in milliseconds
const TEST_TIMEOUT = 5 * 60000;

View File

@ -4,10 +4,7 @@
/* import-globals-from ../../head.js */
function run_test() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
do_check_throws_nsIException(function() {
env.QueryInterface(Ci.nsIFile);
Services.env.QueryInterface(Ci.nsIFile);
}, "NS_NOINTERFACE");
}

View File

@ -388,13 +388,10 @@ function _setupDevToolsServer(breakpointFiles, callback) {
_Services.prefs.setBoolPref("devtools.debugger.remote-enabled", true);
// for debugging-the-debugging, let an env var cause log spew.
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
if (env.get("DEVTOOLS_DEBUGGER_LOG")) {
if (_Services.env.get("DEVTOOLS_DEBUGGER_LOG")) {
_Services.prefs.setBoolPref("devtools.debugger.log", true);
}
if (env.get("DEVTOOLS_DEBUGGER_LOG_VERBOSE")) {
if (_Services.env.get("DEVTOOLS_DEBUGGER_LOG_VERBOSE")) {
_Services.prefs.setBoolPref("devtools.debugger.log.verbose", true);
}
@ -1239,11 +1236,8 @@ function do_disable_fast_shutdown() {
* @return nsIFile of the temporary directory
*/
function do_get_tempdir() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// the python harness sets this in the environment for us
let path = env.get("XPCSHELL_TEST_TEMP_DIR");
let path = _Services.env.get("XPCSHELL_TEST_TEMP_DIR");
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(path);
return file;
@ -1255,11 +1249,8 @@ function do_get_tempdir() {
* @return nsIFile of the minidump directory
*/
function do_get_minidumpdir() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// the python harness may set this in the environment for us
let path = env.get("XPCSHELL_MINIDUMP_DIR");
let path = _Services.env.get("XPCSHELL_MINIDUMP_DIR");
if (path) {
let file = Cc["@mozilla.org/file/local;1"].createInstance(Ci.nsIFile);
file.initWithPath(path);
@ -1281,11 +1272,8 @@ function do_get_profile(notifyProfileAfterChange = false) {
return null;
}
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
// the python harness sets this in the environment for us
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);
@ -1347,7 +1335,6 @@ function do_get_profile(notifyProfileAfterChange = false) {
// The methods of 'provider' will retain this scope so null out everything
// to avoid spurious leak reports.
env = null;
profd = null;
provider = null;
return file.clone();

View File

@ -419,21 +419,15 @@ add_test(function test_child_mozinfo () {
HEADLESS_TRUE = """
add_task(function headless_true() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
Assert.equal(env.get("MOZ_HEADLESS"), "1", "Check MOZ_HEADLESS");
Assert.equal(env.get("DISPLAY"), "77", "Check DISPLAY");
Assert.equal(Services.env.get("MOZ_HEADLESS"), "1", "Check MOZ_HEADLESS");
Assert.equal(Services.env.get("DISPLAY"), "77", "Check DISPLAY");
});
"""
HEADLESS_FALSE = """
add_task(function headless_false() {
let env = Cc["@mozilla.org/process/environment;1"].getService(
Ci.nsIEnvironment
);
Assert.notEqual(env.get("MOZ_HEADLESS"), "1", "Check MOZ_HEADLESS");
Assert.notEqual(env.get("DISPLAY"), "77", "Check DISPLAY");
Assert.notEqual(Services.env.get("MOZ_HEADLESS"), "1", "Check MOZ_HEADLESS");
Assert.notEqual(Services.env.get("DISPLAY"), "77", "Check DISPLAY");
});
"""