43e928482acead4c5c5a74312604975f4c11f0f1
[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 execTypeCharacterCommand() {
73     document.execCommand("InsertText", false, "x");
74 }
75 function typeCharacterCommand() {
76     if (commandDelay > 0) {
77         window.setTimeout(execTypeCharacterCommand, commandCount * commandDelay);
78         commandCount++;
79     }
80     else {
81         execTypeCharacterCommand();
82     }
83 }
84
85 //-------------------------------------------------------------------------------------------------------
86
87 function execSelectAllCommand() {
88     document.execCommand("SelectAll");
89 }
90 function selectAllCommand() {
91     if (commandDelay > 0) {
92         window.setTimeout(execSelectAllCommand, commandCount * commandDelay);
93         commandCount++;
94     }
95     else {
96         execSelectAllCommand();
97     }
98 }
99
100 //-------------------------------------------------------------------------------------------------------
101
102 function execUndoCommand() {
103     document.execCommand("Undo");
104 }
105 function undoCommand() {
106     if (commandDelay > 0) {
107         window.setTimeout(execUndoCommand, commandCount * commandDelay);
108         commandCount++;
109     }
110     else {
111         execUndoCommand();
112     }
113 }
114
115 //-------------------------------------------------------------------------------------------------------
116
117 function execRedoCommand() {
118     document.execCommand("Redo");
119 }
120 function redoCommand() {
121     if (commandDelay > 0) {
122         window.setTimeout(execRedoCommand, commandCount * commandDelay);
123         commandCount++;
124     }
125     else {
126         execRedoCommand();
127     }
128 }
129
130 //-------------------------------------------------------------------------------------------------------
131
132 function execChangeRootSize() {
133     document.getElementById("root").style.width = "600px";
134 }
135 function changeRootSize() {
136     if (commandDelay > 0) {
137         window.setTimeout(execChangeRootSize, commandCount * commandDelay);
138         commandCount++;
139     }
140     else {
141         execChangeRootSize();
142     }
143 }
144
145 //-------------------------------------------------------------------------------------------------------
146
147 function execDeleteCommand() {
148     document.execCommand("Delete");
149 }
150 function deleteCommand() {
151     if (commandDelay > 0) {
152         window.setTimeout(execDeleteCommand, commandCount * commandDelay);
153         commandCount++;
154     }
155     else {
156         execDeleteCommand();
157     }
158 }
159
160 //-------------------------------------------------------------------------------------------------------
161
162 function runEditingTest() {
163     var elem = document.getElementById("test");
164     var selection = window.getSelection();
165     selection.setPosition(elem, 0);
166     editingTest();
167 }
168
169 //-------------------------------------------------------------------------------------------------------