summaryrefslogtreecommitdiffstats
path: root/comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm
diff options
context:
space:
mode:
Diffstat (limited to 'comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm')
-rw-r--r--comm/mail/test/browser/shared-modules/KeyboardHelpers.jsm58
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);
+}