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