Bug 1831373 - [remote] Use a regular ModuleRegistry for MessageHandler browser mochitests r=webdriver-reviewers,whimboo

Depends on D177179

Differential Revision: https://phabricator.services.mozilla.com/D177180
This commit is contained in:
Julian Descottes 2023-05-05 13:38:20 +00:00
Родитель d74e496f4b
Коммит ebaa1d12fb
1 изменённых файлов: 50 добавлений и 11 удалений

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

@ -2,9 +2,45 @@
* 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/. */
const modules = {
root: {},
"windowglobal-in-root": {},
windowglobal: {},
};
const BASE_FOLDER =
"chrome://mochitests/content/browser/remote/shared/messagehandler/test/browser/resources/modules";
// eslint-disable-next-line mozilla/lazy-getter-object-name
ChromeUtils.defineESModuleGetters(modules.root, {
command: `${BASE_FOLDER}/root/command.sys.mjs`,
event: `${BASE_FOLDER}/root/event.sys.mjs`,
invalid: `${BASE_FOLDER}/root/invalid.sys.mjs`,
rootOnly: `${BASE_FOLDER}/root/rootOnly.sys.mjs`,
windowglobaltoroot: `${BASE_FOLDER}/root/windowglobaltoroot.sys.mjs`,
});
// eslint-disable-next-line mozilla/lazy-getter-object-name
ChromeUtils.defineESModuleGetters(modules["windowglobal-in-root"], {
command: `${BASE_FOLDER}/windowglobal-in-root/command.sys.mjs`,
event: `${BASE_FOLDER}/windowglobal-in-root/event.sys.mjs`,
});
// eslint-disable-next-line mozilla/lazy-getter-object-name
ChromeUtils.defineESModuleGetters(modules.windowglobal, {
command: `${BASE_FOLDER}/windowglobal/command.sys.mjs`,
commandwindowglobalonly: `${BASE_FOLDER}/windowglobal/commandwindowglobalonly.sys.mjs`,
event: `${BASE_FOLDER}/windowglobal/event.sys.mjs`,
eventemitter: `${BASE_FOLDER}/windowglobal/eventemitter.sys.mjs`,
eventnointercept: `${BASE_FOLDER}/windowglobal/eventnointercept.sys.mjs`,
eventonprefchange: `${BASE_FOLDER}/windowglobal/eventonprefchange.sys.mjs`,
retry: `${BASE_FOLDER}/windowglobal/retry.sys.mjs`,
sessiondataupdate: `${BASE_FOLDER}/windowglobal/sessiondataupdate.sys.mjs`,
windowglobaltoroot: `${BASE_FOLDER}/windowglobal/windowglobaltoroot.sys.mjs`,
});
/**
* Retrieve the WebDriver BiDi module class matching the provided module name
* and folder.
* Retrieve the module class matching the provided module name and folder.
*
* @param {string} moduleName
* The name of the module to get the class for.
@ -17,14 +53,17 @@
* If the provided module folder is unexpected.
*/
export const getModuleClass = function(moduleName, moduleFolder) {
const root = `chrome://mochitests/content/browser/remote/shared/messagehandler/test/`;
const path = `${root}browser/resources/modules/${moduleFolder}/${moduleName}.sys.mjs`;
try {
return ChromeUtils.importESModule(path)[moduleName];
} catch (e) {
if (e.result == Cr.NS_ERROR_FILE_NOT_FOUND) {
return null;
}
throw e;
if (!modules[moduleFolder]) {
throw new Error(
`Invalid module folder "${moduleFolder}", expected one of "${Object.keys(
modules
)}"`
);
}
if (!modules[moduleFolder][moduleName]) {
return null;
}
return modules[moduleFolder][moduleName];
};