Debian Codegraph @

dijit/tests/editor/robot/EnterKeyHandling.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/EnterKeyHandling Plugin 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/dom", "dojo/keys", "dojo/_base/lang", "dojo/sniff", "dojo/window",
17 "dijit/_editor/range", "dijit/tests/helpers", "dojo/domReady!"
18 ], function(doh, robot, dom, keys, lang, has, winUtils, range, helpers){
19
20 function dom2string(root){
21 // summary:
22 // Simple dump of the HTML inside an editor, skipping
23 // attributes altogether. Similar to `dijit._editor.getNodeHtml`
24 // (maybe want to switch to using that).
25 var out = [];
26
27 function recurse(children){
28 var i=0, node = children[i++];
29 while(node){
30 switch(node.nodeType){
31 case 1: // normal node
32 if(node.childNodes.length){
33 out.push("<" + node.tagName.toLowerCase() + ">");
34 recurse(node.childNodes);
35 out.push("</" + node.tagName.toLowerCase() + ">");
36 }else{
37 out.push("<" + node.tagName.toLowerCase() + "/>");
38 }
39 break;
40 case 3: // text
41 var text = lang.trim(node.textContent || node.data).
42 replace('\u00a0', "&nbsp;");
43 if(text){
44 out.push(text);
45 }
46 break;
47 }
48 node = children[i++];
49 }
50 }
51
52 recurse(root.childNodes);
53 return out.join("");
54 }
55
56 robot.initRobot('../EnterKeyHandling.html');
57
58 var metaKey = has("mac")? {meta: true} : {ctrl: true};
59
60 var registry;
61 doh.register("setup", [
62 {
63 name: "wait for editors to load",
64 timeout: 5000,
65 runTest: helpers.waitForLoad
66 },
67 function setVars(){
68 registry = robot.window.require("dijit/registry");
69 }
70 ]);
71
72 // Tests for BR mode
73 doh.register("blockNodeForEnter=BR", [
74 {
75 name: "wait for editors to load",
76 timeout: 5000,
77 runTest: function(){
78 return helpers.waitForLoad
79 }
80 },
81 {
82 name: "type in some text",
83 timeout: 10000,
84 runTest: function(){
85 var d = new doh.Deferred();
86
87 var br = registry.byId("br");
88 br.set("value", "");
89 br.focus();
90
91 robot.mouseMoveAt(br.iframe, 500);
92 robot.mouseClick({left:true}, 500);
93 robot.keyPress(keys.BACKSPACE, 500, {});
94
95 // tab to the MenuBar... then focus should automatically shift to "File" menu,
96 for(var i=0; i<4; i++){
97 robot.typeKeys("ab345", 500);
98 robot.keyPress(keys.ENTER, 500, {});
99 }
100
101 robot.sequence(d.getTestCallback(function(){
102 // get('value') should call the post-filter which recombines the separate <p> nodes into bigger
103 // paragraphs.
104 var value = br.get('value');
105 value = value.replace(/&nbsp;/g, "");
106 value = value.replace(/ /g, "");
107 value = value.replace(/\xA0/g, "");
108 doh.is('ab345<br/>ab345<br/>ab345<br/>ab345',
109 value,
110 "get('value')");
111 }), 1000);
112
113 return d;
114 }
115 },
116 {
117 name: "copy and paste",
118 timeout: 10000,
119 runTest: function(){
120 var d = new doh.Deferred();
121
122 var br = registry.byId("br");
123 br.set("value", "");
124 br.focus();
125
126 robot.mouseMoveAt(br.iframe, 500);
127 robot.mouseClick({left:true}, 500);
128 robot.keyPress(keys.BACKSPACE, 500, {});
129
130 robot.typeKeys("testingCopyAndPaste", 500);
131 robot.keyPress("a", 500, metaKey); // select all
132 robot.keyPress("c", 500, metaKey); // copy
133 robot.keyPress("v", 500, metaKey); // paste
134 robot.keyPress("v", 500, metaKey); // paste
135 robot.keyPress("v", 500, metaKey); // paste
136 robot.keyPress(keys.ENTER, 500, {shift: false});
137 robot.sequence(d.getTestCallback(function(){
138 // get('value') should call the post-filter which recombines the separate <p> nodes into bigger
139 // paragraphs.
140 var value = br.get('value');
141 value = value.replace(/ /g, "");
142 value = value.replace(/\xA0/g, "");
143 if(has("webkit") && !has("mac")){
144 // Work around webkit bug:
145 // http://code.google.com/p/chromium/issues/detail?id=106551
146 // Should hopefully be fixed in Chrome 19.
147 value = value.replace(/\n/g, "");
148 value = value.replace(/\r\f/g, "");
149 }
150
151 doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste',
152 value,
153 "get('value')");
154 }), 1000);
155 return d;
156 }
157 },
158 {
159 name: "copy and paste split",
160 timeout: 10000,
161 runTest: function(){
162 var d = new doh.Deferred();
163
164 var br = registry.byId("br");
165 br.set("value", "");
166 br.focus();
167
168 robot.mouseMoveAt(br.iframe, 500);
169 robot.mouseClick({left:true}, 500);
170 robot.keyPress(keys.BACKSPACE, 500, {});
171
172 robot.typeKeys("testingCopyAndPaste", 500);
173 robot.keyPress("a", 500, metaKey); // select all
174 robot.keyPress("c", 500, metaKey); // copy
175 robot.keyPress("v", 500, metaKey); // paste
176 robot.keyPress("v", 500, metaKey); // paste
177 robot.keyPress("v", 500, metaKey); // paste
178 robot.keyPress(keys.LEFT_ARROW, 500, {});
179 robot.keyPress(keys.LEFT_ARROW, 500, {});
180 robot.keyPress(keys.LEFT_ARROW, 500, {});
181 robot.keyPress(keys.LEFT_ARROW, 500, {});
182 robot.keyPress(keys.ENTER, 500, {});
183 robot.sequence(d.getTestCallback(function(){
184 // get('value') should call the post-filter which recombines the separate <p> nodes into bigger
185 // paragraphs.
186 var value = br.get('value');
187 value = value.replace(/ /g, "");
188 if(has("webkit") && !has("mac")){
189 // Work around webkit bug:
190 // http://code.google.com/p/chromium/issues/detail?id=106551
191 // Should hopefully be fixed in Chrome 19.
192 value = value.replace(/\n/g, "");
193 value = value.replace(/\r\f/g, "");
194 }
195
196
197 // Safari may end with a trailing/extra br, so we need to remove it.
198 if(/aste<br\/>$/.test(value)){
199 value = value.substring(0, value.length - 5);
200 }
201 doh.is('testingCopyAndPastetestingCopyAndPastetestingCopyAndP<br/>aste',
202 value,
203 "get('value')");
204 }), 1000);
205 return d;
206 }
207 }
208 ]);
209
210 doh.register("Split tests", [
211 {
212 name: "Test div line split",
213 timeout: 10000,
214 runTest: function(){
215 var d = new doh.Deferred();
216 // The initial input was a div with a line of text with a bold tag in the middle.
217 // we want to focus on the bold and enter there, splitting it.
218 var editor = registry.byId("div2");
219 winUtils.scrollIntoView(editor.iframe);
220 var node = dom.byId("boldLine0", editor.document);
221
222 robot.mouseMoveAt(editor.iframe, 500);
223 robot.mouseClick({left:true}, 500);
224
225 robot.sequence(d.getTestErrback(function(){
226 editor.selection.selectElementChildren(node);
227 }), 500);
228
229 // Keyboard kill the selection and shift position between I and S.
230 if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
231 robot.keyPress(keys.LEFT_ARROW, 100, {});
232 robot.keyPress(keys.ENTER, 500);
233
234 robot.sequence(d.getTestCallback(function(){
235 // Do tests here.
236 var val = editor.get("value");
237 // Check that it split the is into two and that the bold and div were properly split.
238 doh.t(val.indexOf("It <b id=\"boldLine0\">I</b></div>") > 0, "start");
239 doh.t(val.indexOf("<div><b>S</b>") > 0, "end");
240 }), 500);
241
242 return d;
243 }
244
245 },
246 {
247 name: "Test div line split style clone",
248 timeout: 10000,
249 runTest: function(){
250 var d = new doh.Deferred();
251 // The initial input was a div with a line of text with a bold tag in the middle.
252 // we want to focus on the bold and enter there, splitting it.
253 var editor = registry.byId("div3");
254 winUtils.scrollIntoView(editor.iframe);
255 var node = dom.byId("boldLine1", editor.document);
256
257 robot.mouseMoveAt(editor.iframe, 500);
258 robot.mouseClick({left:true}, 500);
259
260 robot.sequence(d.getTestErrback(function(){
261 editor.selection.selectElementChildren(node);
262 }), 500);
263
264 // Keyboard kill the selection and shift position between I and S.
265 if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
266 robot.keyPress(keys.LEFT_ARROW, 100, {});
267 robot.keyPress(keys.ENTER, 500);
268
269 robot.sequence(d.getTestCallback(function(){
270 // Do tests here.
271 var val = editor.get("value");
272 // Check that it split the is into two and that the bold and div were properly split.
273 val = val.toLowerCase();
274 doh.t(/it <b\s+id="boldline1"\s+style\s*=\s*"\s*font-size:\s*4em;?\s*">i<\/b><\/div>/.test(val), "start");
275 doh.t(/<div><b\s+style\s*=\s*"\s*font-size:\s*4em;?\s*">s<\/b>/.test(val), "end");
276 }), 500);
277
278 return d;
279 }
280 },
281 {
282 name: "Test div line split font clone",
283 timeout: 10000,
284 runTest: function(){
285 var d = new doh.Deferred();
286 // The initial input was a div with a line of text with a font tag in the middle.
287 // we want to focus on the font and enter there, splitting it.
288 var editor = registry.byId("div4");
289 winUtils.scrollIntoView(editor.iframe);
290 var node = dom.byId("fontLine1", editor.document);
291
292 robot.mouseMoveAt(editor.iframe, 500);
293 robot.mouseClick({left:true}, 500);
294
295 robot.sequence(d.getTestErrback(function(){
296 editor.selection.selectElementChildren(node);
297 }), 500);
298
299 // Keyboard kill the selection and shift position between I and S.
300 if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
301 robot.keyPress(keys.LEFT_ARROW, 100, {});
302 robot.keyPress(keys.ENTER, 500);
303
304 robot.sequence(d.getTestCallback(function(){
305 // Do tests here.
306 var val = editor.get("value");
307 // Check that it split the is into two and that the bold and div were properly split.
308 val = val.toLowerCase();
309 doh.t(/it <font\s+id="fontline1"\s+size\s*=\s*"\s*5?\s*">i<\/font><\/div>/.test(val),"font not set on first line");
310 doh.t(/<div><font\s+size\s*=\s*"\s*5?\s*">s<\/font>/.test(val),"font not set on split line");
311 }), 500);
312
313 return d;
314 }
315 },
316 {
317 name: "copy and paste DIV",
318 timeout: 10000,
319 runTest: function(){
320 var d = new doh.Deferred();
321
322 var editor = registry.byId("div3");
323 winUtils.scrollIntoView(editor.iframe);
324 editor.set("value", "");
325 editor.focus();
326
327 robot.mouseMoveAt(editor.iframe, 500);
328 robot.mouseClick({left:true}, 500);
329 robot.keyPress(keys.BACKSPACE, 500, {});
330
331 robot.typeKeys("testingCopyAndPaste", 500);
332 robot.keyPress("a", 500, metaKey); // select all
333 robot.keyPress("c", 500, metaKey); // copy
334 robot.keyPress("v", 500, metaKey); // paste
335 robot.keyPress("v", 500, metaKey); // paste
336 robot.keyPress("v", 500, metaKey); // paste
337 robot.keyPress(keys.ENTER, 500, {});
338 robot.sequence(d.getTestCallback(function(){
339 var value = editor.get('value');
340 value = value.replace(/\xA0/g, "");
341 if(has("webkit") && !has("mac")){
342 // Work around webkit bug:
343 // http://code.google.com/p/chromium/issues/detail?id=106551
344 // Should hopefully be fixed in Chrome 19.
345 value = value.replace(/\n/g, "");
346 value = value.replace(/\r\f/g, "");
347 }
348 doh.is('<div>testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste</div>',
349 value,
350 "get('value')");
351 }), 1000);
352 return d;
353 }
354 },
355 {
356 name: "copy and paste DIV split",
357 timeout: 10000,
358 runTest: function(){
359 var d = new doh.Deferred();
360
361 var editor = registry.byId("div3");
362 winUtils.scrollIntoView(editor.iframe);
363 editor.set("value", "");
364 editor.focus();
365
366 robot.mouseMoveAt(editor.iframe, 500);
367 robot.mouseClick({left:true}, 500);
368 robot.keyPress(keys.BACKSPACE, 500, {});
369
370 robot.typeKeys("testingCopyAndPaste", 500);
371 robot.keyPress("a", 500, metaKey); // select all
372 robot.keyPress("c", 500, metaKey); // copy
373 robot.keyPress("v", 500, metaKey); // paste
374 robot.keyPress("v", 500, metaKey); // paste
375 robot.keyPress("v", 500, metaKey); // paste
376 robot.keyPress(keys.LEFT_ARROW, 500, {});
377 robot.keyPress(keys.LEFT_ARROW, 500, {});
378 robot.keyPress(keys.LEFT_ARROW, 500, {});
379 robot.keyPress(keys.LEFT_ARROW, 500, {});
380 robot.keyPress(keys.ENTER, 500, {});
381 robot.sequence(d.getTestCallback(function(){
382 // get('value') should call the post-filter which recombines the separate <p> nodes into bigger
383 // paragraphs.
384 var value = editor.get('value');
385 value = value.replace(/\xA0/g, "");
386 if(has("webkit") && !has("mac")){
387 // Work around webkit bug:
388 // http://code.google.com/p/chromium/issues/detail?id=106551
389 // Should hopefully be fixed in Chrome 19.
390 value = value.replace(/\n/g, "");
391 value = value.replace(/\r\f/g, "");
392 }
393
394
395 doh.is('<div>testingCopyAndPastetestingCopyAndPastetestingCopyAndP</div><div>aste</div>',
396 value,
397 "get('value')");
398 }), 1000);
399 return d;
400 }
401 },
402 {
403 name: "Test p line split",
404 timeout: 10000,
405 runTest: function(){
406 var d = new doh.Deferred();
407 // The initial input was a div with a line of text with a bold tag in the middle.
408 // we want to focus on the bold and enter there, splitting it.
409 var editor = registry.byId("p2");
410 winUtils.scrollIntoView(editor.iframe);
411 var node = dom.byId("boldLine2", editor.document);
412
413 robot.mouseMoveAt(editor.iframe, 500);
414 robot.mouseClick({left:true}, 500);
415
416 robot.sequence(d.getTestErrback(function(){
417 editor.selection.selectElementChildren(node);
418 }), 500);
419
420 // Keyboard kill the selection and shift position between I and S.
421 if(!has("moz") || has("mac")){ robot.keyPress(keys.RIGHT_ARROW, 100, {}); }
422 robot.keyPress(keys.LEFT_ARROW, 100, {});
423 robot.keyPress(keys.ENTER, 500);
424
425 robot.sequence(d.getTestCallback(function(){
426 // Do tests here.
427 var val = editor.get("value");
428 // Check that it split the is into two and that the bold and div were properly split.
429 doh.t(val.indexOf("It <b id=\"boldLine2\">I</b></p>") > 0, "start");
430 doh.t(val.indexOf("<p><b>S</b>") > 0, "end");
431 }), 500);
432
433 return d;
434 }
435 },
436 {
437 name: "shift enter to replace all content in p",
438 timeout: 10000,
439 runTest: function(){
440 var d = new doh.Deferred();
441 var editor = registry.byId("p2");
442 editor.set('value','<p>ab</p>');
443 var selection = range.getSelection(editor.window);
444 selection.removeAllRanges();
445 var r = range.create(editor.window);
446 r.setStart(editor.editNode.firstChild, 0);
447 r.setEnd(editor.editNode.firstChild, 1);
448 selection.addRange(r);
449 robot.keyPress(keys.ENTER, 500, {shift: true});
450 robot.sequence(d.getTestCallback(function(){
451 var val = editor.get("value");
452 doh.is(val, '<p><br /></p>');
453 }), 1000);
454 return d;
455 }
456 },
457 {
458 name: "copy and paste P",
459 timeout: 10000,
460 runTest: function(){
461 var d = new doh.Deferred();
462
463 var editor = registry.byId("p2");
464 winUtils.scrollIntoView(editor.iframe);
465 editor.set("value", "");
466 editor.focus();
467
468 robot.mouseMoveAt(editor.iframe, 500);
469 robot.mouseClick({left:true}, 500);
470 robot.keyPress(keys.BACKSPACE, 500, {});
471
472 robot.typeKeys("testingCopyAndPaste", 500);
473 robot.keyPress("a", 500, metaKey); // select all
474 robot.keyPress("c", 500, metaKey); // copy
475 robot.keyPress("v", 500, metaKey); // paste
476 robot.keyPress("v", 500, metaKey); // paste
477 robot.keyPress("v", 500, metaKey); // paste
478 robot.keyPress(keys.ENTER, 500, {});
479 robot.sequence(d.getTestCallback(function(){
480 var value = editor.get('value');
481 value = value.replace(/\xA0/g, "");
482 if(has("webkit") && !has("mac")){
483 // Work around webkit bug:
484 // http://code.google.com/p/chromium/issues/detail?id=106551
485 // Should hopefully be fixed in Chrome 19.
486 value = value.replace(/\n/g, "");
487 value = value.replace(/\r\f/g, "");
488 }
489
490 doh.is('<p>testingCopyAndPastetestingCopyAndPastetestingCopyAndPaste</p>',
491 value,
492 "get('value')");
493 }), 1000);
494 return d;
495 }
496 },
497 {
498 name: "copy and paste P split",
499 timeout: 10000,
500 runTest: function(){
501 var d = new doh.Deferred();
502
503 var editor = registry.byId("p2");
504 winUtils.scrollIntoView(editor.iframe);
505 editor.set("value", "");
506 editor.focus();
507
508 robot.mouseMoveAt(editor.iframe, 500);
509 robot.mouseClick({left:true}, 500);
510 robot.keyPress(keys.BACKSPACE, 500, {});
511
512 robot.typeKeys("testingCopyAndPaste", 500);
513 robot.keyPress("a", 500, metaKey); // select all
514 robot.keyPress("c", 500, metaKey); // copy
515 robot.keyPress("v", 500, metaKey); // paste
516 robot.keyPress("v", 500, metaKey); // paste
517 robot.keyPress("v", 500, metaKey); // paste
518 robot.keyPress(keys.LEFT_ARROW, 500, {});
519 robot.keyPress(keys.LEFT_ARROW, 500, {});
520 robot.keyPress(keys.LEFT_ARROW, 500, {});
521 robot.keyPress(keys.LEFT_ARROW, 500, {});
522 robot.keyPress(keys.ENTER, 500, {});
523 robot.sequence(d.getTestCallback(function(){
524 // get('value') should call the post-filter which recombines the separate <p> nodes into bigger
525 // paragraphs.
526 var value = editor.get('value');
527 value = value.replace(/\xA0/g, "");
528 if(has("webkit") && !has("mac")){
529 // Work around webkit bug:
530 // http://code.google.com/p/chromium/issues/detail?id=106551
531 // Should hopefully be fixed in Chrome 19.
532 value = value.replace(/\n/g, "");
533 value = value.replace(/\r\f/g, "");
534 }
535
536 doh.is('<p>testingCopyAndPastetestingCopyAndPastetestingCopyAndP</p><p>aste</p>',
537 value,
538 "get('value')");
539 }), 1000);
540 return d;
541 }
542 }
543 ]);
544
545 doh.run();
546 });
547 </script>
548 </head>
549 </html>