Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(395)

Side by Side Diff: LayoutTests/fast/events/mouse-event-buttons-attribute.html

Issue 727593003: Implement MouseEvent buttons attribute. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: nits Created 6 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 <!DOCTYPE html>
2 <div id="region" style="width:100px; height:100px; position:absolute; left:0px; top:0px;"></div>
3 <script src="../../resources/js-test.js"></script>
4 <script>
5
6 const L = 'leftButton';
7 const R = 'rightButton';
8 const M = 'middleButton';
9 const TABLE = {
10 'leftButton': 1,
11 'rightButton': 2,
12 'middleButton': 4
13 };
14 const ME = 'MouseEvent';
15 const WE = 'WheelEvent';
16 const GE = 'GestureEvent';
17
18 var buttons = -2;
19 var div = document.getElementById('region');
20 var testSet = [
21 { type: ME, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: d oubleClickAction },
22 { type: ME, name: 'click', modifiers: [L, R], expectedModifiers: [R], action: clickAction },
23 { type: ME, name: 'mousedown', modifiers: [L, M, R], action: clickAction },
24 { type: ME, name: 'mouseup', modifiers: [L, M, R], expectedModifiers: [M, R], action: clickAction },
25 { type: ME, name: 'mousemove', modifiers: [], action: moveAction },
26 { type: ME, name: 'mousemove', modifiers: [L], action: moveAction },
27 { type: ME, name: 'mouseenter', modifiers: [R, M], action: moveAction },
28 { type: ME, name: 'mouseleave', modifiers: [L, R], action: moveAction },
29 { type: ME, name: 'mouseover', modifiers: [L, M], action: moveAction },
30 { type: ME, name: 'mouseout', modifiers: [L], action: moveAction },
31 { type: ME, name: 'contextmenu', modifiers: [R], action: rightClickAction, sho wContextMenuOnMouseUp: false },
32 { type: ME, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action : rightClickAction, showContextMenuOnMouseUp: true },
33 { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction },
34 { type: GE, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: d oubleTapAction },
35 { type: GE, name: 'click', modifiers: [L], expectedModifiers: [], action: tapA ction },
36 { type: GE, name: 'mousedown', modifiers: [L], action: tapAction },
37 { type: GE, name: 'mouseup', modifiers: [L], expectedModifiers: [], action: ta pAction },
38 { type: GE, name: 'mousemove', modifiers: [], action: tapAction },
39 { type: GE, name: 'mousedown', modifiers: [R], action: longPressAction },
40 { type: GE, name: 'contextmenu', modifiers: [R], action: longPressAction, show ContextMenuOnMouseUp: false },
41 { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action : longPressAction, showContextMenuOnMouseUp: true },
42 { type: GE, name: 'contextmenu', modifiers: [R], action: longTapAction, showCo ntextMenuOnMouseUp: false },
43 { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action : longTapAction, showContextMenuOnMouseUp: true },
44 ];
45
46 function eventHandler(e)
47 {
48 buttons = e.buttons;
49 }
50
51 function moveAction(modifiers)
52 {
53 eventSender.mouseMoveTo(-1, -1, modifiers);
54 eventSender.mouseMoveTo(50, 50, modifiers);
55 }
56
57 function clickAction(modifiers)
58 {
59 moveAction(modifiers);
60 eventSender.mouseDown(0, modifiers);
61 eventSender.mouseUp(0, modifiers);
62 }
63
64 function rightClickAction(modifiers)
65 {
66 moveAction(modifiers);
67 eventSender.mouseDown(2, modifiers);
68 eventSender.mouseUp(2, modifiers);
69 }
70
71 function doubleClickAction(modifiers)
72 {
73 clickAction(modifiers);
74 clickAction(modifiers);
75 }
76
77 function wheelAction(modifiers)
78 {
79 moveAction(modifiers);
80 eventSender.mouseScrollBy(0, 120, false, true, modifiers);
81 }
82
83 function tapAction(modifiers)
84 {
85 eventSender.gestureTap(50, 50);
86 }
87
88 function longPressAction(modifiers)
89 {
90 eventSender.gestureLongPress(50, 50);
91 }
92
93 function longTapAction(modifiers)
94 {
95 eventSender.gestureLongPress(50, 50);
96 eventSender.gestureLongTap(50, 50);
97 }
98
99 function doubleTapAction(modifiers)
100 {
101 eventSender.gestureTap(50, 50, 2);
102 }
103
104 function raiseEvent(n)
105 {
106 if (!window.eventSender)
107 return;
108
109 div.addEventListener(testSet[n].name, eventHandler, false);
110 testSet[n].action(testSet[n].modifiers);
111 testSet[n].buttons = buttons;
112 div.removeEventListener(testSet[n].name, eventHandler, false);
113 buttons = -1;
114 }
115
116 function expectedValue(testItem)
117 {
118 var modifiers;
119 if (testItem.expectedModifiers != undefined)
120 modifiers = testItem.expectedModifiers;
121 else
122 modifiers = testItem.modifiers;
123
124 var value = 0;
125 for (var i = 0; i < modifiers.length; i++)
126 value |= TABLE[modifiers[i]];
127
128 return value;
129 }
130
131 function printTestInfo(testItem)
132 {
133 var modifiers = testSet[i].expectedModifiers || testSet[i].modifiers;
134 var expectedModifiersString = ' -> shouldBe([' + modifiers +'])';
135
136 var showContextMenuOnMouseUp = "";
137 if (testSet[i].showContextMenuOnMouseUp != undefined)
138 showContextMenuOnMouseUp = " with |showContextMenuOnMouseUp=" +
139 testSet[i].showContextMenuOnMouseUp + "|";
140
141 debug(testSet[i].type + '::' + testSet[i].name + showContextMenuOnMouseUp + ' '
142 + testSet[i].action.name + '([' + testSet[i].modifiers + '])' + expectedMo difiersString);
143 }
144
145 for (var i = 0; i < testSet.length; i++) {
146 internals.settings.setShowContextMenuOnMouseUp(testSet[i].showContextMenuOnMou seUp);
147 raiseEvent(i);
148 printTestInfo(testSet[i]);
149 shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i]));
150 debug('');
151 }
152
153 </script>
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698