puppeteer/third_party/phantomjs/test/module/webpage/mouseclick-event.js
JoelEinbinder 98ee35655f Mouse (#101)
This patch:
- adds Mouse class which holds mouse state and implements mouse primitives,
such as moving, button down and button up.
- implements high-level mouse api, such as `page.click` and `page.hover`.

References #40, References #89
2017-07-21 20:29:31 -07:00

39 lines
1.5 KiB
JavaScript

test(function () {
var page = require('webpage').create();
page.evaluate(function() {
window.addEventListener('mousedown', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mousedown = {clientX: event.clientX, clientY: event.clientY, shiftKey: event.shiftKey};
}, false);
window.addEventListener('mouseup', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.mouseup = {clientX: event.clientX, clientY: event.clientY, shiftKey: event.shiftKey};
}, false);
});
page.sendEvent('click', 42, 217);
var event = page.evaluate(function() {
return window.loggedEvent;
});
assert_equals(event.mouseup.clientX, 42);
assert_equals(event.mouseup.clientY, 217);
assert_equals(event.mousedown.clientX, 42);
assert_equals(event.mousedown.clientY, 217);
// click with modifier key
page.evaluate(function() {
window.addEventListener('click', function(event) {
window.loggedEvent = window.loggedEvent || {};
window.loggedEvent.click = {clientX: event.clientX, clientY: event.clientY, shiftKey: event.shiftKey};
}, false);
});
page.sendEvent('click', 100, 100, 'left', page.event.modifier.shift);
var event = page.evaluate(function() {
return window.loggedEvent.click;
});
assert_is_true(event.shiftKey);
}, "mouse click events");