Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / third_party / WebKit / 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         queueCommand(execSetSelectionCommand.bind(execSetSelectionCommand, sn, so, en, eo), commandCount * commandDelay);
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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(execFontSizeDeltaCommand.bind(execFontSizeDeltaCommand, s), commandCount * commandDelay);
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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(execInsertHTMLCommand.bind(execInsertHTMLCommand, html), commandCount * commandDelay);
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         queueCommand(execInsertImageCommand.bind(execInsertImageCommand, imgSrc), commandCount * commandDelay);
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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(execTypeCharacterCommand.bind(execTypeCharacterCommand, c), commandCount * commandDelay);
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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(execCreateLinkCommand.bind(execCreateLinkCommand, url), commandCount * commandDelay);
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         queueCommand(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         queueCommand(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         queueCommand(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         queueCommand(execForwardDeleteCommand, commandCount * commandDelay);
861         commandCount++;
862     }
863     else {
864         execForwardDeleteCommand();
865     }
866 }
867
868 //-------------------------------------------------------------------------------------------------------
869
870 (function () {
871     var queue = [];
872     var i = 0;
873     var timer;
874
875     function queueCommand(callback) {
876         queue.push(callback);
877         if (!timer) {
878             if (window.testRunner)
879                 testRunner.waitUntilDone();
880             timer = setTimeout(runCommand, commandDelay);
881         }
882     }
883
884     function runCommand() {
885         queue[i]();
886         i++;
887         if (i < queue.length)
888             setTimeout(runCommand, commandDelay);
889         else if (window.testRunner)
890             testRunner.notifyDone();
891     }
892     
893     window.queueCommand = queueCommand;
894 })();
895
896 function runEditingTest() {
897     if (window.testRunner)
898         testRunner.dumpEditingCallbacks();
899
900     var elem = document.getElementById("test");
901     var selection = window.getSelection();
902     if (elem)
903         selection.collapse(elem, 0);
904     else
905         selection.removeAllRanges();
906     editingTest();
907 }
908
909 var dumpAsText = false;
910 var elementsForDumpingMarkupList = [document.createElement('ol')];
911
912 function runDumpAsTextEditingTest(enableCallbacks) {
913     if (window.testRunner) {
914          testRunner.dumpAsText();
915          if (enableCallbacks)
916             testRunner.dumpEditingCallbacks();
917      }
918
919     dumpAsText = true;
920
921     var elem = document.getElementById("test");
922     var selection = window.getSelection();
923     if (elem)
924         selection.collapse(elem, 0);
925     else
926         selection.removeAllRanges();
927     editingTest();
928
929     for (var i = 0; i < elementsForDumpingMarkupList.length; i++)
930         document.body.appendChild(elementsForDumpingMarkupList[i]);
931 }
932
933 function debugForDumpAsText(name) {
934     if (dumpAsText && document.getElementById("root")) {
935         var newItem = document.createElement('li');
936         newItem.appendChild(document.createTextNode(name+": "+document.getElementById("root").innerHTML));
937         elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].appendChild(newItem);
938     }
939 }
940
941 function startNewMarkupGroup(label) {
942     if (!elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].hasChildNodes())
943         elementsForDumpingMarkupList.pop();
944     elementsForDumpingMarkupList.push(document.createElement('br'));
945     elementsForDumpingMarkupList.push(document.createTextNode(label));
946     elementsForDumpingMarkupList.push(document.createElement('ol'));
947 }
948
949 //-------------------------------------------------------------------------------------------------------
950
951
952 function execBackColorCommand() {
953     document.execCommand("BackColor", false, "Chartreuse");
954     debugForDumpAsText('execBackColorCommand');
955 }
956 function backColorCommand() {
957     if (commandDelay > 0) {
958         queueCommand(execBackColorCommand, commandCount * commandDelay);
959         commandCount++;
960     }
961     else {
962         execBackColorCommand();
963     }
964 }
965
966
967 function execForeColorCommand(color) {
968     document.execCommand("ForeColor", false, color);
969     debugForDumpAsText('execForeColorCommand');
970 }
971 function foreColorCommand(color) {
972     if (commandDelay > 0) {
973         queueCommand(execForeColorCommand.bind(execForeColorCommand, color), commandCount * commandDelay);
974         commandCount++;
975     } else
976         execForeColorCommand(color);
977 }
978
979 //-------------------------------------------------------------------------------------------------------
980
981
982 function runCommand(command, arg1, arg2) {
983     document.execCommand(command,arg1,arg2);
984 }
985
986 function executeCommand(command,arg1,arg2) {
987     if (commandDelay > 0) {
988         queueCommand(runCommand, commandCount * commandDelay);
989         commandCount++;
990     }
991     else {
992         runCommand(command,arg1,arg2);
993     }
994 }
995