OLD | NEW |
---|---|
(Empty) | |
1 <!DOCTYPE html> | |
2 <div id="region" style="width:100px; height:100px;"></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], action: doubleClickAction }, | |
22 { type: ME, name: 'click', modifiers: [L, R], action: clickAction }, | |
Rick Byers
2014/11/25 17:44:27
you're doing a click with the left mouse button, I
zino
2014/11/28 12:29:28
Done.
| |
23 { type: ME, name: 'mousedown', modifiers: [L, M, R], action: clickAction }, | |
24 { type: ME, name: 'mouseup', modifiers: [L, R], modifiersDown: [L, M, R], acti on: mouseUpAction }, | |
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 }, | |
32 { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction }, | |
33 { type: GE, name: 'dblclick', modifiers: [L], action: doubleTapAction }, | |
34 { type: GE, name: 'click', modifiers: [L], action: tapAction }, | |
35 { type: GE, name: 'mousedown', modifiers: [L], action: tapAction }, | |
36 { type: GE, name: 'mouseup', modifiers: [], modifiersDown: [L], action: tapAct ion }, | |
37 { type: GE, name: 'mousemove', modifiers: [], action: tapAction }, | |
38 { type: GE, name: 'contextmenu', modifiers: [R], action: longTapAction }, | |
39 ]; | |
40 | |
41 function eventHandler(e) | |
42 { | |
43 buttons = e.buttons; | |
44 } | |
45 | |
46 function moveAction(modifiers) | |
47 { | |
48 eventSender.mouseMoveTo(-1, -1, modifiers); | |
49 eventSender.mouseMoveTo(50, 50, modifiers); | |
50 } | |
51 | |
52 function clickAction(modifiers) | |
53 { | |
54 moveAction(modifiers); | |
55 eventSender.mouseDown(0, modifiers); | |
56 eventSender.mouseUp(0, modifiers); | |
57 } | |
58 | |
59 function rightClickAction(modifiers) | |
60 { | |
61 moveAction(modifiers); | |
62 eventSender.mouseDown(2, modifiers); | |
63 eventSender.mouseUp(2, modifiers); | |
64 } | |
65 | |
66 function doubleClickAction(modifiers) | |
67 { | |
68 clickAction(modifiers); | |
69 clickAction(modifiers); | |
70 } | |
71 | |
72 function mouseUpAction(modifiers, modifiersDown) | |
73 { | |
74 moveAction(modifiersDown); | |
75 eventSender.mouseDown(0, modifiersDown); | |
Rick Byers
2014/11/25 17:44:28
You should probably be testing the code you added
zino
2014/11/28 12:29:28
Done.
| |
76 eventSender.mouseUp(1, modifiers); | |
77 } | |
78 | |
79 function wheelAction(modifiers) | |
80 { | |
81 moveAction(modifiers); | |
82 eventSender.mouseScrollBy(0, 120, false, true, modifiers); | |
83 } | |
84 | |
85 function tapAction(modifiers) | |
86 { | |
87 eventSender.gestureTap(50, 50); | |
88 } | |
89 | |
90 function longTapAction(modifiers) | |
91 { | |
92 eventSender.gestureLongPress(50, 50); | |
93 } | |
94 | |
95 function doubleTapAction(modifiers) | |
96 { | |
97 eventSender.gestureTap(50, 50, 2); | |
98 } | |
99 | |
100 function raiseEvent(n) | |
101 { | |
102 if (!window.eventSender) | |
103 return; | |
104 | |
105 div.addEventListener(testSet[n].name, eventHandler, false); | |
106 testSet[n].action(testSet[n].modifiers, testSet[n].modifiersDown); | |
107 testSet[n].buttons = buttons; | |
108 div.removeEventListener(testSet[n].name, eventHandler, false); | |
109 buttons = -1; | |
110 } | |
111 | |
112 function expectedValue(modifiers) | |
113 { | |
114 var value = 0; | |
115 for (var i = 0; i < modifiers.length; i++) | |
116 value |= TABLE[modifiers[i]]; | |
117 | |
118 return value; | |
119 } | |
120 | |
121 for (var i = 0; i < testSet.length; i++) | |
122 raiseEvent(i); | |
123 | |
124 for (var i = 0; i < testSet.length; i++) { | |
125 var modifiersDown = ''; | |
126 if (testSet[i].modifiersDown != undefined) | |
127 modifiersDown += '[' + testSet[i].modifiersDown + '] -> '; | |
128 debug(testSet[i].type + '::' + testSet[i].name + ' test ' + modifiersDown + '[ ' + testSet[i].modifiers + ']'); | |
129 shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i].modifiers )); | |
130 debug(''); | |
131 } | |
132 | |
133 </script> | |
OLD | NEW |