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: [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], expectedModifiers: [R], action: longPressAction }, | |
Rick Byers
2014/12/03 16:58:09
nit: you can remove the expectedModifiers here sin
zino
2014/12/04 06:40:05
Done.
| |
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 expectedModifiers = ' -> shouldBe([' + testSet[i].modifiers +'])'; | |
134 var showContextMenuOnMouseUp = ""; | |
135 if (testSet[i].expectedModifiers != undefined) | |
136 expectedModifiers = ' -> shouldBe([' + testSet[i].expectedModifiers + '])'; | |
Rick Byers
2014/12/03 16:58:09
nit: avoid duplicating your strings here. Eg. you
zino
2014/12/04 06:40:05
Done.
| |
137 if (testSet[i].showContextMenuOnMouseUp != undefined) | |
138 showContextMenuOnMouseUp = " with |showContextMenuOnMouseUp=" + | |
139 testSet[i].showContextMenuOnMouseUp + "|"; | |
140 debug(testSet[i].type + '::' + testSet[i].name + showContextMenuOnMouseUp + ' ' | |
141 + testSet[i].action.name + '([' + testSet[i].modifiers + '])' + expectedMo difiers); | |
142 } | |
143 | |
144 for (var i = 0; i < testSet.length; i++) { | |
145 var showContextMenuOnMouseUp; | |
Rick Byers
2014/12/03 16:58:09
Note that comparing to undefined in javascript is
zino
2014/12/04 06:40:05
Done.
| |
146 if (testSet[i].showContextMenuOnMouseUp == undefined) | |
147 showContextMenuOnMouseUp = false; | |
148 else | |
149 showContextMenuOnMouseUp = testSet[i].showContextMenuOnMouseUp; | |
150 internals.settings.setShowContextMenuOnMouseUp(showContextMenuOnMouseUp); | |
151 raiseEvent(i); | |
152 printTestInfo(testSet[i]); | |
153 shouldBeEqualToNumber('testSet[i].buttons', expectedValue(testSet[i])); | |
154 debug(''); | |
155 } | |
156 | |
157 </script> | |
OLD | NEW |