Bug 1707711 - Stop using ChromeUtils.import(..., null) in testing/. r=kmag

Also clean up some unused exclusions in .eslintrc.js.

Differential Revision: https://phabricator.services.mozilla.com/D114623
This commit is contained in:
Mark Banner 2021-05-09 08:06:41 +00:00
Родитель 50f3fc0ecc
Коммит 44419c64f1
5 изменённых файлов: 71 добавлений и 89 удалений

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

@ -489,7 +489,6 @@ module.exports = {
files: [
"browser/base/content/test/forms/head.js",
"browser/base/content/test/general/browser_datachoices_notification.js",
"browser/base/content/test/plugins/head.js",
"browser/base/content/test/sync/browser_fxa_web_channel.js",
"browser/base/content/test/webextensions/head.js",
"browser/components/customizableui/test/browser_1042100_default_placements_update.js",
@ -526,30 +525,18 @@ module.exports = {
"browser/components/extensions/test/browser/browser_ext_windows.js",
"browser/components/extensions/test/browser/browser_ext_windows_events.js",
"browser/components/extensions/test/browser/head.js",
"browser/components/extensions/test/browser/head_webNavigation.js",
"browser/components/extensions/test/xpcshell/test_ext_url_overrides_newtab.js",
"browser/components/migration/tests/unit/test_Edge_db_migration.js",
"browser/components/preferences/tests/browser_contentblocking.js",
"browser/components/translation/test/unit/test_cld2.js",
"browser/components/urlbar/tests/ext/browser/update/browser_getBrowserUpdateStatus_updateDisabledByPolicy.js",
"browser/extensions/formautofill/test/unit/head.js",
"browser/extensions/formautofill/test/unit/test_creditCardRecords.js",
"browser/extensions/formautofill/test/unit/test_migrateRecords.js",
"browser/extensions/formautofill/test/unit/test_storage_remove.js",
"browser/extensions/formautofill/test/unit/test_storage_tombstones.js",
"browser/extensions/formautofill/test/unit/test_sync.js",
"browser/extensions/formautofill/test/unit/test_transformFields.js",
"browser/extensions/report-site-issue/experimentalAPIs/pageActionExtras.js",
"browser/extensions/report-site-issue/test/browser/head.js",
"devtools/client/aboutdebugging/test/browser/browser_aboutdebugging_addons_debug_popup.js",
"dom/ipc/tests/browser_memory_distribution_telemetry.js",
"dom/push/test/xpcshell/head.js",
"dom/push/test/xpcshell/test_broadcast_success.js",
"dom/push/test/xpcshell/test_crypto.js",
"gfx/layers/apz/test/mochitest/browser_test_select_zoom.js",
"security/manager/ssl/RemoteSecuritySettings.jsm",
"security/manager/ssl/tests/unit/test_der.js",
"security/manager/ssl/X509.jsm",
"services/common/tests/unit/head_helpers.js",
"services/common/tests/unit/test_uptake_telemetry.js",
"services/fxaccounts/tests/xpcshell/test_accounts.js",
@ -559,26 +546,15 @@ module.exports = {
"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_doctor.js",
"services/sync/tests/unit/test_postqueue.js",
"testing/marionette/components/marionette.js",
"testing/marionette/driver.js",
"testing/marionette/format.js",
"testing/marionette/server.js",
"testing/marionette/test/unit/test_prefs.js",
"testing/mochitest/browser-test.js",
"testing/mochitest/BrowserTestUtils/content/content-task.js",
"testing/xpcshell/head.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",
"toolkit/components/crashes/tests/xpcshell/test_crash_store.js",
"toolkit/components/enterprisepolicies/tests/browser/head.js",
"toolkit/components/enterprisepolicies/tests/EnterprisePolicyTesting.jsm",
"toolkit/components/enterprisepolicies/tests/xpcshell/head.js",
"toolkit/components/extensions/ExtensionPreferencesManager.jsm",
"toolkit/components/extensions/ExtensionXPCShellUtils.jsm",
"toolkit/components/extensions/ExtensionXPCShellUtils.jsm",
"toolkit/components/extensions/parent/ext-management.js",
"toolkit/components/extensions/test/mochitest/test_ext_contentscript_cache.html",
"toolkit/components/extensions/test/xpcshell/head_native_messaging.js",
@ -597,7 +573,6 @@ module.exports = {
"toolkit/components/extensions/test/xpcshell/test_ext_tab_teardown.js",
"toolkit/components/extensions/test/xpcshell/test_native_manifests.js",
"toolkit/components/featuregates/test/unit/test_FeatureGate.js",
"toolkit/components/mozintl/mozIntl.jsm",
"toolkit/components/normandy/test/browser/browser_actions_ShowHeartbeatAction.js",
"toolkit/components/osfile/modules/osfile_async_front.jsm",
"toolkit/components/osfile/modules/osfile_native.jsm",

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

@ -90,7 +90,7 @@ var XPCOMUtils = {
for (let name of aNames) {
Object.defineProperty(aObject, name, {
get: function() {
Services.scriptloader.loadSubScript(aResource, aObject);
XPCOMUtils._scriptloader.loadSubScript(aResource, aObject);
return aObject[name];
},
set(value) {
@ -102,6 +102,18 @@ var XPCOMUtils = {
}
},
/**
* Overrides the scriptloader definition for tests to help with globals
* tracking. Should only be used for tests.
*
* @param {object} aObject
* The alternative script loader object to use.
*/
overrideScriptLoaderForTests(aObject) {
Cu.crashIfNotInAutomation();
this._scriptloader = aObject;
},
/**
* Defines a getter property on the given object for each of the given
* global names as accepted by Cu.importGlobalProperties. These
@ -477,6 +489,8 @@ var XPCOMUtils = {
},
};
XPCOMUtils.defineLazyGetter(XPCOMUtils, "_scriptloader", () => { return Services.scriptloader; });
/**
* LazyProxyHandler
* This class implements the handler used

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

@ -6,13 +6,14 @@
"use strict";
ChromeUtils.import("resource://testing-common/Task.jsm", this);
ChromeUtils.import("resource://testing-common/ContentTaskUtils.jsm", this);
let { Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
let { ContentTaskUtils } = ChromeUtils.import(
"resource://testing-common/ContentTaskUtils.jsm"
);
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const AssertCls = ChromeUtils.import(
"resource://testing-common/Assert.jsm",
null
).Assert;
const { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
);
// Injects EventUtils into ContentTask scope. To avoid leaks, this does not hold on
// to the window global. This means you **need** to pass the window as an argument to

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

@ -235,40 +235,33 @@ function Tester(aTests, structuredLogger, aCallback) {
this._coverageCollector = null;
const XPCOMUtilsMod = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm",
null
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
// Avoid failing tests when XPCOMUtils.defineLazyScriptGetter is used.
XPCOMUtilsMod.Services = Object.create(Services, {
scriptloader: {
configurable: true,
writable: true,
value: {
loadSubScript: (url, obj) => {
let before = Object.keys(window);
try {
return this._scriptLoader.loadSubScript(url, obj);
} finally {
for (let property of Object.keys(window)) {
if (
!before.includes(property) &&
!this._globalProperties.includes(property)
) {
this._globalProperties.push(property);
this.SimpleTest.info(
"Global property added while loading " + url + ": " + property
);
}
}
XPCOMUtils.overrideScriptLoaderForTests({
loadSubScript: (url, obj) => {
let before = Object.keys(window);
try {
return this._scriptLoader.loadSubScript(url, obj);
} finally {
for (let property of Object.keys(window)) {
if (
!before.includes(property) &&
!this._globalProperties.includes(property)
) {
this._globalProperties.push(property);
this.SimpleTest.info(
`Global property added while loading ${url}: ${property}`
);
}
},
loadSubScriptWithOptions: this._scriptLoader.loadSubScriptWithOptions.bind(
this._scriptLoader
),
},
}
}
},
loadSubScriptWithOptions: this._scriptLoader.loadSubScriptWithOptions.bind(
this._scriptLoader
),
});
}
Tester.prototype = {

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

@ -41,34 +41,35 @@ var _XPCSHELL_PROCESS;
// Register the testing-common resource protocol early, to have access to its
// modules.
var _Services = ChromeUtils.import("resource://gre/modules/Services.jsm", null)
.Services;
let { Services: _Services } = ChromeUtils.import(
"resource://gre/modules/Services.jsm"
);
_register_modules_protocol_handler();
var _AppConstants = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm",
null
).AppConstants;
let { AppConstants: _AppConstants } = ChromeUtils.import(
"resource://gre/modules/AppConstants.jsm"
);
var _PromiseTestUtils = ChromeUtils.import(
"resource://testing-common/PromiseTestUtils.jsm",
null
).PromiseTestUtils;
var _Task = ChromeUtils.import("resource://testing-common/Task.jsm", null).Task;
let { PromiseTestUtils: _PromiseTestUtils } = ChromeUtils.import(
"resource://testing-common/PromiseTestUtils.jsm"
);
let { Task: _Task } = ChromeUtils.import("resource://testing-common/Task.jsm");
let _NetUtil = ChromeUtils.import("resource://gre/modules/NetUtil.jsm", null)
.NetUtil;
let { NetUtil: _NetUtil } = ChromeUtils.import(
"resource://gre/modules/NetUtil.jsm"
);
let _XPCOMUtils = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm",
null
).XPCOMUtils;
let { XPCOMUtils: _XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
let _OS = ChromeUtils.import("resource://gre/modules/osfile.jsm", null).OS;
let { OS: _OS } = ChromeUtils.import("resource://gre/modules/osfile.jsm");
// Support a common assertion library, Assert.jsm.
var AssertCls = ChromeUtils.import("resource://testing-common/Assert.jsm", null)
.Assert;
var { Assert: AssertCls } = ChromeUtils.import(
"resource://testing-common/Assert.jsm"
);
// Pass a custom report function for xpcshell-test style reporting.
var Assert = new AssertCls(function(err, message, stack) {
if (err) {
@ -94,10 +95,9 @@ var _dumpLog = function(raw_msg) {
dump("\n" + JSON.stringify(raw_msg) + "\n");
};
var _LoggerClass = ChromeUtils.import(
"resource://testing-common/StructuredLog.jsm",
null
).StructuredLogger;
var { StructuredLogger: _LoggerClass } = ChromeUtils.import(
"resource://testing-common/StructuredLog.jsm"
);
var _testLogger = new _LoggerClass("xpcshell/head.js", _dumpLog, [_add_params]);
// Disable automatic network detection, so tests work correctly when
@ -1740,10 +1740,9 @@ try {
// We only want to run this for local developer builds (which should have a "default" update channel).
if (runningInParent && _AppConstants.MOZ_UPDATE_CHANNEL == "default") {
let startTime = Cu.now();
let _TelemetryController = ChromeUtils.import(
"resource://gre/modules/TelemetryController.jsm",
null
).TelemetryController;
let { TelemetryController: _TelemetryController } = ChromeUtils.import(
"resource://gre/modules/TelemetryController.jsm"
);
let complete = false;
_TelemetryController.testRegisterJsProbes().finally(() => {