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