fune/remote/shared/messagehandler/test/browser/resources/modules/windowglobal/commandwindowglobalonly.jsm
Julian Descottes 69fa6f5492 Bug 1726800 - [remote] Verify commands as early as possible in MessageHandler r=webdriver-reviewers,whimboo
Depends on D123655
With this patch, the MessageHandler can immediately check if a command is implemented by the modules, and therefore reject as early as possible.
This is implemented via a checkCommand method on MessageHandler.

Other required changes:
- ModuleRegistry now owns the logic to import BiDi modules.
- ModuleCache exposes a `getAllModuleClasses` to get all the relevant modules for a moduleName+destination pair.

Error messages have been improved and are verified with a dedicated test

Differential Revision: https://phabricator.services.mozilla.com/D123655
2021-10-12 16:48:43 +00:00

47 lines
1.1 KiB
JavaScript

/* This Source Code Form is subject to the terms of the Mozilla Public
* 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/. */
"use strict";
const EXPORTED_SYMBOLS = ["commandwindowglobalonly"];
const { Module } = ChromeUtils.import(
"chrome://remote/content/shared/messagehandler/Module.jsm"
);
class CommandWindowGlobalOnly extends Module {
destroy() {}
/**
* Commands
*/
testOnlyInWindowGlobal() {
return "only-in-windowglobal";
}
testBroadcast() {
return `broadcast-${this.messageHandler.contextId}`;
}
testBroadcastWithParameter(params) {
return `broadcast-${this.messageHandler.contextId}-${params.value}`;
}
testError() {
throw new Error("error-from-module");
}
testMissingIntermediaryMethod(params, destination) {
// Spawn a new internal command, but with a commandName which doesn't match
// any method.
return this.messageHandler.handleCommand({
moduleName: "commandwindowglobalonly",
commandName: "missingMethod",
destination,
});
}
}
const commandwindowglobalonly = CommandWindowGlobalOnly;