Skip to content
Snippets Groups Projects
Commit aeebf3da authored by Rob Wu's avatar Rob Wu
Browse files

Bug 1837185 - Use realistic loader in test_webext_apis.js + fix failures...

Bug 1837185 - Use realistic loader in test_webext_apis.js + fix failures r=devtools-reviewers,jdescottes, a=dmeehan

listAddons was broken because webbrowser.js imported AddonManager
through the wrong loader. Consequently, a new instance of the
AddonManager module was loaded, instead of the alreaady-initialized one
from the browser. This lead to the observed bug in the report.

test_webext_apis.js was not realistic because it did not use a dedicated
loader like DevToolsStartup. That prevented the test from catching the
regression. This patch fixes that by replicating the logic at
https://searchfox.org/mozilla-central/rev/aec3a901e6f6b3041b5ec457c9111a042cef1fb1/devtools/startup/DevToolsStartup.sys.mjs#1075-1101

Differential Revision: https://phabricator.services.mozilla.com/D180253
parent 0200675f
No related branches found
No related tags found
No related merge requests found
......@@ -10,7 +10,8 @@ const {
} = require("resource://devtools/shared/specs/addon/addons.js");
const { AddonManager } = ChromeUtils.importESModule(
"resource://gre/modules/AddonManager.sys.mjs"
"resource://gre/modules/AddonManager.sys.mjs",
{ loadInDevToolsLoader: false }
);
const { FileUtils } = ChromeUtils.importESModule(
"resource://gre/modules/FileUtils.sys.mjs"
......
......@@ -49,8 +49,11 @@ loader.lazyRequireGetter(
true
);
const lazy = {};
ChromeUtils.defineESModuleGetters(lazy, {
AddonManager: "resource://gre/modules/AddonManager.sys.mjs",
loader.lazyGetter(lazy, "AddonManager", () => {
return ChromeUtils.importESModule(
"resource://gre/modules/AddonManager.sys.mjs",
{ loadInDevToolsLoader: false }
).AddonManager;
});
/**
......
......@@ -76,6 +76,31 @@ const systemPrincipal = Cc["@mozilla.org/systemprincipal;1"].createInstance(
var { loadSubScript, loadSubScriptWithOptions } = Services.scriptloader;
/**
* The logic here must resemble the logic of --start-debugger-server as closely
* as possible. DevToolsStartup.sys.mjs uses a distinct loader that results in
* the existence of two isolated module namespaces. In practice, this can cause
* bugs such as bug 1837185.
*/
function getDistinctDevToolsServer() {
const {
useDistinctSystemPrincipalLoader,
releaseDistinctSystemPrincipalLoader,
} = ChromeUtils.importESModule(
"resource://devtools/shared/loader/DistinctSystemPrincipalLoader.sys.mjs"
);
const requester = {};
const distinctLoader = useDistinctSystemPrincipalLoader(requester);
registerCleanupFunction(() => {
releaseDistinctSystemPrincipalLoader(requester);
});
const { DevToolsServer: DistinctDevToolsServer } = distinctLoader.require(
"resource://devtools/server/devtools-server.js"
);
return DistinctDevToolsServer;
}
/**
* Initializes any test that needs to work with add-ons.
*
......
......@@ -10,11 +10,10 @@ const { ExtensionTestUtils } = ChromeUtils.importESModule(
"resource://testing-common/ExtensionXPCShellUtils.sys.mjs"
);
const DistinctDevToolsServer = getDistinctDevToolsServer();
ExtensionTestUtils.init(this);
// The `AddonsManager` test helper can only be called once per test script.
// This `setup` task will run first.
add_task(async function setup() {
add_setup(async () => {
Services.prefs.setBoolPref("extensions.blocklist.enabled", false);
await startupAddonsManager();
});
......@@ -44,10 +43,10 @@ async function sendRequest(transport, request) {
// If this test case fails, please reach out to webext peers because
// https://github.com/mozilla/web-ext relies on the APIs tested here.
add_task(async function test_webext_run_apis() {
DevToolsServer.init();
DevToolsServer.registerAllActors();
DistinctDevToolsServer.init();
DistinctDevToolsServer.registerAllActors();
const transport = DevToolsServer.connectPipe();
const transport = DistinctDevToolsServer.connectPipe();
// After calling connectPipe, the root actor will be created on the server
// and a packet will be emitted after a tick. Wait for the initial packet.
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment