2011-04-22 Levi Weintraub <leviw@chromium.org>
[WebKit-https.git] / LayoutTests / editing / editing.js
1 //-------------------------------------------------------------------------------------------------------
2 // Java script library to run editing layout tests
3
4 var commandCount = 1;
5 var commandDelay = window.location.search.substring(1);
6 if (commandDelay == '')
7     commandDelay = 0;
8 var selection = window.getSelection();
9
10 //-------------------------------------------------------------------------------------------------------
11
12 function execSetSelectionCommand(sn, so, en, eo) {
13     window.getSelection().setBaseAndExtent(sn, so, en, eo);
14 }
15
16 // Args are startNode, startOffset, endNode, endOffset
17 function setSelectionCommand(sn, so, en, eo) {
18     if (commandDelay > 0) {
19         window.setTimeout(execSetSelectionCommand, commandCount * commandDelay, sn, so, en, eo);
20         commandCount++;
21     } else
22         execSetSelectionCommand(sn, so, en, eo);
23 }
24
25 //-------------------------------------------------------------------------------------------------------
26
27 function execTransposeCharactersCommand() {
28     document.execCommand("Transpose");
29 }
30 function transposeCharactersCommand() {
31     if (commandDelay > 0) {
32         window.setTimeout(execTransposeCharactersCommand, commandCount * commandDelay);
33         commandCount++;
34     }
35     else {
36         execTransposeCharactersCommand();
37     }
38 }
39
40 //-------------------------------------------------------------------------------------------------------
41
42 function execMoveSelectionLeftByCharacterCommand() {
43     selection.modify("move", "left", "character");
44 }
45 function moveSelectionLeftByCharacterCommand() {
46     if (commandDelay > 0) {
47         window.setTimeout(execMoveSelectionLeftByCharacterCommand, commandCount * commandDelay);
48         commandCount++;
49     }
50     else {
51         execMoveSelectionLeftByCharacterCommand();
52     }
53 }
54
55 //-------------------------------------------------------------------------------------------------------
56
57 function execMoveSelectionRightByCharacterCommand() {
58     selection.modify("move", "Right", "character");
59 }
60 function moveSelectionRightByCharacterCommand() {
61     if (commandDelay > 0) {
62         window.setTimeout(execMoveSelectionRightByCharacterCommand, commandCount * commandDelay);
63         commandCount++;
64     }
65     else {
66         execMoveSelectionRightByCharacterCommand();
67     }
68 }
69
70 //-------------------------------------------------------------------------------------------------------
71
72 function execExtendSelectionLeftByCharacterCommand() {
73     selection.modify("extend", "left", "character");
74 }
75 function extendSelectionLeftByCharacterCommand() {
76     if (commandDelay > 0) {
77         window.setTimeout(execExtendSelectionLeftByCharacterCommand, commandCount * commandDelay);
78         commandCount++;
79     }
80     else {
81         execExtendSelectionLeftByCharacterCommand();
82     }
83 }
84
85 //-------------------------------------------------------------------------------------------------------
86
87 function execExtendSelectionRightByCharacterCommand() {
88     selection.modify("extend", "Right", "character");
89 }
90 function extendSelectionRightByCharacterCommand() {
91     if (commandDelay > 0) {
92         window.setTimeout(execExtendSelectionRightByCharacterCommand, commandCount * commandDelay);
93         commandCount++;
94     }
95     else {
96         execExtendSelectionRightByCharacterCommand();
97     }
98 }
99
100 //-------------------------------------------------------------------------------------------------------
101
102 function execMoveSelectionForwardByCharacterCommand() {
103     selection.modify("move", "forward", "character");
104 }
105 function moveSelectionForwardByCharacterCommand() {
106     if (commandDelay > 0) {
107         window.setTimeout(execMoveSelectionForwardByCharacterCommand, commandCount * commandDelay);
108         commandCount++;
109     }
110     else {
111         execMoveSelectionForwardByCharacterCommand();
112     }
113 }
114
115 //-------------------------------------------------------------------------------------------------------
116
117 function execExtendSelectionForwardByCharacterCommand() {
118     selection.modify("extend", "forward", "character");
119 }
120 function extendSelectionForwardByCharacterCommand() {
121     if (commandDelay > 0) {
122         window.setTimeout(execExtendSelectionForwardByCharacterCommand, commandCount * commandDelay);
123         commandCount++;
124     }
125     else {
126         execExtendSelectionForwardByCharacterCommand();
127     }
128 }
129
130 //-------------------------------------------------------------------------------------------------------
131
132 function execMoveSelectionForwardByWordCommand() {
133     selection.modify("move", "forward", "word");
134 }
135 function moveSelectionForwardByWordCommand() {
136     if (commandDelay > 0) {
137         window.setTimeout(execMoveSelectionForwardByWordCommand, commandCount * commandDelay);
138         commandCount++;
139     }
140     else {
141         execMoveSelectionForwardByWordCommand();
142     }
143 }
144
145 //-------------------------------------------------------------------------------------------------------
146
147 function execExtendSelectionForwardByWordCommand() {
148     selection.modify("extend", "forward", "word");
149 }
150 function extendSelectionForwardByWordCommand() {
151     if (commandDelay > 0) {
152         window.setTimeout(execExtendSelectionForwardByWordCommand, commandCount * commandDelay);
153         commandCount++;
154     }
155     else {
156         execExtendSelectionForwardByWordCommand();
157     }
158 }
159
160 //-------------------------------------------------------------------------------------------------------
161
162 function execMoveSelectionForwardBySentenceCommand() {
163     selection.modify("move", "forward", "sentence");
164 }
165 function moveSelectionForwardBySentenceCommand() {
166     if (commandDelay > 0) {
167         window.setTimeout(execMoveSelectionForwardBySentenceCommand, commandCount * commandDelay);
168         commandCount++;
169     }
170     else {
171         execMoveSelectionForwardBySentenceCommand();
172     }
173 }
174
175 //-------------------------------------------------------------------------------------------------------
176
177 function execExtendSelectionForwardBySentenceCommand() {
178     selection.modify("extend", "forward", "sentence");
179 }
180 function extendSelectionForwardBySentenceCommand() {
181     if (commandDelay > 0) {
182         window.setTimeout(execExtendSelectionForwardBySentenceCommand, commandCount * commandDelay);
183         commandCount++;
184     }
185     else {
186         execExtendSelectionForwardBySentenceCommand();
187     }
188 }
189
190 //-------------------------------------------------------------------------------------------------------
191
192 function execMoveSelectionForwardByLineCommand() {
193     selection.modify("move", "forward", "line");
194 }
195 function moveSelectionForwardByLineCommand() {
196     if (commandDelay > 0) {
197         window.setTimeout(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
198         commandCount++;
199     }
200     else {
201         execMoveSelectionForwardByLineCommand();
202     }
203 }
204
205 //-------------------------------------------------------------------------------------------------------
206
207 function execExtendSelectionForwardByLineCommand() {
208     selection.modify("extend", "forward", "line");
209 }
210 function extendSelectionForwardByLineCommand() {
211     if (commandDelay > 0) {
212         window.setTimeout(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
213         commandCount++;
214     }
215     else {
216         execExtendSelectionForwardByLineCommand();
217     }
218 }
219
220 //-------------------------------------------------------------------------------------------------------
221
222 function execMoveSelectionForwardByLineBoundaryCommand() {
223     selection.modify("move", "forward", "lineBoundary");
224 }
225 function moveSelectionForwardByLineBoundaryCommand() {
226     if (commandDelay > 0) {
227         window.setTimeout(execMoveSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
228         commandCount++;
229     }
230     else {
231         execMoveSelectionForwardByLineBoundaryCommand();
232     }
233 }
234
235 //-------------------------------------------------------------------------------------------------------
236
237 function execExtendSelectionForwardByLineBoundaryCommand() {
238     selection.modify("extend", "forward", "lineBoundary");
239 }
240 function extendSelectionForwardByLineBoundaryCommand() {
241     if (commandDelay > 0) {
242         window.setTimeout(execExtendSelectionForwardByLineBoundaryCommand, commandCount * commandDelay);
243         commandCount++;
244     }
245     else {
246         execExtendSelectionForwardByLineBoundaryCommand();
247     }
248 }
249
250 //-------------------------------------------------------------------------------------------------------
251
252 function execMoveSelectionBackwardByCharacterCommand() {
253     selection.modify("move", "backward", "character");
254 }
255 function moveSelectionBackwardByCharacterCommand() {
256     if (commandDelay > 0) {
257         window.setTimeout(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
258         commandCount++;
259     }
260     else {
261         execMoveSelectionBackwardByCharacterCommand();
262     }
263 }
264
265 //-------------------------------------------------------------------------------------------------------
266
267 function execExtendSelectionBackwardByCharacterCommand() {
268     selection.modify("extend", "backward", "character");
269 }
270 function extendSelectionBackwardByCharacterCommand() {
271     if (commandDelay > 0) {
272         window.setTimeout(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
273         commandCount++;
274     }
275     else {
276         execExtendSelectionBackwardByCharacterCommand();
277     }
278 }
279
280 //-------------------------------------------------------------------------------------------------------
281
282 function execMoveSelectionBackwardByWordCommand() {
283     selection.modify("move", "backward", "word");
284 }
285 function moveSelectionBackwardByWordCommand() {
286     if (commandDelay > 0) {
287         window.setTimeout(execMoveSelectionBackwardByWordCommand, commandCount * commandDelay);
288         commandCount++;
289     }
290     else {
291         execMoveSelectionBackwardByWordCommand();
292     }
293 }
294
295 //-------------------------------------------------------------------------------------------------------
296
297 function execExtendSelectionBackwardByWordCommand() {
298     selection.modify("extend", "backward", "word");
299 }
300 function extendSelectionBackwardByWordCommand() {
301     if (commandDelay > 0) {
302         window.setTimeout(execExtendSelectionBackwardByWordCommand, commandCount * commandDelay);
303         commandCount++;
304     }
305     else {
306         execExtendSelectionBackwardByWordCommand();
307     }
308 }
309
310 //-------------------------------------------------------------------------------------------------------
311
312 function execMoveSelectionBackwardBySentenceCommand() {
313     selection.modify("move", "backward", "sentence");
314 }
315 function moveSelectionBackwardBySentenceCommand() {
316     if (commandDelay > 0) {
317         window.setTimeout(execMoveSelectionBackwardBySentenceCommand, commandCount * commandDelay);
318         commandCount++;
319     }
320     else {
321         execMoveSelectionBackwardBySentenceCommand();
322     }
323 }
324
325 //-------------------------------------------------------------------------------------------------------
326
327 function execExtendSelectionBackwardBySentenceCommand() {
328     selection.modify("extend", "backward", "sentence");
329 }
330 function extendSelectionBackwardBySentenceCommand() {
331     if (commandDelay > 0) {
332         window.setTimeout(execExtendSelectionBackwardBySentenceCommand, commandCount * commandDelay);
333         commandCount++;
334     }
335     else {
336         execExtendSelectionBackwardBySentenceCommand();
337     }
338 }
339
340 //-------------------------------------------------------------------------------------------------------
341
342 function execMoveSelectionBackwardByLineCommand() {
343     selection.modify("move", "backward", "line");
344 }
345 function moveSelectionBackwardByLineCommand() {
346     if (commandDelay > 0) {
347         window.setTimeout(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
348         commandCount++;
349     }
350     else {
351         execMoveSelectionBackwardByLineCommand();
352     }
353 }
354
355 //-------------------------------------------------------------------------------------------------------
356
357 function execExtendSelectionBackwardByLineCommand() {
358     selection.modify("extend", "backward", "line");
359 }
360 function extendSelectionBackwardByLineCommand() {
361     if (commandDelay > 0) {
362         window.setTimeout(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
363         commandCount++;
364     }
365     else {
366         execExtendSelectionBackwardByLineCommand();
367     }
368 }
369
370 //-------------------------------------------------------------------------------------------------------
371
372 function execExtendSelectionBackwardByLineBoundaryCommand() {
373     selection.modify("extend", "backward", "lineBoundary");
374 }
375 function extendSelectionBackwardByLineBoundaryCommand() {
376     if (commandDelay > 0) {
377         window.setTimeout(execExtendSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
378         commandCount++;
379     }
380     else {
381         execExtendSelectionBackwardByLineBoundaryCommand();
382     }
383 }
384
385 //-------------------------------------------------------------------------------------------------------
386
387 function execMoveSelectionBackwardByLineBoundaryCommand() {
388     selection.modify("move", "backward", "lineBoundary");
389 }
390 function moveSelectionBackwardByLineBoundaryCommand() {
391     if (commandDelay > 0) {
392         window.setTimeout(execMoveSelectionBackwardByLineBoundaryCommand, commandCount * commandDelay);
393         commandCount++;
394     }
395     else {
396         execMoveSelectionBackwardByLineBoundaryCommand();
397     }
398 }
399
400 //-------------------------------------------------------------------------------------------------------
401
402 function doubleClick(x, y) {
403     eventSender.mouseMoveTo(x, y);
404     eventSender.mouseDown();
405     eventSender.mouseUp();
406     eventSender.mouseDown();
407     eventSender.mouseUp();
408 }
409
410 function doubleClickAtSelectionStart() {
411     var rects = window.getSelection().getRangeAt(0).getClientRects();
412     var x = rects[0].left;
413     var y = rects[0].top;
414     doubleClick(x, y);
415 }
416
417 //-------------------------------------------------------------------------------------------------------
418
419 function execBoldCommand() {
420     document.execCommand("Bold");
421     debugForDumpAsText("execBoldCommand");
422 }
423 function boldCommand() {
424     if (commandDelay > 0) {
425         window.setTimeout(execBoldCommand, commandCount * commandDelay);
426         commandCount++;
427     }
428     else {
429         execBoldCommand();
430     }
431 }
432
433 //-------------------------------------------------------------------------------------------------------
434
435 function execUnderlineCommand() {
436     document.execCommand("Underline");
437     debugForDumpAsText("execUnderlineCommand");
438 }
439 function underlineCommand() {
440     if (commandDelay > 0) {
441         window.setTimeout(execUnderlineCommand, commandCount * commandDelay);
442         commandCount++;
443     }
444     else {
445         execUnderlineCommand();
446     }
447 }
448
449 //-------------------------------------------------------------------------------------------------------
450
451 function execFontNameCommand() {
452     document.execCommand("FontName", false, "Courier");
453     debugForDumpAsText("execFontNameCommand");
454 }
455 function fontNameCommand() {
456     if (commandDelay > 0) {
457         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
458         commandCount++;
459     }
460     else {
461         execFontNameCommand();
462     }
463 }
464
465 //-------------------------------------------------------------------------------------------------------
466
467 function execFontSizeCommand(s) {
468     if (arguments.length == 0 || s == undefined || s.length == 0)
469         s = '12px';
470     document.execCommand("FontSize", false, s);
471     debugForDumpAsText("execFontSizeCommand");
472 }
473 function fontSizeCommand(s) {
474     if (commandDelay > 0) {
475         window.setTimeout(execFontSizeCommand, commandCount * commandDelay, s);
476         commandCount++;
477     }
478     else {
479         execFontSizeCommand(s);
480     }
481 }
482
483 //-------------------------------------------------------------------------------------------------------
484
485 function execFontSizeDeltaCommand(s) {
486     if (arguments.length == 0 || s == undefined || s.length == 0)
487         s = '1px';
488     document.execCommand("FontSizeDelta", false, s);
489     debugForDumpAsText("execFontSizeDeltaCommand");
490 }
491 function fontSizeDeltaCommand(s) {
492     if (commandDelay > 0) {
493         window.setTimeout(execFontSizeDeltaCommand, commandCount * commandDelay, s);
494         commandCount++;
495     }
496     else {
497         execFontSizeDeltaCommand(s);
498     }
499 }
500
501 //-------------------------------------------------------------------------------------------------------
502
503 function execItalicCommand() {
504     document.execCommand("Italic");
505     debugForDumpAsText("execItalicCommand");
506 }
507 function italicCommand() {
508     if (commandDelay > 0) {
509         window.setTimeout(execItalicCommand, commandCount * commandDelay);
510         commandCount++;
511     }
512     else {
513         execItalicCommand();
514     }
515 }
516
517
518 //-------------------------------------------------------------------------------------------------------
519
520 function execJustifyCenterCommand() {
521     document.execCommand("JustifyCenter");
522     debugForDumpAsText("execJustifyCenterCommand");
523 }
524 function justifyCenterCommand() {
525     if (commandDelay > 0) {
526         window.setTimeout(execJustifyCenterCommand, commandCount * commandDelay);
527         commandCount++;
528     }
529     else {
530         execJustifyCenterCommand();
531     }
532 }
533
534
535 //-------------------------------------------------------------------------------------------------------
536
537 function execJustifyLeftCommand() {
538     document.execCommand("JustifyLeft");
539     debugForDumpAsText("execJustifyLeftCommand");
540 }
541 function justifyLeftCommand() {
542     if (commandDelay > 0) {
543         window.setTimeout(execJustifyLeftCommand, commandCount * commandDelay);
544         commandCount++;
545     }
546     else {
547         execJustifyLeftCommand();
548     }
549 }
550
551
552 //-------------------------------------------------------------------------------------------------------
553
554 function execJustifyRightCommand() {
555     document.execCommand("JustifyRight");
556     debugForDumpAsText("execJustifyRightCommand");
557 }
558 function justifyRightCommand() {
559     if (commandDelay > 0) {
560         window.setTimeout(execJustifyRightCommand, commandCount * commandDelay);
561         commandCount++;
562     }
563     else {
564         execJustifyRightCommand();
565     }
566 }
567
568 //-------------------------------------------------------------------------------------------------------
569
570 function execInsertHTMLCommand(html) {
571     document.execCommand("InsertHTML", false, html);
572     debugForDumpAsText("execInsertHTMLCommand");
573 }
574 function insertHTMLCommand(html) {
575     if (commandDelay > 0) {
576         window.setTimeout(execInsertHTMLCommand, commandCount * commandDelay, html);
577         commandCount++;
578     }
579     else {
580         execInsertHTMLCommand(html);
581     }
582 }
583
584 //-------------------------------------------------------------------------------------------------------
585
586 function execInsertImageCommand(imgSrc) {
587     document.execCommand("InsertImage", false, imgSrc);
588     debugForDumpAsText("execInsertImageCommand");
589 }
590 function insertImageCommand(imgSrc) {
591     if (commandDelay > 0) {
592         window.setTimeout(execInsertImageCommand, commandCount * commandDelay, imgSrc);
593         commandCount++;
594     }
595     else {
596         execInsertImageCommand(imgSrc);
597     }
598 }
599
600 //-------------------------------------------------------------------------------------------------------
601
602 function execInsertLineBreakCommand() {
603     document.execCommand("InsertLineBreak");
604     debugForDumpAsText("execInsertLineBreakCommand");
605 }
606 function insertLineBreakCommand() {
607     if (commandDelay > 0) {
608         window.setTimeout(execInsertLineBreakCommand, commandCount * commandDelay);
609         commandCount++;
610     }
611     else {
612         execInsertLineBreakCommand();
613     }
614 }
615
616 //-------------------------------------------------------------------------------------------------------
617  
618 function execInsertParagraphCommand() {
619     document.execCommand("InsertParagraph");
620     debugForDumpAsText("execInsertParagraphCommand");
621 }
622 function insertParagraphCommand() {
623     if (commandDelay > 0) {
624         window.setTimeout(execInsertParagraphCommand, commandCount * commandDelay);
625         commandCount++;
626     }
627     else {
628         execInsertParagraphCommand();
629     }
630 }
631
632 //-------------------------------------------------------------------------------------------------------
633
634 function execInsertNewlineInQuotedContentCommand() {
635     document.execCommand("InsertNewlineInQuotedContent");
636     debugForDumpAsText("execInsertNewlineInQuotedContentCommand");
637 }
638 function insertNewlineInQuotedContentCommand() {
639     if (commandDelay > 0) {
640         window.setTimeout(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
641         commandCount++;
642     }
643     else {
644         execInsertNewlineInQuotedContentCommand();
645     }
646 }
647
648 //-------------------------------------------------------------------------------------------------------
649
650 function execTypeCharacterCommand(c) {
651     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
652         c = 'x';
653     document.execCommand("InsertText", false, c);
654     debugForDumpAsText("execTypeCharacterCommand");
655 }
656 function typeCharacterCommand(c) {
657     if (commandDelay > 0) {
658         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay, c);
659         commandCount++;
660     }
661     else {
662         execTypeCharacterCommand(c);
663     }
664 }
665
666 //-------------------------------------------------------------------------------------------------------
667
668 function execSelectAllCommand() {
669     document.execCommand("SelectAll");
670 }
671 function selectAllCommand() {
672     if (commandDelay > 0) {
673         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
674         commandCount++;
675     }
676     else {
677         execSelectAllCommand();
678     }
679 }
680
681 //-------------------------------------------------------------------------------------------------------
682
683 function execStrikethroughCommand() {
684     document.execCommand("Strikethrough");
685     debugForDumpAsText("execStrikethroughCommand");
686 }
687 function strikethroughCommand() {
688     if (commandDelay > 0) {
689         window.setTimeout(execStrikethroughCommand, commandCount * commandDelay);
690         commandCount++;
691     }
692     else {
693         execStrikethroughCommand();
694     }
695 }
696
697 //-------------------------------------------------------------------------------------------------------
698
699 function execUndoCommand() {
700     document.execCommand("Undo");
701     debugForDumpAsText("execUndoCommand");
702 }
703 function undoCommand() {
704     if (commandDelay > 0) {
705         window.setTimeout(execUndoCommand, commandCount * commandDelay);
706         commandCount++;
707     }
708     else {
709         execUndoCommand();
710     }
711 }
712
713 //-------------------------------------------------------------------------------------------------------
714
715 function execRedoCommand() {
716     document.execCommand("Redo");
717     debugForDumpAsText("execRedoCommand");
718 }
719 function redoCommand() {
720     if (commandDelay > 0) {
721         window.setTimeout(execRedoCommand, commandCount * commandDelay);
722         commandCount++;
723     }
724     else {
725         execRedoCommand();
726     }
727 }
728
729 //-------------------------------------------------------------------------------------------------------
730
731 function execChangeRootSize() {
732     document.getElementById("root").style.width = "600px";
733 }
734 function changeRootSize() {
735     if (commandDelay > 0) {
736         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
737         commandCount++;
738     }
739     else {
740         execChangeRootSize();
741     }
742 }
743
744 //-------------------------------------------------------------------------------------------------------
745
746 function execCutCommand() {
747     document.execCommand("Cut");
748     debugForDumpAsText("execCutCommand");
749 }
750 function cutCommand() {
751     if (commandDelay > 0) {
752         window.setTimeout(execCutCommand, commandCount * commandDelay);
753         commandCount++;
754     }
755     else {
756         execCutCommand();
757     }
758 }
759
760 //-------------------------------------------------------------------------------------------------------
761
762 function execCopyCommand() {
763     document.execCommand("Copy");
764     debugForDumpAsText("execCopyCommand");
765 }
766 function copyCommand() {
767     if (commandDelay > 0) {
768         window.setTimeout(execCopyCommand, commandCount * commandDelay);
769         commandCount++;
770     }
771     else {
772         execCopyCommand();
773     }
774 }
775
776 //-------------------------------------------------------------------------------------------------------
777
778 function execPasteCommand() {
779     document.execCommand("Paste");
780     debugForDumpAsText("execPasteCommand");
781 }
782 function pasteCommand() {
783     if (commandDelay > 0) {
784         window.setTimeout(execPasteCommand, commandCount * commandDelay);
785         commandCount++;
786     }
787     else {
788         execPasteCommand();
789     }
790 }
791
792 //-------------------------------------------------------------------------------------------------------
793
794 function execCreateLinkCommand(url) {
795     document.execCommand("CreateLink", false, url);
796     debugForDumpAsText("execCreateLinkCommand");
797 }
798 function createLinkCommand(url) {
799     if (commandDelay > 0) {
800         window.setTimeout(execCreateLinkCommand, commandCount * commandDelay, url);
801         commandCount++;
802     } else
803         execCreateLinkCommand(url);
804 }
805
806 //-------------------------------------------------------------------------------------------------------
807
808 function execUnlinkCommand() {
809     document.execCommand("Unlink");
810     debugForDumpAsText("execUnlinkCommand");
811 }
812 function unlinkCommand() {
813     if (commandDelay > 0) {
814         window.setTimeout(execUnlinkCommand, commandCount * commandDelay);
815         commandCount++;
816     } else
817         execUnlinkCommand();
818 }
819
820 //-------------------------------------------------------------------------------------------------------
821
822 function execPasteAndMatchStyleCommand() {
823     document.execCommand("PasteAndMatchStyle");
824     debugForDumpAsText("execPasteAndMatchStyleCommand");
825 }
826 function pasteAndMatchStyleCommand() {
827     if (commandDelay > 0) {
828         window.setTimeout(execPasteAndMatchStyleCommand, commandCount * commandDelay);
829         commandCount++;
830     }
831     else {
832         execPasteAndMatchStyleCommand();
833     }
834 }
835
836 //-------------------------------------------------------------------------------------------------------
837
838 function execDeleteCommand() {
839     document.execCommand("Delete");
840     debugForDumpAsText("execDeleteCommand");
841 }
842 function deleteCommand() {
843     if (commandDelay > 0) {
844         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
845         commandCount++;
846     }
847     else {
848         execDeleteCommand();
849     }
850 }
851
852 //-------------------------------------------------------------------------------------------------------
853
854 function execForwardDeleteCommand() {
855     document.execCommand("ForwardDelete");
856     debugForDumpAsText("execForwardDeleteCommand");
857 }
858 function forwardDeleteCommand() {
859     if (commandDelay > 0) {
860         window.setTimeout(execForwardDeleteCommand, commandCount * commandDelay);
861         commandCount++;
862     }
863     else {
864         execForwardDeleteCommand();
865     }
866 }
867
868 //-------------------------------------------------------------------------------------------------------
869
870 function runEditingTest() {
871     if (window.layoutTestController)
872         layoutTestController.dumpEditingCallbacks();
873
874     var elem = document.getElementById("test");
875     var selection = window.getSelection();
876     selection.setPosition(elem, 0);
877     editingTest();
878 }
879
880 var dumpAsText = false;
881 var markupResultList = document.createElement('ol');
882
883 function runDumpAsTextEditingTest(enableCallbacks) {
884     if (window.layoutTestController) {
885          layoutTestController.dumpAsText();
886          if (enableCallbacks)
887             layoutTestController.dumpEditingCallbacks();
888      }
889
890     dumpAsText = true;
891
892     var elem = document.getElementById("test");
893     var selection = window.getSelection();
894     selection.setPosition(elem, 0);
895     editingTest();
896
897     document.body.appendChild(markupResultList);
898 }
899
900 function debugForDumpAsText(name) {
901     if (dumpAsText && document.getElementById("root")) {
902         var newItem = document.createElement('li');
903         newItem.appendChild(document.createTextNode(name+": "+document.getElementById("root").innerHTML));
904         markupResultList.appendChild(newItem);
905     }
906 }
907
908 //-------------------------------------------------------------------------------------------------------
909
910
911 function execBackColorCommand() {
912     document.execCommand("BackColor", false, "Chartreuse");
913     debugForDumpAsText('execBackColorCommand');
914 }
915 function backColorCommand() {
916     if (commandDelay > 0) {
917         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
918         commandCount++;
919     }
920     else {
921         execBackColorCommand();
922     }
923 }
924
925
926 function execForeColorCommand(color) {
927     document.execCommand("ForeColor", false, color);
928     debugForDumpAsText('execForeColorCommand');
929 }
930 function foreColorCommand(color) {
931     if (commandDelay > 0) {
932         window.setTimeout(execForeColorCommand, commandCount * commandDelay, color);
933         commandCount++;
934     } else
935         execForeColorCommand(color);
936 }
937
938 //-------------------------------------------------------------------------------------------------------
939
940
941 function runCommand(command, arg1, arg2) {
942     document.execCommand(command,arg1,arg2);
943 }
944
945 function executeCommand(command,arg1,arg2) {
946     if (commandDelay > 0) {
947         window.setTimeout(runCommand, commandCount * commandDelay);
948         commandCount++;
949     }
950     else {
951         runCommand(command,arg1,arg2);
952     }
953 }
954