can
Version:
MIT-licensed, client-side, JavaScript framework that makes building rich web applications easy.
168 lines (136 loc) • 4.24 kB
HTML
<html>
<head>
<title>doh.robot keypress event tests</title>
<style>
@import "../../../util/doh/robot/robot.css";
</style>
<!-- required: dojo.js -->
<script type="text/javascript" src="../../../dojo/dojo.js"
djConfig="isDebug: true"></script>
<script type="text/javascript">
dojo.require("dojo.robotx");
var navigation = [
"BACKSPACE",
"TAB",
"ENTER",
"ESCAPE",
"PAGE_UP",
"PAGE_DOWN",
"END",
"HOME",
"LEFT_ARROW",
"UP_ARROW",
"RIGHT_ARROW",
"DOWN_ARROW"
/*
F1 to F10 are just too problematic to test; they have special meanings
on the browsers.
// "F1", // brings up help
"F2",
// "F3", // brings up search
// "F4", // address bar access on IE,
// "F5", // refreshes the page
// "F6", // address bar access on IE
// "F7", // affects "caret browsing" on FF
"F8",
"F9",
// "F10", // access File menu on IE
// "F11", // full screen mode
// "F12" // opens firebug console
*/
];
// Test a few normal keystrokes, but be careful about testing things
// that are entered using the SHIFT key as that produces two onkeypress
// events on IE (one for the SHIFT key and one for the character)
var printables = [" ", "n", "7"];
dojo.addOnLoad(function(){
doh.robot.initRobot('eventKeyPress.html');
var typer, // <input> that will receive keyboard events
events; // array of events on typer, populated by dojo.connect() in eventKeyPress.html
doh.register("setup", function(){
typer = dojo.byId("typer");
});
doh.register("navigation keys", dojo.map(navigation, function(code){
return {
name: code,
timeout: 1000,
runTest: function(){
var d = new doh.Deferred();
events = dojo.global.events = [];
typer.focus();
// Send the keystroke
doh.robot.keyPress(dojo.keys[code], 50, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is(1, events.length, "got (exactly) one onkeypress event");
doh.is(dojo.keys[code], events[0].charOrCode, "correct keycode");
}), 250);
return d;
}
};
}));
doh.register("normal keys", dojo.map(printables, function(c){
return {
name: "'" + c + "'",
timeout: 1000,
runTest: function(){
var d = new doh.Deferred();
events = dojo.global.events = [];
typer.focus();
// Send the keystroke
doh.robot.keyPress(c, 50, {});
doh.robot.sequence(d.getTestCallback(function(){
doh.is(1, events.length, "got (exactly) one onkeypress event");
doh.is(c, events[0].charOrCode, "correct char");
}), 250);
return d;
}
};
}));
/*
TODO: test ctrl-key combinations if/when #9511 is fixed.
106:42,
111:47,
186:59,
187:43,
188:44,
189:45,
190:46,
191:47,
192:96,
219:91,
220:92,
221:93,
222:39
*/
// Ctrl-alphabetic tests.
// Skip ctrl-o and ctrl-p which cause open and print dialogs on IE, even with the dojo.stopEvent()
doh.register("ctrl-alphabetic", dojo.map("abcdefghijklmnqrstuvwxyz", function(c){
return {
name: "ctrl-" + c,
timeout: 1000,
runTest: function(){
var d = new doh.Deferred();
typer.focus();
events = dojo.global.events = [];
// Send the keystroke
doh.robot.keyPress(c, 50, {ctrl: true});
doh.robot.sequence(d.getTestCallback(function(){
console.log("event is: ", events[0]);
doh.is(1, events.length, "got (exactly) one onkeypress event");
doh.is(c, events[0].charOrCode, "correct char");
doh.t(events[0].ctrlKey, "control key was pressed");
}), 250);
return d;
}
};
}));
/* TODO: test preventDefault() of up/down arrows */
/* TODO: ctrl-break, ctrl-enter */
/* TODO: Test preventDefault() (in eventKeyPress.html) stopping down arrow on <button> from scrolling page. */
doh.run();
});
</script>
</head>
</html>