LayoutTests:
[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 function setSelectionCommand(sn, so, en, eo) {
16     if (commandDelay > 0) {
17         window.setTimeout(execSetSelectionCommand, commandCount * commandDelay, sn, so, en, eo);
18         commandCount++;
19     } else
20         execSetSelectionCommand(sn, so, en, eo);
21 }
22
23 //-------------------------------------------------------------------------------------------------------
24
25 function execTransposeCharactersCommand() {
26     document.execCommand("Transpose");
27 }
28 function transposeCharactersCommand() {
29     if (commandDelay > 0) {
30         window.setTimeout(execTransposeCharactersCommand, commandCount * commandDelay);
31         commandCount++;
32     }
33     else {
34         execTransposeCharactersCommand();
35     }
36 }
37
38 //-------------------------------------------------------------------------------------------------------
39
40 function execMoveSelectionForwardByCharacterCommand() {
41     selection.modify("move", "forward", "character");
42 }
43 function moveSelectionForwardByCharacterCommand() {
44     if (commandDelay > 0) {
45         window.setTimeout(execMoveSelectionForwardByCharacterCommand, commandCount * commandDelay);
46         commandCount++;
47     }
48     else {
49         execMoveSelectionForwardByCharacterCommand();
50     }
51 }
52
53 //-------------------------------------------------------------------------------------------------------
54
55 function execExtendSelectionForwardByCharacterCommand() {
56     selection.modify("extend", "forward", "character");
57 }
58 function extendSelectionForwardByCharacterCommand() {
59     if (commandDelay > 0) {
60         window.setTimeout(execExtendSelectionForwardByCharacterCommand, commandCount * commandDelay);
61         commandCount++;
62     }
63     else {
64         execExtendSelectionForwardByCharacterCommand();
65     }
66 }
67
68 //-------------------------------------------------------------------------------------------------------
69
70 function execMoveSelectionForwardByWordCommand() {
71     selection.modify("move", "forward", "word");
72 }
73 function moveSelectionForwardByWordCommand() {
74     if (commandDelay > 0) {
75         window.setTimeout(execMoveSelectionForwardByWordCommand, commandCount * commandDelay);
76         commandCount++;
77     }
78     else {
79         execMoveSelectionForwardByWordCommand();
80     }
81 }
82
83 //-------------------------------------------------------------------------------------------------------
84
85 function execExtendSelectionForwardByWordCommand() {
86     selection.modify("extend", "forward", "word");
87 }
88 function extendSelectionForwardByWordCommand() {
89     if (commandDelay > 0) {
90         window.setTimeout(execExtendSelectionForwardByWordCommand, commandCount * commandDelay);
91         commandCount++;
92     }
93     else {
94         execExtendSelectionForwardByWordCommand();
95     }
96 }
97
98 //-------------------------------------------------------------------------------------------------------
99
100 function execMoveSelectionForwardBySentenceCommand() {
101     selection.modify("move", "forward", "sentence");
102 }
103 function moveSelectionForwardBySentenceCommand() {
104     if (commandDelay > 0) {
105         window.setTimeout(execMoveSelectionForwardBySentenceCommand, commandCount * commandDelay);
106         commandCount++;
107     }
108     else {
109         execMoveSelectionForwardBySentenceCommand();
110     }
111 }
112
113 //-------------------------------------------------------------------------------------------------------
114
115 function execExtendSelectionForwardBySentenceCommand() {
116     selection.modify("extend", "forward", "sentence");
117 }
118 function extendSelectionForwardBySentenceCommand() {
119     if (commandDelay > 0) {
120         window.setTimeout(execExtendSelectionForwardBySentenceCommand, commandCount * commandDelay);
121         commandCount++;
122     }
123     else {
124         execExtendSelectionForwardBySentenceCommand();
125     }
126 }
127
128 //-------------------------------------------------------------------------------------------------------
129
130 function execMoveSelectionForwardByLineCommand() {
131     selection.modify("move", "forward", "line");
132 }
133 function moveSelectionForwardByLineCommand() {
134     if (commandDelay > 0) {
135         window.setTimeout(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
136         commandCount++;
137     }
138     else {
139         execMoveSelectionForwardByLineCommand();
140     }
141 }
142
143 //-------------------------------------------------------------------------------------------------------
144
145 function execExtendSelectionForwardByLineCommand() {
146     selection.modify("extend", "forward", "line");
147 }
148 function extendSelectionForwardByLineCommand() {
149     if (commandDelay > 0) {
150         window.setTimeout(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
151         commandCount++;
152     }
153     else {
154         execExtendSelectionForwardByLineCommand();
155     }
156 }
157
158 //-------------------------------------------------------------------------------------------------------
159
160 function execMoveSelectionBackwardByCharacterCommand() {
161     selection.modify("move", "backward", "character");
162 }
163 function moveSelectionBackwardByCharacterCommand() {
164     if (commandDelay > 0) {
165         window.setTimeout(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
166         commandCount++;
167     }
168     else {
169         execMoveSelectionBackwardByCharacterCommand();
170     }
171 }
172
173 //-------------------------------------------------------------------------------------------------------
174
175 function execExtendSelectionBackwardByCharacterCommand() {
176     selection.modify("extend", "backward", "character");
177 }
178 function extendSelectionBackwardByCharacterCommand() {
179     if (commandDelay > 0) {
180         window.setTimeout(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
181         commandCount++;
182     }
183     else {
184         execExtendSelectionBackwardByCharacterCommand();
185     }
186 }
187
188 //-------------------------------------------------------------------------------------------------------
189
190 function execMoveSelectionBackwardByWordCommand() {
191     selection.modify("move", "backward", "word");
192 }
193 function moveSelectionBackwardByWordCommand() {
194     if (commandDelay > 0) {
195         window.setTimeout(execMoveSelectionBackwardByWordCommand, commandCount * commandDelay);
196         commandCount++;
197     }
198     else {
199         execMoveSelectionBackwardByWordCommand();
200     }
201 }
202
203 //-------------------------------------------------------------------------------------------------------
204
205 function execExtendSelectionBackwardByWordCommand() {
206     selection.modify("extend", "backward", "word");
207 }
208 function extendSelectionBackwardByWordCommand() {
209     if (commandDelay > 0) {
210         window.setTimeout(execExtendSelectionBackwardByWordCommand, commandCount * commandDelay);
211         commandCount++;
212     }
213     else {
214         execExtendSelectionBackwardByWordCommand();
215     }
216 }
217
218 //-------------------------------------------------------------------------------------------------------
219
220 function execMoveSelectionBackwardBySentenceCommand() {
221     selection.modify("move", "backward", "sentence");
222 }
223 function moveSelectionBackwardBySentenceCommand() {
224     if (commandDelay > 0) {
225         window.setTimeout(execMoveSelectionBackwardBySentenceCommand, commandCount * commandDelay);
226         commandCount++;
227     }
228     else {
229         execMoveSelectionBackwardBySentenceCommand();
230     }
231 }
232
233 //-------------------------------------------------------------------------------------------------------
234
235 function execExtendSelectionBackwardBySentenceCommand() {
236     selection.modify("extend", "backward", "sentence");
237 }
238 function extendSelectionBackwardBySentenceCommand() {
239     if (commandDelay > 0) {
240         window.setTimeout(execExtendSelectionBackwardBySentenceCommand, commandCount * commandDelay);
241         commandCount++;
242     }
243     else {
244         execExtendSelectionBackwardBySentenceCommand();
245     }
246 }
247
248 //-------------------------------------------------------------------------------------------------------
249
250 function execMoveSelectionBackwardByLineCommand() {
251     selection.modify("move", "backward", "line");
252 }
253 function moveSelectionBackwardByLineCommand() {
254     if (commandDelay > 0) {
255         window.setTimeout(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
256         commandCount++;
257     }
258     else {
259         execMoveSelectionBackwardByLineCommand();
260     }
261 }
262
263 //-------------------------------------------------------------------------------------------------------
264
265 function execExtendSelectionBackwardByLineCommand() {
266     selection.modify("extend", "backward", "line");
267 }
268 function extendSelectionBackwardByLineCommand() {
269     if (commandDelay > 0) {
270         window.setTimeout(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
271         commandCount++;
272     }
273     else {
274         execExtendSelectionBackwardByLineCommand();
275     }
276 }
277
278 //-------------------------------------------------------------------------------------------------------
279
280 function execBoldCommand() {
281     document.execCommand("Bold");
282 }
283 function boldCommand() {
284     if (commandDelay > 0) {
285         window.setTimeout(execBoldCommand, commandCount * commandDelay);
286         commandCount++;
287     }
288     else {
289         execBoldCommand();
290     }
291 }
292
293 //-------------------------------------------------------------------------------------------------------
294
295 function execUnderlineCommand() {
296     document.execCommand("Underline");
297 }
298 function underlineCommand() {
299     if (commandDelay > 0) {
300         window.setTimeout(execUnderlineCommand, commandCount * commandDelay);
301         commandCount++;
302     }
303     else {
304         execUnderlineCommand();
305     }
306 }
307
308 //-------------------------------------------------------------------------------------------------------
309
310 function execFontNameCommand() {
311     document.execCommand("FontName", false, "Courier");
312 }
313 function fontNameCommand() {
314     if (commandDelay > 0) {
315         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
316         commandCount++;
317     }
318     else {
319         execFontNameCommand();
320     }
321 }
322
323 //-------------------------------------------------------------------------------------------------------
324
325 function execFontSizeCommand(s) {
326     if (arguments.length == 0 || s == undefined || s.length == 0)
327         s = '12px';
328     document.execCommand("FontSize", false, s);
329 }
330 function fontSizeCommand(s) {
331     if (commandDelay > 0) {
332         window.setTimeout(execFontSizeCommand, commandCount * commandDelay, s);
333         commandCount++;
334     }
335     else {
336         execFontSizeCommand(s);
337     }
338 }
339
340 //-------------------------------------------------------------------------------------------------------
341
342 function execFontSizeDeltaCommand(s) {
343     if (arguments.length == 0 || s == undefined || s.length == 0)
344         s = '1px';
345     document.execCommand("FontSizeDelta", false, s);
346 }
347 function fontSizeDeltaCommand(s) {
348     if (commandDelay > 0) {
349         window.setTimeout(execFontSizeDeltaCommand, commandCount * commandDelay, s);
350         commandCount++;
351     }
352     else {
353         execFontSizeDeltaCommand(s);
354     }
355 }
356
357 //-------------------------------------------------------------------------------------------------------
358
359 function execItalicCommand() {
360     document.execCommand("Italic");
361 }
362 function italicCommand() {
363     if (commandDelay > 0) {
364         window.setTimeout(execItalicCommand, commandCount * commandDelay);
365         commandCount++;
366     }
367     else {
368         execItalicCommand();
369     }
370 }
371
372
373 //-------------------------------------------------------------------------------------------------------
374
375 function execJustifyCenterCommand() {
376     document.execCommand("JustifyCenter");
377 }
378 function justifyCenterCommand() {
379     if (commandDelay > 0) {
380         window.setTimeout(execJustifyCenterCommand, commandCount * commandDelay);
381         commandCount++;
382     }
383     else {
384         execJustifyCenterCommand();
385     }
386 }
387
388
389 //-------------------------------------------------------------------------------------------------------
390
391 function execJustifyLeftCommand() {
392     document.execCommand("JustifyLeft");
393 }
394 function justifyLeftCommand() {
395     if (commandDelay > 0) {
396         window.setTimeout(execJustifyLeftCommand, commandCount * commandDelay);
397         commandCount++;
398     }
399     else {
400         execJustifyLeftCommand();
401     }
402 }
403
404
405 //-------------------------------------------------------------------------------------------------------
406
407 function execJustifyRightCommand() {
408     document.execCommand("JustifyRight");
409 }
410 function justifyRightCommand() {
411     if (commandDelay > 0) {
412         window.setTimeout(execJustifyRightCommand, commandCount * commandDelay);
413         commandCount++;
414     }
415     else {
416         execJustifyRightCommand();
417     }
418 }
419
420 //-------------------------------------------------------------------------------------------------------
421
422 function execInsertHTMLCommand(html) {
423     document.execCommand("InsertHTML", false, html);
424 }
425 function insertHTMLCommand(html) {
426     if (commandDelay > 0) {
427         window.setTimeout(execInsertHTMLCommand, commandCount * commandDelay, html);
428         commandCount++;
429     }
430     else {
431         execInsertHTMLCommand(html);
432     }
433 }
434
435 //-------------------------------------------------------------------------------------------------------
436
437 function execInsertImageCommand(imgSrc) {
438     document.execCommand("InsertImage", false, imgSrc);
439 }
440 function insertImageCommand(imgSrc) {
441     if (commandDelay > 0) {
442         window.setTimeout(execInsertImageCommand, commandCount * commandDelay, imgSrc);
443         commandCount++;
444     }
445     else {
446         execInsertImageCommand(imgSrc);
447     }
448 }
449
450 //-------------------------------------------------------------------------------------------------------
451
452 function execInsertLineBreakCommand() {
453     document.execCommand("InsertLineBreak");
454 }
455 function insertLineBreakCommand() {
456     if (commandDelay > 0) {
457         window.setTimeout(execInsertLineBreakCommand, commandCount * commandDelay);
458         commandCount++;
459     }
460     else {
461         execInsertLineBreakCommand();
462     }
463 }
464
465 //-------------------------------------------------------------------------------------------------------
466  
467 function execInsertParagraphCommand() {
468     document.execCommand("InsertParagraph");
469 }
470 function insertParagraphCommand() {
471     if (commandDelay > 0) {
472         window.setTimeout(execInsertParagraphCommand, commandCount * commandDelay);
473         commandCount++;
474     }
475     else {
476         execInsertParagraphCommand();
477     }
478 }
479
480 //-------------------------------------------------------------------------------------------------------
481
482 function execInsertNewlineInQuotedContentCommand() {
483     document.execCommand("InsertNewlineInQuotedContent");
484 }
485 function insertNewlineInQuotedContentCommand() {
486     if (commandDelay > 0) {
487         window.setTimeout(execInsertNewlineInQuotedContentCommand, commandCount * commandDelay);
488         commandCount++;
489     }
490     else {
491         execInsertNewlineInQuotedContentCommand();
492     }
493 }
494
495 //-------------------------------------------------------------------------------------------------------
496
497 function execTypeCharacterCommand(c) {
498     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
499         c = 'x';
500     document.execCommand("InsertText", false, c);
501 }
502 function typeCharacterCommand(c) {
503     if (commandDelay > 0) {
504         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay, c);
505         commandCount++;
506     }
507     else {
508         execTypeCharacterCommand(c);
509     }
510 }
511
512 //-------------------------------------------------------------------------------------------------------
513
514 function execSelectAllCommand() {
515     document.execCommand("SelectAll");
516 }
517 function selectAllCommand() {
518     if (commandDelay > 0) {
519         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
520         commandCount++;
521     }
522     else {
523         execSelectAllCommand();
524     }
525 }
526
527 //-------------------------------------------------------------------------------------------------------
528
529 function execStrikethroughCommand() {
530     document.execCommand("Strikethrough");
531 }
532 function strikethroughCommand() {
533     if (commandDelay > 0) {
534         window.setTimeout(execStrikethroughCommand, commandCount * commandDelay);
535         commandCount++;
536     }
537     else {
538         execStrikethroughCommand();
539     }
540 }
541
542 //-------------------------------------------------------------------------------------------------------
543
544 function execUndoCommand() {
545     document.execCommand("Undo");
546 }
547 function undoCommand() {
548     if (commandDelay > 0) {
549         window.setTimeout(execUndoCommand, commandCount * commandDelay);
550         commandCount++;
551     }
552     else {
553         execUndoCommand();
554     }
555 }
556
557 //-------------------------------------------------------------------------------------------------------
558
559 function execRedoCommand() {
560     document.execCommand("Redo");
561 }
562 function redoCommand() {
563     if (commandDelay > 0) {
564         window.setTimeout(execRedoCommand, commandCount * commandDelay);
565         commandCount++;
566     }
567     else {
568         execRedoCommand();
569     }
570 }
571
572 //-------------------------------------------------------------------------------------------------------
573
574 function execChangeRootSize() {
575     document.getElementById("root").style.width = "600px";
576 }
577 function changeRootSize() {
578     if (commandDelay > 0) {
579         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
580         commandCount++;
581     }
582     else {
583         execChangeRootSize();
584     }
585 }
586
587 //-------------------------------------------------------------------------------------------------------
588
589 function execCutCommand() {
590     document.execCommand("Cut");
591 }
592 function cutCommand() {
593     if (commandDelay > 0) {
594         window.setTimeout(execCutCommand, commandCount * commandDelay);
595         commandCount++;
596     }
597     else {
598         execCutCommand();
599     }
600 }
601
602 //-------------------------------------------------------------------------------------------------------
603
604 function execCopyCommand() {
605     document.execCommand("Copy");
606 }
607 function copyCommand() {
608     if (commandDelay > 0) {
609         window.setTimeout(execCopyCommand, commandCount * commandDelay);
610         commandCount++;
611     }
612     else {
613         execCopyCommand();
614     }
615 }
616
617 //-------------------------------------------------------------------------------------------------------
618
619 function execPasteCommand() {
620     document.execCommand("Paste");
621 }
622 function pasteCommand() {
623     if (commandDelay > 0) {
624         window.setTimeout(execPasteCommand, commandCount * commandDelay);
625         commandCount++;
626     }
627     else {
628         execPasteCommand();
629     }
630 }
631
632 //-------------------------------------------------------------------------------------------------------
633
634 function execCreateLinkCommand(url) {
635     document.execCommand("CreateLink", false, url);
636 }
637 function createLinkCommand(url) {
638     if (commandDelay > 0) {
639         window.setTimeout(execCreateLinkCommand, commandCount * commandDelay, url);
640         commandCount++;
641     } else
642         execCreateLinkCommand(url);
643 }
644
645 //-------------------------------------------------------------------------------------------------------
646
647 function execUnlinkCommand() {
648     document.execCommand("Unlink");
649 }
650 function unlinkCommand() {
651     if (commandDelay > 0) {
652         window.setTimeout(execUnlinkCommand, commandCount * commandDelay);
653         commandCount++;
654     } else
655         execUnlinkCommand();
656 }
657
658 //-------------------------------------------------------------------------------------------------------
659
660 function execPasteAndMatchStyleCommand() {
661     document.execCommand("PasteAndMatchStyle");
662 }
663 function pasteAndMatchStyleCommand() {
664     if (commandDelay > 0) {
665         window.setTimeout(execPasteAndMatchStyleCommand, commandCount * commandDelay);
666         commandCount++;
667     }
668     else {
669         execPasteAndMatchStyleCommand();
670     }
671 }
672
673 //-------------------------------------------------------------------------------------------------------
674
675 function execDeleteCommand() {
676     document.execCommand("Delete");
677 }
678 function deleteCommand() {
679     if (commandDelay > 0) {
680         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
681         commandCount++;
682     }
683     else {
684         execDeleteCommand();
685     }
686 }
687
688 //-------------------------------------------------------------------------------------------------------
689
690 function execForwardDeleteCommand() {
691     document.execCommand("ForwardDelete");
692 }
693 function forwardDeleteCommand() {
694     if (commandDelay > 0) {
695         window.setTimeout(execForwardDeleteCommand, commandCount * commandDelay);
696         commandCount++;
697     }
698     else {
699         execForwardDeleteCommand();
700     }
701 }
702
703 //-------------------------------------------------------------------------------------------------------
704
705 function runEditingTest() {
706     var elem = document.getElementById("test");
707     var selection = window.getSelection();
708     selection.setPosition(elem, 0);
709     editingTest();
710 }
711
712 //-------------------------------------------------------------------------------------------------------
713
714
715 function execBackColorCommand() {
716     document.execCommand("BackColor", false, "Chartreuse");
717 }
718 function backColorCommand() {
719     if (commandDelay > 0) {
720         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
721         commandCount++;
722     }
723     else {
724         execBackColorCommand();
725     }
726 }
727
728 //-------------------------------------------------------------------------------------------------------
729
730
731 function runCommand(command, arg1, arg2) {
732     document.execCommand(command,arg1,arg2);
733 }
734
735 function executeCommand(command,arg1,arg2) {
736     if (commandDelay > 0) {
737         window.setTimeout(runCommand, commandCount * commandDelay);
738         commandCount++;
739     }
740     else {
741         runCommand(command,arg1,arg2);
742     }
743 }
744