summaryrefslogtreecommitdiffstats
path: root/testing/marionette
diff options
context:
space:
mode:
authorjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-31 11:12:17 +0200
committerjanekptacijarabaci <janekptacijarabaci@seznam.cz>2018-03-31 11:12:17 +0200
commit78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1 (patch)
tree01881c17d1da7537112da5bad3694b6ef9005f89 /testing/marionette
parent3430e8690ada79729c9347e46c6b7818bee50b28 (diff)
downloadUXP-78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1.tar
UXP-78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1.tar.gz
UXP-78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1.tar.lz
UXP-78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1.tar.xz
UXP-78074eb34ffd54e9af8ed7458e0a9af0b13ee2b1.zip
moebius#72: Fix Marionette's DateTimeValue when dom.forms.datetime is enabled
Diffstat (limited to 'testing/marionette')
-rw-r--r--testing/marionette/interaction.js50
-rw-r--r--testing/marionette/listener.js4
2 files changed, 54 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
diff --git a/testing/marionette/listener.js b/testing/marionette/listener.js
index b64eb378d..619ac249d 100644
--- a/testing/marionette/listener.js
+++ b/testing/marionette/listener.js
@@ -30,6 +30,7 @@ Cu.import("chrome://marionette/content/session.js");
Cu.import("chrome://marionette/content/simpletest.js");
Cu.import("resource://gre/modules/FileUtils.jsm");
+Cu.import("resource://gre/modules/Preferences.jsm");
Cu.import("resource://gre/modules/Task.jsm");
Cu.import("resource://gre/modules/XPCOMUtils.jsm");
@@ -1465,6 +1466,9 @@ function* sendKeysToElement(id, val) {
if (el.type == "file") {
let path = val.join("");
yield interaction.uploadFile(el, path);
+ } else if ((el.type == "date" || el.type == "time") &&
+ Preferences.get("dom.forms.datetime")) {
+ yield interaction.setFormControlValue(el, val);
} else {
yield interaction.sendKeysToElement(
el, val, false, capabilities.get("moz:accessibilityChecks"));