gecko-dev/remote/marionette/permissions.js
Henrik Skupin f5a13d6348 Bug 1691481 - [remote] Share Marionette's errors module with WebDriver BiDi. r=webdriver-reviewers,jdescottes
The WebDriver BiDi specification relies on the same
error types as WebDriver HTTP. As such the existing
module needs to be shared.

Differential Revision: https://phabricator.services.mozilla.com/D117650
2021-06-21 12:53:48 +00:00

68 lines
2.2 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 = ["permissions"];
const { Services } = ChromeUtils.import("resource://gre/modules/Services.jsm");
const { XPCOMUtils } = ChromeUtils.import(
"resource://gre/modules/XPCOMUtils.jsm"
);
XPCOMUtils.defineLazyModuleGetters(this, {
error: "chrome://remote/content/shared/webdriver/Errors.jsm",
MarionettePrefs: "chrome://remote/content/marionette/prefs.js",
});
/** @namespace */
this.permissions = {};
/**
* Set a permission's state.
* Note: Currently just a shim to support testdriver's set_permission.
*
* @param {Object} descriptor
* Descriptor with the `name` property.
* @param {string} state
* State of the permission. It can be `granted`, `denied` or `prompt`.
* @param {boolean} oneRealm
* Currently ignored
*
* @throws {UnsupportedOperationError}
* If `marionette.setpermission.enabled` is not set or
* an unsupported permission is used.
*/
permissions.set = function(descriptor, state, oneRealm) {
if (!MarionettePrefs.setPermissionEnabled) {
throw new error.UnsupportedOperationError(
"'Set Permission' is not available"
);
}
const { name } = descriptor;
if (!["clipboard-write", "clipboard-read"].includes(name)) {
throw new error.UnsupportedOperationError(
`'Set Permission' doesn't support '${name}'`
);
}
if (state === "prompt") {
throw new error.UnsupportedOperationError(
"'Set Permission' doesn't support prompt"
);
}
// This is not a real implementation of the permissions API.
// Instead the purpose of this implementation is to have web-platform-tests
// that use `set_permission('clipboard-write|read')` not fail.
// We enable dom.events.testing.asyncClipboard for the whole test suite anyway,
// so no extra permission is necessary.
if (!Services.prefs.getBoolPref("dom.events.testing.asyncClipboard", false)) {
throw new error.UnsupportedOperationError(
"'Set Permission' expected dom.events.testing.asyncClipboard to be set"
);
}
};