Skip to content

Commit

Permalink
Bug 1745977 - Stop using the second argument to ChromeUtils.import in…
Browse files Browse the repository at this point in the history
… various files in services/. r=markh

Differential Revision: https://phabricator.services.mozilla.com/D133776
  • Loading branch information
Standard8 committed Dec 15, 2021
1 parent 315d8e8 commit 07f6cf4
Show file tree
Hide file tree
Showing 16 changed files with 32 additions and 51 deletions.
10 changes: 0 additions & 10 deletions .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -550,16 +550,6 @@ module.exports = {
"dom/push/test/xpcshell/head.js",
"dom/push/test/xpcshell/test_broadcast_success.js",
"dom/push/test/xpcshell/test_crypto.js",
"services/common/tests/unit/head_helpers.js",
"services/common/tests/unit/test_uptake_telemetry.js",
"services/fxaccounts/tests/xpcshell/test_accounts.js",
"services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js",
"services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js",
"services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js",
"services/fxaccounts/tests/xpcshell/test_oauth_tokens.js",
"services/fxaccounts/tests/xpcshell/test_web_channel.js",
"services/sync/modules-testing/utils.js",
"services/sync/tests/unit/test_postqueue.js",
"toolkit/components/cloudstorage/tests/unit/test_cloudstorage.js",
"toolkit/components/crashes/tests/xpcshell/test_crash_manager.js",
"toolkit/components/crashes/tests/xpcshell/test_crash_service.js",
Expand Down
14 changes: 5 additions & 9 deletions services/common/tests/unit/head_helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,19 +282,15 @@ function checkUptakeTelemetry(snapshot1, snapshot2, expectedIncrements) {
}

async function withFakeChannel(channel, f) {
const module = ChromeUtils.import(
"resource://services-common/uptake-telemetry.js",
null
const { Policy } = ChromeUtils.import(
"resource://services-common/uptake-telemetry.js"
);
const oldPolicy = module.Policy;
module.Policy = {
...oldPolicy,
getChannel: () => channel,
};
let oldGetChannel = Policy.getChannel;
Policy.getChannel = () => channel;
try {
return await f();
} finally {
module.Policy = oldPolicy;
Policy.getChannel = oldGetChannel;
}
}

Expand Down
18 changes: 6 additions & 12 deletions services/common/tests/unit/test_uptake_telemetry.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,3 @@
const { ClientID } = ChromeUtils.import("resource://gre/modules/ClientID.jsm");
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { TelemetryTestUtils } = ChromeUtils.import(
"resource://testing-common/TelemetryTestUtils.jsm"
);
Expand All @@ -10,20 +8,16 @@ const { UptakeTelemetry } = ChromeUtils.import(
const COMPONENT = "remotesettings";

async function withFakeClientID(uuid, f) {
const module = ChromeUtils.import(
"resource://services-common/uptake-telemetry.js",
null
const { Policy } = ChromeUtils.import(
"resource://services-common/uptake-telemetry.js"
);
const oldPolicy = module.Policy;
module.Policy = {
...oldPolicy,
_clientIDHash: null,
getClientID: () => Promise.resolve(uuid),
};
let oldGetClientID = Policy.getClientID;
Policy._clientIDHash = null;
Policy.getClientID = () => Promise.resolve(uuid);
try {
return await f();
} finally {
module.Policy = oldPolicy;
Policy.getClientID = oldGetClientID;
}
}

Expand Down
2 changes: 1 addition & 1 deletion services/common/uptake-telemetry.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

"use strict";

var EXPORTED_SYMBOLS = ["UptakeTelemetry"];
var EXPORTED_SYMBOLS = ["UptakeTelemetry", "Policy"];

const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
Expand Down
3 changes: 2 additions & 1 deletion services/fxaccounts/FxAccounts.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -1622,4 +1622,5 @@ XPCOMUtils.defineLazyGetter(this, "fxAccounts", function() {
return a;
});

var EXPORTED_SYMBOLS = ["fxAccounts", "FxAccounts"];
// `AccountState` is exported for tests.
var EXPORTED_SYMBOLS = ["fxAccounts", "FxAccounts", "AccountState"];
2 changes: 2 additions & 0 deletions services/fxaccounts/FxAccountsStorage.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
var EXPORTED_SYMBOLS = [
"FxAccountsStorageManagerCanStoreField",
"FxAccountsStorageManager",
// Exported for tests.
"LoginManagerStorage",
];

const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
Expand Down
7 changes: 6 additions & 1 deletion services/fxaccounts/FxAccountsWebChannel.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@
* about account state changes.
*/

var EXPORTED_SYMBOLS = ["EnsureFxAccountsWebChannel"];
var EXPORTED_SYMBOLS = [
"EnsureFxAccountsWebChannel",
// These are exported for tests.
"FxAccountsWebChannel",
"FxAccountsWebChannelHelpers",
];

const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
Expand Down
3 changes: 1 addition & 2 deletions services/fxaccounts/tests/xpcshell/test_accounts.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,7 @@ const { PromiseUtils } = ChromeUtils.import(

// We grab some additional stuff via backstage passes.
var { AccountState } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
null
"resource://gre/modules/FxAccounts.jsm"
);

const ONE_HOUR_MS = 1000 * 60 * 60;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,7 @@ const {
ON_DEVICE_DISCONNECTED_NOTIFICATION,
} = ChromeUtils.import("resource://gre/modules/FxAccountsCommon.js");
var { AccountState } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
null
"resource://gre/modules/FxAccounts.jsm"
);

initTestLogging("Trace");
Expand Down
3 changes: 1 addition & 2 deletions services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,7 @@ const { FXA_PWDMGR_HOST, FXA_PWDMGR_REALM } = ChromeUtils.import(
// Use a backstage pass to get at our LoginManagerStorage object, so we can
// mock the prototype.
var { LoginManagerStorage } = ChromeUtils.import(
"resource://gre/modules/FxAccountsStorage.jsm",
null
"resource://gre/modules/FxAccountsStorage.jsm"
);
var isLoggedIn = true;
LoginManagerStorage.prototype.__defineGetter__("_isLoggedIn", () => isLoggedIn);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ const { FxAccountsClient } = ChromeUtils.import(

// We grab some additional stuff via backstage passes.
var { AccountState } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
null
"resource://gre/modules/FxAccounts.jsm"
);

function promiseNotification(topic) {
Expand Down
3 changes: 1 addition & 2 deletions services/fxaccounts/tests/xpcshell/test_oauth_tokens.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,7 @@ const { FxAccountsClient } = ChromeUtils.import(
"resource://gre/modules/FxAccountsClient.jsm"
);
var { AccountState } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
null
"resource://gre/modules/FxAccounts.jsm"
);

function promiseNotification(topic) {
Expand Down
2 changes: 1 addition & 1 deletion services/fxaccounts/tests/xpcshell/test_web_channel.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ const { CryptoUtils } = ChromeUtils.import(
const {
FxAccountsWebChannel,
FxAccountsWebChannelHelpers,
} = ChromeUtils.import("resource://gre/modules/FxAccountsWebChannel.jsm", null);
} = ChromeUtils.import("resource://gre/modules/FxAccountsWebChannel.jsm");

const URL_STRING = "https://example.com";

Expand Down
3 changes: 1 addition & 2 deletions services/sync/modules-testing/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,7 @@ const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");

// and grab non-exported stuff via a backstage pass.
const { AccountState } = ChromeUtils.import(
"resource://gre/modules/FxAccounts.jsm",
null
"resource://gre/modules/FxAccounts.jsm"
);

// A mock "storage manager" for FxAccounts that doesn't actually write anywhere.
Expand Down
2 changes: 2 additions & 0 deletions services/sync/modules/record.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ var EXPORTED_SYMBOLS = [
"CryptoWrapper",
"CollectionKeyManager",
"Collection",
// Exported for tests.
"PostQueue",
];

const CRYPTO_COLLECTION = "crypto";
Expand Down
5 changes: 1 addition & 4 deletions services/sync/tests/unit/test_postqueue.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */

let { PostQueue } = ChromeUtils.import(
"resource://services-sync/record.js",
null
);
let { PostQueue } = ChromeUtils.import("resource://services-sync/record.js");

function makeRecord(nbytes) {
return {
Expand Down

0 comments on commit 07f6cf4

Please sign in to comment.