Commit 2d4371b7 2d4371b7d6cf982a775b16a70105ee2a001bf51b by Nicolas Perriault

Added `casper.mouse.doubleclick()`

1 parent 48802a01
......@@ -5,6 +5,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>
......
/*global casper*/
/*jshint strict:false*/
/*jshint strict:false maxstatements: 99*/
casper.start('tests/site/index.html', function() {
this.click('a[href="test.html"]');
});
......@@ -56,6 +56,16 @@ casper.then(function() {
this.mouse.move(200, 100);
results = this.getGlobal('results');
this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
this.test.comment('Mouse.doubleclick()');
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");
}
});
// element focus on click
......@@ -67,5 +77,5 @@ casper.then(function() {
});
casper.run(function() {
this.test.done(22);
this.test.done(23);
});
......