Reviewed by me
[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 execMoveSelectionForwardByLineCommand() {
43     selection.modify("move", "forward", "line");
44 }
45 function moveSelectionForwardByLineCommand() {
46     if (commandDelay > 0) {
47         window.setTimeout(execMoveSelectionForwardByLineCommand, commandCount * commandDelay);
48         commandCount++;
49     }
50     else {
51         execMoveSelectionForwardByLineCommand();
52     }
53 }
54
55 //-------------------------------------------------------------------------------------------------------
56
57 function execExtendSelectionForwardByLineCommand() {
58     selection.modify("extend", "forward", "line");
59 }
60 function extendSelectionForwardByLineCommand() {
61     if (commandDelay > 0) {
62         window.setTimeout(execExtendSelectionForwardByLineCommand, commandCount * commandDelay);
63         commandCount++;
64     }
65     else {
66         execExtendSelectionForwardByLineCommand();
67     }
68 }
69
70 //-------------------------------------------------------------------------------------------------------
71
72 function execMoveSelectionBackwardByCharacterCommand() {
73     selection.modify("move", "backward", "character");
74 }
75 function moveSelectionBackwardByCharacterCommand() {
76     if (commandDelay > 0) {
77         window.setTimeout(execMoveSelectionBackwardByCharacterCommand, commandCount * commandDelay);
78         commandCount++;
79     }
80     else {
81         execMoveSelectionBackwardByCharacterCommand();
82     }
83 }
84
85 //-------------------------------------------------------------------------------------------------------
86
87 function execExtendSelectionBackwardByCharacterCommand() {
88     selection.modify("extend", "backward", "character");
89 }
90 function extendSelectionBackwardByCharacterCommand() {
91     if (commandDelay > 0) {
92         window.setTimeout(execExtendSelectionBackwardByCharacterCommand, commandCount * commandDelay);
93         commandCount++;
94     }
95     else {
96         execExtendSelectionBackwardByCharacterCommand();
97     }
98 }
99
100 //-------------------------------------------------------------------------------------------------------
101
102 function execMoveSelectionBackwardByLineCommand() {
103     selection.modify("move", "backward", "line");
104 }
105 function moveSelectionBackwardByLineCommand() {
106     if (commandDelay > 0) {
107         window.setTimeout(execMoveSelectionBackwardByLineCommand, commandCount * commandDelay);
108         commandCount++;
109     }
110     else {
111         execMoveSelectionBackwardByLineCommand();
112     }
113 }
114
115 //-------------------------------------------------------------------------------------------------------
116
117 function execExtendSelectionBackwardByLineCommand() {
118     selection.modify("extend", "backward", "line");
119 }
120 function extendSelectionBackwardByLineCommand() {
121     if (commandDelay > 0) {
122         window.setTimeout(execExtendSelectionBackwardByLineCommand, commandCount * commandDelay);
123         commandCount++;
124     }
125     else {
126         execExtendSelectionBackwardByLineCommand();
127     }
128 }
129
130 //-------------------------------------------------------------------------------------------------------
131
132 function execBoldCommand() {
133     document.execCommand("Bold");
134 }
135 function boldCommand() {
136     if (commandDelay > 0) {
137         window.setTimeout(execBoldCommand, commandCount * commandDelay);
138         commandCount++;
139     }
140     else {
141         execBoldCommand();
142     }
143 }
144
145
146 //-------------------------------------------------------------------------------------------------------
147
148 function execItalicCommand() {
149     document.execCommand("Italic");
150 }
151 function italicCommand() {
152     if (commandDelay > 0) {
153         window.setTimeout(execItalicCommand, commandCount * commandDelay);
154         commandCount++;
155     }
156     else {
157         execItalicCommand();
158     }
159 }
160
161
162 //-------------------------------------------------------------------------------------------------------
163
164 function execInsertNewlineCommand() {
165     document.execCommand("InsertNewline");
166 }
167 function insertNewlineCommand() {
168     if (commandDelay > 0) {
169         window.setTimeout(execInsertNewlineCommand, commandCount * commandDelay);
170         commandCount++;
171     }
172     else {
173         execInsertNewlineCommand();
174     }
175 }
176
177 //-------------------------------------------------------------------------------------------------------
178
179 function execTypeCharacterCommand(c) {
180     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
181         c = 'x';
182     document.execCommand("InsertText", false, c);
183 }
184 function typeCharacterCommand(c) {
185     if (commandDelay > 0) {
186         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay);
187         commandCount++;
188     }
189     else {
190         execTypeCharacterCommand(c);
191     }
192 }
193
194 //-------------------------------------------------------------------------------------------------------
195
196 function execSelectAllCommand() {
197     document.execCommand("SelectAll");
198 }
199 function selectAllCommand() {
200     if (commandDelay > 0) {
201         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
202         commandCount++;
203     }
204     else {
205         execSelectAllCommand();
206     }
207 }
208
209 //-------------------------------------------------------------------------------------------------------
210
211 function execUndoCommand() {
212     document.execCommand("Undo");
213 }
214 function undoCommand() {
215     if (commandDelay > 0) {
216         window.setTimeout(execUndoCommand, commandCount * commandDelay);
217         commandCount++;
218     }
219     else {
220         execUndoCommand();
221     }
222 }
223
224 //-------------------------------------------------------------------------------------------------------
225
226 function execRedoCommand() {
227     document.execCommand("Redo");
228 }
229 function redoCommand() {
230     if (commandDelay > 0) {
231         window.setTimeout(execRedoCommand, commandCount * commandDelay);
232         commandCount++;
233     }
234     else {
235         execRedoCommand();
236     }
237 }
238
239 //-------------------------------------------------------------------------------------------------------
240
241 function execChangeRootSize() {
242     document.getElementById("root").style.width = "600px";
243 }
244 function changeRootSize() {
245     if (commandDelay > 0) {
246         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
247         commandCount++;
248     }
249     else {
250         execChangeRootSize();
251     }
252 }
253
254 //-------------------------------------------------------------------------------------------------------
255
256 function execCutCommand() {
257     document.execCommand("Cut");
258 }
259 function cutCommand() {
260     if (commandDelay > 0) {
261         window.setTimeout(execCutCommand, commandCount * commandDelay);
262         commandCount++;
263     }
264     else {
265         execCutCommand();
266     }
267 }
268
269 //-------------------------------------------------------------------------------------------------------
270
271 function execCopyCommand() {
272     document.execCommand("Copy");
273 }
274 function copyCommand() {
275     if (commandDelay > 0) {
276         window.setTimeout(execCopyCommand, commandCount * commandDelay);
277         commandCount++;
278     }
279     else {
280         execCopyCommand();
281     }
282 }
283
284 //-------------------------------------------------------------------------------------------------------
285
286 function execPasteCommand() {
287     document.execCommand("Paste");
288 }
289 function pasteCommand() {
290     if (commandDelay > 0) {
291         window.setTimeout(execPasteCommand, commandCount * commandDelay);
292         commandCount++;
293     }
294     else {
295         execPasteCommand();
296     }
297 }
298
299 //-------------------------------------------------------------------------------------------------------
300
301 function execDeleteCommand() {
302     document.execCommand("Delete");
303 }
304 function deleteCommand() {
305     if (commandDelay > 0) {
306         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
307         commandCount++;
308     }
309     else {
310         execDeleteCommand();
311     }
312 }
313
314 //-------------------------------------------------------------------------------------------------------
315
316 function runEditingTest() {
317     var elem = document.getElementById("test");
318     var selection = window.getSelection();
319     selection.setPosition(elem, 0);
320     editingTest();
321 }
322
323 //-------------------------------------------------------------------------------------------------------
324
325
326 function execBackColorCommand() {
327     document.execCommand("BackColor", false, "Chartreuse");
328 }
329 function backColorCommand() {
330     if (commandDelay > 0) {
331         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
332         commandCount++;
333     }
334     else {
335         execBackColorCommand();
336     }
337 }
338
339
340 //-------------------------------------------------------------------------------------------------------
341
342
343 function execFontNameCommand() {
344     document.execCommand("FontName", false, "Courier");
345 }
346 function fontNameCommand() {
347     if (commandDelay > 0) {
348         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
349         commandCount++;
350     }
351     else {
352         execFontNameCommand();
353     }
354 }
355
356 //-------------------------------------------------------------------------------------------------------
357
358
359 function runCommand(command, arg1, arg2) {
360     document.execCommand(command,arg1,arg2);
361 }
362
363 function executeCommand(command,arg1,arg2) {
364     if (commandDelay > 0) {
365         window.setTimeout(runCommand, commandCount * commandDelay);
366         commandCount++;
367     }
368     else {
369         runCommand(command,arg1,arg2);
370     }
371 }
372