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