test_charboundary.html (4486B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>Char boundary text tests</title> 5 <link rel="stylesheet" type="text/css" 6 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 7 8 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 9 <script type="application/javascript" 10 src="../common.js"></script> 11 <script type="application/javascript" 12 src="../text.js"></script> 13 14 <script type="application/javascript"> 15 function doTest() { 16 // //////////////////////////////////////////////////////////////////////// 17 // 18 // __h__e__l__l__o__ __m__y__ __f__r__i__e__n__d__ 19 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 20 21 var IDs = [ "i1", "d1", "e1", "t1" ]; 22 23 testCharBeforeOffset(IDs, 0, "", 0, 0); 24 testCharBeforeOffset(IDs, 1, "h", 0, 1); 25 testCharBeforeOffset(IDs, 14, "n", 13, 14); 26 testCharBeforeOffset(IDs, 15, "d", 14, 15); 27 28 testCharAtOffset(IDs, 0, "h", 0, 1); 29 testCharAtOffset(IDs, 1, "e", 1, 2); 30 testCharAtOffset(IDs, 14, "d", 14, 15); 31 testCharAtOffset(IDs, 15, "", 15, 15); 32 33 testCharAfterOffset(IDs, 0, "e", 1, 2); 34 testCharAfterOffset(IDs, 1, "l", 2, 3); 35 testCharAfterOffset(IDs, 14, "", 15, 15); 36 testCharAfterOffset(IDs, 15, "", 15, 15); 37 38 // //////////////////////////////////////////////////////////////////////// 39 // 40 // __B__r__a__v__e__ __S__i__r__ __ __R__o__b__i__n__ __ __ __r__a__n 41 // 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 42 43 IDs = [ "i2", "d2", "e2", "t2" ]; 44 45 testCharBeforeOffset(IDs, 0, "", 0, 0); 46 testCharBeforeOffset(IDs, 1, "B", 0, 1); 47 testCharBeforeOffset(IDs, 6, " ", 5, 6); 48 testCharBeforeOffset(IDs, 10, " ", 9, 10); 49 testCharBeforeOffset(IDs, 11, " ", 10, 11); 50 testCharBeforeOffset(IDs, 17, " ", 16, 17); 51 testCharBeforeOffset(IDs, 19, " ", 18, 19); 52 53 testCharAtOffset(IDs, 0, "B", 0, 1); 54 testCharAtOffset(IDs, 1, "r", 1, 2); 55 testCharAtOffset(IDs, 5, " ", 5, 6); 56 testCharAtOffset(IDs, 9, " ", 9, 10); 57 testCharAtOffset(IDs, 10, " ", 10, 11); 58 testCharAtOffset(IDs, 17, " ", 17, 18); 59 60 testCharAfterOffset(IDs, 0, "r", 1, 2); 61 testCharAfterOffset(IDs, 1, "a", 2, 3); 62 testCharAfterOffset(IDs, 4, " ", 5, 6); 63 testCharAfterOffset(IDs, 5, "S", 6, 7); 64 testCharAfterOffset(IDs, 8, " ", 9, 10); 65 testCharAfterOffset(IDs, 9, " ", 10, 11); 66 testCharAfterOffset(IDs, 10, "R", 11, 12); 67 testCharAfterOffset(IDs, 15, " ", 16, 17); 68 testCharAfterOffset(IDs, 16, " ", 17, 18); 69 testCharAfterOffset(IDs, 17, " ", 18, 19); 70 testCharAfterOffset(IDs, 18, "r", 19, 20); 71 72 // //////////////////////////////////////////////////////////////////////// 73 // 74 // __o__n__e__w__o__r__d__\n 75 // 0 1 2 3 4 5 6 7 76 // __\n 77 // 8 78 // __t__w__o__ __w__o__r__d__s__\n 79 // 9 10 11 12 13 14 15 16 17 18 80 81 IDs = ["d3", "dbr3", "e3", "ebr3", "t3"]; 82 83 testCharBeforeOffset(IDs, 8, "\n", 7, 8); 84 testCharBeforeOffset(IDs, 9, "\n", 8, 9); 85 testCharBeforeOffset(IDs, 10, "t", 9, 10); 86 87 testCharAtOffset(IDs, 7, "\n", 7, 8); 88 testCharAtOffset(IDs, 8, "\n", 8, 9); 89 testCharAtOffset(IDs, 9, "t", 9, 10); 90 91 testCharAfterOffset(IDs, 6, "\n", 7, 8); 92 testCharAfterOffset(IDs, 7, "\n", 8, 9); 93 testCharAfterOffset(IDs, 8, "t", 9, 10); 94 95 SimpleTest.finish(); 96 } 97 98 SimpleTest.waitForExplicitFinish(); 99 addA11yLoadEvent(doTest); 100 </script> 101 </head> 102 <body> 103 104 <p id="display"></p> 105 <div id="content" style="display: none"></div> 106 <pre id="test"> 107 </pre> 108 109 <input id="i1" value="hello my friend"/> 110 <div id="d1">hello my friend</div> 111 <div id="e1" contenteditable="true">hello my friend</div> 112 <textarea id="t1" contenteditable="true">hello my friend</textarea> 113 114 <input id="i2" value="Brave Sir Robin ran"/> 115 <pre> 116 <div id="d2">Brave Sir Robin ran</div> 117 <div id="e2" contenteditable="true">Brave Sir Robin ran</div> 118 </pre> 119 <textarea id="t2" cols="300">Brave Sir Robin ran</textarea> 120 121 <pre> 122 <div id="d3">oneword 123 124 two words 125 </div> 126 <div id="dbr3">oneword<br/><br/>two words<br/></div> 127 <div id="e3" contenteditable="true">oneword 128 129 two words 130 </div> 131 <div id="ebr3" contenteditable="true">oneword<br/><br/>two words<br/></div> 132 <textarea id="t3" cols="300">oneword 133 134 two words</textarea> 135 </pre> 136 137 </body> 138 </html>