Commit 2d4371b7 2d4371b7d6cf982a775b16a70105ee2a001bf51b by Nicolas Perriault

Added `casper.mouse.doubleclick()`

1 parent 48802a01
...@@ -5,6 +5,7 @@ XXXX-XX-XX, v1.0.1 ...@@ -5,6 +5,7 @@ XXXX-XX-XX, v1.0.1
5 ------------------ 5 ------------------
6 6
7 - fixed [#336](https://github.com/n1k0/casperjs/issues/336) - Test result duration may have an exotic value 7 - fixed [#336](https://github.com/n1k0/casperjs/issues/336) - Test result duration may have an exotic value
8 - Added `casper.mouse.doubleclick()`
8 9
9 2012-12-24, v1.0.0 10 2012-12-24, v1.0.0
10 ------------------ 11 ------------------
......
...@@ -43,11 +43,13 @@ var Mouse = function Mouse(casper) { ...@@ -43,11 +43,13 @@ var Mouse = function Mouse(casper) {
43 throw new CasperError('Mouse() needs a Casper instance'); 43 throw new CasperError('Mouse() needs a Casper instance');
44 } 44 }
45 45
46 var slice = Array.prototype.slice; 46 var slice = Array.prototype.slice,
47 47 nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove'];
48 var nativeEvents = ['mouseup', 'mousedown', 'click', 'mousemove']; 48 if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
49 var emulatedEvents = ['mouseover', 'mouseout']; 49 nativeEvents.push('doubleclick');
50 var supportedEvents = nativeEvents.concat(emulatedEvents); 50 }
51 var emulatedEvents = ['mouseover', 'mouseout'],
52 supportedEvents = nativeEvents.concat(emulatedEvents);
51 53
52 function computeCenter(selector) { 54 function computeCenter(selector) {
53 var bounds = casper.getElementBounds(selector); 55 var bounds = casper.getElementBounds(selector);
...@@ -94,6 +96,10 @@ var Mouse = function Mouse(casper) { ...@@ -94,6 +96,10 @@ var Mouse = function Mouse(casper) {
94 processEvent('click', arguments); 96 processEvent('click', arguments);
95 }; 97 };
96 98
99 this.doubleclick = function doubleclick() {
100 processEvent('doubleclick', arguments);
101 };
102
97 this.down = function down() { 103 this.down = function down() {
98 processEvent('mousedown', arguments); 104 processEvent('mousedown', arguments);
99 }; 105 };
......
...@@ -19,7 +19,8 @@ ...@@ -19,7 +19,8 @@
19 testdown: [], 19 testdown: [],
20 testup: [], 20 testup: [],
21 testmove: [], 21 testmove: [],
22 testclick: [] 22 testclick: [],
23 testdoubleclick: []
23 }; 24 };
24 document.querySelector('#test4').onclick = function(event) { 25 document.querySelector('#test4').onclick = function(event) {
25 results.test4 = true; 26 results.test4 = true;
...@@ -34,6 +35,9 @@ ...@@ -34,6 +35,9 @@
34 window.onmousemove = function(event) { 35 window.onmousemove = function(event) {
35 results.testmove = [event.x, event.y]; 36 results.testmove = [event.x, event.y];
36 }; 37 };
38 window.ondblclick = function(event) {
39 results.testdoubleclick = [event.x, event.y];
40 };
37 })(window); 41 })(window);
38 </script> 42 </script>
39 </body> 43 </body>
......
1 /*global casper*/ 1 /*global casper*/
2 /*jshint strict:false*/ 2 /*jshint strict:false maxstatements: 99*/
3 casper.start('tests/site/index.html', function() { 3 casper.start('tests/site/index.html', function() {
4 this.click('a[href="test.html"]'); 4 this.click('a[href="test.html"]');
5 }); 5 });
...@@ -56,6 +56,16 @@ casper.then(function() { ...@@ -56,6 +56,16 @@ casper.then(function() {
56 this.mouse.move(200, 100); 56 this.mouse.move(200, 100);
57 results = this.getGlobal('results'); 57 results = this.getGlobal('results');
58 this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position'); 58 this.test.assertEquals(results.testmove, [200, 100], 'Mouse.move() has moved to the specified position');
59
60 if (phantom.version.major >= 1 && phantom.version.minor >= 8) {
61 this.test.comment('Mouse.doubleclick()');
62 this.mouse.doubleclick(200, 100);
63 results = this.getGlobal('results');
64 this.test.assertEquals(results.testdoubleclick, [200, 100],
65 'Mouse.doubleclick() double-clicked the specified position');
66 } else {
67 this.test.pass("Mouse.doubleclick() requires PhantomJS >= 1.8");
68 }
59 }); 69 });
60 70
61 // element focus on click 71 // element focus on click
...@@ -67,5 +77,5 @@ casper.then(function() { ...@@ -67,5 +77,5 @@ casper.then(function() {
67 }); 77 });
68 78
69 casper.run(function() { 79 casper.run(function() {
70 this.test.done(22); 80 this.test.done(23);
71 }); 81 });
......