Adding tests for mouse events
Showing
2 changed files
with
84 additions
and
0 deletions
tests/site/mouse-events.html
0 → 100644
1 | <!DOCTYPE html> | ||
2 | <html> | ||
3 | <head> | ||
4 | <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> | ||
5 | <title>CasperJS test mouse events</title> | ||
6 | </head> | ||
7 | <body> | ||
8 | <a id="test1" href="#" onmousedown="results.test1 = true;">test</a> | ||
9 | <a id="test2" href="#">test</a> | ||
10 | <a id="test3" href="#" onmouseup="results.test3 = true;">test</a> | ||
11 | <a id="test4" href="#">test</a> | ||
12 | <a id="test5" href="#" onmouseover="results.test5 = true;">test</a> | ||
13 | <a id="test6" href="#">test</a> | ||
14 | <a id="test7" href="#" onmouseout="results.test7 = true;">test</a> | ||
15 | <a id="test8" href="#">test</a> | ||
16 | <script> | ||
17 | (function(window) { | ||
18 | window.results = { | ||
19 | test1: false, | ||
20 | test2: false, | ||
21 | test3: false, | ||
22 | test4: false, | ||
23 | test5: false, | ||
24 | test6: false, | ||
25 | test7: false, | ||
26 | test8: false | ||
27 | }; | ||
28 | document.querySelector('#test2').onmousedown = function(event) { | ||
29 | results.test2 = true; | ||
30 | event.preventDefault(); | ||
31 | }; | ||
32 | document.querySelector('#test4').onmouseup = function(event) { | ||
33 | results.test4 = true; | ||
34 | event.preventDefault(); | ||
35 | }; | ||
36 | document.querySelector('#test6').onmouseover = function(event) { | ||
37 | results.test6 = true; | ||
38 | event.preventDefault(); | ||
39 | }; | ||
40 | document.querySelector('#test8').onmouseout = function(event) { | ||
41 | results.test8 = true; | ||
42 | event.preventDefault(); | ||
43 | }; | ||
44 | })(window); | ||
45 | </script> | ||
46 | </body> | ||
47 | </html> |
tests/suites/casper/mouseevents.js
0 → 100644
1 | casper.start('tests/site/mouse-events.html'); | ||
2 | |||
3 | casper.then(function() { | ||
4 | this.test.comment('CasperUtils.mouseEvent()'); | ||
5 | this.test.assert(this.mouseEvent('mousedown', '#test1'), 'CasperUtils.mouseEvent() can dispatch a mousedown event'); | ||
6 | this.test.assert(this.mouseEvent('mousedown', '#test2'), 'CasperUtils.mouseEvent() can dispatch a mousedown event handled by unobstrusive js'); | ||
7 | this.test.assert(this.mouseEvent('mouseup', '#test3'), 'CasperUtils.mouseEvent() can dispatch a mouseup event'); | ||
8 | this.test.assert(this.mouseEvent('mouseup', '#test4'), 'CasperUtils.mouseEvent() can dispatch a mouseup event handled by unobstrusive js'); | ||
9 | this.test.assert(this.mouseEvent('mouseover', '#test5'), 'CasperUtils.mouseEvent() can dispatch a mouseover event'); | ||
10 | this.test.assert(this.mouseEvent('mouseout', '#test7'), 'CasperUtils.mouseEvent() can dispatch a mouseout event'); | ||
11 | |||
12 | /* The commented-out tests below will fail - the synthetic event doesn't register success, and | ||
13 | there's no fallback support in PhantomJS for native mouseover and mouseup (see | ||
14 | http://code.google.com/p/phantomjs/issues/detail?id=491). However, the events themselves | ||
15 | seem to be properly dispatched by the client-side utilities. | ||
16 | |||
17 | this.test.assert(this.mouseEvent('mouseover', '#test6'), 'CasperUtils.mouseEvent() can dispatch a mouseover event handled by unobstrusive js'); | ||
18 | this.test.assert(this.mouseEvent('mouseout', '#test8'), 'CasperUtils.mouseEvent() can dispatch a mouseout event handled by unobstrusive js'); | ||
19 | |||
20 | */ | ||
21 | this.mouseEvent('mouseover', '#test6'); | ||
22 | this.mouseEvent('mouseout', '#test8'); | ||
23 | |||
24 | var results = this.getGlobal('results'); | ||
25 | this.test.assert(results.test1, 'CasperUtils.mouseEvent() triggered mousedown'); | ||
26 | this.test.assert(results.test2, 'CasperUtils.mouseEvent() triggered mousedown via unobstrusive js'); | ||
27 | this.test.assert(results.test3, 'CasperUtils.mouseEvent() triggered mouseup'); | ||
28 | this.test.assert(results.test4, 'CasperUtils.mouseEvent() triggered mouseup via unobstrusive js'); | ||
29 | this.test.assert(results.test5, 'CasperUtils.mouseEvent() triggered mouseover'); | ||
30 | this.test.assert(results.test6, 'CasperUtils.mouseEvent() triggered mouseover via unobstrusive js'); | ||
31 | this.test.assert(results.test7, 'CasperUtils.mouseEvent() triggered mouseout'); | ||
32 | this.test.assert(results.test8, 'CasperUtils.mouseEvent() triggered mouseout via unobstrusive js'); | ||
33 | }); | ||
34 | |||
35 | casper.run(function() { | ||
36 | this.test.done(); | ||
37 | }); |
-
Please register or sign in to post a comment