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 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(c) {
134     if (arguments.length == 0 || c == undefined || c.length == 0 || c.length > 1)
135         c = 'x';
136     document.execCommand("InsertText", false, c);
137 }
138 function typeCharacterCommand(c) {
139     if (commandDelay > 0) {
140         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay);
141         commandCount++;
142     }
143     else {
144         execTypeCharacterCommand(c);
145     }
146 }
147
148 //-------------------------------------------------------------------------------------------------------
149
150 function execSelectAllCommand() {
151     document.execCommand("SelectAll");
152 }
153 function selectAllCommand() {
154     if (commandDelay > 0) {
155         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
156         commandCount++;
157     }
158     else {
159         execSelectAllCommand();
160     }
161 }
162
163 //-------------------------------------------------------------------------------------------------------
164
165 function execUndoCommand() {
166     document.execCommand("Undo");
167 }
168 function undoCommand() {
169     if (commandDelay > 0) {
170         window.setTimeout(execUndoCommand, commandCount * commandDelay);
171         commandCount++;
172     }
173     else {
174         execUndoCommand();
175     }
176 }
177
178 //-------------------------------------------------------------------------------------------------------
179
180 function execRedoCommand() {
181     document.execCommand("Redo");
182 }
183 function redoCommand() {
184     if (commandDelay > 0) {
185         window.setTimeout(execRedoCommand, commandCount * commandDelay);
186         commandCount++;
187     }
188     else {
189         execRedoCommand();
190     }
191 }
192
193 //-------------------------------------------------------------------------------------------------------
194
195 function execChangeRootSize() {
196     document.getElementById("root").style.width = "600px";
197 }
198 function changeRootSize() {
199     if (commandDelay > 0) {
200         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
201         commandCount++;
202     }
203     else {
204         execChangeRootSize();
205     }
206 }
207
208 //-------------------------------------------------------------------------------------------------------
209
210 function execCutCommand() {
211     document.execCommand("Cut");
212 }
213 function cutCommand() {
214     if (commandDelay > 0) {
215         window.setTimeout(execCutCommand, commandCount * commandDelay);
216         commandCount++;
217     }
218     else {
219         execCutCommand();
220     }
221 }
222
223 //-------------------------------------------------------------------------------------------------------
224
225 function execCopyCommand() {
226     document.execCommand("Copy");
227 }
228 function copyCommand() {
229     if (commandDelay > 0) {
230         window.setTimeout(execCopyCommand, commandCount * commandDelay);
231         commandCount++;
232     }
233     else {
234         execCopyCommand();
235     }
236 }
237
238 //-------------------------------------------------------------------------------------------------------
239
240 function execPasteCommand() {
241     document.execCommand("Paste");
242 }
243 function pasteCommand() {
244     if (commandDelay > 0) {
245         window.setTimeout(execPasteCommand, commandCount * commandDelay);
246         commandCount++;
247     }
248     else {
249         execPasteCommand();
250     }
251 }
252
253 //-------------------------------------------------------------------------------------------------------
254
255 function execDeleteCommand() {
256     document.execCommand("Delete");
257 }
258 function deleteCommand() {
259     if (commandDelay > 0) {
260         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
261         commandCount++;
262     }
263     else {
264         execDeleteCommand();
265     }
266 }
267
268 //-------------------------------------------------------------------------------------------------------
269
270 function runEditingTest() {
271     var elem = document.getElementById("test");
272     var selection = window.getSelection();
273     selection.setPosition(elem, 0);
274     editingTest();
275 }
276
277 //-------------------------------------------------------------------------------------------------------
278
279
280 function execBackColorCommand() {
281     document.execCommand("BackColor", false, "Chartreuse");
282 }
283 function backColorCommand() {
284     if (commandDelay > 0) {
285         window.setTimeout(execBackColorCommand, commandCount * commandDelay);
286         commandCount++;
287     }
288     else {
289         execBackColorCommand();
290     }
291 }
292
293
294 //-------------------------------------------------------------------------------------------------------
295
296
297 function execFontNameCommand() {
298     document.execCommand("FontName", false, "Courier");
299 }
300 function fontNameCommand() {
301     if (commandDelay > 0) {
302         window.setTimeout(execFontNameCommand, commandCount * commandDelay);
303         commandCount++;
304     }
305     else {
306         execFontNameCommand();
307     }
308 }
309
310 //-------------------------------------------------------------------------------------------------------
311
312
313 function runCommand(command, arg1, arg2) {
314     document.execCommand(command,arg1,arg2);
315 }
316
317 function executeCommand(command,arg1,arg2) {
318     if (commandDelay > 0) {
319         window.setTimeout(runCommand, commandCount * commandDelay);
320         commandCount++;
321     }
322     else {
323         runCommand(command,arg1,arg2);
324     }
325 }
326