diff options
author | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-17 08:26:02 +0200 |
---|---|---|
committer | janekptacijarabaci <janekptacijarabaci@seznam.cz> | 2018-04-17 08:26:02 +0200 |
commit | b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a (patch) | |
tree | 2e3d8df53e48b5dd2897f796295401faaec42a85 /testing/marionette/interaction.js | |
parent | 90c68b34abf51ae0b1a2848094fc3115b30ee498 (diff) | |
parent | e719d7b3be222dfafad78c71761bad2bafb1243d (diff) | |
download | UXP-b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a.tar UXP-b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a.tar.gz UXP-b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a.tar.lz UXP-b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a.tar.xz UXP-b18a9cf86ea25bc52d9cfea584e3aa8bfbe81f0a.zip |
Merge branch 'master' of https://github.com/MoonchildProductions/UXP into pm_url_1
Diffstat (limited to 'testing/marionette/interaction.js')
-rw-r--r-- | testing/marionette/interaction.js | 50 |
1 files changed, 50 insertions, 0 deletions
diff --git a/testing/marionette/interaction.js b/testing/marionette/interaction.js index c8275665d..2392485d7 100644 --- a/testing/marionette/interaction.js +++ b/testing/marionette/interaction.js @@ -76,6 +76,30 @@ const SELECTED_PROPERTY_SUPPORTED_XUL = new Set([ "TAB", ]); +/** + * Common form controls that user can change the value property interactively. + */ +const COMMON_FORM_CONTROLS = new Set([ + "input", + "textarea", + "select", +]); + +/** + * Input elements that do not fire "input" and "change" events when value + * property changes. + */ +const INPUT_TYPES_NO_EVENT = new Set([ + "checkbox", + "radio", + "file", + "hidden", + "image", + "reset", + "button", + "submit", +]); + this.interaction = {}; /** @@ -339,6 +363,32 @@ interaction.uploadFile = function (el, path) { }; /** + * Sets a form element's value. + * + * @param {DOMElement} el + * An form element, e.g. input, textarea, etc. + * @param {string} value + * The value to be set. + * + * @throws TypeError + * If |el| is not an supported form element. + */ +interaction.setFormControlValue = function* (el, value) { + if (!COMMON_FORM_CONTROLS.has(el.localName)) { + throw new TypeError("This function is for form elements only"); + } + + el.value = value; + + if (INPUT_TYPES_NO_EVENT.has(el.type)) { + return; + } + + event.input(el); + event.change(el); +}; + +/** * Send keys to element. * * @param {DOMElement|XULElement} el |