Skip to content

Commit

Permalink
Bug 1777951 - Enable partially implemented WebDriver BIDi features on…
Browse files Browse the repository at this point in the history
… Nightly channel only. r=webdriver-reviewers,whimboo,jdescottes

Differential Revision: https://phabricator.services.mozilla.com/D151364
  • Loading branch information
lutien committed Jul 12, 2022
1 parent eda51ed commit 61d71c7
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 0 deletions.
7 changes: 7 additions & 0 deletions modules/libpref/init/all.js
Original file line number Diff line number Diff line change
Expand Up @@ -4241,6 +4241,13 @@ pref("services.common.log.logger.tokenserverclient", "Debug");
// 3: WebDriver BiDi + CDP
pref("remote.active-protocols", 3);

// Enable WebDriver BiDi experimental commands and events.
#if defined(NIGHTLY_BUILD)
pref("remote.experimental.enabled", true);
#else
pref("remote.experimental.enabled", false);
#endif

// Defines the verbosity of the internal logger.
//
// Available levels are, in descending order of severity, "Trace", "Debug",
Expand Down
5 changes: 5 additions & 0 deletions remote/doc/Prefs.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@ WebDriver BiDi (`1`), and CDP (`2`). Multiple protocols can be activated
at the same time by using bitwise or with the values. Defaults to `3` (WebDriver
BiDi and CDP).

### `remote.experimental.enabled`

Defines if WebDriver BiDi experimental commands and events are available for usage.
Defaults to `true` in Nightly builds, and `false` otherwise.

### `remote.log.level`

Defines the verbosity of the internal logger. Available levels
Expand Down
42 changes: 42 additions & 0 deletions remote/shared/messagehandler/Module.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ const lazy = {};
XPCOMUtils.defineLazyModuleGetters(lazy, {
ContextDescriptorType:
"chrome://remote/content/shared/messagehandler/MessageHandler.jsm",
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
});

XPCOMUtils.defineLazyGetter(lazy, "disabledExperimentalAPI", () => {
return !Services.prefs.getBoolPref("remote.experimental.enabled");
});

class Module {
Expand Down Expand Up @@ -108,6 +113,43 @@ class Module {
);
}

/**
* Assert if experimental commands are enabled.
*
* @param {String} methodName
* Name of the command.
*
* @throws {UnknownCommandError}
* If experimental commands are disabled.
*/
assertExperimentalCommandsEnabled(methodName) {
// TODO: 1778987. Move it to a BiDi specific place.
if (lazy.disabledExperimentalAPI) {
throw new lazy.error.UnknownCommandError(methodName);
}
}

/**
* Assert if experimental events are enabled.
*
* @param {string} moduleName
* Name of the module.
*
* @param {string} event
* Name of the event.
*
* @throws {InvalidArgumentError}
* If experimental events are disabled.
*/
assertExperimentalEventsEnabled(moduleName, event) {
// TODO: 1778987. Move it to a BiDi specific place.
if (lazy.disabledExperimentalAPI) {
throw new lazy.error.InvalidArgumentError(
`Module ${moduleName} does not support event ${event}`
);
}
}

/**
* Remove session data for a given module and event.
*
Expand Down
6 changes: 6 additions & 0 deletions remote/webdriver-bidi/modules/root/script.jsm
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,9 @@ class ScriptModule extends Module {
* If the target cannot be found.
*/
async callFunction(options = {}) {
// TODO: Bug 1778976. Remove once command is fully supported.
this.assertExperimentalCommandsEnabled("script.callFunction");

const {
arguments: commandArguments = null,
awaitPromise,
Expand Down Expand Up @@ -229,6 +232,9 @@ class ScriptModule extends Module {
* If the target cannot be found.
*/
async evaluate(options = {}) {
// TODO: Bug 1778976. Remove once command is fully supported.
this.assertExperimentalCommandsEnabled("script.evaluate");

const {
awaitPromise,
expression: source,
Expand Down
2 changes: 2 additions & 0 deletions testing/profiles/web-platform/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,5 @@ user_pref("layout.css.prefers-color-scheme.content-override", 1);
user_pref("gfx.offscreencanvas.enabled", true);
user_pref("dom.workers.requestAnimationFrame", true);
user_pref("layout.css.font-loading-api.workers.enabled", true);
// Enable WebDriver BiDi experimental commands and events during tests.
user_pref("remote.experimental.enabled", true);

0 comments on commit 61d71c7

Please sign in to comment.