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