Debian Codegraph @

dijit/tests/form/robot/Slider_a11y.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("dijit.robotx");
16
17 // These are all the sliders
18 var accessibleSliders = ['slider1','slider2','slider3'];
19 var accessibleSliderInit_min = [0.2,10,2,1200];
20 var accessibleSliderInit_max = [99.8,90,2,2800];
21 var sliderIds = ["slider1", "slider2", "slider3", "sliderH2"];
22 var sliderNames = ["horizontal1","vertical1","horizontal2","horizontalH2"];
23 var onChange = {slider1: 'slider1input', slider2: 'slider2input'};
24
25 function a11yBoundaryTest(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 // Use the arrow key once to get to the final value, and
31 // then use the arrow key again (value shouldn't change second time)
32
33 var d = new doh.Deferred();
34 var key = initValue < finalValue ? dojo.keys.RIGHT_ARROW : dojo.keys.LEFT_ARROW;
35
36 // Set slider to initial value, one value away from the min or max
37 slider.set('value', initValue, false);
38
39 // Focus the slider
40 slider.focus();
41
42 // First key press moves to either min or max
43 doh.robot.keyPress(key, 500);
44 doh.robot.sequence(d.getTestErrback(function(){
45 doh.is(Number(finalValue).toFixed(1), Number(slider.get('value')).toFixed(1),
46 "value after first " + (key == dojo.keys.RIGHT_ARROW ? "right arrow" : "left arrow"));
47 if(onChange[slider.id]){
48 doh.is(Number(finalValue).toFixed(1), Number(parseFloat(dojo.byId(onChange[slider.id]).value)).toFixed(1),
49 "onchange after first " + (key == dojo.keys.RIGHT_ARROW ? "right arrow" : "left arrow"));
50 }
51
52 // Second key press should have no effect, but confirm it
53 doh.robot.keyPress(key, 500);
54 doh.robot.sequence(d.getTestCallback(function(){
55 doh.is(Number(finalValue).toFixed(1), Number(slider.get('value')).toFixed(1),
56 "value after second " + (key == dojo.keys.RIGHT_ARROW ? "right arrow" : "left arrow"));
57 if(onChange[slider.id]){
58 doh.is(Number(finalValue).toFixed(1), Number(parseFloat(dojo.byId(onChange[slider.id]).value)).toFixed(1),
59 "onchange after second " + (key == dojo.keys.RIGHT_ARROW ? "right arrow" : "left arrow"));
60 }
61 }), 500);
62 }), 500);
63 return d;
64 }
65
66 // machinery for testing keyboard manipulation of sliders
67 var eaVals = []; // array holding expected values and actual values after arrow etc. keypresses
68 var strokeIndex = 0;
69 var noteChanges;
70
71 function keyStrokeSetup(inSliderId){
72 // summary:
73 // Populates eaVals[] with expected slider values after each keystroke (in this test),
74 // and sets up listener to record actual value into same eaVals[] array.
75
76 var slider = registry.byId(inSliderId);
77 eaVals = populateExpected(slider);
78 strokeIndex = 0;
79 noteChanges = dojo.global.dojo.connect(slider, "onChange", function(){
80 eaVals[strokeIndex++].actual = slider.get('value');
81 });
82 }
83
84 function populateExpected(/*Slider Widget*/inSlider){
85 // summary:
86 // Returns array of expected slider values after each keystroke (in this test)
87
88 var initVal = inSlider.get('value');
89 var eVals = [];
90
91 // The values expected by pressing HOME, right arrow five times,
92 // PgUp twice, PgDn, up arrow twice, down arrow once,
93 // left arrow once, and END.
94 inSlider.set('value', inSlider.minimum, false);
95 eVals.push({stroke: "HOME", expected: inSlider.get('value')});
96 for(var i = 0; i < 5; i++){
97 inSlider._bumpValue(1, false);
98 eVals.push({stroke: "RIGHT", expected: inSlider.get('value')});
99 }
100 for(i = 0; i < 2; i++){
101 inSlider._bumpValue(inSlider.pageIncrement, false);
102 eVals.push({stroke: "PgUp", expected: inSlider.get('value')});
103 }
104 inSlider._bumpValue(-inSlider.pageIncrement, false);
105 eVals.push({stroke: "PgDn", expected: inSlider.get('value')});
106 for(i = 0; i < 2; i++){
107 inSlider._bumpValue(1, false);
108 eVals.push({stroke: "UP", expected: inSlider.get('value')});
109 }
110 inSlider._bumpValue(-1, false);
111 eVals.push({stroke: "DOWN", expected: inSlider.get('value')});
112 inSlider._bumpValue(-1, false);
113 eVals.push({stroke: "LEFT", expected: inSlider.get('value')});
114 inSlider.set('value', inSlider.maximum, false);
115 eVals.push({stroke: "END", expected: inSlider.get('value')});
116
117 // reset <inSlider> back to its initial value, and return
118 inSlider.set('value', initVal, false);
119 return eVals;
120 }
121
122 function a11yTabFocusTest(inSliderId){
123 var d = new doh.Deferred();
124 var slider = registry.byId(inSliderId);
125 var focusCount = 0;
126 var blurCount = 0;
127 var gotFocus = function(){
128 focusCount++;
129 };
130 var lostFocus = function(){
131 blurCount++;
132 };
133 var focusFunc = dojo.global.dojo.connect(slider.focusNode, "onfocus", gotFocus);
134 var blurFunc = dojo.global.dojo.connect(slider.focusNode, "onblur", lostFocus);
135
136 // insure a known focus starting point -- the slider to test.
137 slider.focus();
138
139 // Shift-tab away, tab to, tab away, shift-tab back.
140 doh.robot.keyPress(dojo.keys.TAB, 1000, {
141 shift: true
142 });
143 doh.robot.keyPress(dojo.keys.TAB, 500);
144 doh.robot.keyPress(dojo.keys.TAB, 500);
145 doh.robot.keyPress(dojo.keys.TAB, 500, {
146 shift: true
147 });
148 var checkGotFocus = function(){
149 doh.assertEqual(3, focusCount, slider.id + ": # of times focussed");
150 doh.assertEqual(2, blurCount, slider.id + ": # of times lost focus");
151 dojo.disconnect(focusFunc);
152 dojo.disconnect(blurFunc);
153 };
154 doh.robot.sequence(d.getTestCallback(checkGotFocus), 1000, 500);
155 return d;
156 }
157
158 function a11yKeystrokeTest(inSliderId){
159 var d = new doh.Deferred();
160 var slider = registry.byId(inSliderId);
161 var initVal = slider.get('value');
162 // get focus on slider thumb before pressing keys.
163 slider.focus();
164 doh.robot.sequence(function(){
165 strokeIndex = 0;
166 }, 1000); // insure onChange events have stopped
167 doh.robot.keyPress(dojo.keys.HOME, 200);
168 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 1000);
169 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 200);
170 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 200);
171 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 200);
172 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 200);
173 doh.robot.keyPress(dojo.keys.PAGE_UP, 200);
174 doh.robot.keyPress(dojo.keys.PAGE_UP, 500);
175 doh.robot.keyPress(dojo.keys.PAGE_DOWN, 500);
176 doh.robot.keyPress(dojo.keys.UP_ARROW, 500);
177 doh.robot.keyPress(dojo.keys.UP_ARROW, 200);
178 doh.robot.keyPress(dojo.keys.DOWN_ARROW, 200);
179 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 200);
180 doh.robot.keyPress(dojo.keys.END, 200);
181 doh.robot.sequence(d.getTestCallback(function(){
182 dojo.disconnect(noteChanges);
183 slider.set('value', initVal, false);
184 for(var i = 0; i < eaVals.length; i++){
185 doh.assertEqual(eaVals[i].expected, eaVals[i].actual, eaVals[i].stroke + " (" + slider.id + ")");
186 }
187 }), 1000, 500);
188 return d;
189 }
190
191 dojo.ready(function(){
192 doh.robot.initRobot('../test_Slider.html');
193
194 doh.register(function setup(){
195 // get pointer to registry in the iframe
196 registry = doh.robot.window.require("dijit/registry");
197 dfocus = doh.robot.window.require("dijit/focus");
198 });
199
200 // TODO: move to Slider.html
201 // This tests that Slider is structured so that dojo.query can find the hidden input.
202 doh.register("dojo.query() by name",
203 function slider1(){
204 var slider = registry.byId("slider1"),
205 queried = dojo.query("input[name=horizontal1]"),
206 bar = slider.valueNode.parentNode,
207 barWidth = bar.offsetWidth;
208 accessibleSliderInit_min[0] = 100 / (barWidth-1); // discover slider smallest non min value
209 accessibleSliderInit_max[0] = 100 - accessibleSliderInit_min[0]; // discover slider largest non max value
210 doh.is(1, queried.length, "Expected 1 slider with name horizontal1");
211 doh.is(slider.valueNode, queried[0], "Slider's valueNode did not match the one found by dojo.query.");
212 }
213 );
214
215 // This tests that pressing the arrow keys has no effect on a disabled slider
216 // TODO: this doesn't make sense, should just be testing that slider can't get
217 // focus. (And if it doesn't have focus then testing keystrokes is meaningless)
218 doh.register("disabledTest",{
219 name: accessibleSliders[0]+'_a11y_min',
220 slider: accessibleSliders[0],
221 timeout: 30000,
222 runTest: function(){
223 this.slider = registry.byId(this.slider);
224 this.slider.set('disabled', true);
225 var value = accessibleSliderInit_min[0];
226 return a11yBoundaryTest(this.slider, value, value);
227 }
228 });
229
230 // This tests to make sure that the error keys don't go beyond the min or max values
231 doh.register("a11yBoundaryTest - min", {
232 name: accessibleSliders[0]+'_a11y_min',
233 slider: accessibleSliders[0],
234 timeout: 30000,
235 runTest: function(){
236 this.slider = registry.byId(this.slider);
237 this.slider.set('disabled', false);
238 return a11yBoundaryTest(this.slider, accessibleSliderInit_min[0], this.slider.minimum);
239 }
240 });
241 doh.register("a11yBoundaryTest",{
242 name: accessibleSliders[0]+'_a11y_max',
243 slider: accessibleSliders[0],
244 timeout: 30000,
245 runTest: function(){
246 this.slider = registry.byId(this.slider);
247 return a11yBoundaryTest(this.slider, accessibleSliderInit_max[0], this.slider.maximum);
248 }
249 });
250
251 // keyboard a11y tests (robot) -- tab focus
252 doh.register("a11yTabFocus",
253 [
254 {
255 name: "slider2TabFocus",
256 timeout: 9000,
257 runTest: function(){
258 return a11yTabFocusTest("slider2");
259 }
260 },
261 {
262 name: "slider3TabFocus",
263 timeout: 9000,
264 runTest: function(){
265 return a11yTabFocusTest("slider3");
266 }
267 }
268 ]);
269
270 // keyboard a11y tests (robot) -- manipulate slider via keystrokes
271 doh.register("a11yKeystrokes", [
272 {
273 name: "slider1Keystrokes",
274 timeout: 9000,
275 setUp: function(){
276 keyStrokeSetup("slider1");
277 },
278 runTest: function(){
279 return a11yKeystrokeTest("slider1");
280 }
281 },
282 {
283 name: "slider2Keystrokes",
284 timeout: 9000,
285 setUp: function(){
286 keyStrokeSetup("slider2");
287 },
288 runTest: function(){
289 return a11yKeystrokeTest("slider2");
290 }
291 },
292 {
293 name: "disabledTabStop",
294 timeout: 9000,
295 runTest: function(){
296 var d = new doh.Deferred();
297
298 // focus element after slider 2, and disable slider 2
299 doh.robot.window.document.getElementById("slider2input").focus();
300 registry.byId("slider2").set("disabled", true);
301
302 // jump to element before slider 2 (hopefully)
303 doh.robot.keyPress(dojo.keys.TAB, 1000, {
304 shift: true
305 });
306
307 doh.robot.sequence(d.getTestCallback(function(){
308 doh.is("disableButton", dfocus.curNode.id, "disabled tab stop should be skipped");
309 }), 500);
310 return d;
311 }
312 },
313 {
314 // Check for rounding errors on a fractional slider.
315 name: "fractional value",
316 timeout: 9000,
317 runTest: function(){
318 var d = new doh.Deferred();
319 var slider = registry.byId("fractionalSlider");
320 slider.focus();
321 doh.is("0.28", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #0");
322
323 doh.robot.keyPress(dojo.keys.RIGHT_ARROW, 500);
324 doh.robot.sequence(d.getTestErrback(function(){
325 doh.is("0.3", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #1");
326 doh.is("0.3", slider.get("value"), "get('value') #1");
327 doh.is("0.3", dojo.byId("fractionalSliderInput").value, "value reported in input #1");
328 }), 500);
329
330 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500);
331 doh.robot.sequence(d.getTestErrback(function(){
332 doh.is("0.28", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #2");
333 }), 500);
334
335 doh.robot.keyPress(dojo.keys.LEFT_ARROW, 500);
336 doh.robot.sequence(d.getTestCallback(function(){
337 doh.is("0.26", slider.focusNode.getAttribute("aria-valuenow"), "aria-valuenow #3");
338 doh.is("0.26", slider.get("value"), "get('value') #3");
339 doh.is("0.26", dojo.byId("fractionalSliderInput").value, "value reported in input #3");
340 }), 500);
341
342 return d;
343 }
344 }
345 ]);
346
347 doh.run();
348 });
349 </script>
350 </head>
351 </html>