1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
|
<?xml version="1.0"?>
<?xml-stylesheet href="chrome://global/skin" type="text/css"?>
<?xml-stylesheet href="chrome://mochikit/content/tests/SimpleTest/test.css" type="text/css"?>
<!--
XUL <scale> dragging tests
-->
<window title="Dragging XUL scale tests" width="500" height="600"
xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul">
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
<hbox flex="1">
<scale id="scale1" orient="horizontal" flex="1" min="0" max="4" value="2"/>
<scale id="scale2" orient="vertical" flex="1" min="0" max="4" value="2"/>
<scale id="scale3" orient="horizontal" flex="1" movetoclick="true" min="0" max="4" value="2"/>
</hbox>
<body xmlns="http://www.w3.org/1999/xhtml">
<p id="display"></p>
<div id="content" style="display: none">
</div>
<pre id="test">
</pre>
</body>
<script>
<![CDATA[
SimpleTest.waitForExplicitFinish();
function getThumb(aScale) {
return document.getAnonymousElementByAttribute(aScale, "class", "scale-thumb");
}
function sendTouch(aType, aRect, aDX, aDY, aMods) {
var cwu = SpecialPowers.getDOMWindowUtils(window);
var x = aRect.left + aRect.width/2 + aDX;
var y = aRect.top + aRect.height/2 + aDY;
if (/mouse/.test(aType))
cwu.sendMouseEvent(aType, x, y, 0, 1, aMods || 0, false);
else
cwu.sendTouchEvent(aType, [0], [x], [y], [1], [1], [0], [1], 1, aMods || 0, true);
}
function getOffset(aScale, aDir) {
var rect = aScale.getBoundingClientRect();
var d = aScale.orient == "horizontal" ? rect.width/4 : rect.height/4;
switch (aDir) {
case "right": return [ d, 0];
case "left": return [-1*d, 0];
case "up": return [ 0,-1*d];
case "down": return [ 0, d];
case "downleft": return [ -1*d, d];
case "upleft": return [ -1*d,-1*d];
case "downright": return [d, d];
case "upright": return [d,-1*d];
}
return [0,0];
}
function testTouchDragThumb(aDesc, aId, aDir, aVal1, aVal2, aMods) {
info(aDesc);
var scale = document.getElementById(aId);
var [x,y] = getOffset(scale, aDir);
sendTouch("touchstart", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal1, "Touchstart on thumb has correct value");
sendTouch("touchmove", getThumb(scale).getBoundingClientRect(), x, y, aMods);
sendTouch("touchend", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal2, "After touch " + (aDir ? ("and drag " + aDir + " ") : "") + "on thumb, scale has correct value");
scale.value = 2;
}
function testMouseDragThumb(aDesc, aId, aDir, aVal1, aVal2, aMods) {
info(aDesc);
var scale = document.getElementById(aId);
var [x,y] = getOffset(scale, aDir);
sendTouch("mousedown", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal1, "Mousedown on thumb has correct value");
sendTouch("mousemove", getThumb(scale).getBoundingClientRect(), x, y, aMods);
sendTouch("mouseup", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal2, "After mouseup " + (aDir ? ("and drag " + aDir + " ") : "") + "on thumb, scale has correct value");
scale.value = 2;
}
function testTouchDragSlider(aDesc, aId, aDir, aVal1, aVal2, aMods) {
info(aDesc);
var scale = document.getElementById(aId);
var [x,y] = getOffset(scale, aDir);
sendTouch("touchstart", getThumb(scale).getBoundingClientRect(), x, y, aMods);
is(scale.value, aVal1, "Touchstart on slider has correct value");
sendTouch("touchmove", getThumb(scale).getBoundingClientRect(), -x, -y, aMods);
sendTouch("touchend", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal2, "After touch " + (aDir ? ("and drag " + aDir + " ") : "") + "on slider, scale has correct value");
scale.value = 2;
}
function testMouseDragSlider(aDesc, aId, aDir, aVal1, aVal2, aMods) {
info(aDesc);
var scale = document.getElementById(aId);
var [x,y] = getOffset(scale, aDir);
sendTouch("mousedown", getThumb(scale).getBoundingClientRect(), x, y, aMods);
is(scale.value, aVal1, "Mousedown on slider has correct value");
sendTouch("mousemove", getThumb(scale).getBoundingClientRect(), -x, -y, aMods);
sendTouch("mouseup", getThumb(scale).getBoundingClientRect(), 0, 0, aMods);
is(scale.value, aVal2, "After mouseup " + (aDir ? ("and drag " + aDir + " ") : "") + "on slider, scale has correct value");
scale.value = 2;
}
function runTests() {
// test dragging a horizontal slider with touch events by tapping on the thumb
testTouchDragThumb("Touch Horizontal Thumb", "scale1", "", 2, 2);
testTouchDragThumb("TouchDrag Horizontal Thumb Left", "scale1", "left", 2, 1);
testTouchDragThumb("TouchDrag Horizontal Thumb Right", "scale1", "right", 2, 3);
testTouchDragThumb("TouchDrag Horizontal Thumb Up", "scale1", "up", 2, 2);
testTouchDragThumb("TouchDrag Horizontal Thumb Down", "scale1", "down", 2, 2);
testTouchDragThumb("TouchDrag Horizontal Thumb Downleft", "scale1", "downleft", 2, 1);
testTouchDragThumb("TouchDrag Horizontal Thumb Upleft", "scale1", "upleft", 2, 1);
testTouchDragThumb("TouchDrag Horizontal Thumb Upright", "scale1", "upright", 2, 3);
testTouchDragThumb("TouchDrag Horizontal Thumb Downright", "scale1", "downright", 2, 3);
// test dragging a horizontal slider with mouse events by clicking on the thumb
testMouseDragThumb("Click Horizontal Thumb", "scale1", "", 2, 2);
testMouseDragThumb("MouseDrag Horizontal Thumb Left", "scale1", "left", 2, 1);
testMouseDragThumb("MouseDrag Horizontal Thumb Right", "scale1", "right", 2, 3);
testMouseDragThumb("MouseDrag Horizontal Thumb Up", "scale1", "up", 2, 2);
testMouseDragThumb("MouseDrag Horizontal Thumb Down", "scale1", "down", 2, 2);
testMouseDragThumb("MouseDrag Horizontal Thumb Downleft", "scale1", "downleft", 2, 1);
testMouseDragThumb("MouseDrag Horizontal Thumb Upleft", "scale1", "upleft", 2, 1);
testMouseDragThumb("MouseDrag Horizontal Thumb Upright", "scale1", "upright", 2, 3);
testMouseDragThumb("MouseDrag Horizontal Thumb Downright", "scale1", "downright", 2, 3);
// test dragging a vertical slider with touch events by tapping on the thumb
testTouchDragThumb("Touch Vertical Thumb", "scale2", "", 2, 2);
testTouchDragThumb("TouchDrag Vertical Thumb Left", "scale2", "left", 2, 2);
testTouchDragThumb("TouchDrag Vertical Thumb Right", "scale2", "right", 2, 2);
testTouchDragThumb("TouchDrag Vertical Thumb Up", "scale2", "up", 2, 1);
testTouchDragThumb("TouchDrag Vertical Thumb Down", "scale2", "down", 2, 3);
testTouchDragThumb("TouchDrag Vertical Thumb Downleft", "scale2", "downleft", 2, 3);
testTouchDragThumb("TouchDrag Vertical Thumb Upleft", "scale2", "upleft", 2, 1);
testTouchDragThumb("TouchDrag Vertical Thumb Upright", "scale2", "upright", 2, 1);
testTouchDragThumb("TouchDrag Vertical Thumb Downright", "scale2", "downright", 2, 3);
// test dragging a vertical slider with mouse events by clicking on the thumb
testMouseDragThumb("Click Vertical Thumb", "scale2", "", 2, 2);
testMouseDragThumb("MouseDrag Vertical Thumb Left", "scale2", "left", 2, 2);
testMouseDragThumb("MouseDrag Vertical Thumb Right", "scale2", "right", 2, 2);
testMouseDragThumb("MouseDrag Vertical Thumb Up", "scale2", "up", 2, 1);
testMouseDragThumb("MouseDrag Vertical Thumb Down", "scale2", "down", 2, 3);
testMouseDragThumb("MouseDrag Vertical Thumb Downleft", "scale2", "downleft", 2, 3);
testMouseDragThumb("MouseDrag Vertical Thumb Upleft", "scale2", "upleft", 2, 1);
testMouseDragThumb("MouseDrag Vertical Thumb Upright", "scale2", "upright", 2, 1);
testMouseDragThumb("MouseDrag Vertical Thumb Downright", "scale2", "downright", 2, 3);
var isMac = /Mac/.test(navigator.platform);
// test dragging a slider by tapping off the thumb
testTouchDragSlider("TouchDrag Slider Left", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0);
testTouchDragSlider("TouchDrag Slider Right", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4);
testMouseDragSlider("MouseDrag Slider Left", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0);
testMouseDragSlider("MouseDrag Slider Right", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4);
// test dragging a slider by tapping off the thumb and holding shift
// modifiers don't affect touch events
var mods = /Mac/.test(navigator.platform) ? Components.interfaces.nsIDOMNSEvent.ALT_MASK :
Components.interfaces.nsIDOMNSEvent.SHIFT_MASK;
testTouchDragSlider("TouchDrag Slider Left+Shift", "scale1", "left", isMac ? 1 : 0, isMac ? 2 : 0, mods);
testTouchDragSlider("TouchDrag Slider Right+Shift", "scale1", "right", isMac ? 3 : 4, isMac ? 2 : 4, mods);
testMouseDragSlider("MouseDrag Slider Left+Shift", "scale1", "left", isMac ? 0 : 1, isMac ? 0 : 2, mods);
testMouseDragSlider("MouseDrag Slider Right+Shift", "scale1", "right", isMac ? 4 : 3, isMac ? 4 : 2, mods);
// test dragging a slider with movetoclick="true" by tapping off the thumb
testTouchDragSlider("TouchDrag Slider Left+MoveToClick", "scale3", "left", 1, 2);
testTouchDragSlider("TouchDrag Slider Right+MoveToClick", "scale3", "right", 3, 2);
testMouseDragSlider("MouseDrag Slider Left+MoveToClick", "scale3", "left", 1, 2);
testMouseDragSlider("MouseDrag Slider Right+MoveToClick", "scale3", "right", 3, 2);
// test dragging a slider by tapping off the thumb and holding shift
// modifiers don't affect touch events
testTouchDragSlider("MouseDrag Slider Left+MoveToClick+Shift", "scale3", "left", 1, 2, mods);
testTouchDragSlider("MouseDrag Slider Right+MoveToClick+Shift", "scale3", "right", 3, 2, mods);
testMouseDragSlider("MouseDrag Slider Left+MoveToClick+Shift", "scale3", "left", 0, 0, mods);
testMouseDragSlider("MouseDrag Slider Right+MoveToClick+Shift", "scale3", "right", 4, 4, mods);
SimpleTest.finish();
}
addLoadEvent(function() { SimpleTest.executeSoon(runTests); });
]]></script>
</window>
|