4 <title>Test Word Movement (including nsTextFrame::PeekOffsetWord)
</title>
5 <script type=
"text/javascript" src=
"/MochiKit/MochiKit.js"></script>
6 <script type=
"text/javascript" src=
"/tests/SimpleTest/SimpleTest.js"></script>
7 <script type=
"application/javascript" src=
"/tests/SimpleTest/EventUtils.js"></script>
8 <link rel=
"stylesheet" type=
"text/css" href=
"/tests/SimpleTest/test.css" />
12 <div id=
"content" style=
"display: block">
13 <div contentEditable
id=
"editor"></div>
15 <p id=
"catch">Catch-all
16 <pre id=
"test"><script class=
"testbody" type=
"text/javascript;version=1.7">
18 /** Test for Bug
384147 **/
20 SimpleTest.waitForExplicitFinish();
22 // This seems to be necessary because the selection is not set up properly otherwise
28 const prefSvcContractID =
"@mozilla.org/preferences-service;1";
29 const prefSvcIID = Components.interfaces.nsIPrefService;
30 return Components.classes[prefSvcContractID].getService(prefSvcIID)
31 .getBranch(
"layout.word_select.");
34 function setPrefs(eat_space, stop_at_punctuation) {
35 getPrefs().setBoolPref(
"eat_space_to_next_word", eat_space);
36 getPrefs().setBoolPref(
"stop_at_punctuation", stop_at_punctuation);
40 function restorePrefs() {
42 getPrefs().clearUserPref(
"eat_space_to_next_word");
45 getPrefs().clearUserPref(
"stop_at_punctuation");
50 netscape.security.PrivilegeManager.enablePrivilege(
"UniversalXPConnect");
53 (navigator.platform.indexOf(
"Mac")
>=
0) ? {altKey:true} : {ctrlKey:true};
54 var sel = window.getSelection();
55 var editor = document.getElementById(
"editor");
57 function errString(dir) {
58 return dir +
" movement broken with eatSpace=" + eatSpace +
" in \"" + editor.innerHTML +
59 "\
"; sel.anchorNode.parentNode=" + sel.anchorNode.parentNode;
62 function testRight(node, offset) {
63 synthesizeKey(
"VK_RIGHT", wordModifiers);
64 is(sel.anchorNode, node, errString(
"Right"));
65 is(sel.anchorOffset, offset, errString(
"Right"));
68 function testLeft(node, offset) {
69 synthesizeKey(
"VK_LEFT", wordModifiers);
70 is(sel.anchorNode, node, errString(
"Left"));
71 is(sel.anchorOffset, offset, errString(
"Left"));
74 var afterEditorNode = document.getElementById(
"catch").firstChild;
76 setPrefs(false, true);
78 editor.innerHTML =
"Hello Kitty";
79 sel.collapse(editor.firstChild,
0);
80 testRight(editor.firstChild,
5);
81 testRight(editor.firstChild,
11);
82 testLeft(editor.firstChild,
6);
83 testLeft(editor.firstChild,
0);
85 editor.innerHTML =
"<b>Hello</b> Kitty";
86 sel.collapse(editor.firstChild.firstChild,
0);
87 testRight(editor.firstChild.nextSibling,
0);
88 testRight(editor.firstChild.nextSibling,
6);
89 testLeft(editor.firstChild.nextSibling,
1);
90 testLeft(editor.firstChild.firstChild,
0);
92 editor.innerHTML =
"<b>Hello </b>Kitty";
93 sel.collapse(editor.firstChild.firstChild,
0);
94 testRight(editor.firstChild.firstChild,
5);
95 testRight(editor.firstChild.nextSibling,
5);
96 testLeft(editor.firstChild.firstChild,
6);
97 testLeft(editor.firstChild.firstChild,
0);
99 editor.innerHTML =
"<b>Log out</b> roc";
100 sel.collapse(editor.firstChild.firstChild,
0);
101 testRight(editor.firstChild.firstChild,
3);
102 testRight(editor.firstChild.nextSibling,
0);
103 testRight(editor.firstChild.nextSibling,
5);
104 // In the next test, we expect to be at the end of the
105 // space that is not collapsed away
106 testLeft(editor.firstChild.nextSibling,
1);
107 testLeft(editor.firstChild.firstChild,
4);
108 testLeft(editor.firstChild.firstChild,
0);
110 editor.innerHTML =
"http://www.mozilla.org";
111 sel.collapse(editor.firstChild,
0);
112 testRight(editor.firstChild,
7);
113 testRight(editor.firstChild,
11);
114 testRight(editor.firstChild,
19);
115 testLeft(editor.firstChild,
11);
116 testLeft(editor.firstChild,
7);
117 testLeft(editor.firstChild,
0);
119 editor.innerHTML =
"Set .rc to <b>'</b>quiz'";
120 sel.collapse(editor.firstChild,
0);
121 testRight(editor.firstChild,
3);
122 testRight(editor.firstChild,
7);
123 testRight(editor.firstChild,
10);
124 testRight(editor.firstChild.nextSibling.nextSibling,
5);
125 testLeft(editor.firstChild.nextSibling.firstChild,
1);
126 testLeft(editor.firstChild,
10);
127 testLeft(editor.firstChild,
8);
128 testLeft(editor.firstChild,
5);
129 testLeft(editor.firstChild,
3);
130 testLeft(editor.firstChild,
0);
132 var ChineseChars =
"漢字";
133 var HiraganaChars =
"ひらがな";
134 var KatakanaChars =
"カタカナ";
135 var JapaneseFullStop =
"。";
136 var JapaneseComma =
"、";
138 editor.innerHTML = ChineseChars + HiraganaChars + ChineseChars;
139 sel.collapse(editor.firstChild,
0);
140 testRight(editor.firstChild,
2);
141 testRight(editor.firstChild,
6);
142 testRight(editor.firstChild,
8);
143 testLeft(editor.firstChild,
6);
144 testLeft(editor.firstChild,
2);
145 testLeft(editor.firstChild,
0);
147 editor.innerHTML = ChineseChars + KatakanaChars + ChineseChars;
148 sel.collapse(editor.firstChild,
0);
149 testRight(editor.firstChild,
2);
150 testRight(editor.firstChild,
6);
151 testRight(editor.firstChild,
8);
152 testLeft(editor.firstChild,
6);
153 testLeft(editor.firstChild,
2);
154 testLeft(editor.firstChild,
0);
156 editor.innerHTML = KatakanaChars + HiraganaChars + KatakanaChars;
157 sel.collapse(editor.firstChild,
0);
158 testRight(editor.firstChild,
4);
159 testRight(editor.firstChild,
8);
160 testRight(editor.firstChild,
12);
161 testLeft(editor.firstChild,
8);
162 testLeft(editor.firstChild,
4);
163 testLeft(editor.firstChild,
0);
165 editor.innerHTML = HiraganaChars + JapaneseComma + HiraganaChars + JapaneseFullStop + HiraganaChars;
166 sel.collapse(editor.firstChild,
0);
167 testRight(editor.firstChild,
5);
168 testRight(editor.firstChild,
10);
169 testRight(editor.firstChild,
14);
170 testLeft(editor.firstChild,
10);
171 testLeft(editor.firstChild,
5);
172 testLeft(editor.firstChild,
0);
174 editor.innerHTML = KatakanaChars + JapaneseComma + KatakanaChars + JapaneseFullStop + KatakanaChars;
175 sel.collapse(editor.firstChild,
0);
176 testRight(editor.firstChild,
5);
177 testRight(editor.firstChild,
10);
178 testRight(editor.firstChild,
14);
179 testLeft(editor.firstChild,
10);
180 testLeft(editor.firstChild,
5);
181 testLeft(editor.firstChild,
0);
183 editor.innerHTML = ChineseChars + JapaneseComma + ChineseChars + JapaneseFullStop + ChineseChars;
184 sel.collapse(editor.firstChild,
0);
185 testRight(editor.firstChild,
3);
186 testRight(editor.firstChild,
6);
187 testRight(editor.firstChild,
8);
188 testLeft(editor.firstChild,
6);
189 testLeft(editor.firstChild,
3);
190 testLeft(editor.firstChild,
0);
192 setPrefs(true, true);
194 // test basic word movement with eat_space_next_to_word true.
196 editor.innerHTML =
"Hello Kitty";
197 sel.collapse(editor.firstChild,
0);
198 testRight(editor.firstChild,
6);
199 testRight(afterEditorNode,
0);
200 testLeft(editor.firstChild,
6);
201 testLeft(editor.firstChild,
0);
203 editor.innerHTML =
"<b>Hello</b> Kitty";
204 sel.collapse(editor.firstChild.firstChild,
0);
205 testRight(editor.firstChild.nextSibling,
1);
206 testRight(afterEditorNode,
0);
207 testLeft(editor.firstChild.nextSibling,
1);
208 testLeft(editor.firstChild.firstChild,
0);
210 editor.innerHTML =
"<b>Hello </b>Kitty";
211 sel.collapse(editor.firstChild.firstChild,
0);
212 testRight(editor.firstChild.nextSibling,
0);
213 testRight(afterEditorNode,
0);
214 testLeft(editor.firstChild.firstChild,
6);
215 testLeft(editor.firstChild.firstChild,
0);
217 editor.innerHTML =
"<b>Log out</b> roc";
218 sel.collapse(editor.firstChild.firstChild,
0);
219 testRight(editor.firstChild.firstChild,
4);
220 testRight(editor.firstChild.nextSibling,
2);
221 testRight(afterEditorNode,
0);
222 testLeft(editor.firstChild.nextSibling,
1);
223 testLeft(editor.firstChild.firstChild,
4);
224 testLeft(editor.firstChild.firstChild,
0);
226 editor.innerHTML =
"http://www.mozilla.org";
227 sel.collapse(editor.firstChild,
0);
228 testRight(editor.firstChild,
7);
229 testRight(editor.firstChild,
11);
230 testRight(editor.firstChild,
19);
231 testLeft(editor.firstChild,
11);
232 testLeft(editor.firstChild,
7);
233 testLeft(editor.firstChild,
0);
235 editor.innerHTML =
"Set .rc to <b>'</b>quiz'";
236 sel.collapse(editor.firstChild,
0);
237 testRight(editor.firstChild,
4);
238 testRight(editor.firstChild,
8);
239 testRight(editor.firstChild.nextSibling.firstChild,
0);
240 testRight(afterEditorNode,
0);
241 testLeft(editor.firstChild.nextSibling.firstChild,
1);
242 testLeft(editor.firstChild,
10);
243 testLeft(editor.firstChild,
8);
244 testLeft(editor.firstChild,
5);
245 testLeft(editor.firstChild,
3);
246 testLeft(editor.firstChild,
0);
248 editor.innerHTML = ChineseChars + HiraganaChars + ChineseChars;
249 sel.collapse(editor.firstChild,
0);
250 testRight(editor.firstChild,
2);
251 testRight(editor.firstChild,
6);
252 testRight(afterEditorNode,
0);
253 testLeft(editor.firstChild,
6);
254 testLeft(editor.firstChild,
2);
255 testLeft(editor.firstChild,
0);
257 editor.innerHTML = ChineseChars + KatakanaChars + ChineseChars;
258 sel.collapse(editor.firstChild,
0);
259 testRight(editor.firstChild,
2);
260 testRight(editor.firstChild,
6);
261 testRight(afterEditorNode,
0);
262 testLeft(editor.firstChild,
6);
263 testLeft(editor.firstChild,
2);
264 testLeft(editor.firstChild,
0);
266 editor.innerHTML = KatakanaChars + HiraganaChars + KatakanaChars;
267 sel.collapse(editor.firstChild,
0);
268 testRight(editor.firstChild,
4);
269 testRight(editor.firstChild,
8);
270 testRight(afterEditorNode,
0);
271 testLeft(editor.firstChild,
8);
272 testLeft(editor.firstChild,
4);
273 testLeft(editor.firstChild,
0);
275 editor.innerHTML = HiraganaChars + JapaneseComma + HiraganaChars + JapaneseFullStop + HiraganaChars;
276 sel.collapse(editor.firstChild,
0);
277 testRight(editor.firstChild,
5);
278 testRight(editor.firstChild,
10);
279 testRight(afterEditorNode,
0);
280 testLeft(editor.firstChild,
10);
281 testLeft(editor.firstChild,
5);
282 testLeft(editor.firstChild,
0);
284 editor.innerHTML = KatakanaChars + JapaneseComma + KatakanaChars + JapaneseFullStop + KatakanaChars;
285 sel.collapse(editor.firstChild,
0);
286 testRight(editor.firstChild,
5);
287 testRight(editor.firstChild,
10);
288 testRight(afterEditorNode,
0);
289 testLeft(editor.firstChild,
10);
290 testLeft(editor.firstChild,
5);
291 testLeft(editor.firstChild,
0);
293 editor.innerHTML = ChineseChars + JapaneseComma + ChineseChars + JapaneseFullStop + ChineseChars;
294 sel.collapse(editor.firstChild,
0);
295 testRight(editor.firstChild,
3);
296 testRight(editor.firstChild,
6);
297 testRight(afterEditorNode,
0);
298 testLeft(editor.firstChild,
6);
299 testLeft(editor.firstChild,
3);
300 testLeft(editor.firstChild,
0);