|
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 Widget Test for scale |
|
6 --> |
|
7 <window title="scale" width="500" height="600" |
|
8 onload="setTimeout(testtag_scale, 0);" |
|
9 xmlns="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"> |
|
10 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
11 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> |
|
12 |
|
13 <hbox> |
|
14 <vbox> |
|
15 <scale id="scale-horizontal-normal"/> |
|
16 <scale id="scale-horizontal-reverse" dir="reverse"/> |
|
17 </vbox> |
|
18 <scale id="scale-vertical-normal" orient="vertical"/> |
|
19 <scale id="scale-vertical-reverse" orient="vertical" dir="reverse"/> |
|
20 </hbox> |
|
21 |
|
22 <body xmlns="http://www.w3.org/1999/xhtml"> |
|
23 <p id="display"></p> |
|
24 <div id="content" style="display: none"> |
|
25 </div> |
|
26 <pre id="test"> |
|
27 </pre> |
|
28 </body> |
|
29 |
|
30 <script> |
|
31 <![CDATA[ |
|
32 |
|
33 SimpleTest.waitForExplicitFinish(); |
|
34 |
|
35 function testtag_scale() |
|
36 { |
|
37 testtag_scale_inner("scale-horizontal-normal", true, false); |
|
38 testtag_scale_inner("scale-horizontal-reverse", true, true); |
|
39 testtag_scale_inner("scale-vertical-normal", false, false); |
|
40 testtag_scale_inner("scale-vertical-reverse", false, true); |
|
41 |
|
42 SimpleTest.finish(); |
|
43 } |
|
44 |
|
45 function testtag_scale_inner(elementid, horiz, reverse) |
|
46 { |
|
47 var testid = (horiz ? "horizontal " : "vertical ") + |
|
48 (reverse ? "reverse " : "normal "); |
|
49 |
|
50 var element = document.getElementById(elementid); |
|
51 |
|
52 testtag_scale_States(element, 0, "", 0, 100, testid + "initial"); |
|
53 |
|
54 element.min = 0; |
|
55 element.max = 10; |
|
56 testtag_scale_States(element, 0, "", 0, 10, testid + "first set"); |
|
57 |
|
58 element.decrease(); |
|
59 is(element.value, 0, testid + "decrease"); |
|
60 element.increase(); |
|
61 is(element.value, 1, testid + "increase"); |
|
62 element.value = 0; |
|
63 is(element.value, 0, testid + "set value"); |
|
64 |
|
65 testtag_scale_Increments(element, 0, 10, 6, 7, testid + "increase decrease"); |
|
66 |
|
67 // check if changing the min and max adjusts the value to fit in range |
|
68 element.min = 5; |
|
69 testtag_scale_States(element, 5, "5", 5, 10, testid + "change min"); |
|
70 element.value = 15; |
|
71 is(element.value, 10, testid + "change minmax value set too high"); |
|
72 element.max = 8; |
|
73 is(element.value, 8, testid + "change max"); |
|
74 element.value = 2; |
|
75 is(element.value, 5, testid + "change minmax set too low"); |
|
76 |
|
77 // check negative values |
|
78 element.min = -15; |
|
79 element.max = -5; |
|
80 testtag_scale_States(element, -5, "-5", -15, -5, testid + "minmax negative"); |
|
81 element.value = -15; |
|
82 is(element.value, -15, testid + "change max negative"); |
|
83 testtag_scale_Increments(element, -15, -5, 7, 8, testid + "increase decrease negative"); |
|
84 |
|
85 // check case when min is negative and max is positive |
|
86 element.min = -10; |
|
87 element.max = 35; |
|
88 testtag_scale_States(element, -10, "-10", -10, 35, testid + "minmax mixed sign"); |
|
89 testtag_scale_Increments(element, -10, 35, 25, 30, testid + "increase decrease mixed sign"); |
|
90 |
|
91 testtag_scale_UI(element, testid, horiz, reverse); |
|
92 } |
|
93 |
|
94 function testtag_scale_UI(element, testid, horiz, reverse) |
|
95 { |
|
96 element.min = 0; |
|
97 element.max = 20; |
|
98 element.value = 7; |
|
99 element.increment = 2; |
|
100 element.pageIncrement = 4; |
|
101 |
|
102 element.focus(); |
|
103 |
|
104 var leftIncrements = horiz && reverse; |
|
105 var upDecrements = !horiz && !reverse; |
|
106 synthesizeKeyExpectEvent("VK_LEFT", { }, element, "change", testid + "key left"); |
|
107 is(element.value, leftIncrements ? 9 : 5, testid + " key left"); |
|
108 synthesizeKeyExpectEvent("VK_RIGHT", { }, element, "change", testid + "key right"); |
|
109 is(element.value, 7, testid + " key right"); |
|
110 synthesizeKeyExpectEvent("VK_UP", { }, element, "change", testid + "key up"); |
|
111 is(element.value, upDecrements ? 5 : 9, testid + " key up"); |
|
112 synthesizeKeyExpectEvent("VK_DOWN", { }, element, "change", testid + "key down"); |
|
113 is(element.value, 7, testid + " key down"); |
|
114 |
|
115 synthesizeKeyExpectEvent("VK_PAGE_UP", { }, element, "change", testid + "key page up"); |
|
116 is(element.value, upDecrements ? 3 : 11, testid + " key page up"); |
|
117 synthesizeKeyExpectEvent("VK_PAGE_DOWN", { }, element, "change", testid + "key page down"); |
|
118 is(element.value, 7, testid + " key page down"); |
|
119 |
|
120 synthesizeKeyExpectEvent("VK_HOME", { }, element, "change", testid + "key home"); |
|
121 is(element.value, reverse ? 20 : 0, testid + " key home"); |
|
122 synthesizeKeyExpectEvent("VK_END", { }, element, "change", testid + "key end"); |
|
123 is(element.value, reverse ? 0 : 20, testid + " key end"); |
|
124 |
|
125 testtag_scale_UI_Mouse(element, testid, horiz, reverse, 4); |
|
126 |
|
127 element.min = 4; |
|
128 element.pageIncrement = 3; |
|
129 testtag_scale_UI_Mouse(element, testid + " with min", horiz, reverse, 3); |
|
130 |
|
131 element.pageIncrement = 30; |
|
132 testtag_scale_UI_Mouse(element, testid + " with min past", horiz, reverse, 30); |
|
133 } |
|
134 |
|
135 function testtag_scale_UI_Mouse(element, testid, horiz, reverse, pinc) |
|
136 { |
|
137 var initial = reverse ? 8 : 12; |
|
138 var newval = initial + (reverse ? pinc : -pinc); |
|
139 var endval = initial; |
|
140 // in the pinc == 30 case, the page increment is large enough that it would |
|
141 // just cause the thumb to reach the end of the scale. Make sure that the |
|
142 // mouse click does not go past the end. |
|
143 if (pinc == 30) { |
|
144 newval = reverse ? 20 : 4; |
|
145 endval = reverse ? 4 : 20; |
|
146 } |
|
147 element.value = initial; |
|
148 |
|
149 var hmove = horiz ? 25 : 10; |
|
150 var vmove = horiz ? 10 : 25; |
|
151 |
|
152 var leftFn = function () { return reverse ? element.value < newval + 3 : element.value > newval - 3; } |
|
153 var rightFn = function () { return reverse ? element.value < endval - 3 : element.value < endval + 3; } |
|
154 |
|
155 // check that clicking the mouse on the trough moves the thumb properly |
|
156 synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=default"); |
|
157 |
|
158 if (navigator.platform.indexOf("Mac") >= 0) { |
|
159 if (pinc == 30) |
|
160 ok(element.value > 4, testid + " mouse on left movetoclick=default"); |
|
161 else |
|
162 ok(leftFn, testid + " mouse on left movetoclick=default"); |
|
163 } |
|
164 else { |
|
165 is(element.value, newval, testid + " mouse on left movetoclick=default"); |
|
166 } |
|
167 |
|
168 var rect = element.getBoundingClientRect(); |
|
169 synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
|
170 rect.bottom - rect.top - vmove, { }, |
|
171 element, "change", testid + " mouse on right movetoclick=default"); |
|
172 |
|
173 if (navigator.platform.indexOf("Mac") >= 0) { |
|
174 if (pinc == 30) |
|
175 ok(element.value < 20, testid + " mouse on right movetoclick=default"); |
|
176 else |
|
177 ok(rightFn, testid + " mouse on right movetoclick=default"); |
|
178 } |
|
179 else { |
|
180 is(element.value, endval, testid + " mouse on right movetoclick=default"); |
|
181 } |
|
182 |
|
183 element.setAttribute("movetoclick", "true"); |
|
184 element.value = initial; |
|
185 |
|
186 synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=true"); |
|
187 if (pinc == 30) |
|
188 ok(element.value > 4, testid + " mouse on left movetoclick=true"); |
|
189 else |
|
190 ok(leftFn, testid + " mouse on left movetoclick=true"); |
|
191 |
|
192 var rect = element.getBoundingClientRect(); |
|
193 synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
|
194 rect.bottom - rect.top - vmove, { }, |
|
195 element, "change", testid + " mouse on right movetoclick=true"); |
|
196 if (pinc == 30) |
|
197 ok(element.value < 20, testid + " mouse on right movetoclick=true"); |
|
198 else |
|
199 ok(rightFn, testid + " mouse on right movetoclick=true"); |
|
200 |
|
201 element.setAttribute("movetoclick", "false"); |
|
202 element.value = initial; |
|
203 |
|
204 synthesizeMouseExpectEvent(element, hmove, vmove, { }, element, "change", testid + "mouse on left movetoclick=false"); |
|
205 is(element.value, newval, testid + " mouse on left movetoclick=false"); |
|
206 |
|
207 var rect = element.getBoundingClientRect(); |
|
208 synthesizeMouseExpectEvent(element, rect.right - rect.left - hmove, |
|
209 rect.bottom - rect.top - vmove, { }, |
|
210 element, "change", testid + " mouse on right movetoclick=false"); |
|
211 is(element.value, endval, testid + " mouse on right movetoclick=false"); |
|
212 |
|
213 element.removeAttribute("movetoclick"); |
|
214 |
|
215 element.value = reverse ? element.max : element.min; |
|
216 |
|
217 synthesizeMouse(element, 8, 8, { type: "mousedown" }); |
|
218 synthesizeMouse(element, horiz ? 2000 : 8, horiz ? 8 : 2000, { type: "mousemove" }); |
|
219 is(element.value, reverse ? element.min : element.max, testid + " move mouse too far after end"); |
|
220 synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
|
221 |
|
222 synthesizeMouse(element, rect.width - 8, rect.height - 8, { type: "mousedown" }); |
|
223 synthesizeMouse(element, horiz ? -2000 : rect.width - 8, horiz ? rect.height - 8 : -2000, { type: "mousemove" }); |
|
224 is(element.value, reverse ? element.max : element.min, testid + " move mouse too far before start"); |
|
225 |
|
226 synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
|
227 |
|
228 // now check if moving outside in both directions works. On Windows, |
|
229 // it should snap back to the original location. |
|
230 element.value = reverse ? element.max : element.min; |
|
231 |
|
232 var expected = (navigator.platform.indexOf("Win") >= 0) ? element.value : |
|
233 (reverse ? element.min : element.max); |
|
234 synthesizeMouse(element, 7, 7, { type: "mousedown" }); |
|
235 synthesizeMouse(element, 2000, 2000, { type: "mousemove" }); |
|
236 is(element.value, expected, testid + " move mouse ouside in both directions"); |
|
237 synthesizeMouse(element, 2, 2, { type: "mouseup" }); |
|
238 } |
|
239 |
|
240 function testtag_scale_States(element, evalue, evalueattr, emin, emax, testid) |
|
241 { |
|
242 is(element.getAttribute("value"), evalueattr, testid + " value attribute"); |
|
243 is(element.value, evalue, testid + " value"); |
|
244 is(element.min, emin, testid + " min"); |
|
245 is(element.max, emax, testid + " max"); |
|
246 } |
|
247 |
|
248 function testtag_scale_Increments(element, min, max, increment, pageIncrement, testid) |
|
249 { |
|
250 // check the increase and decrease methods |
|
251 element.increment = increment; |
|
252 element.increase(); |
|
253 is(element.value, min + increment, testid + " increase 1"); |
|
254 element.increase(); |
|
255 is(element.value, max, testid + " increase 2"); |
|
256 element.decrease(); |
|
257 is(element.value, max - increment, testid + " decrease 1"); |
|
258 element.decrease(); |
|
259 is(element.value, min, testid + " decrease 2"); |
|
260 |
|
261 // check the increasePage and decreasePage methods |
|
262 element.pageIncrement = pageIncrement; |
|
263 element.increasePage(); |
|
264 is(element.value, min + pageIncrement, testid + " increasePage 1"); |
|
265 element.increasePage(); |
|
266 is(element.value, max, testid + " increasePage 2"); |
|
267 element.decreasePage(); |
|
268 is(element.value, max - pageIncrement, testid + " decreasePage 1"); |
|
269 element.decreasePage(); |
|
270 is(element.value, min, testid + " decreasePage 2"); |
|
271 } |
|
272 |
|
273 ]]> |
|
274 |
|
275 </script> |
|
276 |
|
277 </window> |