OLD | NEW |
---|---|
(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: [L, R], action: 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], expectedModifiers: [], action : rightClickAction }, | |
32 { type: WE, name: 'mousewheel', modifiers: [L, R], action: wheelAction }, | |
33 { type: GE, name: 'dblclick', modifiers: [L], expectedModifiers: [], action: d oubleTapAction }, | |
34 { type: GE, name: 'click', modifiers: [L], expectedModifiers: [], action: tapA ction }, | |
35 { type: GE, name: 'mousedown', modifiers: [L], action: tapAction }, | |
36 { type: GE, name: 'mouseup', modifiers: [L], expectedModifiers: [], action: ta pAction }, | |
37 { type: GE, name: 'mousemove', modifiers: [], action: tapAction }, | |
38 { type: GE, name: 'contextmenu', modifiers: [R], expectedModifiers: [], action : longTapAction }, | |
Rick Byers
2014/11/28 17:36:02
please add a longTapAction 'mousedown' test (since
zino
2014/12/03 15:47:15
Done.
| |
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(modifiersDown, modifiersUp) | |
53 { | |
54 moveAction(modifiersDown); | |
55 eventSender.mouseDown(0, modifiersDown); | |
56 eventSender.mouseUp(0, modifiersUp); | |
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(modifiersDown, modifiersUp) | |
73 { | |
74 moveAction(modifiersDown); | |
75 eventSender.mouseDown(0, modifiersDown); | |
76 eventSender.mouseUp(1, modifiersUp); | |
Rick Byers
2014/11/28 17:36:02
This says to press the left mouse button (0) then
zino
2014/12/03 15:47:15
Done.
| |
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); | |
Rick Byers
2014/11/28 17:36:02
This is a little confusing. LongPress and LongTap
zino
2014/12/03 15:47:15
Thank you for the information.
I added contextmen
Rick Byers
2014/12/03 16:58:09
Yes, ignore drag and drop here. Touch drag and dro
| |
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].expectedModifiers); | |
Rick Byers
2014/11/28 17:36:02
you shouldn't have to pass your 'expected modifier
zino
2014/12/03 15:47:15
Done.
| |
107 testSet[n].buttons = buttons; | |
108 div.removeEventListener(testSet[n].name, eventHandler, false); | |
109 buttons = -1; | |
110 } | |
111 | |
112 function expectedValue(testItem) | |
113 { | |
114 var modifiers; | |
115 if (testItem.expectedModifiers != undefined) | |
116 modifiers = testItem.expectedModifiers; | |
117 else | |
118 modifiers = testItem.modifiers; | |
119 | |
120 var value = 0; | |
121 for (var i = 0; i < modifiers.length; i++) | |
122 value |= TABLE[modifiers[i]]; | |
123 | |
124 return value; | |
125 } | |
126 | |
127 for (var i = 0; i < testSet.length; i++) { | |
128 raiseEvent(i); | |
129 var expectedModifiers = ''; | |
130 if (testSet[i].expectedModifiers != undefined) | |
131 expectedModifiers += ' -> [' + testSet[i].expectedModifiers + ']'; | |
132 debug(testSet[i].type + '::' + testSet[i].name + ' test [' + testSet[i].modifi ers + ']' + expectedModifiers); | |
133 shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i])); | |
134 debug(''); | |
135 } | |
136 | |
137 </script> | |
OLD | NEW |