Commit fe240a71 fe240a71f4196e16b0ff87657bd5721165c1e27a by nrabinowitz

Adding tests for mouse events

1 parent 884e1b60
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>CasperJS test mouse events</title>
</head>
<body>
<a id="test1" href="#" onmousedown="results.test1 = true;">test</a>
<a id="test2" href="#">test</a>
<a id="test3" href="#" onmouseup="results.test3 = true;">test</a>
<a id="test4" href="#">test</a>
<a id="test5" href="#" onmouseover="results.test5 = true;">test</a>
<a id="test6" href="#">test</a>
<a id="test7" href="#" onmouseout="results.test7 = true;">test</a>
<a id="test8" href="#">test</a>
<script>
(function(window) {
window.results = {
test1: false,
test2: false,
test3: false,
test4: false,
test5: false,
test6: false,
test7: false,
test8: false
};
document.querySelector('#test2').onmousedown = function(event) {
results.test2 = true;
event.preventDefault();
};
document.querySelector('#test4').onmouseup = function(event) {
results.test4 = true;
event.preventDefault();
};
document.querySelector('#test6').onmouseover = function(event) {
results.test6 = true;
event.preventDefault();
};
document.querySelector('#test8').onmouseout = function(event) {
results.test8 = true;
event.preventDefault();
};
})(window);
</script>
</body>
</html>
casper.start('tests/site/mouse-events.html');
casper.then(function() {
this.test.comment('CasperUtils.mouseEvent()');
this.test.assert(this.mouseEvent('mousedown', '#test1'), 'CasperUtils.mouseEvent() can dispatch a mousedown event');
this.test.assert(this.mouseEvent('mousedown', '#test2'), 'CasperUtils.mouseEvent() can dispatch a mousedown event handled by unobstrusive js');
this.test.assert(this.mouseEvent('mouseup', '#test3'), 'CasperUtils.mouseEvent() can dispatch a mouseup event');
this.test.assert(this.mouseEvent('mouseup', '#test4'), 'CasperUtils.mouseEvent() can dispatch a mouseup event handled by unobstrusive js');
this.test.assert(this.mouseEvent('mouseover', '#test5'), 'CasperUtils.mouseEvent() can dispatch a mouseover event');
this.test.assert(this.mouseEvent('mouseout', '#test7'), 'CasperUtils.mouseEvent() can dispatch a mouseout event');
/* The commented-out tests below will fail - the synthetic event doesn't register success, and
there's no fallback support in PhantomJS for native mouseover and mouseup (see
http://code.google.com/p/phantomjs/issues/detail?id=491). However, the events themselves
seem to be properly dispatched by the client-side utilities.
this.test.assert(this.mouseEvent('mouseover', '#test6'), 'CasperUtils.mouseEvent() can dispatch a mouseover event handled by unobstrusive js');
this.test.assert(this.mouseEvent('mouseout', '#test8'), 'CasperUtils.mouseEvent() can dispatch a mouseout event handled by unobstrusive js');
*/
this.mouseEvent('mouseover', '#test6');
this.mouseEvent('mouseout', '#test8');
var results = this.getGlobal('results');
this.test.assert(results.test1, 'CasperUtils.mouseEvent() triggered mousedown');
this.test.assert(results.test2, 'CasperUtils.mouseEvent() triggered mousedown via unobstrusive js');
this.test.assert(results.test3, 'CasperUtils.mouseEvent() triggered mouseup');
this.test.assert(results.test4, 'CasperUtils.mouseEvent() triggered mouseup via unobstrusive js');
this.test.assert(results.test5, 'CasperUtils.mouseEvent() triggered mouseover');
this.test.assert(results.test6, 'CasperUtils.mouseEvent() triggered mouseover via unobstrusive js');
this.test.assert(results.test7, 'CasperUtils.mouseEvent() triggered mouseout');
this.test.assert(results.test8, 'CasperUtils.mouseEvent() triggered mouseout via unobstrusive js');
});
casper.run(function() {
this.test.done();
});