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 execFontNameCommand() {
208     document.execCommand("FontName", false, "Courier");
209 }
210 function fontNameCommand() {
211     if (commandDelay > 0) {
212         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
213         commandCount++;
214     }
215     else {
216         execFontNameCommand();
217     }
218 }
219
220 //-------------------------------------------------------------------------------------------------------
221
222 function execFontSizeCommand(s) {
223     if (arguments.length == 0 || s == undefined || s.length == 0)
224         s = '12px';
225     document.execCommand("FontSize", false, s);
226 }
227 function fontSizeCommand(s) {
228     if (commandDelay > 0) {
229         window.setTimeout(execFontSizeCommand, commandCount * commandDelay, s);
230         commandCount++;
231     }
232     else {
233         execFontSizeCommand(s);
234     }
235 }
236
237 //-------------------------------------------------------------------------------------------------------
238
239 function execFontSizeDeltaCommand(s) {
240     if (arguments.length == 0 || s == undefined || s.length == 0)
241         s = '1px';
242     document.execCommand("FontSizeDelta", false, s);
243 }
244 function fontSizeDeltaCommand(s) {
245     if (commandDelay > 0) {
246         window.setTimeout(execFontSizeDeltaCommand, commandCount * commandDelay, s);
247         commandCount++;
248     }
249     else {
250         execFontSizeDeltaCommand(s);
251     }
252 }
253
254 //-------------------------------------------------------------------------------------------------------
255
256 function execItalicCommand() {
257     document.execCommand("Italic");
258 }
259 function italicCommand() {
260     if (commandDelay > 0) {
261         window.setTimeout(execItalicCommand, commandCount * commandDelay);
262         commandCount++;
263     }
264     else {
265         execItalicCommand();
266     }
267 }
268
269
270 //-------------------------------------------------------------------------------------------------------
271
272 function execJustifyCenterCommand() {
273     document.execCommand("JustifyCenter");
274 }
275 function justifyCenterCommand() {
276     if (commandDelay > 0) {
277         window.setTimeout(execJustifyCenterCommand, commandCount * commandDelay);
278         commandCount++;
279     }
280     else {
281         execJustifyCenterCommand();
282     }
283 }
284
285
286 //-------------------------------------------------------------------------------------------------------
287
288 function execJustifyLeftCommand() {
289     document.execCommand("JustifyLeft");
290 }
291 function justifyLeftCommand() {
292     if (commandDelay > 0) {
293         window.setTimeout(execJustifyLeftCommand, commandCount * commandDelay);
294         commandCount++;
295     }
296     else {
297         execJustifyLeftCommand();
298     }
299 }
300
301
302 //-------------------------------------------------------------------------------------------------------
303
304 function execJustifyRightCommand() {
305     document.execCommand("JustifyRight");
306 }
307 function justifyRightCommand() {
308     if (commandDelay > 0) {
309         window.setTimeout(execJustifyRightCommand, commandCount * commandDelay);
310         commandCount++;
311     }
312     else {
313         execJustifyRightCommand();
314     }
315 }
316
317
318 //-------------------------------------------------------------------------------------------------------
319
320 function execInsertLineBreakCommand() {
321     document.execCommand("InsertLineBreak");
322 }
323 function insertLineBreakCommand() {
324     if (commandDelay > 0) {
325         window.setTimeout(execInsertLineBreakCommand, commandCount * commandDelay);
326         commandCount++;
327     }
328     else {
329         execInsertLineBreakCommand();
330     }
331 }
332
333 //-------------------------------------------------------------------------------------------------------
334  
335 function execInsertParagraphCommand() {
336     document.execCommand("InsertParagraph");
337 }
338 function insertParagraphCommand() {
339     if (commandDelay > 0) {
340         window.setTimeout(execInsertParagraphCommand, commandCount * commandDelay);
341         commandCount++;
342     }
343     else {
344         execInsertParagraphCommand();
345     }
346 }
347
348 //-------------------------------------------------------------------------------------------------------
349
350 function execTypeCharacterCommand(c) {
351     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
352         c = 'x';
353     document.execCommand("InsertText", false, c);
354 }
355 function typeCharacterCommand(c) {
356     if (commandDelay > 0) {
357         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay, c);
358         commandCount++;
359     }
360     else {
361         execTypeCharacterCommand(c);
362     }
363 }
364
365 //-------------------------------------------------------------------------------------------------------
366
367 function execSelectAllCommand() {
368     document.execCommand("SelectAll");
369 }
370 function selectAllCommand() {
371     if (commandDelay > 0) {
372         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
373         commandCount++;
374     }
375     else {
376         execSelectAllCommand();
377     }
378 }
379
380 //-------------------------------------------------------------------------------------------------------
381
382 function execUndoCommand() {
383     document.execCommand("Undo");
384 }
385 function undoCommand() {
386     if (commandDelay > 0) {
387         window.setTimeout(execUndoCommand, commandCount * commandDelay);
388         commandCount++;
389     }
390     else {
391         execUndoCommand();
392     }
393 }
394
395 //-------------------------------------------------------------------------------------------------------
396
397 function execRedoCommand() {
398     document.execCommand("Redo");
399 }
400 function redoCommand() {
401     if (commandDelay > 0) {
402         window.setTimeout(execRedoCommand, commandCount * commandDelay);
403         commandCount++;
404     }
405     else {
406         execRedoCommand();
407     }
408 }
409
410 //-------------------------------------------------------------------------------------------------------
411
412 function execChangeRootSize() {
413     document.getElementById("root").style.width = "600px";
414 }
415 function changeRootSize() {
416     if (commandDelay > 0) {
417         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
418         commandCount++;
419     }
420     else {
421         execChangeRootSize();
422     }
423 }
424
425 //-------------------------------------------------------------------------------------------------------
426
427 function execCutCommand() {
428     document.execCommand("Cut");
429 }
430 function cutCommand() {
431     if (commandDelay > 0) {
432         window.setTimeout(execCutCommand, commandCount * commandDelay);
433         commandCount++;
434     }
435     else {
436         execCutCommand();
437     }
438 }
439
440 //-------------------------------------------------------------------------------------------------------
441
442 function execCopyCommand() {
443     document.execCommand("Copy");
444 }
445 function copyCommand() {
446     if (commandDelay > 0) {
447         window.setTimeout(execCopyCommand, commandCount * commandDelay);
448         commandCount++;
449     }
450     else {
451         execCopyCommand();
452     }
453 }
454
455 //-------------------------------------------------------------------------------------------------------
456
457 function execPasteCommand() {
458     document.execCommand("Paste");
459 }
460 function pasteCommand() {
461     if (commandDelay > 0) {
462         window.setTimeout(execPasteCommand, commandCount * commandDelay);
463         commandCount++;
464     }
465     else {
466         execPasteCommand();
467     }
468 }
469
470 //-------------------------------------------------------------------------------------------------------
471
472 function execDeleteCommand() {
473     document.execCommand("Delete");
474 }
475 function deleteCommand() {
476     if (commandDelay > 0) {
477         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
478         commandCount++;
479     }
480     else {
481         execDeleteCommand();
482     }
483 }
484
485 //-------------------------------------------------------------------------------------------------------
486
487 function runEditingTest() {
488     var elem = document.getElementById("test");
489     var selection = window.getSelection();
490     selection.setPosition(elem, 0);
491     editingTest();
492 }
493
494 //-------------------------------------------------------------------------------------------------------
495
496
497 function execBackColorCommand() {
498     document.execCommand("BackColor", false, "Chartreuse");
499 }
500 function backColorCommand() {
501     if (commandDelay > 0) {
502         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
503         commandCount++;
504     }
505     else {
506         execBackColorCommand();
507     }
508 }
509
510 //-------------------------------------------------------------------------------------------------------
511
512
513 function runCommand(command, arg1, arg2) {
514     document.execCommand(command,arg1,arg2);
515 }
516
517 function executeCommand(command,arg1,arg2) {
518     if (commandDelay > 0) {
519         window.setTimeout(runCommand, commandCount * commandDelay);
520         commandCount++;
521     }
522     else {
523         runCommand(command,arg1,arg2);
524     }
525 }
526