Bug 1366188 - Part 1: Fix Marionette's DateTimeValue when dom.forms.datetime is enabled. r=ato

When we enable "dom.forms.datetime", <input type=date> and <input type=time>
are displayed as multi-field text box, where the fields are ordered depending
on locale. To avoid too much overhead, instead of synthesising each key event,
we set the element's value property and fire the corresponding events to
emulate user interaction.

MozReview-Commit-ID: Ao6ip61CNT6

--HG--
extra : rebase_source : f03d9c5d2e2540e6c2189b542d9270be5fb63919
This commit is contained in:
Jessica Jong 2017-05-30 23:37:00 +02:00
Родитель 3148018ed7
Коммит efe6bfa010
2 изменённых файлов: 56 добавлений и 0 удалений

Просмотреть файл

@ -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 = {};
/**
@ -344,6 +368,32 @@ interaction.uploadFile = function* (el, path) {
event.change(el);
};
/**
* 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.
*

Просмотреть файл

@ -30,11 +30,14 @@ 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");
Cu.importGlobalProperties(["URL"]);
const INPUT_DATETIME_PREF = "dom.forms.datetime";
var contentLog = new logging.ContentLogger();
var marionetteTestName;
@ -1437,6 +1440,9 @@ function* sendKeysToElement(id, val) {
let el = seenEls.get(id, curContainer);
if (el.type == "file") {
yield interaction.uploadFile(el, val);
} else if ((el.type == "date" || el.type == "time") &&
Preferences.get(INPUT_DATETIME_PREF)) {
yield interaction.setFormControlValue(el, val);
} else {
yield interaction.sendKeysToElement(
el, val, false, capabilities.get("moz:accessibilityChecks"));