| 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 Spinner Test</title> |
| 6 |
|
| 7 |
<style> |
| 8 |
@import "../../../../util/doh/robot/robot.css"; |
| 9 |
</style> |
| 10 |
|
| 11 |
|
| 12 |
<script type="text/javascript" src="../../../../dojo/dojo.js"></script> |
| 13 |
|
| 14 |
<script type="text/javascript"> |
| 15 |
dojo.require("dijit.robotx"); |
| 16 |
|
| 17 |
dojo.ready(function(){ |
| 18 |
var spin1; |
| 19 |
var spin2; |
| 20 |
var spin3; |
| 21 |
var delta=1; // redefine with doh.robot.mouseWheelSize when it is available |
| 22 |
doh.robot.initRobot('../test_Spinner.html'); |
| 23 |
|
| 24 |
doh.register("setUp",{ |
| 25 |
name: "setUp", |
| 26 |
timeout: 15000, |
| 27 |
setUp:function(){ |
| 28 |
spin1=dijit.byId('integerspinner1'); |
| 29 |
spin2=dijit.byId('integerspinner2'); |
| 30 |
spin3=dijit.byId('realspinner1'); |
| 31 |
}, |
| 32 |
runTest: function(){ |
| 33 |
// assert onChange not fired |
| 34 |
doh.is("not fired yet!", dojo.byId('oc1').value); |
| 35 |
|
| 36 |
// make sure initial values are what we expect |
| 37 |
doh.is(1, spin1.smallDelta); |
| 38 |
doh.is(900, spin1.get('value'), "integerspinner1"); |
| 39 |
doh.is(1000, spin2.get('value'), "integerspinner2"); |
| 40 |
doh.is(1.0, spin3.get('value'), "realspinner1"); |
| 41 |
} |
| 42 |
}); |
| 43 |
|
| 44 |
doh.register("setvaluetest", [ |
| 45 |
{ |
| 46 |
name: "valid", |
| 47 |
runTest:function(){ |
| 48 |
spin1.set('value', 400); |
| 49 |
doh.is(400, spin1.focusNode.value); |
| 50 |
doh.is(true, spin1.isValid()); |
| 51 |
|
| 52 |
} |
| 53 |
}, |
| 54 |
|
| 55 |
{ |
| 56 |
name: "null_notrequired", |
| 57 |
runTest:function(){ |
| 58 |
spin1.set('value', null); |
| 59 |
spin1.set('required',false); |
| 60 |
doh.is('', spin1.focusNode.value); |
| 61 |
doh.is(true, spin1.isValid()); |
| 62 |
doh.is(true, isNaN(spin1.get('value'))); |
| 63 |
}, |
| 64 |
tearDown:function(){ |
| 65 |
spin1.set('required',true); |
| 66 |
spin1.set('value', 900); |
| 67 |
} |
| 68 |
}, |
| 69 |
|
| 70 |
{ |
| 71 |
name: "null_required", |
| 72 |
runTest:function(){ |
| 73 |
spin1.set('value', null); |
| 74 |
doh.is('', spin1.focusNode.value); |
| 75 |
doh.is(false, spin1.isValid()); |
| 76 |
doh.is(true, isNaN(spin1.get('value'))); |
| 77 |
} |
| 78 |
}, |
| 79 |
|
| 80 |
{ |
| 81 |
name: "spinner1_invalid", |
| 82 |
timeout: 15000, |
| 83 |
runTest: function(){ |
| 84 |
// assert invalid works |
| 85 |
var d=new doh.Deferred(); |
| 86 |
doh.robot.mouseMoveAt(spin1.focusNode, 1, 0); |
| 87 |
doh.robot.mouseClick({left:true}, 500); |
| 88 |
doh.robot.sequence(function(){ |
| 89 |
spin1.set("value", NaN); |
| 90 |
}, 500); |
| 91 |
doh.robot.typeKeys("0.5", 500, 600); |
| 92 |
doh.robot.sequence(function(){ |
| 93 |
try{ |
| 94 |
// test before user clicks away |
| 95 |
doh.f(spin1.isValid(), "spin1 is marked as error"); |
| 96 |
doh.robot.keyPress(dojo.keys.TAB, 500); |
| 97 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 98 |
// also test after user clicks away |
| 99 |
doh.f(spin1.isValid(), "spin1 is marked as error"); |
| 100 |
}), 500); |
| 101 |
}catch(e){d.callback(e);} |
| 102 |
}, 500); |
| 103 |
return d; |
| 104 |
}, |
| 105 |
tearDown:function(){ |
| 106 |
spin1.set('value', 1); |
| 107 |
} |
| 108 |
}, |
| 109 |
|
| 110 |
{ |
| 111 |
name: "spinner3_invalid", |
| 112 |
timeout: 15000, |
| 113 |
runTest: function(){ |
| 114 |
// assert invalid works |
| 115 |
var d=new doh.Deferred(); |
| 116 |
doh.robot.mouseMoveAt(spin3.focusNode, 1, 0); |
| 117 |
doh.robot.mouseClick({left:true}, 500); |
| 118 |
doh.robot.sequence(function(){ |
| 119 |
spin3.set("value", NaN); |
| 120 |
}, 500); |
| 121 |
doh.robot.typeKeys("0.a", 500, 600); // vs 0.5 in spinner1_invalid, spin3 would accept that |
| 122 |
doh.robot.sequence(function(){ |
| 123 |
try{ |
| 124 |
// test before user clicks away |
| 125 |
doh.f(spin3.isValid(), "spin3 is marked as error"); |
| 126 |
doh.robot.keyPress(dojo.keys.TAB, 500); |
| 127 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 128 |
// also test after user clicks away |
| 129 |
doh.f(spin3.isValid(), "spin3 is marked as error"); |
| 130 |
}), 500); |
| 131 |
}catch(e){d.callback(e);} |
| 132 |
}, 500); |
| 133 |
return d; |
| 134 |
}, |
| 135 |
tearDown:function(){ |
| 136 |
spin3.set('value', 1); |
| 137 |
} |
| 138 |
} |
| 139 |
]); |
| 140 |
|
| 141 |
doh.register("arrowButton", [ |
| 142 |
{ |
| 143 |
name: "spinner1_typematic", |
| 144 |
timeout: 20000, |
| 145 |
setUp:function(){ |
| 146 |
spin1.set('value', 900); |
| 147 |
}, |
| 148 |
runTest: function(){ |
| 149 |
// test typematic |
| 150 |
var d=new doh.Deferred(); |
| 151 |
doh.robot.mouseMoveAt(spin1.focusNode, 1, 0); // scroll both buttons into view |
| 152 |
doh.robot.mouseMoveAt(spin1.downArrowNode, 1, 0); |
| 153 |
doh.robot.mousePress({left:true, middle:false, right:false}, 1000); |
| 154 |
doh.robot.mouseRelease({left:true, middle:false, right:false}, 5000); // going too fast overwhelms the CPU and starves the robot thread |
| 155 |
doh.robot.mousePress({left:true, middle:false, right:false}, 500); |
| 156 |
doh.robot.mouseRelease({left:true, middle:false, right:false}, 5000); |
| 157 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 158 |
var v = spin1.get('value'); |
| 159 |
// also test after user clicks away |
| 160 |
doh.t(v <= 875, "Error in typematic test. Expected <= 875, got " + v); |
| 161 |
}), 500); |
| 162 |
return d; |
| 163 |
} |
| 164 |
}, |
| 165 |
|
| 166 |
{ |
| 167 |
name: "spinner1_max", |
| 168 |
timeout: 15000, |
| 169 |
setUp:function(){ |
| 170 |
spin1.set('value', 1549); |
| 171 |
}, |
| 172 |
runTest: function(){ |
| 173 |
// test max with arrow button |
| 174 |
var d=new doh.Deferred(); |
| 175 |
// press once: should move up |
| 176 |
doh.robot.mouseMoveAt(spin1.focusNode, 1, 0); // scroll both buttons into view |
| 177 |
doh.robot.mouseMoveAt(spin1.upArrowNode, 1, 0); |
| 178 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 179 |
doh.robot.mouseMoveAt('sv1_4', 1, 0); |
| 180 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 181 |
doh.robot.sequence(d.getTestErrback(function(){ |
| 182 |
doh.is(1550, spin1.get('value')); |
| 183 |
doh.is("1,550", spin1.focusNode.value); |
| 184 |
doh.is("1550", dojo.byId('oc1').value); |
| 185 |
doh.is(true, spin1.isValid()); |
| 186 |
// press again: shouldn't move |
| 187 |
doh.robot.mouseMoveAt(spin1.upArrowNode, 1, 0); |
| 188 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 189 |
doh.robot.mouseMoveAt('sv1_4', 1, 0); |
| 190 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 191 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 192 |
doh.is(1550, spin1.get('value')); |
| 193 |
doh.is("1,550", spin1.focusNode.value); |
| 194 |
doh.is("1550", dojo.byId('oc1').value); |
| 195 |
doh.is(true, spin1.isValid()); |
| 196 |
}), 500); |
| 197 |
}), 500); |
| 198 |
|
| 199 |
return d; |
| 200 |
} |
| 201 |
}, |
| 202 |
|
| 203 |
{ |
| 204 |
name: "spinner1_min", |
| 205 |
timeout: 15000, |
| 206 |
setUp:function(){ |
| 207 |
spin1.set('value', 1); |
| 208 |
}, |
| 209 |
runTest: function(){ |
| 210 |
// test min with arrow button |
| 211 |
var d=new doh.Deferred(); |
| 212 |
// press once: should move up |
| 213 |
doh.robot.mouseMoveAt(spin1.focusNode, 1, 0); // scroll both buttons into view |
| 214 |
doh.robot.mouseMoveAt(spin1.downArrowNode, 1, 0); |
| 215 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 216 |
doh.robot.mouseMoveAt('sv1_4', 1, 0); |
| 217 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 218 |
doh.robot.sequence(d.getTestErrback(function(){ |
| 219 |
doh.is(0, spin1.get('value')); |
| 220 |
doh.is("0", spin1.focusNode.value); |
| 221 |
doh.is("0", dojo.byId('oc1').value); |
| 222 |
doh.is(true, spin1.isValid()); |
| 223 |
// press again: can move since no min |
| 224 |
doh.robot.mouseMoveAt(spin1.downArrowNode, 1, 0); |
| 225 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 226 |
doh.robot.mouseMoveAt('sv1_4', 1, 0); |
| 227 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 228 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 229 |
doh.is(-1, spin1.get('value')); |
| 230 |
doh.is("-1", spin1.focusNode.value); |
| 231 |
doh.is("-1", dojo.byId('oc1').value); |
| 232 |
doh.is(true, spin1.isValid()); |
| 233 |
}), 500); |
| 234 |
}), 500); |
| 235 |
|
| 236 |
return d; |
| 237 |
} |
| 238 |
} |
| 239 |
]); |
| 240 |
|
| 241 |
doh.register("mouseWheel", [ |
| 242 |
{ |
| 243 |
name:"spinner1", |
| 244 |
timeout:5500, |
| 245 |
setUp:function(){ |
| 246 |
spin1.set('value', 900); |
| 247 |
}, |
| 248 |
runTest:function(){ |
| 249 |
// get the mouse's delta |
| 250 |
// note that Spinner spins backwards! |
| 251 |
delta=-doh.robot.mouseWheelSize; |
| 252 |
var d=new doh.Deferred(); |
| 253 |
doh.robot.mouseMoveAt(spin1.domNode, 1, 0); |
| 254 |
doh.robot.mouseClick({left:true}, 500); |
| 255 |
// wheel up 10 times |
| 256 |
// this should increase the value by 10 |
| 257 |
// takes 100ms/click |
| 258 |
doh.robot.mouseWheel(-10, 1000, 1000); |
| 259 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 260 |
var v=spin1.get('value'); |
| 261 |
doh.is(v, (900+10*delta), "spinner 1: wrong value, expected "+(900+10*delta)+", got "+v); |
| 262 |
}), 1000); |
| 263 |
return d; |
| 264 |
} |
| 265 |
}, |
| 266 |
|
| 267 |
{ |
| 268 |
name:"spinner2", |
| 269 |
timeout:5500, |
| 270 |
setUp:function(){ |
| 271 |
spin2.set('value', 1000); |
| 272 |
}, |
| 273 |
runTest:function(){ |
| 274 |
// test custom delta with mouse wheel |
| 275 |
// it should increment 10 per mouse wheel |
| 276 |
var d=new doh.Deferred(); |
| 277 |
doh.robot.mouseMoveAt(spin2.domNode, 1, 0); |
| 278 |
doh.robot.mouseClick({left:true}, 500); |
| 279 |
// wheel down 9 times |
| 280 |
// this should decrease the value by 90 |
| 281 |
// takes 100ms/click |
| 282 |
doh.robot.mouseWheel(9, 1000, 900); |
| 283 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 284 |
var v = spin2.get('value'); |
| 285 |
doh.is(v, (1000-90*delta), "spinner 2: wrong value, expected "+(1000-90*delta)+", got "+v); |
| 286 |
}), 1000); |
| 287 |
return d; |
| 288 |
} |
| 289 |
}, |
| 290 |
|
| 291 |
{ |
| 292 |
name:"spinner3", |
| 293 |
timeout:5500, |
| 294 |
setUp:function(){ |
| 295 |
spin3.set('value', 1.0); |
| 296 |
}, |
| 297 |
runTest:function(){ |
| 298 |
// test real number spinner with mouse wheel |
| 299 |
// it should increment 0.1 per mouse wheel |
| 300 |
var d=new doh.Deferred(); |
| 301 |
doh.robot.mouseMoveAt(spin3.domNode, 1, 0); |
| 302 |
doh.robot.mouseClick({left:true}, 500); |
| 303 |
// wheel up 10 |
| 304 |
// this should increase the value by 1.0 |
| 305 |
// takes 100ms/click |
| 306 |
doh.robot.mouseWheel(-10, 1000, 1000); |
| 307 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 308 |
var v = spin3.get('value'); |
| 309 |
doh.is(v, (1.0+delta), "spinner 3: wrong value, expected "+(1.0+delta)+", got "+v); |
| 310 |
}), 1000); |
| 311 |
return d; |
| 312 |
} |
| 313 |
}, |
| 314 |
|
| 315 |
{ |
| 316 |
name: "spinner3_max", |
| 317 |
timeout: 15000, |
| 318 |
setUp:function(){ |
| 319 |
spin3.set('value', 155-0.1*delta); |
| 320 |
}, |
| 321 |
runTest: function(){ |
| 322 |
// test max with arrow key |
| 323 |
var d=new doh.Deferred(); |
| 324 |
// press once: should move up |
| 325 |
doh.robot.mouseMoveAt(spin3.focusNode, 1, 0); |
| 326 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 327 |
// wheel up 1; this will increase the value by delta |
| 328 |
doh.robot.mouseWheel(-1, 500, 1); |
| 329 |
doh.robot.sequence(d.getTestErrback(function(){ |
| 330 |
doh.is(155.0, spin3.get('value')); |
| 331 |
doh.is("155.0", spin3.focusNode.value); |
| 332 |
doh.is(true, spin3.isValid()); |
| 333 |
// press again: shouldn't move |
| 334 |
doh.robot.mouseMoveAt(spin3.focusNode, 1, 0); |
| 335 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 336 |
// wheel up 1; this will increase the value by delta |
| 337 |
doh.robot.mouseWheel(-1, 500, 1); |
| 338 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 339 |
doh.is(155.0, spin3.get('value')); |
| 340 |
doh.is("155.0", spin3.focusNode.value); |
| 341 |
doh.is(true, spin3.isValid()); |
| 342 |
}), 500); |
| 343 |
}), 500); |
| 344 |
|
| 345 |
return d; |
| 346 |
} |
| 347 |
}, |
| 348 |
|
| 349 |
{ |
| 350 |
name: "spinner3_min", |
| 351 |
timeout: 15000, |
| 352 |
setUp:function(){ |
| 353 |
spin3.set('value', -10.9+0.1*delta); |
| 354 |
}, |
| 355 |
runTest: function(){ |
| 356 |
// test min with arrow key |
| 357 |
var d=new doh.Deferred(); |
| 358 |
// press once: should move up |
| 359 |
doh.robot.mouseMoveAt(spin3.focusNode, 1, 0); |
| 360 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 361 |
doh.robot.keyPress(dojo.keys.DOWN_ARROW, 500); |
| 362 |
doh.robot.mouseWheel(1, 500, 1); |
| 363 |
doh.robot.sequence(d.getTestErrback(function(){ |
| 364 |
doh.is(-10.9, spin3.get('value')); |
| 365 |
doh.is("-10.9", spin3.focusNode.value); |
| 366 |
doh.is(true, spin3.isValid()); |
| 367 |
// press again: shouldn't move |
| 368 |
doh.robot.mouseMoveAt(spin3.focusNode, 1, 0); |
| 369 |
doh.robot.mouseClick({left:true, middle:false, right:false}, 500); |
| 370 |
doh.robot.mouseWheel(1, 500, 1); |
| 371 |
doh.robot.sequence(d.getTestCallback(function(){ |
| 372 |
doh.is(-10.9, spin3.get('value')); |
| 373 |
doh.is("-10.9", spin3.focusNode.value); |
| 374 |
doh.is(true, spin3.isValid()); |
| 375 |
}), 500); |
| 376 |
}), 500); |
| 377 |
|
| 378 |
return d; |
| 379 |
} |
| 380 |
} |
| 381 |
]); |
| 382 |
|
| 383 |
doh.run(); |
| 384 |
}); |
| 385 |
</script> |
| 386 |
</head> |
| 387 |
</html> |