diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-07 17:32:43 +0000 |
commit | 6bf0a5cb5034a7e684dcc3500e841785237ce2dd (patch) | |
tree | a68f146d7fa01f0134297619fbe7e33db084e0aa /remote/marionette/permissions.sys.mjs | |
parent | Initial commit. (diff) | |
download | thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.tar.xz thunderbird-6bf0a5cb5034a7e684dcc3500e841785237ce2dd.zip |
Adding upstream version 1:115.7.0.upstream/1%115.7.0upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'remote/marionette/permissions.sys.mjs')
-rw-r--r-- | remote/marionette/permissions.sys.mjs | 69 |
1 files changed, 69 insertions, 0 deletions
diff --git a/remote/marionette/permissions.sys.mjs b/remote/marionette/permissions.sys.mjs new file mode 100644 index 0000000000..d67e2c46b7 --- /dev/null +++ b/remote/marionette/permissions.sys.mjs @@ -0,0 +1,69 @@ +/* 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/. */ + +const lazy = {}; + +ChromeUtils.defineESModuleGetters(lazy, { + error: "chrome://remote/content/shared/webdriver/Errors.sys.mjs", + MarionettePrefs: "chrome://remote/content/marionette/prefs.sys.mjs", +}); + +/** @namespace */ +export const 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 (!lazy.MarionettePrefs.setPermissionEnabled) { + throw new lazy.error.UnsupportedOperationError( + "'Set Permission' is not available" + ); + } + + if (state === "prompt") { + throw new lazy.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()` not fail. + // Each test needs the corresponding testing pref to make it actually work. + const { name } = descriptor; + if (["clipboard-write", "clipboard-read"].includes(name)) { + if ( + Services.prefs.getBoolPref("dom.events.testing.asyncClipboard", false) + ) { + return; + } + throw new lazy.error.UnsupportedOperationError( + "'Set Permission' expected dom.events.testing.asyncClipboard to be set" + ); + } else if (name === "notifications") { + if (Services.prefs.getBoolPref("notification.prompt.testing", false)) { + return; + } + throw new lazy.error.UnsupportedOperationError( + "'Set Permission' expected notification.prompt.testing to be set" + ); + } + + throw new lazy.error.UnsupportedOperationError( + `'Set Permission' doesn't support '${name}'` + ); +}; |