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