Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / third_party / WebKit / LayoutTests / fast / events / mouse-event-buttons-attribute.html
blobedbd4b6bc51b023deadde901c7c30d47fd251821
1 <!DOCTYPE html>
2 <div id="target" style="width:100px; height:100px; position:absolute; left:0px; top:0px;"></div>
3 <img id="drag" src="resources/greenbox30.png" style="position:absolute; left:0px; top:100px;" draggable>
4 <script src="../../resources/js-test.js"></script>
5 <script>
7 const L = 'leftButton';
8 const R = 'rightButton';
9 const M = 'middleButton';
10 const TABLE = {
11 'leftButton': 1,
12 'rightButton': 2,
13 'middleButton': 4
15 const ME = 'MouseEvent';
16 const WE = 'WheelEvent';
17 const GE = 'GestureEvent';
18 const DE = 'DragEvent';
20 var target = document.getElementById('target');
21 var drag = document.getElementById('drag');
22 var buttons = -2;
23 var testSet = [
24 { type: ME, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: doubleClickAction },
25 { type: ME, name: 'click', modifiers: [L, R], expectedModifiers: [R], action: clickAction },
26 { type: ME, name: 'mousedown', modifiers: [L, M, R], action: clickAction },
27 { type: ME, name: 'mouseup', modifiers: [L, M, R], expectedModifiers: [M, R], action: clickAction },
28 { type: ME, name: 'mousemove', modifiers: [], action: moveAction },
29 { type: ME, name: 'mousemove', modifiers: [L], action: moveAction },
30 { type: ME, name: 'mouseenter', modifiers: [R, M], action: moveAction },
31 { type: ME, name: 'mouseleave', modifiers: [L, R], action: moveAction },
32 { type: ME, name: 'mouseover', modifiers: [L, M], action: moveAction },
33 { type: ME, name: 'mouseout', modifiers: [L], action: moveAction },
34 { type: ME, name: 'contextmenu', modifiers: [R], action: rightClickAction, showContextMenuOnMouseUp: false },
35 { type: ME, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: rightClickAction, showContextMenuOnMouseUp: true },
36 { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction },
37 { type: GE, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: doubleTapAction },
38 { type: GE, name: 'click', modifiers: [L], expectedModifiers: [], action: tapAction },
39 { type: GE, name: 'mousedown', modifiers: [L], action: tapAction },
40 { type: GE, name: 'mouseup', modifiers: [L], expectedModifiers: [], action: tapAction },
41 { type: GE, name: 'mousemove', modifiers: [], action: tapAction },
42 { type: GE, name: 'mousedown', modifiers: [R], action: longPressAction },
43 { type: GE, name: 'contextmenu', modifiers: [R], action: longPressAction, showContextMenuOnMouseUp: false },
44 { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: longPressAction, showContextMenuOnMouseUp: true },
45 { type: GE, name: 'contextmenu', modifiers: [R], action: longTapAction, showContextMenuOnMouseUp: false },
46 { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action: longTapAction, showContextMenuOnMouseUp: true },
47 { type: DE, name: 'dragstart', modifiers: [L, R], action: dragDropAction, eventTarget: drag },
48 { type: DE, name: 'drag', modifiers: [L, M, R], action: dragDropAction, eventTarget: drag },
49 { type: DE, name: 'dragend', modifiers: [L, R], expectedModifiers: [], action: dragDropAction, eventTarget: drag },
50 { type: DE, name: 'dragenter', modifiers: [L, M], action: dragDropAction },
51 { type: DE, name: 'dragleave', modifiers: [L, R], action: dragDropAction },
52 { type: DE, name: 'dragover', modifiers: [L, M], action: dragDropAction },
55 function eventHandler(e)
57 buttons = e.buttons;
60 function moveAction(modifiers)
62 eventSender.mouseMoveTo(-1, -1, modifiers);
63 eventSender.mouseMoveTo(50, 50, modifiers);
66 function clickAction(modifiers)
68 moveAction(modifiers);
69 eventSender.mouseDown(0, modifiers);
70 eventSender.mouseUp(0, modifiers);
73 function rightClickAction(modifiers)
75 moveAction(modifiers);
76 eventSender.mouseDown(2, modifiers);
77 eventSender.mouseUp(2, modifiers);
80 function doubleClickAction(modifiers)
82 clickAction(modifiers);
83 clickAction(modifiers);
86 function wheelAction(modifiers)
88 moveAction(modifiers);
89 eventSender.mouseScrollBy(0, 120, false, true, modifiers);
92 function tapAction(modifiers)
94 eventSender.gestureTap(50, 50);
97 function longPressAction(modifiers)
99 eventSender.gestureLongPress(50, 50);
102 function longTapAction(modifiers)
104 eventSender.gestureLongPress(50, 50);
105 eventSender.gestureLongTap(50, 50);
108 function doubleTapAction(modifiers)
110 eventSender.gestureTap(50, 50, 2);
113 function dragDropAction(modifiers)
115 eventSender.mouseMoveTo(10, 110, modifiers);
116 eventSender.mouseDown(0, modifiers);
117 eventSender.mouseMoveTo(10, 80, modifiers);
118 eventSender.mouseMoveTo(10, 110, modifiers);
119 eventSender.mouseMoveTo(10, 80, modifiers);
120 eventSender.mouseUp(0, modifiers);
123 function raiseEvent(n)
125 if (!window.eventSender)
126 return;
128 var eventTarget = testSet[n].eventTarget || target;
130 eventTarget.addEventListener(testSet[n].name, eventHandler, false);
131 testSet[n].action(testSet[n].modifiers);
132 testSet[n].buttons = buttons;
133 eventTarget.removeEventListener(testSet[n].name, eventHandler, false);
134 buttons = -1;
137 function expectedValue(testItem)
139 var modifiers;
140 if (testItem.expectedModifiers != undefined)
141 modifiers = testItem.expectedModifiers;
142 else
143 modifiers = testItem.modifiers;
145 var value = 0;
146 for (var i = 0; i < modifiers.length; i++)
147 value |= TABLE[modifiers[i]];
149 return value;
152 function printTestInfo(testItem)
154 var modifiers = testSet[i].expectedModifiers || testSet[i].modifiers;
155 var expectedModifiersString = ' -> shouldBe([' + modifiers +'])';
157 var showContextMenuOnMouseUp = "";
158 if (testSet[i].showContextMenuOnMouseUp != undefined)
159 showContextMenuOnMouseUp = " with |showContextMenuOnMouseUp=" +
160 testSet[i].showContextMenuOnMouseUp + "|";
162 debug(testSet[i].type + '::' + testSet[i].name + showContextMenuOnMouseUp + ' '
163 + testSet[i].action.name + '([' + testSet[i].modifiers + '])' + expectedModifiersString);
166 for (var i = 0; i < testSet.length; i++) {
167 internals.settings.setShowContextMenuOnMouseUp(testSet[i].showContextMenuOnMouseUp);
168 raiseEvent(i);
169 printTestInfo(testSet[i]);
170 shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i]));
171 debug('');
174 </script>