AX: <svg> elements with labels and no accessible contents are exposed as empty AXGroups
[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         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 moveMouseToCenterOfElement(element) {
403     if (!window.eventSender)
404         return;
405
406     const centerX = element.offsetLeft + element.offsetWidth / 2;
407     const centerY = element.offsetTop + element.offsetHeight / 2;
408     eventSender.mouseMoveTo(centerX, centerY);
409 }
410
411 function dragFilesOntoElement(element, files) {
412     if (!window.eventSender)
413         return;
414
415     eventSender.beginDragWithFiles(files);
416     moveMouseToCenterOfElement(element);
417     eventSender.mouseUp();
418 }
419
420 //-------------------------------------------------------------------------------------------------------
421
422 function doubleClick(x, y) {
423     eventSender.mouseMoveTo(x, y);
424     eventSender.mouseDown();
425     eventSender.mouseUp();
426     eventSender.mouseDown();
427     eventSender.mouseUp();
428 }
429
430 function doubleClickAtSelectionStart() {
431     var rects = window.getSelection().getRangeAt(0).getClientRects();
432     var x = rects[0].left;
433     var y = rects[0].top;
434     doubleClick(x, y);
435 }
436
437 //-------------------------------------------------------------------------------------------------------
438
439 function execBoldCommand() {
440     document.execCommand("Bold");
441     debugForDumpAsText("execBoldCommand");
442 }
443 function boldCommand() {
444     if (commandDelay > 0) {
445         queueCommand(execBoldCommand, commandCount * commandDelay);
446         commandCount++;
447     }
448     else {
449         execBoldCommand();
450     }
451 }
452
453 //-------------------------------------------------------------------------------------------------------
454
455 function execUnderlineCommand() {
456     document.execCommand("Underline");
457     debugForDumpAsText("execUnderlineCommand");
458 }
459 function underlineCommand() {
460     if (commandDelay > 0) {
461         queueCommand(execUnderlineCommand, commandCount * commandDelay);
462         commandCount++;
463     }
464     else {
465         execUnderlineCommand();
466     }
467 }
468
469 //-------------------------------------------------------------------------------------------------------
470
471 function execFontNameCommand() {
472     document.execCommand("FontName", false, "Courier");
473     debugForDumpAsText("execFontNameCommand");
474 }
475 function fontNameCommand() {
476     if (commandDelay > 0) {
477         queueCommand(execFontNameCommand, commandCount * commandDelay);
478         commandCount++;
479     }
480     else {
481         execFontNameCommand();
482     }
483 }
484
485 //-------------------------------------------------------------------------------------------------------
486
487 function execFontSizeCommand(s) {
488     if (arguments.length == 0 || s == undefined || s.length == 0)
489         s = '12px';
490     document.execCommand("FontSize", false, s);
491     debugForDumpAsText("execFontSizeCommand");
492 }
493 function fontSizeCommand(s) {
494     if (commandDelay > 0) {
495         queueCommand(execFontSizeCommand, commandCount * commandDelay, s);
496         commandCount++;
497     }
498     else {
499         execFontSizeCommand(s);
500     }
501 }
502
503 //-------------------------------------------------------------------------------------------------------
504
505 function execFontSizeDeltaCommand(s) {
506     if (arguments.length == 0 || s == undefined || s.length == 0)
507         s = '1px';
508     document.execCommand("FontSizeDelta", false, s);
509     debugForDumpAsText("execFontSizeDeltaCommand");
510 }
511 function fontSizeDeltaCommand(s) {
512     if (commandDelay > 0) {
513         queueCommand(execFontSizeDeltaCommand.bind(execFontSizeDeltaCommand, s), commandCount * commandDelay);
514         commandCount++;
515     }
516     else {
517         execFontSizeDeltaCommand(s);
518     }
519 }
520
521 //-------------------------------------------------------------------------------------------------------
522
523 function execItalicCommand() {
524     document.execCommand("Italic");
525     debugForDumpAsText("execItalicCommand");
526 }
527 function italicCommand() {
528     if (commandDelay > 0) {
529         queueCommand(execItalicCommand, commandCount * commandDelay);
530         commandCount++;
531     }
532     else {
533         execItalicCommand();
534     }
535 }
536
537
538 //-------------------------------------------------------------------------------------------------------
539
540 function execJustifyCenterCommand() {
541     document.execCommand("JustifyCenter");
542     debugForDumpAsText("execJustifyCenterCommand");
543 }
544 function justifyCenterCommand() {
545     if (commandDelay > 0) {
546         queueCommand(execJustifyCenterCommand, commandCount * commandDelay);
547         commandCount++;
548     }
549     else {
550         execJustifyCenterCommand();
551     }
552 }
553
554
555 //-------------------------------------------------------------------------------------------------------
556
557 function execJustifyLeftCommand() {
558     document.execCommand("JustifyLeft");
559     debugForDumpAsText("execJustifyLeftCommand");
560 }
561 function justifyLeftCommand() {
562     if (commandDelay > 0) {
563         queueCommand(execJustifyLeftCommand, commandCount * commandDelay);
564         commandCount++;
565     }
566     else {
567         execJustifyLeftCommand();
568     }
569 }
570
571
572 //-------------------------------------------------------------------------------------------------------
573
574 function execJustifyRightCommand() {
575     document.execCommand("JustifyRight");
576     debugForDumpAsText("execJustifyRightCommand");
577 }
578 function justifyRightCommand() {
579     if (commandDelay > 0) {
580         queueCommand(execJustifyRightCommand, commandCount * commandDelay);
581         commandCount++;
582     }
583     else {
584         execJustifyRightCommand();
585     }
586 }
587
588 //-------------------------------------------------------------------------------------------------------
589
590 function execInsertHTMLCommand(html) {
591     document.execCommand("InsertHTML", false, html);
592     debugForDumpAsText("execInsertHTMLCommand");
593 }
594 function insertHTMLCommand(html) {
595     if (commandDelay > 0) {
596         queueCommand(execInsertHTMLCommand.bind(execInsertHTMLCommand, html), commandCount * commandDelay);
597         commandCount++;
598     }
599     else {
600         execInsertHTMLCommand(html);
601     }
602 }
603
604 //-------------------------------------------------------------------------------------------------------
605
606 function execInsertImageCommand(imgSrc) {
607     document.execCommand("InsertImage", false, imgSrc);
608     debugForDumpAsText("execInsertImageCommand");
609 }
610 function insertImageCommand(imgSrc) {
611     if (commandDelay > 0) {
612         queueCommand(execInsertImageCommand.bind(execInsertImageCommand, imgSrc), commandCount * commandDelay);
613         commandCount++;
614     }
615     else {
616         execInsertImageCommand(imgSrc);
617     }
618 }
619
620 //-------------------------------------------------------------------------------------------------------
621
622 function execInsertLineBreakCommand() {
623     document.execCommand("InsertLineBreak");
624     debugForDumpAsText("execInsertLineBreakCommand");
625 }
626 function insertLineBreakCommand() {
627     if (commandDelay > 0) {
628         queueCommand(execInsertLineBreakCommand, commandCount * commandDelay);
629         commandCount++;
630     }
631     else {
632         execInsertLineBreakCommand();
633     }
634 }
635
636 //-------------------------------------------------------------------------------------------------------
637  
638 function execInsertParagraphCommand() {
639     document.execCommand("InsertParagraph");
640     debugForDumpAsText("execInsertParagraphCommand");
641 }
642 function insertParagraphCommand() {
643     if (commandDelay > 0) {
644         queueCommand(execInsertParagraphCommand, commandCount * commandDelay);
645         commandCount++;
646     }
647     else {
648         execInsertParagraphCommand();
649     }
650 }
651
652 //-------------------------------------------------------------------------------------------------------
653
654 function execInsertNewlineInQuotedContentCommand() {
655     document.execCommand("InsertNewlineInQuotedContent");
656     debugForDumpAsText("execInsertNewlineInQuotedContentCommand");
657 }
658 function insertNewlineInQuotedContentCommand() {
659     if (commandDelay > 0) {
660         queueCommand(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
661         commandCount++;
662     }
663     else {
664         execInsertNewlineInQuotedContentCommand();
665     }
666 }
667
668 //-------------------------------------------------------------------------------------------------------
669
670 function execTypeCharacterCommand(c) {
671     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
672         c = 'x';
673     document.execCommand("InsertText", false, c);
674     debugForDumpAsText("execTypeCharacterCommand");
675 }
676 function typeCharacterCommand(c) {
677     if (commandDelay > 0) {
678         queueCommand(execTypeCharacterCommand.bind(execTypeCharacterCommand, c), commandCount * commandDelay);
679         commandCount++;
680     }
681     else {
682         execTypeCharacterCommand(c);
683     }
684 }
685
686 //-------------------------------------------------------------------------------------------------------
687
688 function execSelectAllCommand() {
689     document.execCommand("SelectAll");
690 }
691 function selectAllCommand() {
692     if (commandDelay > 0) {
693         queueCommand(execSelectAllCommand, commandCount * commandDelay);
694         commandCount++;
695     }
696     else {
697         execSelectAllCommand();
698     }
699 }
700
701 //-------------------------------------------------------------------------------------------------------
702
703 function execStrikethroughCommand() {
704     document.execCommand("Strikethrough");
705     debugForDumpAsText("execStrikethroughCommand");
706 }
707 function strikethroughCommand() {
708     if (commandDelay > 0) {
709         queueCommand(execStrikethroughCommand, commandCount * commandDelay);
710         commandCount++;
711     }
712     else {
713         execStrikethroughCommand();
714     }
715 }
716
717 //-------------------------------------------------------------------------------------------------------
718
719 function execUndoCommand() {
720     document.execCommand("Undo");
721     debugForDumpAsText("execUndoCommand");
722 }
723 function undoCommand() {
724     if (commandDelay > 0) {
725         queueCommand(execUndoCommand, commandCount * commandDelay);
726         commandCount++;
727     }
728     else {
729         execUndoCommand();
730     }
731 }
732
733 //-------------------------------------------------------------------------------------------------------
734
735 function execRedoCommand() {
736     document.execCommand("Redo");
737     debugForDumpAsText("execRedoCommand");
738 }
739 function redoCommand() {
740     if (commandDelay > 0) {
741         queueCommand(execRedoCommand, commandCount * commandDelay);
742         commandCount++;
743     }
744     else {
745         execRedoCommand();
746     }
747 }
748
749 //-------------------------------------------------------------------------------------------------------
750
751 function execChangeRootSize() {
752     document.getElementById("root").style.width = "600px";
753 }
754 function changeRootSize() {
755     if (commandDelay > 0) {
756         queueCommand(execChangeRootSize, commandCount * commandDelay);
757         commandCount++;
758     }
759     else {
760         execChangeRootSize();
761     }
762 }
763
764 //-------------------------------------------------------------------------------------------------------
765
766 function execCutCommand() {
767     document.execCommand("Cut");
768     debugForDumpAsText("execCutCommand");
769 }
770 function cutCommand() {
771     if (commandDelay > 0) {
772         queueCommand(execCutCommand, commandCount * commandDelay);
773         commandCount++;
774     }
775     else {
776         execCutCommand();
777     }
778 }
779
780 //-------------------------------------------------------------------------------------------------------
781
782 function execCopyCommand() {
783     document.execCommand("Copy");
784     debugForDumpAsText("execCopyCommand");
785 }
786 function copyCommand() {
787     if (commandDelay > 0) {
788         queueCommand(execCopyCommand, commandCount * commandDelay);
789         commandCount++;
790     }
791     else {
792         execCopyCommand();
793     }
794 }
795
796 //-------------------------------------------------------------------------------------------------------
797
798 function execPasteCommand() {
799     document.execCommand("Paste");
800     debugForDumpAsText("execPasteCommand");
801 }
802 function pasteCommand() {
803     if (commandDelay > 0) {
804         queueCommand(execPasteCommand, commandCount * commandDelay);
805         commandCount++;
806     }
807     else {
808         execPasteCommand();
809     }
810 }
811
812 //-------------------------------------------------------------------------------------------------------
813
814 function execCreateLinkCommand(url) {
815     document.execCommand("CreateLink", false, url);
816     debugForDumpAsText("execCreateLinkCommand");
817 }
818 function createLinkCommand(url) {
819     if (commandDelay > 0) {
820         queueCommand(execCreateLinkCommand.bind(execCreateLinkCommand, url), commandCount * commandDelay);
821         commandCount++;
822     } else
823         execCreateLinkCommand(url);
824 }
825
826 //-------------------------------------------------------------------------------------------------------
827
828 function execUnlinkCommand() {
829     document.execCommand("Unlink");
830     debugForDumpAsText("execUnlinkCommand");
831 }
832 function unlinkCommand() {
833     if (commandDelay > 0) {
834         queueCommand(execUnlinkCommand, commandCount * commandDelay);
835         commandCount++;
836     } else
837         execUnlinkCommand();
838 }
839
840 //-------------------------------------------------------------------------------------------------------
841
842 function execPasteAndMatchStyleCommand() {
843     document.execCommand("PasteAndMatchStyle");
844     debugForDumpAsText("execPasteAndMatchStyleCommand");
845 }
846 function pasteAndMatchStyleCommand() {
847     if (commandDelay > 0) {
848         queueCommand(execPasteAndMatchStyleCommand, commandCount * commandDelay);
849         commandCount++;
850     }
851     else {
852         execPasteAndMatchStyleCommand();
853     }
854 }
855
856 //-------------------------------------------------------------------------------------------------------
857
858 function execDeleteCommand() {
859     document.execCommand("Delete");
860     debugForDumpAsText("execDeleteCommand");
861 }
862 function deleteCommand() {
863     if (commandDelay > 0) {
864         queueCommand(execDeleteCommand, commandCount * commandDelay);
865         commandCount++;
866     }
867     else {
868         execDeleteCommand();
869     }
870 }
871
872 //-------------------------------------------------------------------------------------------------------
873
874 function execForwardDeleteCommand() {
875     document.execCommand("ForwardDelete");
876     debugForDumpAsText("execForwardDeleteCommand");
877 }
878 function forwardDeleteCommand() {
879     if (commandDelay > 0) {
880         queueCommand(execForwardDeleteCommand, commandCount * commandDelay);
881         commandCount++;
882     }
883     else {
884         execForwardDeleteCommand();
885     }
886 }
887
888 //-------------------------------------------------------------------------------------------------------
889
890 (function () {
891     var queue = [];
892     var i = 0;
893     var timer;
894
895     function queueCommand(callback) {
896         queue.push(callback);
897         if (!timer) {
898             if (window.testRunner)
899                 testRunner.waitUntilDone();
900             timer = setTimeout(runCommand, commandDelay);
901         }
902     }
903
904     function runCommand() {
905         queue[i]();
906         i++;
907         if (i < queue.length)
908             setTimeout(runCommand, commandDelay);
909         else if (window.testRunner)
910             testRunner.notifyDone();
911     }
912     
913     window.queueCommand = queueCommand;
914 })();
915
916 function runEditingTest() {
917     runEditingTestWithCallbackLogging(true);
918 }
919
920 function runEditingTestWithCallbackLogging(enableCallbackLogging) {
921     if (window.testRunner && enableCallbackLogging)
922         testRunner.dumpEditingCallbacks();
923
924     var elem = document.getElementById("test");
925     var selection = window.getSelection();
926     selection.setPosition(elem, 0);
927     
928     const result = editingTest();
929  
930     if (result instanceof Promise) {
931         if (window.testRunner)
932             testRunner.waitUntilDone();
933         result.then(() => {
934             if (window.testRunner)
935                 testRunner.notifyDone();
936         });
937     }
938 }
939
940 var dumpAsText = false;
941 var elementsForDumpingMarkupList = [document.createElement('ol')];
942
943 function runDumpAsTextEditingTest(enableCallbacks) {
944     if (window.testRunner) {
945          testRunner.dumpAsText();
946          if (enableCallbacks)
947             testRunner.dumpEditingCallbacks();
948      }
949
950     dumpAsText = true;
951
952     var elem = document.getElementById("test");
953     var selection = window.getSelection();
954     selection.setPosition(elem, 0);
955     const result = editingTest();
956
957     const postTask = () => {
958         for (var i = 0; i < elementsForDumpingMarkupList.length; i++)
959             document.body.appendChild(elementsForDumpingMarkupList[i]);
960     }
961
962     if (result instanceof Promise) {
963         if (window.testRunner)
964             testRunner.waitUntilDone();
965         result.then(() => {
966             postTask();
967             if (window.testRunner)
968                 testRunner.notifyDone();
969         });
970     } else
971         postTask();
972 }
973
974 function debugForDumpAsText(name) {
975     if (dumpAsText && document.getElementById("root")) {
976         var newItem = document.createElement('li');
977         newItem.appendChild(document.createTextNode(name+": "+document.getElementById("root").innerHTML));
978         elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].appendChild(newItem);
979     }
980 }
981
982 function startNewMarkupGroup(label) {
983     if (!elementsForDumpingMarkupList[elementsForDumpingMarkupList.length - 1].hasChildNodes())
984         elementsForDumpingMarkupList.pop();
985     elementsForDumpingMarkupList.push(document.createElement('br'));
986     elementsForDumpingMarkupList.push(document.createTextNode(label));
987     elementsForDumpingMarkupList.push(document.createElement('ol'));
988 }
989
990 //-------------------------------------------------------------------------------------------------------
991
992
993 function execBackColorCommand() {
994     document.execCommand("BackColor", false, "Chartreuse");
995     debugForDumpAsText('execBackColorCommand');
996 }
997 function backColorCommand() {
998     if (commandDelay > 0) {
999         queueCommand(execBackColorCommand, commandCount * commandDelay);
1000         commandCount++;
1001     }
1002     else {
1003         execBackColorCommand();
1004     }
1005 }
1006
1007
1008 function execForeColorCommand(color) {
1009     document.execCommand("ForeColor", false, color);
1010     debugForDumpAsText('execForeColorCommand');
1011 }
1012 function foreColorCommand(color) {
1013     if (commandDelay > 0) {
1014         queueCommand(execForeColorCommand.bind(execForeColorCommand, color), commandCount * commandDelay);
1015         commandCount++;
1016     } else
1017         execForeColorCommand(color);
1018 }
1019
1020 //-------------------------------------------------------------------------------------------------------
1021
1022
1023 function runCommand(command, arg1, arg2) {
1024     document.execCommand(command,arg1,arg2);
1025 }
1026
1027 function executeCommand(command,arg1,arg2) {
1028     if (commandDelay > 0) {
1029         queueCommand(runCommand, commandCount * commandDelay);
1030         commandCount++;
1031     }
1032     else {
1033         runCommand(command,arg1,arg2);
1034     }
1035 }
1036