From 07f6cf42b9a54fd55dafae6a03930e1df91f6277 Mon Sep 17 00:00:00 2001 From: Mark Banner Date: Wed, 15 Dec 2021 10:05:35 +0000 Subject: [PATCH] Bug 1745977 - Stop using the second argument to ChromeUtils.import in various files in services/. r=markh Differential Revision: https://phabricator.services.mozilla.com/D133776 --- .eslintrc.js | 10 ---------- services/common/tests/unit/head_helpers.js | 14 +++++--------- .../common/tests/unit/test_uptake_telemetry.js | 18 ++++++------------ services/common/uptake-telemetry.js | 2 +- services/fxaccounts/FxAccounts.jsm | 3 ++- services/fxaccounts/FxAccountsStorage.jsm | 2 ++ services/fxaccounts/FxAccountsWebChannel.jsm | 7 ++++++- .../fxaccounts/tests/xpcshell/test_accounts.js | 3 +-- .../test_accounts_device_registration.js | 3 +-- .../tests/xpcshell/test_loginmgr_storage.js | 3 +-- .../tests/xpcshell/test_oauth_token_storage.js | 3 +-- .../tests/xpcshell/test_oauth_tokens.js | 3 +-- .../tests/xpcshell/test_web_channel.js | 2 +- services/sync/modules-testing/utils.js | 3 +-- services/sync/modules/record.js | 2 ++ services/sync/tests/unit/test_postqueue.js | 5 +---- 16 files changed, 32 insertions(+), 51 deletions(-) diff --git a/.eslintrc.js b/.eslintrc.js index d03179b215d40..ce19181b77900 100644 --- a/.eslintrc.js +++ b/.eslintrc.js @@ -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", diff --git a/services/common/tests/unit/head_helpers.js b/services/common/tests/unit/head_helpers.js index ab515fdd7e847..03b9c55ae68b5 100644 --- a/services/common/tests/unit/head_helpers.js +++ b/services/common/tests/unit/head_helpers.js @@ -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; } } diff --git a/services/common/tests/unit/test_uptake_telemetry.js b/services/common/tests/unit/test_uptake_telemetry.js index 7449ce594596e..5a0e846b08884 100644 --- a/services/common/tests/unit/test_uptake_telemetry.js +++ b/services/common/tests/unit/test_uptake_telemetry.js @@ -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" ); @@ -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; } } diff --git a/services/common/uptake-telemetry.js b/services/common/uptake-telemetry.js index 0fc5d9d254e9e..a0a763344d52f 100644 --- a/services/common/uptake-telemetry.js +++ b/services/common/uptake-telemetry.js @@ -4,7 +4,7 @@ "use strict"; -var EXPORTED_SYMBOLS = ["UptakeTelemetry"]; +var EXPORTED_SYMBOLS = ["UptakeTelemetry", "Policy"]; const { XPCOMUtils } = ChromeUtils.import( "resource://gre/modules/XPCOMUtils.jsm" diff --git a/services/fxaccounts/FxAccounts.jsm b/services/fxaccounts/FxAccounts.jsm index 5c8c39fefff79..93c680784ef1e 100644 --- a/services/fxaccounts/FxAccounts.jsm +++ b/services/fxaccounts/FxAccounts.jsm @@ -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"]; diff --git a/services/fxaccounts/FxAccountsStorage.jsm b/services/fxaccounts/FxAccountsStorage.jsm index 099d5a25b49a7..17af8ac140335 100644 --- a/services/fxaccounts/FxAccountsStorage.jsm +++ b/services/fxaccounts/FxAccountsStorage.jsm @@ -6,6 +6,8 @@ var EXPORTED_SYMBOLS = [ "FxAccountsStorageManagerCanStoreField", "FxAccountsStorageManager", + // Exported for tests. + "LoginManagerStorage", ]; const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm"); diff --git a/services/fxaccounts/FxAccountsWebChannel.jsm b/services/fxaccounts/FxAccountsWebChannel.jsm index 236c0759e0f32..6d6b66d688c41 100644 --- a/services/fxaccounts/FxAccountsWebChannel.jsm +++ b/services/fxaccounts/FxAccountsWebChannel.jsm @@ -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" diff --git a/services/fxaccounts/tests/xpcshell/test_accounts.js b/services/fxaccounts/tests/xpcshell/test_accounts.js index 5db5d7c0fcf5f..7e48892b87f00 100644 --- a/services/fxaccounts/tests/xpcshell/test_accounts.js +++ b/services/fxaccounts/tests/xpcshell/test_accounts.js @@ -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; diff --git a/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js b/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js index 28d49be5bea6f..45fd5ba4c7e9c 100644 --- a/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js +++ b/services/fxaccounts/tests/xpcshell/test_accounts_device_registration.js @@ -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"); diff --git a/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js b/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js index 7a51b60c17c09..a6b39cec0d031 100644 --- a/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js +++ b/services/fxaccounts/tests/xpcshell/test_loginmgr_storage.js @@ -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); diff --git a/services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js b/services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js index 3258e4fd92308..1eb188ef7b76a 100644 --- a/services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js +++ b/services/fxaccounts/tests/xpcshell/test_oauth_token_storage.js @@ -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) { diff --git a/services/fxaccounts/tests/xpcshell/test_oauth_tokens.js b/services/fxaccounts/tests/xpcshell/test_oauth_tokens.js index 441ceb102cea6..24835979cbc90 100644 --- a/services/fxaccounts/tests/xpcshell/test_oauth_tokens.js +++ b/services/fxaccounts/tests/xpcshell/test_oauth_tokens.js @@ -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) { diff --git a/services/fxaccounts/tests/xpcshell/test_web_channel.js b/services/fxaccounts/tests/xpcshell/test_web_channel.js index 93cafb248278a..47f77a5317df5 100644 --- a/services/fxaccounts/tests/xpcshell/test_web_channel.js +++ b/services/fxaccounts/tests/xpcshell/test_web_channel.js @@ -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"; diff --git a/services/sync/modules-testing/utils.js b/services/sync/modules-testing/utils.js index fa332cd11f8b4..0ad7b0465529e 100644 --- a/services/sync/modules-testing/utils.js +++ b/services/sync/modules-testing/utils.js @@ -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. diff --git a/services/sync/modules/record.js b/services/sync/modules/record.js index 65389287be10f..41230f2c26dc2 100644 --- a/services/sync/modules/record.js +++ b/services/sync/modules/record.js @@ -9,6 +9,8 @@ var EXPORTED_SYMBOLS = [ "CryptoWrapper", "CollectionKeyManager", "Collection", + // Exported for tests. + "PostQueue", ]; const CRYPTO_COLLECTION = "crypto"; diff --git a/services/sync/tests/unit/test_postqueue.js b/services/sync/tests/unit/test_postqueue.js index 21879e5f60df8..b8d6752a861f8 100644 --- a/services/sync/tests/unit/test_postqueue.js +++ b/services/sync/tests/unit/test_postqueue.js @@ -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 {