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 keypress event tests</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" |
---|
13 | djConfig="isDebug: true"></script> |
---|
14 | |
---|
15 | <script type="text/javascript"> |
---|
16 | dojo.require("dojo.robotx"); |
---|
17 | |
---|
18 | var navigation = [ |
---|
19 | "BACKSPACE", |
---|
20 | "TAB", |
---|
21 | "ENTER", |
---|
22 | "ESCAPE", |
---|
23 | "PAGE_UP", |
---|
24 | "PAGE_DOWN", |
---|
25 | "END", |
---|
26 | "HOME", |
---|
27 | "LEFT_ARROW", |
---|
28 | "UP_ARROW", |
---|
29 | "RIGHT_ARROW", |
---|
30 | "DOWN_ARROW" |
---|
31 | |
---|
32 | /* |
---|
33 | F1 to F10 are just too problematic to test; they have special meanings |
---|
34 | on the browsers. |
---|
35 | |
---|
36 | // "F1", // brings up help |
---|
37 | "F2", |
---|
38 | // "F3", // brings up search |
---|
39 | // "F4", // address bar access on IE, |
---|
40 | // "F5", // refreshes the page |
---|
41 | // "F6", // address bar access on IE |
---|
42 | // "F7", // affects "caret browsing" on FF |
---|
43 | "F8", |
---|
44 | "F9", |
---|
45 | // "F10", // access File menu on IE |
---|
46 | // "F11", // full screen mode |
---|
47 | // "F12" // opens firebug console |
---|
48 | */ |
---|
49 | ]; |
---|
50 | |
---|
51 | // Test a few normal keystrokes, but be careful about testing things |
---|
52 | // that are entered using the SHIFT key as that produces two onkeypress |
---|
53 | // events on IE (one for the SHIFT key and one for the character) |
---|
54 | var printables = [" ", "n", "7"]; |
---|
55 | |
---|
56 | dojo.addOnLoad(function(){ |
---|
57 | doh.robot.initRobot('eventKeyPress.html'); |
---|
58 | |
---|
59 | var typer, // <input> that will receive keyboard events |
---|
60 | events; // array of events on typer, populated by dojo.connect() in eventKeyPress.html |
---|
61 | |
---|
62 | doh.register("setup", function(){ |
---|
63 | typer = dojo.byId("typer"); |
---|
64 | }); |
---|
65 | |
---|
66 | doh.register("navigation keys", dojo.map(navigation, function(code){ |
---|
67 | return { |
---|
68 | name: code, |
---|
69 | timeout: 1000, |
---|
70 | runTest: function(){ |
---|
71 | var d = new doh.Deferred(); |
---|
72 | |
---|
73 | events = dojo.global.events = []; |
---|
74 | typer.focus(); |
---|
75 | |
---|
76 | // Send the keystroke |
---|
77 | doh.robot.keyPress(dojo.keys[code], 50, {}); |
---|
78 | |
---|
79 | doh.robot.sequence(d.getTestCallback(function(){ |
---|
80 | doh.is(1, events.length, "got (exactly) one onkeypress event"); |
---|
81 | doh.is(dojo.keys[code], events[0].charOrCode, "correct keycode"); |
---|
82 | }), 250); |
---|
83 | |
---|
84 | return d; |
---|
85 | } |
---|
86 | }; |
---|
87 | })); |
---|
88 | |
---|
89 | doh.register("normal keys", dojo.map(printables, function(c){ |
---|
90 | return { |
---|
91 | name: "'" + c + "'", |
---|
92 | timeout: 1000, |
---|
93 | runTest: function(){ |
---|
94 | var d = new doh.Deferred(); |
---|
95 | |
---|
96 | events = dojo.global.events = []; |
---|
97 | typer.focus(); |
---|
98 | |
---|
99 | // Send the keystroke |
---|
100 | doh.robot.keyPress(c, 50, {}); |
---|
101 | |
---|
102 | doh.robot.sequence(d.getTestCallback(function(){ |
---|
103 | doh.is(1, events.length, "got (exactly) one onkeypress event"); |
---|
104 | doh.is(c, events[0].charOrCode, "correct char"); |
---|
105 | }), 250); |
---|
106 | |
---|
107 | return d; |
---|
108 | } |
---|
109 | }; |
---|
110 | })); |
---|
111 | |
---|
112 | /* |
---|
113 | TODO: test ctrl-key combinations if/when #9511 is fixed. |
---|
114 | 106:42, |
---|
115 | 111:47, |
---|
116 | 186:59, |
---|
117 | 187:43, |
---|
118 | 188:44, |
---|
119 | 189:45, |
---|
120 | 190:46, |
---|
121 | 191:47, |
---|
122 | 192:96, |
---|
123 | 219:91, |
---|
124 | 220:92, |
---|
125 | 221:93, |
---|
126 | 222:39 |
---|
127 | */ |
---|
128 | |
---|
129 | // Ctrl-alphabetic tests. |
---|
130 | // Skip ctrl-o and ctrl-p which cause open and print dialogs on IE, even with the dojo.stopEvent() |
---|
131 | doh.register("ctrl-alphabetic", dojo.map("abcdefghijklmnqrstuvwxyz", function(c){ |
---|
132 | return { |
---|
133 | name: "ctrl-" + c, |
---|
134 | timeout: 1000, |
---|
135 | runTest: function(){ |
---|
136 | var d = new doh.Deferred(); |
---|
137 | |
---|
138 | typer.focus(); |
---|
139 | |
---|
140 | events = dojo.global.events = []; |
---|
141 | |
---|
142 | // Send the keystroke |
---|
143 | doh.robot.keyPress(c, 50, {ctrl: true}); |
---|
144 | |
---|
145 | doh.robot.sequence(d.getTestCallback(function(){ |
---|
146 | console.log("event is: ", events[0]); |
---|
147 | doh.is(1, events.length, "got (exactly) one onkeypress event"); |
---|
148 | doh.is(c, events[0].charOrCode, "correct char"); |
---|
149 | doh.t(events[0].ctrlKey, "control key was pressed"); |
---|
150 | }), 250); |
---|
151 | |
---|
152 | return d; |
---|
153 | } |
---|
154 | }; |
---|
155 | })); |
---|
156 | |
---|
157 | /* TODO: test preventDefault() of up/down arrows */ |
---|
158 | |
---|
159 | /* TODO: ctrl-break, ctrl-enter */ |
---|
160 | |
---|
161 | /* TODO: Test preventDefault() (in eventKeyPress.html) stopping down arrow on <button> from scrolling page. */ |
---|
162 | |
---|
163 | doh.run(); |
---|
164 | }); |
---|
165 | </script> |
---|
166 | </head> |
---|
167 | </html> |
---|