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 /comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm | |
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 'comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm')
-rw-r--r-- | comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm | 58 |
1 files changed, 58 insertions, 0 deletions
diff --git a/comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm b/comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm new file mode 100644 index 0000000000..e99c5bd484 --- /dev/null +++ b/comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm @@ -0,0 +1,58 @@ +/* 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 = [ + "input_value", + "delete_existing", + "delete_all_existing", +]; + +var EventUtils = ChromeUtils.import( + "resource://testing-common/mozmill/EventUtils.jsm" +); + +/** + * Emulates manual input + * + * @param aController The window controller to input keypresses into + * @param aStr The string to input into the control element + * @param aElement (optional) Element on which to perform the input + */ +function input_value(aController, aStr, aElement) { + if (aElement) { + aElement.focus(); + } + for (let i = 0; i < aStr.length; i++) { + EventUtils.synthesizeKey(aStr.charAt(i), {}, aController.window); + } +} + +/** + * Emulates deleting strings via the keyboard + * + * @param aController The window controller to input keypresses into + * @param aElement The element in which to delete characters + * @param aNumber The number of times to press the delete key. + */ +function delete_existing(aController, aElement, aNumber) { + for (let i = 0; i < aNumber; ++i) { + aElement.focus(); + EventUtils.synthesizeKey("VK_BACK_SPACE", {}, aController.window); + } +} + +/** + * Emulates deleting the entire string by pressing Ctrl-A and DEL + * + * @param aController The window controller to input keypresses into + * @param aElement The element in which to delete characters + */ +function delete_all_existing(aController, aElement) { + aElement.focus(); + EventUtils.synthesizeKey("a", { accelKey: true }, aController.window); + aElement.focus(); + EventUtils.synthesizeKey("VK_DELETE", {}, aController.window); +} |