test_lineboundary.html (18092B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Line boundary getText* functions tests</title> 5 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 6 7 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 8 <script type="application/javascript" 9 src="../common.js"></script> 10 <script type="application/javascript" 11 src="../text.js"></script> 12 <script type="application/javascript"> 13 function doTest() { 14 testTextAtOffset("line_test_1", BOUNDARY_LINE_START, 15 [[0, 6, "Line 1 ", 0, 7], 16 // See the kOk test below. 17 // [7, 7, kEmbedChar, 7, 8], 18 [8, 15, "Line 3 ", 8, 15]]); 19 testTextAtOffset(/* aOffset */ 7, BOUNDARY_LINE_START, 20 kEmbedChar, /* aStartOffset */ 7, /* aEndOffset */ 8, 21 "line_test_1", 22 /* returned text */ kOk, 23 /* returned start offset */ kOk, /* returned end offset */ kOk); 24 25 // //////////////////////////////////////////////////////////////////////// 26 // __h__e__l__l__o__ __m__y__ __f__r__i__e__n__d__ 27 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 28 29 var IDs = [ "input", "div", "editable", "textarea", 30 getNode("ta", getNode("ta_cntr").contentDocument) ]; 31 32 testTextBeforeOffset(IDs, BOUNDARY_LINE_START, 33 [ [ 0, 15, "", 0, 0 ] ]); 34 testTextBeforeOffset(IDs, BOUNDARY_LINE_END, 35 [ [ 0, 15, "", 0, 0 ] ]); 36 37 testTextAtOffset(IDs, BOUNDARY_LINE_START, 38 [ [ 0, 15, "hello my friend", 0, 15 ] ]); 39 testTextAtOffset(IDs, BOUNDARY_LINE_END, 40 [ [ 0, 15, "hello my friend", 0, 15 ] ]); 41 42 testTextAfterOffset(IDs, BOUNDARY_LINE_START, 43 [ [ 0, 15, "", 15, 15 ] ]); 44 testTextAfterOffset(IDs, BOUNDARY_LINE_END, 45 [ [ 0, 15, "", 15, 15 ] ]); 46 47 // //////////////////////////////////////////////////////////////////////// 48 // __o__n__e__w__o__r__d__\n 49 // 0 1 2 3 4 5 6 7 50 // __\n 51 // 8 52 // __t__w__o__ __w__o__r__d__s__\n 53 // 9 10 11 12 13 14 15 16 17 18 54 55 IDs = [ "ml_div", "ml_divbr", "ml_editable", "ml_editablebr", "ml_textarea"]; 56 57 testTextBeforeOffset(IDs, BOUNDARY_LINE_START, 58 [ [ 0, 7, "", 0, 0 ], 59 [ 8, 8, "oneword\n", 0, 8 ], 60 [ 9, 18, "\n", 8, 9 ], 61 [ 19, 19, "two words\n", 9, 19 ]]); 62 63 testTextBeforeOffset(IDs, BOUNDARY_LINE_END, 64 [ [ 0, 7, "", 0, 0 ], 65 [ 8, 8, "oneword", 0, 7 ], 66 [ 9, 18, "\n", 7, 8 ], 67 [ 19, 19, "\ntwo words", 8, 18 ]]); 68 69 testTextAtOffset(IDs, BOUNDARY_LINE_START, 70 [ [ 0, 7, "oneword\n", 0, 8 ], 71 [ 8, 8, "\n", 8, 9 ], 72 [ 9, 18, "two words\n", 9, 19 ], 73 [ 19, 19, "", 19, 19 ]]); 74 testTextAtOffset(IDs, BOUNDARY_LINE_END, 75 [ [ 0, 7, "oneword", 0, 7 ], 76 [ 8, 8, "\n", 7, 8 ], 77 [ 9, 18, "\ntwo words", 8, 18 ], 78 [ 19, 19, "\n", 18, 19 ]]); 79 80 testTextAfterOffset(IDs, BOUNDARY_LINE_START, 81 [ [ 0, 7, "\n", 8, 9 ], 82 [ 8, 8, "two words\n", 9, 19 ], 83 [ 9, 19, "", 19, 19 ]]); 84 testTextAfterOffset(IDs, BOUNDARY_LINE_END, 85 [ [ 0, 7, "\n", 7, 8 ], 86 [ 8, 8, "\ntwo words", 8, 18 ], 87 [ 9, 18, "\n", 18, 19 ], 88 [ 19, 19, "", 19, 19 ]]); 89 90 // //////////////////////////////////////////////////////////////////////// 91 // a * b (* is embedded char for link) 92 testTextBeforeOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_START, 93 [ [ 0, 5, "", 0, 0 ] ]); 94 95 testTextBeforeOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_END, 96 [ [ 0, 5, "", 0, 0 ] ]); 97 98 testTextAtOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_START, 99 [ [ 0, 5, "a " + kEmbedChar + " c", 0, 5 ] ]); 100 101 testTextAtOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_END, 102 [ [ 0, 5, "a " + kEmbedChar + " c", 0, 5 ] ]); 103 104 testTextAfterOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_START, 105 [ [ 0, 5, "", 5, 5 ] ]); 106 107 testTextAfterOffset([ getAccessible("ht_1").firstChild ], BOUNDARY_LINE_END, 108 [ [ 0, 5, "", 5, 5 ] ]); 109 110 // //////////////////////////////////////////////////////////////////////// 111 // foo<br> and foo<br><br> 112 113 testTextAtOffset([ getAccessible("ht_2").firstChild.firstChild ], 114 BOUNDARY_LINE_START, 115 [ [ 0, 3, "foo\n", 0, 4 ] ]); 116 testTextAtOffset([ getAccessible("ht_3").firstChild.firstChild ], 117 BOUNDARY_LINE_START, 118 [ [ 0, 3, "foo\n", 0, 4 ], [ 4, 4, "\n", 4, 5 ] ]); 119 120 // //////////////////////////////////////////////////////////////////////// 121 // 'Hello world ' (\n is rendered as space) 122 123 testTextAtOffset([ "ht_4" ], BOUNDARY_LINE_START, 124 [ [ 0, 12, "Hello world ", 0, 12 ] ]); 125 126 // //////////////////////////////////////////////////////////////////////// 127 // list items 128 129 testTextAtOffset([ "li1" ], BOUNDARY_LINE_START, 130 [ [ 0, 6, kDiscBulletText + "Item", 0, 6 ] ]); 131 testTextAtOffset([ "li2" ], BOUNDARY_LINE_START, 132 [ [ 0, 2, kDiscBulletText, 0, 2 ] ]); 133 testTextAtOffset([ "li3" ], BOUNDARY_LINE_START, 134 [ [ 0, 8, kDiscBulletText + "a long ", 0, 9 ], 135 [ 9, 12, "and ", 9, 13 ] ]); 136 testTextAtOffset([ "li4" ], BOUNDARY_LINE_START, 137 [ [ 0, 7, kDiscBulletText + "a " + kEmbedChar + " c", 0, 7 ] ]); 138 testTextAtOffset([ "li5" ], BOUNDARY_LINE_START, 139 [ [ 0, 2, kDiscBulletText + "\n", 0, 3 ], 140 [ 3, 7, "hello", 3, 8 ] ]); 141 testTextAtOffset([ "ul1" ], BOUNDARY_LINE_START, 142 [ [ 0, 0, kEmbedChar, 0, 1 ], 143 [ 1, 1, kEmbedChar, 1, 2 ], 144 [ 2, 2, kEmbedChar, 2, 3 ], 145 [ 3, 3, kEmbedChar, 3, 4 ], 146 [ 4, 5, kEmbedChar, 4, 5 ] ]); 147 148 testTextAtOffset([ "li6" ], BOUNDARY_LINE_START, 149 [ [ 0, 7, "1. Item", 0, 7 ] ]); 150 testTextAtOffset([ "li7" ], BOUNDARY_LINE_START, 151 [ [ 0, 3, "2. ", 0, 3 ] ]); 152 testTextAtOffset([ "li8" ], BOUNDARY_LINE_START, 153 [ [ 0, 9, "3. a long ", 0, 10 ], 154 [ 10, 13, "and ", 10, 14 ] ]); 155 testTextAtOffset([ "li9" ], BOUNDARY_LINE_START, 156 [ [ 0, 8, "4. a " + kEmbedChar + " c", 0, 8 ] ]); 157 testTextAtOffset([ "li10" ], BOUNDARY_LINE_START, 158 [ [ 0, 3, "5. \n", 0, 4 ], 159 [ 4, 8, "hello", 4, 9 ] ]); 160 testTextAtOffset([ "ol1" ], BOUNDARY_LINE_START, 161 [ [ 0, 0, kEmbedChar, 0, 1 ], 162 [ 1, 1, kEmbedChar, 1, 2 ], 163 [ 2, 2, kEmbedChar, 2, 3 ], 164 [ 3, 3, kEmbedChar, 3, 4 ], 165 [ 4, 5, kEmbedChar, 4, 5 ] ]); 166 167 // //////////////////////////////////////////////////////////////////////// 168 // Nested hypertexts 169 170 testTextAtOffset(["ht_5" ], BOUNDARY_LINE_START, 171 [ [ 0, 0, kEmbedChar, 0, 1 ] ]); 172 173 // //////////////////////////////////////////////////////////////////////// 174 // Block followed by list 175 176 testTextAtOffset([ "block_then_ul" ], BOUNDARY_LINE_START, 177 [ [ 0, 0, kEmbedChar, 0, 1 ], 178 [ 1, 1, kEmbedChar, 1, 2 ] ]); 179 180 // Embedded char containing a line break breaks line offsets in parent. 181 testTextAtOffset([ "brInEmbed" ], BOUNDARY_LINE_START, 182 [ [0, 1, "a " + kEmbedChar, 0, 3], 183 [2, 2, "a " + kEmbedChar + " d", 0, 5], 184 [3, 5, kEmbedChar + " d", 2, 5] ]); 185 testTextAtOffset([ "brInEmbedAndBefore" ], BOUNDARY_LINE_START, 186 [ [0, 1, "a\n", 0, 2], 187 [2, 3, "b " + kEmbedChar, 2, 5], 188 [4, 4, "b " + kEmbedChar + " e", 2, 7], 189 [5, 7, kEmbedChar + " e", 4, 7] ]); 190 testTextAtOffset([ "brInEmbedAndAfter" ], BOUNDARY_LINE_START, 191 [ [0, 1, "a " + kEmbedChar, 0, 3], 192 [2, 2, "a " + kEmbedChar + " d\n", 0, 6], 193 [3, 5, kEmbedChar + " d\n", 2, 6], 194 [6, 7, "e", 6, 7] ]); 195 testTextAtOffset([ "brInEmbedAndBlockElementAfter" ], BOUNDARY_LINE_START, 196 [ [0, 2, "a " + kEmbedChar, 0, 3], 197 [3, 4, kEmbedChar, 3, 4] ]); 198 testTextAtOffset([ "brInEmbedThenTextThenBlockElement" ], BOUNDARY_LINE_START, 199 [ [0, 1, "a " + kEmbedChar, 0, 3], 200 [2, 2, "a " + kEmbedChar + " d", 0, 5], 201 [3, 4, kEmbedChar + " d", 2, 5], 202 [5, 6, kEmbedChar, 5, 6] ]); 203 testTextAtOffset([ "noBrInEmbedButOneBefore" ], BOUNDARY_LINE_START, 204 [ [0, 1, "a\n", 0, 2], 205 [2, 7, "b " + kEmbedChar + " d", 2, 7] ]); 206 testTextAtOffset([ "noBrInEmbedButOneAfter" ], BOUNDARY_LINE_START, 207 [ [0, 3, "a " + kEmbedChar + "\n", 0, 4], 208 [4, 5, "c", 4, 5] ]); 209 testTextAtOffset([ "twoEmbedsWithBRs" ], BOUNDARY_LINE_START, 210 [ [0, 1, "a " + kEmbedChar, 0, 3], 211 [2, 2, "a " + kEmbedChar + kEmbedChar, 0, 4], 212 [3, 3, kEmbedChar + kEmbedChar + " f", 2, 6], 213 [4, 6, kEmbedChar + " f", 3, 6] ]); 214 215 // Inline block span with nested spans and BRs 216 testTextAtOffset([ "inlineBlockWithSpansAndBrs" ], BOUNDARY_LINE_START, 217 [ [0, 1, "a\n", 0, 2], 218 [2, 3, "b\n", 2, 4], 219 [4, 5, "c", 4, 5] ]); 220 221 // Spans with BRs and whitespaces. 222 testTextAtOffset([ "spansWithWhitespaces" ], BOUNDARY_LINE_START, 223 [ [0, 6, "Line 1\n", 0, 7], 224 [7, 13, "Line 2\n", 7, 14], 225 [14, 20, "Line 3\n", 14, 21], 226 [21, 27, "Line 4\n", 21, 28], 227 [28, 28, "", 28, 28] ]); 228 229 // A line with an empty display: contents leaf in the middle. 230 testTextAtOffset([ "displayContents" ], BOUNDARY_LINE_START, 231 // See the kOk test below. 232 // [ [0, 3, `a${kEmbedChar}b`, 0, 3] ]); 233 [ [0, 0, `a${kEmbedChar}b`, 0, 3], 234 [2, 3, `a${kEmbedChar}b`, 0, 3] ]); 235 testTextAtOffset(/* aOffset */ 1, BOUNDARY_LINE_START, 236 `a${kEmbedChar}b`, /* aStartOffset */ 0, /* aEndOffset */ 3, 237 "displayContents", 238 /* returned text */ kOk, 239 /* returned start offset */ kOk, 240 /* returned end offset */ kOk); 241 242 // A line which wraps, followed by a br, followed by another line. 243 testTextAtOffset([ "brAfterWrapped" ], BOUNDARY_LINE_START, 244 [ [0, 1, "a ", 0, 2], 245 [2, 3, "b\n", 2, 4], 246 [4, 5, "c", 4, 5] ]); 247 248 testTextAtOffset([ "inlineInput" ], BOUNDARY_LINE_END, 249 [ [0, 1, "a", 0, 1], 250 [2, 7, `\nb ${kEmbedChar} d`, 1, 7, 251 [ [ 4, "inlineInput", kOk, kOk, kOk] ] ] ]); 252 253 testTextAtOffset([ "inlineInput2" ], BOUNDARY_LINE_END, 254 [ [0, 1, "a", 0, 1], 255 [2, 7, `\n${kEmbedChar} c d`, 1, 7, 256 [ [ 2, "inlineInput2", kOk, kOk, kOk] ] ] ]); 257 258 testTextAtOffset([ "inlineInput3" ], BOUNDARY_LINE_END, 259 [ [0, 1, "a", 0, 1], 260 [2, 8, `\nb${kEmbedChar} c d`, 1, 8, 261 [ [ 3, "inlineInput3", kOk, kOk, kOk] ] ] ]); 262 263 testTextAtOffset([ "inlineInput4" ], BOUNDARY_LINE_END, 264 [ [0, 1, "a", 0, 1], 265 [2, 7, `\n${kEmbedChar}b c d`, 1, 8, 266 [ [ 2, "inlineInput4", kOk, kOk, kOk ] ] ] ]); 267 268 testTextAtOffset(/* aOffset */ 0, BOUNDARY_LINE_START, 269 kEmbedChar, 0, 1, "contentEditableTable", 270 /* returned text */ kOk, 271 /* returned start offset */ kOk, 272 /* returned end offset */ kOk); 273 274 SimpleTest.finish(); 275 } 276 277 SimpleTest.waitForExplicitFinish(); 278 addA11yLoadEvent(doTest); 279 </script> 280 </head> 281 <body> 282 283 <a target="_blank" 284 title="getTextAtOffset for word boundaries: beginning of a new life" 285 href="https://bugzilla.mozilla.org/show_bug.cgi?id=853340"> 286 Bug 853340 287 </a> 288 <a target="_blank" 289 title="getTextBeforeOffset for word boundaries: evolving" 290 href="https://bugzilla.mozilla.org/show_bug.cgi?id=855732"> 291 Bug 855732 292 </a> 293 <a target="_blank" 294 title=" getTextAfterOffset for line boundary on new rails" 295 href="https://bugzilla.mozilla.org/show_bug.cgi?id=882292"> 296 Bug 882292 297 </a> 298 <a target="_blank" 299 title="getTextAtOffset broken for last object when closing tag is preceded by newline char" 300 href="https://bugzilla.mozilla.org/show_bug.cgi?id=947170"> 301 Bug 947170 302 </a> 303 304 <p id="display"></p> 305 <div id="content" style="display: none"></div> 306 <pre id="test"> 307 </pre> 308 309 <input id="input" value="hello my friend"/> 310 <div id="div">hello my friend</div> 311 <div id="editable" contenteditable="true">hello my friend</div> 312 <textarea id="textarea">hello my friend</textarea> 313 <iframe id="ta_cntr" 314 src="data:text/html,<html><body><textarea id='ta'>hello my friend</textarea></body></html>"></iframe> 315 316 <pre> 317 <div id="ml_div" style="border-style:outset;">oneword 318 319 two words 320 </div> 321 <div id="ml_divbr" style="border-style:outset;">oneword<br/><br/>two words<br/></div> 322 <div id="ml_editable" style="border-style:outset;" contenteditable="true">oneword 323 324 two words 325 </div> 326 <div id="ml_editablebr" contenteditable="true" style="border-style:outset;">oneword<br/><br/>two words<br/></div> 327 <textarea id="ml_textarea" cols="300">oneword 328 329 two words 330 </textarea> 331 </pre> 332 333 <iframe id="ht_1" src="data:text/html,<html><body>a <a href=''>b</a> c</body></html>"></iframe> 334 335 <iframe id="ht_2" src="data:text/html,<div contentEditable='true'>foo<br/></div>"></iframe> 336 <iframe id="ht_3" src="data:text/html,<div contentEditable='true'>foo<br/><br/></div>"></iframe> 337 338 <p id="ht_4">Hello world 339 </p> 340 341 <ul id="ul1"> 342 <li id="li1">Item</li> 343 <li id="li2"></li> 344 <li id="li3" style="font-family:monospace; font-size:10pt; width:8ch;">a long and winding road that lead me to your door</li> 345 <li id="li4">a <a href=''>b</a> c</li> 346 <li id="li5"><br>hello</li> 347 </ul> 348 349 <ol id="ol1"> 350 <li id="li6">Item</li> 351 <li id="li7"></li> 352 <li id="li8" style="font-family:monospace; font-size:10pt; width:8ch;">a long and winding road that lead me to your door</li> 353 <li id="li9">a <a href=''>b</a> c</li> 354 <li id="li10"><br>hello</li> 355 </ol> 356 357 <div id="ht_5"> 358 <div> 359 <p>sectiounus</p> 360 <p>seciofarus</p> 361 </div> 362 </div> 363 <div id="line_test_1"> 364 Line 1 365 <center><input type="TEXT"><input value="Button" type="SUBMIT"></center> 366 Line 3 367 </div> 368 369 <div id="block_then_ul"> 370 <p>Block</p> 371 <ul><li>Li</li></ul> 372 </div> 373 <div id="brInEmbed" contenteditable>a <a href="https://mozilla.org/">b<br>c</a> d</div> 374 <div id="brInEmbedAndBefore">a<br>b <a href="https://mozilla.org/">c<br>d</a> e</div> 375 <div id="brInEmbedAndAfter">a <a href="https://mozilla.org/">b<br>c</a> d<br>e</div> 376 <div id="brInEmbedAndBlockElementAfter">a <a href="https://mozilla.org/">b<br>c</a><p>d</p></div> 377 <div id="brInEmbedThenTextThenBlockElement">a <a href="https://mozilla.org/">b<br>c</a> d<p>e</p></div> 378 <div id="noBrInEmbedButOneBefore">a<br>b <a href="https://mozilla.org/">c</a> d</div> 379 <div id="noBrInEmbedButOneAfter">a <a href="https://mozilla.org/">b</a><br>c</div> 380 <div id="twoEmbedsWithBRs">a <a href="https://mozilla.org">b<br>c</a><a href="https://mozilla.org">d<br>e</a> f</div> 381 <span id="inlineBlockWithSpansAndBrs" style="display: inline-block;"><span>a<br>b<br><span></span></span>c</span> 382 <div id="spansWithWhitespaces"> <!-- Don't indent the following block --> 383 <span>Line 1<br/> 384 </span> 385 <span>Line 2<br/> 386 </span> 387 <span>Line 3<br/> 388 </span> 389 <span>Line 4<br/> 390 </span></div><!-- OK to indent again --> 391 <div id="displayContents">a<ul style="display: contents;"><li style="display: contents;"></li></ul>b</div> 392 <div id="brAfterWrapped" style="width: 10px;">a b<br>c</div> 393 <div id="inlineInput">a<br>b <input value="c"> d</div> 394 <div id="inlineInput2">a<br><input value="b"> c d</div> 395 <div id="inlineInput3">a<br> b<input value=""> c d</div> 396 <div id="inlineInput4">a<br><input value="">b c d</div> 397 <div id="contentEditableTable" contenteditable> 398 <table style="display: inline-table"> 399 <thead> 400 <th>Foo</th> 401 </thead> 402 <tbody> 403 <tr> 404 <td>Bar</td> 405 </tr> 406 </tbody> 407 </table> 408 <br> 409 <table style="display: inline-table"> 410 <thead> 411 <th>Foo</th> 412 </thead> 413 <tbody> 414 <tr> 415 <td>Bar</td> 416 </tr> 417 </tbody> 418 </table> 419 <br> 420 </div> 421 </body> 422 </html>