diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 00:47:55 +0000 |
commit | 26a029d407be480d791972afb5975cf62c9360a6 (patch) | |
tree | f435a8308119effd964b339f76abb83a57c29483 /browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js | |
parent | Initial commit. (diff) | |
download | firefox-26a029d407be480d791972afb5975cf62c9360a6.tar.xz firefox-26a029d407be480d791972afb5975cf62c9360a6.zip |
Adding upstream version 124.0.1.upstream/124.0.1
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js')
-rw-r--r-- | browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js b/browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js new file mode 100644 index 0000000000..8196ab0e24 --- /dev/null +++ b/browser/components/extensions/test/xpcshell/test_ext_manifest_commands.js @@ -0,0 +1,52 @@ +/* -*- Mode: indent-tabs-mode: nil; js-indent-level: 2 -*- */ +/* vim: set sts=2 sw=2 et tw=80: */ +"use strict"; + +add_task(async function test_manifest_commands() { + const validShortcuts = [ + "Ctrl+Y", + "MacCtrl+Y", + "Command+Y", + "Alt+Shift+Y", + "Ctrl+Alt+Y", + "F1", + "MediaNextTrack", + ]; + const invalidShortcuts = ["Shift+Y", "Y", "Ctrl+Ctrl+Y", "Ctrl+Command+Y"]; + + async function validateShortcut(shortcut, isValid) { + let normalized = await ExtensionTestUtils.normalizeManifest({ + commands: { + "toggle-feature": { + suggested_key: { default: shortcut }, + description: "Send a 'toggle-feature' event to the extension", + }, + }, + }); + if (isValid) { + ok(!normalized.error, "There should be no manifest errors."); + } else { + let expectedError = + String.raw`Error processing commands.toggle-feature.suggested_key.default: Error: ` + + String.raw`Value "${shortcut}" must consist of ` + + String.raw`either a combination of one or two modifiers, including ` + + String.raw`a mandatory primary modifier and a key, separated by '+', ` + + String.raw`or a media key. For details see: ` + + String.raw`https://developer.mozilla.org/en-US/Add-ons/WebExtensions/manifest.json/commands#Key_combinations`; + + ok( + normalized.error.includes(expectedError), + `The manifest error ${JSON.stringify( + normalized.error + )} must contain ${JSON.stringify(expectedError)}` + ); + } + } + + for (let shortcut of validShortcuts) { + validateShortcut(shortcut, true); + } + for (let shortcut of invalidShortcuts) { + validateShortcut(shortcut, false); + } +}); |