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