Commit 7db58eff 7db58effa1887f1c40f19b3431e31536ad904d6e by Nicolas Perriault

Revert #160 related commits

- eb584737.
- b66b6b90.
- 3121f0d6.
1 parent eb584737
......@@ -869,38 +869,6 @@ Casper.prototype.mouseEvent = function mouseEvent(type, selector) {
};
/**
* Emulates an keyboard event on the element from the provided selector
*
* In case of success, `true` is returned, `false` otherwise.
*
* @param String type Type of event to emulate
* @param String selector A DOM CSS3 compatible selector
* @param String character Character value of the key pressed
* @param String key Key value of the key pressed
* @return Boolean
*/
Casper.prototype.keyboardEvent = function keyboardEvent(type, selector, character, key) {
"use strict";
this.log("Keyboard event '" + type + "' on selector: " + selector, "debug");
if (!this.exists(selector)) {
throw new CasperError(f("Cannot dispatch %s event on nonexistent selector: %s", type, selector));
}
var eventSuccess = this.evaluate(function(type, selector, character, key) {
return window.__utils__.keyboardEvent(type, selector, character, key);
}, {
type: type,
selector: selector,
character: character,
key: key
});
if (!eventSuccess) {
this.log(f("Couldn't emulate '%s' event on %s: %s", type, selector, e), "error");
return false;
}
return true;
};
/**
* Performs an HTTP request, with optional settings.
*
* Available settings are:
......
......@@ -415,31 +415,6 @@
};
/**
* Dispatches a keyboard event to the DOM element behind the provided selector.
*
* @see http://www.w3.org/TR/DOM-Level-3-Events/#events-KeyboardEvent
*
* @param String type Type of event to dispatch
* @param String selector A CSS3 selector to the element to click
* @param String character Character value of the key pressed
* @param String key Key value of the key pressed
* @return Boolean
*/
this.keyboardEvent = function keyboardEvent(type, selector, character, key) {
var elem = this.findOne(selector);
if (!elem) {
this.log("keyboardEvent(): Couldn't find any element matching '" + selector + "' selector", "error");
return false;
}
var evt = document.createEvent("KeyboardEvents");
evt.initKeyboardEvent(type, true, true, window, character, key, false, false, false, false, false);
elem.value += character;
// dispatchEvent return value is false if at least one of the event
// handlers which handled this event called preventDefault
return elem.dispatchEvent(evt);
};
/**
* Processes a selector input, either as a string or an object.
*
* If passed an object, if must be of the form:
......
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test keyboard events</title>
</head>
<body>
<form>
<textarea id="test1"></textarea>
<select id="test2">
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
<option value="6">6</option>
</select>
</form>
</body>
</html>
casper.start('tests/site/keyboard-events.html');
casper.then(function() {
this.test.comment('CasperUtils.keyboardEvent()');
this.test.assert(this.keyboardEvent('keypress', '#test1', '0'), 'CasperUtils.keyboardEvent() can dispatch a keypress event');
this.test.assert(this.keyboardEvent('keydown', '#test1', '1'), 'CasperUtils.keyboardEvent() can dispatch a keydown event');
this.test.assert(this.keyboardEvent('keyup', '#test1', '2'), 'CasperUtils.keyboardEvent() can dispatch a keyup event');
this.test.assert(this.keyboardEvent('keydown', '#test2', 'Down'), 'CasperUtils.keyboardEvent() can dispatch an arrow key');
this.keyboardEvent('keydown', '#test2', 'Down');
this.keyboardEvent('keydown', '#test2', 'Down');
var results = this.getGlobal('results');
this.test.assertEvalEquals(function() {
return document.querySelector('#test1').value;
}, "012", 'CasperUtils.keyboardEvent() can set the value of a textarea');
this.test.assertEvalEquals(function() {
return document.querySelector('#test2').selectedIndex;
}, 3, 'CasperUtils.keyboardEvent() can update the value of a select');
});
casper.run(function() {
this.test.done();
});