diff --git a/node_modules/marionette-helper/index.js b/node_modules/marionette-helper/index.js
index 50a3e8c2..7135457f 100644
--- a/node_modules/marionette-helper/index.js
+++ b/node_modules/marionette-helper/index.js
@@ -181,10 +181,81 @@ MarionetteHelper.prototype = {
});
},
+ /**
+ * Tap input element and fill the value.
+ * To do: Support the time, date, datetime, and datetime-local input
+ * correctly.
+ * Please refer to http://bugzil.la/976453.
+ *
+ * @param {Marionette.Element|String} el marionette element object or
+ * css selector.
+ * @param {String|Object} input text or datetime object for the input.
+ */
+ fillInputField: function(el, input) {
+ if (!isElement(el)) {
+ el = this.client.findElement(el);
+ }
+ var inputText;
+ if (input instanceof Date) {
+ // XXX: bug 978685
+ // We cannot get type through element.getAttribute('type') if the type is
+ // datetime or datetime-local, so we use below workaround.
+ var eleType = this.client.executeScript(function(el) {
+ return el.getAttribute('type');
+ }, [el]);
+
+ switch (eleType) {
+ case 'date':
+ inputText = input.getFullYear() + '-' +
+ addLeadZero(input.getMonth()) +
+ '-' + addLeadZero(input.getDate());
+ break;
+ case 'time':
+ inputText = addLeadZero(input.getHours()) + ':' +
+ addLeadZero(input.getMinutes());
+ break;
+ case 'datetime':
+ inputText = input.toISOString();
+ break;
+ case 'datetime-local':
+ inputText = input.getFullYear() + '-' +
+ addLeadZero(input.getMonth()) +
+ '-' + addLeadZero(input.getDate()) + 'T' +
+ addLeadZero(input.getHours()) + ':' +
+ addLeadZero(input.getMinutes()) + ':' +
+ addLeadZero(input.getSeconds()) + '.' +
+ input.getMilliseconds();
+ break;
+ default:
+ throw new Error('The ' + eleType + ' type element is not supported' +
+ ' when the input param is a Date object.');
+ }
+ } else {
+ inputText = input;
+ }
+
+ // Below script is to trigger input event on the input correctly and fill
+ // the data.
+ this.client.executeScript(function(el, value) {
+ el.value = value;
+ var evt = new Event('input', {
+ 'view': window,
+ 'bubbles': true,
+ 'cancelable': true
+ });
+ el.dispatchEvent(evt);
+ }, [el, inputText]);
+
+ // We add lead zero on single digit. ex: 1 -> 01, 9 -> 09.
+ function addLeadZero(num) {
+ return num >= 10 ? num : ('0' + num);
+ }
+ },
+
/**
* select specific option from target select element
* @param {Marionette.Element|String} el element or some css selector.
- * @param {String} optionText text for the option
+ * @param {String} optionText text for the option.
*/
tapSelectOption: function(el, optionText) {
var selectedOption = null;
diff --git a/node_modules/marionette-helper/package.json b/node_modules/marionette-helper/package.json
index 07d85966..76295a99 100644
--- a/node_modules/marionette-helper/package.json
+++ b/node_modules/marionette-helper/package.json
@@ -1,6 +1,6 @@
{
"name": "marionette-helper",
- "version": "0.2.1",
+ "version": "0.2.2",
"author": {
"name": "Gareth Aye",
"email": "gaye@mozilla.com"
diff --git a/node_modules/marionette-helper/test/integration/fakeapp/index.html b/node_modules/marionette-helper/test/integration/fakeapp/index.html
index e18cd3e4..7035052c 100644
--- a/node_modules/marionette-helper/test/integration/fakeapp/index.html
+++ b/node_modules/marionette-helper/test/integration/fakeapp/index.html
@@ -17,5 +17,11 @@
+
+
+
+
+
+