Debian Codegraph @

dijit/tests/form/robot/Slider_mouse.html

raw symbols SCIP
1 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
2 "http://www.w3.org/TR/html4/strict.dtd">
3 <html>
4 <head>
5 <title>doh.robot Slider Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <!-- required: dojo.js -->
12 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
13
14 <script type="text/javascript">
15 dojo.require("dojo.window");
16 dojo.require("dijit.robotx");
17
18 var arrowSliders = ['slider1','slider2'];
19 var arrowSliderInit_min = [0.2,10,1200];
20 var arrowSliderInit_max = [99.8,90,2800];
21 var sliderIds = ["slider1", "slider2", "slider3", "sliderH2"];
22
23 var onChange = {slider1: 'slider1input', slider2: 'slider2input'};
24
25 function boundaryTest(slider, initValue, finalValue){
26 // summary:
27 // Sets slider to initValue, which should be either one below the
28 // max, or one above the min.
29 //
30 // Click the arrow button once to get to the final value, and
31 // then click the arrow button again (value shouldn't change second time)
32 var d = new doh.Deferred();
33 slider.set('value', initValue);
34 var button = slider._descending ?
35 (initValue<finalValue?slider.decrementButton: slider.incrementButton) :
36 (initValue<finalValue?slider.incrementButton: slider.decrementButton);
37 doh.robot.sequence(function(){
38 dojo.window.scrollIntoView(slider.domNode);
39 },500);
40 doh.robot.mouseMoveAt(button, 500);
41 doh.robot.mouseClick({left: true}, 500);
42 doh.robot.sequence(d.getTestErrback(function(){
43 doh.is(Number(finalValue).toFixed(2), Number(slider.get('value')).toFixed(2));
44 if(onChange[slider.id]){
45 doh.is(Number(finalValue).toFixed(1), Number(parseFloat(dojo.byId(onChange[slider.id]).value)).toFixed(1));
46 }
47 doh.robot.mouseMoveAt(button, 500);
48 doh.robot.mouseClick({left: true}, 500);
49 doh.robot.sequence(d.getTestCallback(function(){
50 doh.is(Number(finalValue).toFixed(2), Number(slider.get('value')).toFixed(2));
51 if(onChange[slider.id]){
52 doh.is(Number(finalValue).toFixed(1), Number(parseFloat(dojo.byId(onChange[slider.id]).value)).toFixed(1));
53 }
54 }), 500);
55 }), 500);
56 return d;
57 }
58
59 function buttonHeldTest(slider, initValue, finalValue){
60 var d = new doh.Deferred();
61 slider.set('value', initValue);
62 var button = slider._descending?(initValue<finalValue?slider.decrementButton: slider.incrementButton): (initValue<finalValue?slider.incrementButton: slider.decrementButton);
63 doh.robot.sequence(function(){
64 dojo.window.scrollIntoView(slider.domNode);
65 },500);
66 doh.robot.mouseMoveAt(button, 500);
67 doh.robot.mousePress({left: true}, 500);
68 doh.robot.mouseRelease({left: true}, 5000);
69 doh.robot.sequence(d.getTestCallback(function(){
70 doh.is(finalValue, new Number(slider.get('value')).toFixed(1));
71 if(onChange[slider.id]){
72 doh.is(finalValue, parseFloat(dojo.byId(onChange[slider.id]).value));
73 }
74 }), 500);
75 return d;
76 }
77
78 function mouseWheelTest(slider, initValue, finalValue){
79 if(slider.discreteValues != Infinity){
80 var d = new doh.Deferred();
81 slider.set('value', initValue);
82 var direction = (finalValue-initValue)/Math.abs(finalValue-initValue);
83 var delta = Math.ceil((slider.discreteValues-1)*Math.abs(doh.robot.mouseWheelSize)/doh.robot.mouseWheelSize);
84 doh.robot.sequence(function(){
85 dojo.window.scrollIntoView(slider.domNode);
86 },500);
87 doh.robot.mouseMoveAt(slider.focusNode, 500);
88 doh.robot.mouseClick({left: true}, 500);
89 doh.robot.mouseWheel(delta*direction, 500, Math.abs(delta)*200);
90 doh.robot.sequence(d.getTestCallback(function(){
91 doh.is(finalValue, new Number(slider.get('value')).toFixed(1));
92 if(onChange[slider.id]){
93 doh.is(finalValue, parseFloat(dojo.byId(onChange[slider.id]).value));
94 }
95 }), 500);
96 return d;
97 }
98 }
99
100 dojo.ready(function(){
101 doh.robot.initRobot('../test_Slider.html');
102
103 doh.register(function setup(){
104 // get pointer to registry in the iframe
105 registry = doh.robot.window.require("dijit/registry");
106 });
107
108 // Test initial values
109 doh.register("initial values", function initialValues(){
110 var slider = registry.byId(arrowSliders[0]),
111 bar = slider.valueNode.parentNode,
112 barWidth = bar.offsetWidth;
113 arrowSliderInit_min[0] = 100 / (barWidth-1); // discover slider smallest non min value
114 arrowSliderInit_max[0] = 100 - arrowSliderInit_min[0]; // discover slider largest non max value
115 doh.is(10, registry.byId("slider1").get("value"), "horizontal1");
116 doh.is(10, registry.byId("slider2").get("value"), "vertical1");
117 doh.is(2, registry.byId("slider3").get("value"), "horizontal2");
118 doh.is(10, registry.byId("sliderH2").get("value"), "sliderH2");
119 });
120
121 doh.register("set('value', ...)", [
122 function valid(){
123 var slider = registry.byId(arrowSliders[0]);
124 slider.set('value', 50);
125 var d = new doh.Deferred();
126 doh.robot.sequence(d.getTestCallback(function(){
127 doh.is(50, parseFloat(dojo.byId(onChange[slider.id]).value));
128 }), 500);
129 return d;
130 },
131 function setToNull(){
132 // No idea why setting to null makes it go to 0 but apparently that's expected behavior
133 var slider = registry.byId(arrowSliders[0]);
134 slider.set('value', null);
135 var d = new doh.Deferred();
136 doh.robot.sequence(d.getTestCallback(function(){
137 doh.is(0, parseFloat(dojo.byId(onChange[slider.id]).value));
138 }), 500);
139 return d;
140 }
141 ]);
142
143 // Test that disabled sliders don't respond to mouse clicks (or at least,
144 // the left/right arrow buttons don't)
145 doh.register("disabledTest", [
146 {
147 name: arrowSliders[0]+'_setUp',
148 slider: arrowSliders[0],
149 timeout: 30000,
150 runTest: function(){
151 var d = new doh.Deferred();
152 doh.robot.mouseMoveAt('disableButton',500);
153 doh.robot.mouseClick({left: true}, 500);
154 if(dojo.isMac){
155 // Workaround mac/FF bug where first click doesn't register
156 doh.robot.mouseClick({
157 left: true
158 }, 500);
159 }
160 doh.robot.sequence(function(){ d.callback(true); },500);
161 return d;
162 }
163 },
164 {
165 name: arrowSliders[0]+'_min',
166 slider: arrowSliders[0],
167 timeout: 30000,
168 runTest: function(){
169 this.slider = registry.byId(this.slider);
170 var value = arrowSliderInit_min[0];
171 return boundaryTest(this.slider, value, value);
172 }
173 },
174 {
175 name: arrowSliders[0]+'_tearDown',
176 slider: arrowSliders[0],
177 timeout: 30000,
178 runTest: function(){
179 var d = new doh.Deferred();
180 doh.robot.mouseMoveAt('enableButton',500);
181 doh.robot.mouseClick({left: true}, 500);
182 doh.robot.sequence(function(){ d.callback(true); },500);
183 return d;
184 }
185 }
186 ]);
187
188 doh.register("buttonBoundaryTest", [
189 {
190 name: arrowSliders[0]+'_min',
191 slider: arrowSliders[0],
192 timeout: 30000,
193 runTest: function(){
194 this.slider = registry.byId(this.slider);
195 return boundaryTest(this.slider, arrowSliderInit_min[0], this.slider.minimum);
196 }
197 },
198 {
199 name: arrowSliders[0]+'_max',
200 slider: arrowSliders[0],
201 timeout: 30000,
202 runTest: function(){
203 this.slider = registry.byId(this.slider);
204 return boundaryTest(this.slider, arrowSliderInit_max[0], this.slider.maximum);
205 }
206 }
207 ]);
208
209 doh.register("buttonHeldTest", [
210 {
211 name: arrowSliders[1]+'_minToMax',
212 slider: arrowSliders[1],
213 timeout: 30000,
214 runTest: function(){
215 this.slider = registry.byId(this.slider);
216 return buttonHeldTest(this.slider, this.slider.minimum, this.slider.maximum);
217 }
218 },
219 {
220 name: arrowSliders[1]+'_maxToMin',
221 slider: arrowSliders[1],
222 timeout: 30000,
223 runTest: function(){
224 this.slider = registry.byId(this.slider);
225 return buttonHeldTest(this.slider, this.slider.maximum, this.slider.minimum);
226 }
227 }
228 ]);
229
230 doh.register("mouseWheelTest", [
231 {
232 name: arrowSliders[1]+'_minToMax',
233 slider: arrowSliders[1],
234 timeout: 30000,
235 runTest: function(){
236 this.slider = registry.byId(this.slider);
237 return mouseWheelTest(this.slider, this.slider.minimum, this.slider.maximum);
238 }
239 },
240 {
241 name: arrowSliders[1]+'_maxToMin',
242 slider: arrowSliders[1],
243 timeout: 30000,
244 runTest: function(){
245 this.slider = registry.byId(this.slider);
246 return mouseWheelTest(this.slider, this.slider.maximum, this.slider.minimum);
247 }
248 }
249 ]);
250
251 doh.register("general tests", [
252 {
253 name: "slider1",
254 timeout: 5000, // this is the animated slider so there is a 500ms delay
255 runTest: function(){
256 var d = new doh.Deferred();
257 var slider = registry.byId("slider1");
258 slider.set('value', 10);
259 dojo.window.scrollIntoView(slider.domNode);
260 doh.robot.mouseMoveAt(slider.focusNode, 1, 0);
261 doh.robot.mousePress({left: true}, 500);
262 // drag to 20% marker
263 var marker = dojo.query("div[style*='20%']", dojo.byId('dijit_form_HorizontalRule_0'))[0];
264 doh.robot.mouseMoveAt(marker, 500, 0);
265 doh.robot.mouseRelease({left: true}, 500);
266 doh.robot.sequence(d.getTestCallback(function(){
267 var value = slider.get('value');
268 doh.t(value >= 19 && value <= 21, "Expected 20-ish, got "+value);
269 }), 1000);
270 return d;
271 }
272 },
273
274 {
275 name: "slider2",
276 timeout: 5000,
277 runTest: function(){
278 var d = new doh.Deferred();
279 var slider = registry.byId("slider2");
280 slider.set('value', 10);
281 dojo.window.scrollIntoView(slider.domNode);
282 doh.robot.mouseMoveAt(slider.focusNode, 1, 0);
283 doh.robot.mousePress({left: true}, 500);
284 // drag to 20% marker (Slider is in descending order so it's 100-20=80%)
285 var marker = dojo.query("div[style*='80%']", dojo.byId('dijit_form_VerticalRule_1'))[0];
286 doh.robot.mouseMoveAt(marker, 500, 0);
287 doh.robot.mouseRelease({left: true}, 500);
288 doh.robot.sequence(d.getTestCallback(function(){
289 var value = slider.get('value');
290 doh.is(20, value);
291 }), 1000);
292 return d;
293 }
294 }
295 ]);
296
297 doh.register("drag tests", [
298 {
299 name: "horizontal",
300 timeout: 10000,
301 runTest: function(){
302 var d = new doh.Deferred();
303 var slider = registry.byId("slider1");
304 slider.set('value', 50);
305 dojo.window.scrollIntoView(slider.domNode);
306 doh.robot.mouseMoveAt(slider.focusNode, 1, 0);
307 doh.robot.mousePress({left: true}, 500);
308 doh.robot.mouseMoveAt(slider.incrementButton, 1000, 0);
309 doh.robot.mouseRelease({left: true}, 500);
310 doh.robot.mouseMoveAt(slider.decrementButton, 1000, 0);
311 doh.robot.sequence(d.getTestCallback(function(){
312 var value = slider.get('value');
313 doh.is(value, 100, "Expected max value of 100, got "+value);
314 }), 1000);
315 return d;
316 }
317 }
318 ]);
319
320 doh.register("fractional slider test", {
321 // Check for rounding errors on a fractional slider.
322 name: "fractional value",
323 timeout: 9000,
324 runTest: function(){
325 var d = new doh.Deferred();
326 var slider = registry.byId("fractionalSlider");
327 doh.is("0.28", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #0");
328
329 doh.robot.mouseMoveAt(slider.incrementButton, 1000, 0);
330 doh.robot.mouseClick({left: true}, 500);
331 doh.robot.sequence(d.getTestErrback(function(){
332 doh.is("0.3", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #1");
333 doh.is("0.3", slider.get("value"), "get('value') #1");
334 doh.is("0.3", dojo.byId("fractionalSliderInput").value, "value reported in input #1");
335 }), 500);
336
337 doh.robot.mouseMoveAt(slider.decrementButton, 1000, 0);
338 doh.robot.mouseClick({left: true}, 500);
339 doh.robot.sequence(d.getTestErrback(function(){
340 doh.is("0.28", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #2");
341 }), 500);
342
343 doh.robot.mouseClick({left: true}, 500);
344 doh.robot.sequence(d.getTestCallback(function(){
345 doh.is("0.26", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #3");
346 doh.is("0.26", slider.get("value"), "get('value') #3");
347 doh.is("0.26", dojo.byId("fractionalSliderInput").value, "value reported in input #3");
348 }), 500);
349 return d;
350 }
351 });
352
353 doh.run();
354 });
355 </script>
356 </head>
357 </html>