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