blob: f24160244edd7d743e3a8136648e38ccd81813a7 [file] [log] [blame]
<!DOCTYPE html>
<style>
#target {
width: 100px;
height: 100px;
background: blue;
position: absolute;
left: 0px;
top: 0px;
}
#drag{
position: absolute;
left: 0px;
top: 100px;
}
</style>
<div id="target"></div>
<img id="drag" src="resources/greenbox30.png" draggable>
<script src="../../resources/js-test.js"></script>
<script>
const L = 'leftButton';
const R = 'rightButton';
const M = 'middleButton';
var seqNo = 0;
var testSet = [
{ initialButtons: [], action: doubleClickAction },
{ initialButtons: [R], action: clickAction },
{ initialButtons: [M, R], action: clickAction },
{ initialButtons: [L, M, R], action: moveAction },
{ initialButtons: [], action: rightClickAction, showContextMenuOnMouseUp: false },
{ initialButtons: [], action: rightClickAction, showContextMenuOnMouseUp: true },
{ initialButtons: [L, R], action: wheelAction },
{ initialButtons: [], action: doubleTapAction },
{ initialButtons: [], action: tapAction },
{ initialButtons: [], action: longPressAction, showContextMenuOnMouseUp: false },
{ initialButtons: [], action: longPressAction, showContextMenuOnMouseUp: true },
{ initialButtons: [], action: longTapAction, showContextMenuOnMouseUp: false },
{ initialButtons: [], action: longTapAction, showContextMenuOnMouseUp: true },
{ initialButtons: [], action: dragDropAction },
{ initialButtons: [R], action: dragDropAction },
{ initialButtons: [M, R], action: dragDropAction },
];
function moveAction()
{
eventSender.mouseMoveTo(-1, -1);
eventSender.mouseMoveTo(50, 50);
}
function clickAction()
{
moveAction();
eventSender.mouseDown(0);
eventSender.mouseUp(0);
}
function rightClickAction()
{
moveAction();
eventSender.mouseDown(2);
eventSender.mouseUp(2);
}
function doubleClickAction()
{
moveAction();
eventSender.mouseDown(0);
eventSender.mouseUp(0);
eventSender.mouseDown(0);
eventSender.mouseUp(0);
}
function wheelAction()
{
moveAction();
eventSender.mouseScrollBy(0, 120, false, true);
}
function tapAction()
{
eventSender.gestureTap(50, 50);
}
function longPressAction()
{
eventSender.gestureLongPress(50, 50);
}
function longTapAction()
{
eventSender.gestureLongPress(50, 50);
eventSender.gestureLongTap(50, 50);
}
function doubleTapAction()
{
eventSender.gestureTap(50, 50, 1);
eventSender.gestureTap(50, 50, 2);
}
function dragDropAction()
{
eventSender.mouseMoveTo(10, 110);
eventSender.mouseDown(0);
eventSender.mouseMoveTo(10, 80);
eventSender.mouseMoveTo(10, 110);
eventSender.mouseMoveTo(10, 80);
eventSender.mouseUp(0);
}
function printTestInfo(testItem)
{
var showContextMenuOnMouseUp = "";
if (testItem.showContextMenuOnMouseUp != undefined)
showContextMenuOnMouseUp = "and showContextMenuOnMouseUp=" +
testItem.showContextMenuOnMouseUp + " ";
debug('===== ' + testItem.action.name + ' with initial state=[' + testItem.initialButtons + '] '
+ showContextMenuOnMouseUp + '=====');
}
function init() {
var targetDiv = document.getElementById('target');
var dragImg = document.getElementById('drag');
var eventList = ['dblclick', 'click', 'mousedown', 'mouseup', 'mousemove', 'mouseenter', 'mouseleave', 'mouseover', 'mouseout', 'mousewheel', 'dragstart', 'dragend', 'dragenter', 'dragleave', 'dragover', 'drag', 'contextmenu'];
eventList.forEach(function(eventName) {
targetDiv.addEventListener(eventName, function(event) {
debug(++seqNo + ". targetDiv received " + event.type + " buttons: " + event.buttons);
});
dragImg.addEventListener(eventName, function(event) {
debug(++seqNo + ". dragImg received " + event.type + " buttons: " + event.buttons);
});
});
}
window.onload=function() {
init();
if(window.eventSender) {
for (var i = 0; i < testSet.length; i++) {
printTestInfo(testSet[i]);
// Reset the state for the new test
seqNo = 0;
eventSender.setMouseButtonState(-1, testSet[i].initialButtons);
internals.settings.setShowContextMenuOnMouseUp(testSet[i].showContextMenuOnMouseUp);
testSet[i].action();
// Reset the mouse position
eventSender.mouseMoveTo(-1, -1);
debug('');
}
}
}
if (!window.eventSender) {
debug("This test requires eventSender");
}
</script>