Commit 3a4ed2c8 3a4ed2c834295de2d13d40022f834de09a4b72f7 by Nicolas Perriault

fixes #410 - click() triggers mousedown and mousedown events

1 parent 0522099e
......@@ -103,11 +103,12 @@ Last, all the casper test suites have been upgraded to use the new testing featu
### Bugfixes & enhancements
- heavy lifint of casperjs bootstrap script
- heavy lifting of casperjs bootstrap script
- closed [#392](https://github.com/n1k0/casperjs/issues/392) - `--direct` & `--log-level` options available for the `casperjs` executable
- closed [#350](https://github.com/n1k0/casperjs/issues/350) - Add a [`Casper#waitForSelectorTextChange()`](http://docs.casperjs.org/en/latest/modules/casper.html#waitforselectortextchange) method
- fixed [#387](https://github.com/n1k0/casperjs/issues/387) - Setting viewport isn't quite synchronous
- Added [`Casper#bypass`](http://docs.casperjs.org/en/latest/modules/casper.html#bypass), [`Casper#thenBypass`](http://docs.casperjs.org/en/latest/modules/casper.html#thenbypass), [`Casper#thenBypassIf`](http://docs.casperjs.org/en/latest/modules/casper.html#thenbypassif), [`Casper#thenBypassUnless`](http://docs.casperjs.org/en/latest/modules/casper.html#thenbypassunless) methods
- fixes [#410](https://github.com/n1k0/casperjs/issues/410) - trigger `mousedown` and `mousedown` events on click
- Added [`Tester#skip`](http://docs.casperjs.org/en/latest/modules/tester.html#skip) method
2013-02-08, v1.0.2
......
......@@ -420,14 +420,15 @@ Casper.prototype.clear = function clear() {
Casper.prototype.click = function click(selector) {
"use strict";
this.checkStarted();
var success = this.mouseEvent('click', selector);
var success = this.mouseEvent('mousedown', selector);
success = success && this.mouseEvent('click', selector);
this.evaluate(function(selector) {
var element = __utils__.findOne(selector);
if (element) {
element.focus();
}
}, selector);
return success;
return success && this.mouseEvent('mouseup', selector);
};
/**
......
......@@ -9,6 +9,7 @@
<a id="test2" href="#" onclick="results.test2 = true;">test2</a>
<a id="test3" href="page1.html" onclick="results.test3 = true; return false">test3</a>
<a id="test4" href="http://www.google.com/">test4</a>
<a id="test5" href="#">test5</a>
<script>
(function(window) {
window.results = {
......@@ -16,6 +17,7 @@
test2: false,
test3: false,
test4: false,
test5: [],
testdown: [],
testup: [],
testmove: [],
......@@ -38,6 +40,13 @@
window.ondblclick = function(event) {
results.testdoubleclick = [event.x, event.y];
};
var test5elem = document.querySelector('#test5');
test5elem.addEventListener('mousedown', function(event) {
results.test5.push('mousedown');
});
test5elem.addEventListener('mouseup', function(event) {
results.test5.push('mouseup');
});
})(window);
</script>
</body>
......
......@@ -92,3 +92,17 @@ casper.test.begin('element focus on click', 1, function(test) {
test.done();
});
});
casper.test.begin('mouse events on click', 2, function(test) {
casper.start('tests/site/click.html', function() {
this.click('#test5');
}).then(function() {
var results = this.getGlobal('results');
test.assert(results.test5.indexOf('mousedown') !== -1,
'Casper.click() triggers mousedown event');
test.assert(results.test5.indexOf('mouseup') !== -1,
'Casper.click() triggers mouseup event');
}).run(function() {
test.done();
});
});
......