Skip to content

Commit

Permalink
Bug 1541508 - Use Services.env in remote/ r=whimboo,webdriver-reviewers
Browse files Browse the repository at this point in the history
  • Loading branch information
Barret Rennie committed Nov 2, 2022
1 parent e48f6a3 commit 3618828
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 35 deletions.
11 changes: 2 additions & 9 deletions remote/components/Marionette.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -24,13 +24,6 @@ XPCOMUtils.defineLazyGetter(lazy, "logger", () =>

XPCOMUtils.defineLazyGetter(lazy, "textEncoder", () => new TextEncoder());

XPCOMUtils.defineLazyServiceGetter(
lazy,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);

const NOTIFY_LISTENING = "marionette-listening";

// Complements -marionette flag for starting the Marionette server.
Expand Down Expand Up @@ -72,7 +65,7 @@ class MarionetteParentProcess {
this.helpInfo = " --marionette Enable remote control server.\n";

// Initially set the enabled state based on the environment variable.
this.enabled = lazy.env.exists(ENV_ENABLED);
this.enabled = Services.env.exists(ENV_ENABLED);

Services.ppmm.addMessageListener("Marionette:IsRunning", this);

Expand Down Expand Up @@ -238,7 +231,7 @@ class MarionetteParentProcess {
return;
}

lazy.env.set(ENV_ENABLED, "1");
Services.env.set(ENV_ENABLED, "1");
Services.obs.notifyObservers(this, NOTIFY_LISTENING, true);
lazy.logger.debug("Marionette is listening");

Expand Down
15 changes: 2 additions & 13 deletions remote/marionette/prefs.sys.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,6 @@
* 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/. */

import { XPCOMUtils } from "resource://gre/modules/XPCOMUtils.sys.mjs";

const lazy = {};

XPCOMUtils.defineLazyServiceGetter(
lazy,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);

const { PREF_BOOL, PREF_INT, PREF_INVALID, PREF_STRING } = Ci.nsIPrefBranch;

export class Branch {
Expand Down Expand Up @@ -169,13 +158,13 @@ export class EnvironmentPrefs {
* @return {Iterable.<string, (string|boolean|number)>
*/
static *from(key) {
if (!lazy.env.exists(key)) {
if (!Services.env.exists(key)) {
return;
}

let prefs;
try {
prefs = JSON.parse(lazy.env.get(key));
prefs = JSON.parse(Services.env.get(key));
} catch (e) {
throw new TypeError(`Unable to parse prefs from ${key}`, e);
}
Expand Down
15 changes: 2 additions & 13 deletions remote/marionette/test/xpcshell/test_prefs.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,6 @@

"use strict";

const { XPCOMUtils } = ChromeUtils.importESModule(
"resource://gre/modules/XPCOMUtils.sys.mjs"
);

XPCOMUtils.defineLazyServiceGetter(
this,
"env",
"@mozilla.org/process/environment;1",
"nsIEnvironment"
);

const {
Branch,
EnvironmentPrefs,
Expand Down Expand Up @@ -94,14 +83,14 @@ add_test(function test_EnvironmentPrefs_from() {
"test.int": 888,
"test.string": "bar",
};
env.set("FOO", JSON.stringify(prefsTable));
Services.env.set("FOO", JSON.stringify(prefsTable));

try {
for (let [key, value] of EnvironmentPrefs.from("FOO")) {
equal(prefsTable[key], value);
}
} finally {
env.set("FOO", null);
Services.env.set("FOO", null);
}

run_next_test();
Expand Down

0 comments on commit 3618828

Please sign in to comment.