Debian Codegraph @

dijit/tests/editor/robot/Editor_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 Editor A11Y Test</title>
6
7 <style>
8 @import "../../../../util/doh/robot/robot.css";
9 </style>
10
11 <script type="text/javascript" src="../../../../dojo/dojo.js"></script>
12
13 <script type="text/javascript">
14 require([
15 "doh/runner", "dojo/robotx",
16 "dojo/_base/array", "dojo/dom", "dojo/keys", "dojo/_base/lang", "dojo/sniff", "dojo/window",
17 "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, array, dom, keys, lang, has, winUtils, helpers){
19
20 function normalize(str){
21 // try to do some normalization to make all browsers look
22 // the same. Would be nice if we didn't need this, the normalization should
23 // probably happen as pre and post filters on the editor
24 return str.
25 replace(' />', '/>').
26 replace('<br/>', ''). // FF. Because of EnterKeyHandling plugin?
27 replace(/^<p>/, '').replace(/<\/p>$/, ''). // Safari. Because of EnterKeyHandling plugin?
28 replace(new RegExp(String.fromCharCode(160), "g"), " "); // Safari: nbsp (char code 160) to normal space (char code 32)
29 }
30
31 robot.initRobot('../test_Editor.html');
32
33 // For some reason the meta key (meta-a for selection, meta-b for bold, etc) doesn't work
34 // on mac/safari... use ctrl- instead, just like on windows. (#9553)
35 var metaKey = {ctrl: true};
36
37 var editor0,
38 editor1, editor1oldValue, editor1newValue, editor1onChange = "no onchange event yet";
39
40 var registry, focus;
41 doh.register("setup", [
42 {
43 name: "wait for editors to load",
44 timeout: 5000,
45 runTest: helpers.waitForLoad
46 },
47 function setVars(){
48 registry = robot.window.require("dijit/registry");
49 focus = robot.window.require("dijit/focus");
50 editor0 = registry.byId("editor0");
51 editor1 = registry.byId("editor1");
52 editor1.watch("value", function(attr, oldVal, newVal){
53 editor1oldValue = normalize(oldVal);
54 editor1newValue = normalize(newVal);
55 });
56 editor1.onChange = function(newValue){
57 editor1onChange = normalize(newValue);
58 };
59 }
60 ]);
61
62 doh.register("keyboard shortcuts", [
63 {
64 name: "bold/italic",
65 timeout: 15000,
66 runTest: function(){
67 var d = new doh.Deferred();
68
69 winUtils.scrollIntoView(editor1.domNode);
70
71 // Set contents of editor1
72 robot.sequence(d.getTestErrback(function(){
73 editor1.focus();
74 }), 500);
75 robot.keyPress("a", 500, metaKey); // select all
76 robot.typeKeys("hello ", 500, 750); // and erase (by typing something new)
77 robot.keyPress("b", 500, metaKey); // start bold
78 robot.typeKeys("bold", 500, 600);
79 robot.keyPress("b", 500, metaKey); // stop bold
80 robot.typeKeys(" and ", 500, 750);
81 robot.keyPress("i", 500, metaKey); // start italic
82 robot.typeKeys("exciting", 500, 1200);
83 robot.keyPress("i", 500, metaKey); // stop italic
84 robot.typeKeys(" new world.", 500, 1650);
85
86 robot.sequence(d.getTestCallback(function(){
87 var val = normalize(editor1.get('value'));
88 doh.is("hello <b>bold</b> and <i>exciting</i> new world.", val);
89 }), 500);
90
91 return d;
92 }
93 }
94 ]);
95
96 // Check that toolbar buttons are depressed/not depressed (etc.) based on
97 // where caret is in document
98 doh.register("toolbar state", [
99 {
100 name: "setup",
101 timeout: 10000,
102 runTest: function(){
103 var d = new doh.Deferred();
104
105 winUtils.scrollIntoView(editor1.domNode);
106
107 // strange things happen if you alter an editor's value while it is focused,
108 // so temporarily move to the toolbar while setting content
109 robot.keyPress(keys.TAB, 500, {shift: true}); // go to toolbar
110 robot.sequence(d.getTestErrback(function(){
111 editor1.set("value", "toolbar <b>state</b> <i>test</i>.");
112
113 // set() should fire watch() callbacks but not call onChange()
114 doh.is("toolbar <b>state</b> <i>test</i>.", editor1newValue, "value set successfully");
115 doh.is("no onchange event yet", editor1onChange, "onChange not called");
116 }), 500);
117 robot.keyPress(keys.TAB, 500); // goes to content
118 robot.keyPress(keys.HOME, 500, {}); // go to start of content
119 robot.sequence(d.getTestCallback(function(){
120 // just to signal that we are done
121 }));
122
123 return d;
124 }
125 },
126 {
127 name: "no buttons depressed",
128 timeout: 10000,
129 runTest: function(){
130 var d = new doh.Deferred();
131
132 robot.sequence(d.getTestCallback(function(){
133 var toolbar = editor1.toolbar;
134 doh.t(toolbar, "found toolbar");
135
136 var boldButton = toolbar.getChildren()[7];
137 doh.t(boldButton, "found bold button");
138 doh.f(boldButton.get("checked"), "bold button not depressed");
139
140 var italicButton = toolbar.getChildren()[8];
141 doh.t(italicButton, "found italic button");
142 doh.f(italicButton.get("checked"), "italic button not depressed");
143 }), 500);
144
145 return d;
146 }
147 },
148 {
149 name: "bold button depressed",
150 timeout: 10000,
151 runTest: function(){
152 var d = new doh.Deferred();
153 robot.sequence(d.getTestErrback(function(){
154 editor1.placeCursorAtStart();
155 }), 500);
156 for(var i = 0; i < 9; i++){
157 // Move to second letter of second word.
158 robot.keyPress(keys.RIGHT_ARROW, 500);
159 }
160 robot.sequence(d.getTestCallback(function(){
161 var toolbar = editor1.toolbar;
162 doh.t(toolbar, "found toolbar");
163
164 var boldButton = toolbar.getChildren()[7];
165 doh.t(boldButton, "found bold button");
166 doh.t(boldButton.get("checked"), "bold button depressed");
167
168 var italicButton = toolbar.getChildren()[8];
169 doh.t(italicButton, "found italic button");
170 doh.f(italicButton.get("checked"), "italic button not depressed");
171 }), 1000);
172
173 return d;
174 }
175 },
176 {
177 name: "italic button depressed",
178 timeout: 10000,
179 runTest: function(){
180 var d = new doh.Deferred();
181
182 robot.sequence(d.getTestErrback(function(){
183 editor1.placeCursorAtStart();
184 }), 500);
185 for(var i = 0; i < 15; i++){
186 // Move to second letter of third word.
187 robot.keyPress(keys.RIGHT_ARROW, 500);
188 }
189 robot.sequence(d.getTestCallback(function(){
190 var toolbar = editor1.toolbar;
191 doh.t(toolbar, "found toolbar");
192
193 var boldButton = toolbar.getChildren()[7];
194 doh.t(boldButton, "found bold button");
195 doh.f(boldButton.get("checked"), "bold button not depressed");
196
197 var italicButton = toolbar.getChildren()[8];
198 doh.t(italicButton, "found italic button");
199 doh.t(italicButton.get("checked"), "italic button depressed");
200 }), 1000);
201
202 return d;
203 }
204 }
205 ]);
206
207 doh.register("toolbar navigation", [
208 {
209 name: "bold",
210 timeout: 15000,
211 runTest: function(){
212 var d = new doh.Deferred();
213
214 winUtils.scrollIntoView(editor1.domNode);
215
216 // Write "hello" in editor and also make sure there's something in the system
217 // clipboard, so that the paste button in the toolbar is guaranteed to be enabled.
218 // (otherwise the two RIGHT_ARROW commands below will overshoot the bold button
219 // and end up on the italic button)
220 robot.sequence(d.getTestErrback(function(){
221 editor1.focus();
222 }), 500);
223 robot.keyPress("a", 1000, metaKey); // select all
224 robot.keyPress("c", 500, has("mac") ? {meta: true} : {ctrl: true}); // copy into clipboard
225 robot.typeKeys("hello ", 500, 900); // and erase (by typing something new)
226
227 // Go to toolbar and turn on bold.
228 // We only have to right-arrow twice because it skips the vertical divider bars
229 // and also skips cut and copy (they are disabled b/c nothing is selected)
230 robot.keyPress(keys.TAB, 500, {shift: true});
231 robot.keyPress(keys.RIGHT_ARROW, 1000);
232 robot.keyPress(keys.RIGHT_ARROW, 500);
233 robot.keyPress(keys.SPACE, 500);
234
235 // Focus and caret should be back after "hello ", type "world" in bold
236 robot.typeKeys("world", 1000, 750);
237
238 robot.sequence(d.getTestCallback(function(){
239 // Get the value and try to do some normalization to make all browsers look
240 // the same. Would be nice if we didn't need this, the normalization should
241 // probably happen as pre and post filters on the editor
242 var val = normalize(editor1.get('value'));
243 doh.is("hello <b>world</b>", val);
244 }), 1500);
245
246 return d;
247 }
248 }
249 ]);
250
251 doh.register("tabbing", [
252 {
253 name: "into editor1 toolbar",
254 timeout: 10000,
255 runTest: function(){
256 var d = new doh.Deferred();
257
258 winUtils.scrollIntoView(editor1.domNode);
259
260 // Focus on link before editor
261 robot.sequence(d.getTestErrback(function(){
262 dom.byId("focusBefore", robot.doc).focus();
263 }), 500);
264
265 // Go to toolbar of editor1
266 robot.keyPress(keys.TAB, 500);
267
268 // We should get focus on one of the toolbar buttons, although which one depends
269 // on whether the editor's contents have been modified (undo button enabled), and
270 // whether there is something in the browser's paste buffer, etc.)
271 robot.sequence(d.getTestCallback(function(){
272 var curFocus = registry.getEnclosingWidget(focus.curNode);
273 doh.isNot(-1, array.indexOf(editor1.toolbar.getChildren(), curFocus), "focused on button of editor1 toolbar");
274 }), 500);
275
276 return d;
277 }
278 },
279 {
280 name: "into editor1",
281 timeout: 10000,
282 runTest: function(){
283 var d = new doh.Deferred();
284
285 // Go to content of editor1
286 robot.keyPress(keys.TAB, 500);
287
288 robot.sequence(d.getTestErrback(function(){
289 doh.is("editor1_iframe", focus.curNode.id, "focused on editor content");
290 }), 500);
291
292 robot.keyPress("a", 500, metaKey); // select all
293 robot.typeKeys("tabbing test", 500, 1800); // and replace with "tabbing test"
294
295 robot.sequence(d.getTestCallback(function(){
296 // just here to make deferred fire
297 }), 500);
298
299 return d;
300 }
301 },
302 {
303 name: "out of editor1",
304 timeout: 10000,
305 runTest: function(){
306 var d = new doh.Deferred();
307
308 // Go to link after editor1
309 robot.keyPress(keys.TAB, 500);
310
311 robot.sequence(d.getTestCallback(function(){
312 doh.is("focusAfter", focus.curNode.id, "focused after editor1");
313
314 doh.is("tabbing test", editor1newValue, "watch()");
315 doh.is("tabbing test", editor1onChange, "onChange");
316 }), 500);
317
318 return d;
319 }
320 },
321 {
322 name: "shift-tab back into editor1",
323 timeout: 10000,
324 runTest: function(){
325 var d = new doh.Deferred();
326
327 // Go to content of editor1
328 robot.keyPress(keys.TAB, 500, {shift: true});
329
330 robot.sequence(d.getTestCallback(function(){
331 doh.is("editor1_iframe", focus.curNode.id, "focused on editor content");
332 }), 500);
333
334 return d;
335 }
336 },
337 {
338 name: "shift-tab back to toolbar",
339 timeout: 10000,
340 runTest: function(){
341 var d = new doh.Deferred();
342
343 robot.keyPress(keys.TAB, 500, {shift: true});
344
345 robot.sequence(d.getTestCallback(function(){
346 var curFocus = registry.getEnclosingWidget(focus.curNode);
347 doh.isNot(-1, array.indexOf(editor1.toolbar.getChildren(), curFocus), "focused on button of editor1 toolbar");
348 }), 500);
349
350 return d;
351 }
352 },
353 {
354 name: "shift-tab to before editor",
355 timeout: 10000,
356 runTest: function(){
357 var d = new doh.Deferred();
358
359 robot.keyPress(keys.TAB, 500, {shift: true});
360
361 robot.sequence(d.getTestCallback(function(){
362 doh.is("focusBefore", focus.curNode.id, "focused before editor1");
363 }), 500);
364
365 return d;
366 }
367 }
368 ]);
369
370 doh.register("clear then focus", {
371 name: "#10268",
372 timeout: 10000,
373 runTest: function(){
374 var d = new doh.Deferred();
375
376 dom.byId("focusBefore", robot.doc).focus();
377 winUtils.scrollIntoView(editor1.domNode);
378 editor1.set("value", "");
379 editor1.focus();
380
381 robot.typeKeys("hello ", 500, 750);
382
383 robot.sequence(d.getTestCallback(function(){
384 doh.is("hello", lang.trim(editor1.get("value")), "get('value')");
385 }), 500);
386
387 return d;
388 }
389 });
390
391 doh.run();
392 });
393
394
395 </script>
396 </head>
397 </html>