1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
|
<!DOCTYPE html>
<html>
<head>
<title>Word boundary text tests</title>
<link rel="stylesheet" type="text/css"
href="chrome://mochikit/content/tests/SimpleTest/test.css" />
<script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
<script type="application/javascript"
src="../common.js"></script>
<script type="application/javascript"
src="../text.js"></script>
<script type="application/javascript">
function doTest() {
// "hello"
// __h__e__l__l__o__
// 0 1 2 3 4 5
var ids = [ "i1", "d1", "e1", "t1" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 0, 0 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "hello", 0, 5 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "hello", 0, 5 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 5, 5 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 5, 5 ] ]);
// "hello "
// __h__e__l__l__o__ __
// 0 1 2 3 4 5 6
ids = [ "i2", "d2", "p2", "e2", "t2" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 6, "", 0, 0 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ],
[ 6, 6, "hello", 0, 5 ],
]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 6, "hello ", 0, 6 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 4, "hello", 0, 5 ],
[ 5, 6, " ", 5, 6 ],
]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 6, "", 6, 6 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, " ", 5, 6 ],
[ 6, 6, "", 6, 6 ],
]);
// "hello all"
// __h__e__l__l__o__ __a__l__l__
// 0 1 2 3 4 5 6 7 8 9
ids = [ "i6", "d6", "e6", "t6" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 0, 0 ],
[ 6, 9, "hello ", 0, 6 ]]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ],
[ 6, 9, "hello", 0, 5 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "hello ", 0, 6 ],
[ 6, 9, "all", 6, 9 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 4, "hello", 0, 5 ],
[ 5, 9, " all", 5, 9 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "all", 6, 9 ],
[ 6, 9, "", 9, 9 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, " all", 5, 9 ],
[ 6, 9, "", 9, 9 ] ]);
// " hello all " (with whitespace collapsing)
// __h__e__l__l__o__ __a__l__l__ __
// 0 1 2 3 4 5 6 7 8 9 10
ids = [ "d6a", "e6a" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 0, 0 ],
[ 6, 10, "hello ", 0, 6 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ],
[ 6, 9, "hello", 0, 5 ],
[ 10, 10, " all", 5, 9 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "hello ", 0, 6 ],
[ 6, 10, "all ", 6, 10 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 4, "hello", 0, 5 ],
[ 5, 8, " all", 5, 9 ],
[ 9, 10, " ", 9, 10 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "all ", 6, 10 ],
[ 6, 10, "", 10, 10 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, " all", 5, 9 ],
[ 6, 9, " ", 9, 10 ],
[ 10, 10, "", 10, 10 ] ]);
// "hello my friend"
// __h__e__l__l__o__ __m__y__ __f__r__i__e__n__d__
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
ids = [ "i7", "d7", "e7", "t7", "w7" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 0, 0 ],
[ 6, 8, "hello ", 0, 6 ],
[ 9, 15, "my ", 6, 9 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ],
[ 6, 8, "hello", 0, 5 ],
[ 9, 15, " my", 5, 8 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "hello ", 0, 6 ],
[ 6, 8, "my ", 6, 9 ],
[ 9, 15, "friend", 9, 15] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 4, "hello", 0, 5 ],
[ 5, 7, " my", 5, 8 ],
[ 8, 15, " friend", 8, 15] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "my ", 6, 9 ],
[ 6, 8, "friend", 9, 15 ],
[ 9, 15, "", 15, 15 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, " my", 5, 8 ],
[ 6, 8, " friend", 8, 15 ],
[ 9, 15, "", 15, 15 ] ]);
// "Brave Sir Robin ran"
// __B__r__a__v__e__ __S__i__r__ __ __R__o__b__i__n__ __ __ __r__a__n__
// 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
ids = [ "i8", "d8", "e8", "t8" ];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "", 0, 0 ],
[ 6, 10, "Brave ", 0, 6 ],
[ 11, 18, "Sir ", 6, 11 ],
[ 19, 22, "Robin ", 11, 19 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, "", 0, 0 ],
[ 6, 9, "Brave", 0, 5 ],
[ 10, 16, " Sir", 5, 9 ],
[ 17, 22, " Robin", 9, 16 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "Brave ", 0, 6 ],
[ 6, 10, "Sir ", 6, 11 ],
[ 11, 18, "Robin ", 11, 19 ],
[ 19, 22, "ran", 19, 22 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 4, "Brave", 0, 5 ],
[ 5, 8, " Sir", 5, 9 ],
[ 9, 15, " Robin", 9, 16 ],
[ 16, 22, " ran", 16, 22 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 5, "Sir ", 6, 11 ],
[ 6, 10, "Robin ", 11, 19 ],
[ 11, 18, "ran", 19, 22 ],
[ 19, 22, "", 22, 22 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 5, " Sir", 5, 9 ],
[ 6, 9, " Robin", 9, 16 ],
[ 10, 16, " ran", 16, 22 ],
[ 17, 22, "", 22, 22 ] ]);
// 'oneword
// '
// 'two words
// '
// __o__n__e__w__o__r__d__\n
// 0 1 2 3 4 5 6 7
// __\n
// 8
// __t__w__o__ __w__o__r__d__s__\n__
// 9 10 11 12 13 14 15 16 17 18 19
ids = ["ml_div1", "ml_divbr1", "ml_ediv1", "ml_edivbr1", "ml_t1"];
testTextBeforeOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 8, "", 0, 0 ],
[ 9, 12, "oneword\n\n", 0, 9 ],
[ 13, 19, "two ", 9, 13 ] ]);
testTextBeforeOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 7, "", 0, 0 ],
[ 8, 12, "oneword", 0, 7,
[ [ 8, "ml_divbr1", kOk, kOk, kOk ],
[ 8, "ml_edivbr1", kOk, kOk, kOk ],
[ 9, "ml_divbr1", kOk, kOk, kOk ],
[ 9, "ml_edivbr1", kOk, kOk, kOk ] ] ],
[ 13, 18, "\n\ntwo", 7, 12 ],
[ 19, 19, " words", 12, 18,
[ [ 19, "ml_divbr1", kOk, kOk, kOk ],
[ 19, "ml_edivbr1", kOk, kOk, kOk ] ] ],
] );
testTextAtOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 8, "oneword\n\n", 0, 9 ],
[ 9, 12, "two ", 9, 13 ],
[ 13, 19, "words\n", 13, 19 ] ]);
testTextAtOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 6, "oneword", 0, 7 ],
[ 7, 11, "\n\ntwo", 7, 12 ],
[ 12, 17, " words", 12, 18 ],
[ 18, 19, "\n", 18, 19,
[ [ 18, "ml_divbr1", kOk, kOk, kOk ],
[ 18, "ml_edivbr1", kOk, kOk, kOk ],
[ 19, "ml_divbr1", kOk, kOk, kOk ],
[ 19, "ml_edivbr1", kOk, kOk, kOk ] ] ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_START,
[ [ 0, 8, "two ", 9, 13 ],
[ 9, 12, "words\n", 13, 19 ],
[ 13, 19, "", 19, 19 ] ]);
testTextAfterOffset(ids, BOUNDARY_WORD_END,
[ [ 0, 7, "\n\ntwo", 7, 12 ],
[ 8, 12, " words", 12, 18 ],
[ 13, 18, "\n", 18, 19,
[ [ 18, "ml_divbr1", kOk, kOk, kOk ],
[ 18, "ml_edivbr1", kOk, kOk, kOk ] ] ],
[ 19, 19, "", 19, 19 ] ]);
// a <a href="#">b</a>
// a *
testTextBeforeOffset("cntr_1", BOUNDARY_WORD_START,
[ [ 0, 1, "", 0, 0 ],
[ 2, 3, "a ", 0, 2 ] ]);
testTextAtOffset("cntr_1", BOUNDARY_WORD_START,
[ [ 0, 1, "a ", 0, 2 ],
[ 2, 3, kEmbedChar, 2, 3 ] ]);
testTextAfterOffset("cntr_1", BOUNDARY_WORD_START,
[ [ 0, 1, kEmbedChar, 2, 3 ],
[ 2, 3, "", 3, 3 ] ]);
// Punctuation tests.
testTextAtOffset("punc_alone", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 4, "@@ ", 2, 5 ],
[ 5, 6, "b", 5, 6 ]
]);
testTextAtOffset("punc_begin", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 5, "@@b ", 2, 6 ],
[ 6, 7, "c", 6, 7 ]
]);
testTextAtOffset("punc_end", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 5, "b@@ ", 2, 6 ],
[ 6, 7, "c", 6, 7 ]
]);
testTextAtOffset("punc_middle", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 4, "b@@", 2, 5 ],
[ 5, 6, "c ", 5, 7 ],
[ 7, 8, "d", 7, 8 ]
]);
testTextAtOffset("punc_everywhere", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 6, "@@b@@", 2, 7 ],
[ 7, 10, "c@@ ", 7, 11 ],
[ 11, 12, "d", 11, 12 ]
]);
// Multi-word embedded object test.
testTextAtOffset("multiword_embed", BOUNDARY_WORD_START, [
[ 0, 1, "a ", 0, 2 ],
[ 2, 3, `${kEmbedChar} `, 2, 4, [
// Word at offset 2 returns end offset 3, should be 4.
[ 2, "multiword_embed", kOk, kOk, kOk ]
] ],
[ 4, 5, "b", 4, 5 ]
]);
SimpleTest.finish();
}
SimpleTest.waitForExplicitFinish();
addA11yLoadEvent(doTest);
</script>
</head>
<body>
<p id="display"></p>
<div id="content" style="display: none"></div>
<pre id="test">
</pre>
<input id="i1" value="hello"/>
<div id="d1">hello</div>
<div id="e1" contenteditable="true">hello</div>
<textarea id="t1">hello</textarea>
<input id="i2" value="hello "/>
<div id="d2"> hello </div>
<pre><div id="p2">hello </div></pre>
<div id="e2" contenteditable="true" style='white-space:pre'>hello </div>
<textarea id="t2">hello </textarea>
<input id="i6" value="hello all"/>
<div id="d6"> hello all</div>
<div id="e6" contenteditable="true">hello all</div>
<textarea id="t6">hello all</textarea>
<div id="d6a"> hello all </div>
<div id="e6a" contenteditable="true"> hello all </div>
<input id="i7" value="hello my friend"/>
<div id="d7"> hello my friend</div>
<div id="e7" contenteditable="true">hello my friend</div>
<textarea id="t7">hello my friend</textarea>
<div id="w7" style="width:1em"> hello my friend</div>
<input id="i8" value="Brave Sir Robin ran"/>
<pre>
<div id="d8">Brave Sir Robin ran</div>
<div id="e8" contenteditable="true">Brave Sir Robin ran</div>
</pre>
<textarea id="t8" cols="300">Brave Sir Robin ran</textarea>
<pre>
<div id="ml_div1">oneword
two words
</div>
<div id="ml_divbr1">oneword<br/><br/>two words<br/></div>
<div id="ml_ediv1" contenteditable="true">oneword
two words
</div>
<div id="ml_edivbr1" contenteditable="true">oneword<br/><br/>two words<br/></div>
<textarea id="ml_t1" cols="300">oneword
two words
</textarea>
</pre>
<div id="cntr_1">a <a href="#">b</a></div>
<p id="punc_alone">a @@ b</p>
<p id="punc_begin">a @@b c</p>
<p id="punc_end">a b@@ c</p>
<p id="punc_middle">a b@@c d</p>
<p id="punc_everywhere">a @@b@@c@@ d</p>
<p id="multiword_embed">a <a href="#">x y</a> b</p>
</body>
</html>
|