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 execInsertNewlineCommand() {
273     document.execCommand("InsertNewline");
274 }
275 function insertNewlineCommand() {
276     if (commandDelay > 0) {
277         window.setTimeout(execInsertNewlineCommand, commandCount * commandDelay);
278         commandCount++;
279     }
280     else {
281         execInsertNewlineCommand();
282     }
283 }
284
285 //-------------------------------------------------------------------------------------------------------
286
287 function execTypeCharacterCommand(c) {
288     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
289         c = 'x';
290     document.execCommand("InsertText", false, c);
291 }
292 function typeCharacterCommand(c) {
293     if (commandDelay > 0) {
294         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay, c);
295         commandCount++;
296     }
297     else {
298         execTypeCharacterCommand(c);
299     }
300 }
301
302 //-------------------------------------------------------------------------------------------------------
303
304 function execSelectAllCommand() {
305     document.execCommand("SelectAll");
306 }
307 function selectAllCommand() {
308     if (commandDelay > 0) {
309         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
310         commandCount++;
311     }
312     else {
313         execSelectAllCommand();
314     }
315 }
316
317 //-------------------------------------------------------------------------------------------------------
318
319 function execUndoCommand() {
320     document.execCommand("Undo");
321 }
322 function undoCommand() {
323     if (commandDelay > 0) {
324         window.setTimeout(execUndoCommand, commandCount * commandDelay);
325         commandCount++;
326     }
327     else {
328         execUndoCommand();
329     }
330 }
331
332 //-------------------------------------------------------------------------------------------------------
333
334 function execRedoCommand() {
335     document.execCommand("Redo");
336 }
337 function redoCommand() {
338     if (commandDelay > 0) {
339         window.setTimeout(execRedoCommand, commandCount * commandDelay);
340         commandCount++;
341     }
342     else {
343         execRedoCommand();
344     }
345 }
346
347 //-------------------------------------------------------------------------------------------------------
348
349 function execChangeRootSize() {
350     document.getElementById("root").style.width = "600px";
351 }
352 function changeRootSize() {
353     if (commandDelay > 0) {
354         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
355         commandCount++;
356     }
357     else {
358         execChangeRootSize();
359     }
360 }
361
362 //-------------------------------------------------------------------------------------------------------
363
364 function execCutCommand() {
365     document.execCommand("Cut");
366 }
367 function cutCommand() {
368     if (commandDelay > 0) {
369         window.setTimeout(execCutCommand, commandCount * commandDelay);
370         commandCount++;
371     }
372     else {
373         execCutCommand();
374     }
375 }
376
377 //-------------------------------------------------------------------------------------------------------
378
379 function execCopyCommand() {
380     document.execCommand("Copy");
381 }
382 function copyCommand() {
383     if (commandDelay > 0) {
384         window.setTimeout(execCopyCommand, commandCount * commandDelay);
385         commandCount++;
386     }
387     else {
388         execCopyCommand();
389     }
390 }
391
392 //-------------------------------------------------------------------------------------------------------
393
394 function execPasteCommand() {
395     document.execCommand("Paste");
396 }
397 function pasteCommand() {
398     if (commandDelay > 0) {
399         window.setTimeout(execPasteCommand, commandCount * commandDelay);
400         commandCount++;
401     }
402     else {
403         execPasteCommand();
404     }
405 }
406
407 //-------------------------------------------------------------------------------------------------------
408
409 function execDeleteCommand() {
410     document.execCommand("Delete");
411 }
412 function deleteCommand() {
413     if (commandDelay > 0) {
414         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
415         commandCount++;
416     }
417     else {
418         execDeleteCommand();
419     }
420 }
421
422 //-------------------------------------------------------------------------------------------------------
423
424 function runEditingTest() {
425     var elem = document.getElementById("test");
426     var selection = window.getSelection();
427     selection.setPosition(elem, 0);
428     editingTest();
429 }
430
431 //-------------------------------------------------------------------------------------------------------
432
433
434 function execBackColorCommand() {
435     document.execCommand("BackColor", false, "Chartreuse");
436 }
437 function backColorCommand() {
438     if (commandDelay > 0) {
439         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
440         commandCount++;
441     }
442     else {
443         execBackColorCommand();
444     }
445 }
446
447
448 //-------------------------------------------------------------------------------------------------------
449
450
451 function execFontNameCommand() {
452     document.execCommand("FontName", false, "Courier");
453 }
454 function fontNameCommand() {
455     if (commandDelay > 0) {
456         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
457         commandCount++;
458     }
459     else {
460         execFontNameCommand();
461     }
462 }
463
464 //-------------------------------------------------------------------------------------------------------
465
466
467 function runCommand(command, arg1, arg2) {
468     document.execCommand(command,arg1,arg2);
469 }
470
471 function executeCommand(command,arg1,arg2) {
472     if (commandDelay > 0) {
473         window.setTimeout(runCommand, commandCount * commandDelay);
474         commandCount++;
475     }
476     else {
477         runCommand(command,arg1,arg2);
478     }
479 }
480