eventKeyPressRobot.html
4.14 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<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>