Commit 8c6dd1f3 8c6dd1f368aac0f5ab153af3238a7bcaf8d7fd9a by Nicolas Perriault

Added `casper.mouse.doubleclick()`

1 parent cd44ddab
......@@ -70,6 +70,7 @@ XXXX-XX-XX, v1.0.1
------------------
- fixed [#336](https://github.com/n1k0/casperjs/issues/336) - Test result duration may have an exotic value
- Added `casper.mouse.doubleclick()`
2012-12-24, v1.0.0
------------------
......
......@@ -43,11 +43,13 @@ var Mouse = function Mouse(casper) {
throw new CasperError('Mouse() needs a Casper instance');
}
var slice = Array.prototype.slice;
var nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'];
var emulatedEvents = ['mouseover', 'mouseout'];
var supportedEvents = nativeEvents.concat(emulatedEvents);
var slice = Array.prototype.slice,
nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'];
if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
nativeEvents.push('doubleclick');
}
var emulatedEvents = ['mouseover', 'mouseout'],
supportedEvents = nativeEvents.concat(emulatedEvents);
function computeCenter(selector) {
var bounds = casper.getElementBounds(selector);
......@@ -94,6 +96,10 @@ var Mouse = function Mouse(casper) {
processEvent('click', arguments);
};
this.doubleclick = function doubleclick() {
processEvent('doubleclick', arguments);
};
this.down = function down() {
processEvent('mousedown', arguments);
};
......
......@@ -16,10 +16,11 @@
test2: false,
test3: false,
test4: false,
testdown: [],
testup: [],
testmove: [],
testclick: []
testdown: [],
testup: [],
testmove: [],
testclick: [],
testdoubleclick: []
};
document.querySelector('#test4').onclick = function(event) {
results.test4 = true;
......@@ -34,6 +35,9 @@
window.onmousemove = function(event) {
results.testmove = [event.x, event.y];
};
window.ondblclick = function(event) {
results.testdoubleclick = [event.x, event.y];
};
})(window);
</script>
</body>
......
......@@ -52,7 +52,7 @@ casper.test.begin('clickLabel tests tests', 8, function(test) {
});
});
casper.test.begin('casper.mouse tests', 3, function(test) {
casper.test.begin('casper.mouse tests', 4, function(test) {
casper.start('tests/site/click.html', function() {
this.mouse.down(200, 100);
var results = this.getGlobal('results');
......@@ -66,6 +66,14 @@ casper.test.begin('casper.mouse tests', 3, function(test) {
results = this.getGlobal('results');
test.assertEquals(results.testmove, [200, 100],
'Mouse.move() has moved to the specified position');
if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
this.mouse.doubleclick(200, 100);
results = this.getGlobal('results');
this.test.assertEquals(results.testdoubleclick, [200, 100],
'Mouse.doubleclick() double-clicked the specified position');
} else {
this.test.pass("Mouse.doubleclick() requires PhantomJS >= 1.8");
}
}).run(function() {
test.done();
});
......