test_general.html (5602B)
1 <html> 2 3 <head> 4 <title>Text accessible caret testing</title> 5 6 <link rel="stylesheet" type="text/css" 7 href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 8 9 <script src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 10 11 <script type="application/javascript" 12 src="../common.js"></script> 13 <script type="application/javascript" 14 src="../events.js"></script> 15 16 <script type="application/javascript"> 17 /** 18 * Turn on/off the caret browsing mode. 19 */ 20 function turnCaretBrowsing(aIsOn) { 21 Services.prefs.setBoolPref("accessibility.browsewithcaret", aIsOn); 22 } 23 24 /** 25 * Test caret offset for the given accessible. 26 */ 27 function testCaretOffset(aID, aCaretOffset) { 28 var acc = getAccessible(aID, [nsIAccessibleText]); 29 is(acc.caretOffset, aCaretOffset, 30 "Wrong caret offset for " + aID); 31 } 32 33 function testCaretOffsets(aList) { 34 for (var i = 0; i < aList.length; i++) 35 testCaretOffset(aList[0][0], aList[0][1]); 36 } 37 38 function queueTraversalList(aList, aFocusNode) { 39 for (var i = 0 ; i < aList.length; i++) { 40 var node = aList[i].DOMPoint[0]; 41 var nodeOffset = aList[i].DOMPoint[1]; 42 43 var textAcc = aList[i].point[0]; 44 var textOffset = aList[i].point[1]; 45 var textList = aList[i].pointList; 46 var invoker = 47 new moveCaretToDOMPoint(textAcc, node, nodeOffset, textOffset, 48 ((i == 0) ? aFocusNode : null), 49 testCaretOffsets.bind(null, textList)); 50 gQueue.push(invoker); 51 } 52 } 53 54 /** 55 * Do tests. 56 */ 57 var gQueue = null; 58 59 // gA11yEventDumpID = "eventdump"; // debug stuff 60 // gA11yEventDumpToConsole = true; 61 62 function doTests() { 63 turnCaretBrowsing(true); 64 65 // test caret offsets 66 testCaretOffset(document, 0); // because of no selection ranges 67 testCaretOffset("textbox", -1); 68 testCaretOffset("textarea", -1); 69 testCaretOffset("p", -1); 70 71 // test caret move events and caret offsets 72 gQueue = new eventQueue(); 73 74 gQueue.push(new setCaretOffset("textbox", 1, "textbox")); 75 gQueue.push(new setCaretOffset("link", 1, "link")); 76 gQueue.push(new setCaretOffset("heading", 1, document)); 77 78 // a*b*c 79 var p2Doc = getNode("p2_container").contentDocument; 80 var traversalList = [ 81 { // before 'a' 82 DOMPoint: [ getNode("p2", p2Doc).firstChild, 0 ], 83 point: [ getNode("p2", p2Doc), 0 ], 84 pointList: [ [ p2Doc, 0 ] ], 85 }, 86 { // after 'a' (before anchor) 87 DOMPoint: [ getNode("p2", p2Doc).firstChild, 1 ], 88 point: [ getNode("p2", p2Doc), 1 ], 89 pointList: [ [ p2Doc, 0 ] ], 90 }, 91 { // before 'b' (inside anchor) 92 DOMPoint: [ getNode("p2_a", p2Doc).firstChild, 0 ], 93 point: [ getNode("p2_a", p2Doc), 0 ], 94 pointList: [ 95 [ getNode("p2", p2Doc), 1 ], 96 [ p2Doc, 0 ], 97 ], 98 }, 99 { // after 'b' (inside anchor) 100 DOMPoint: [ getNode("p2_a", p2Doc).firstChild, 1 ], 101 point: [ getNode("p2_a", p2Doc), 1 ], 102 pointList: [ 103 [ getNode("p2", p2Doc), 1 ], 104 [ p2Doc, 0 ], 105 ], 106 }, 107 { // before 'c' (after anchor) 108 DOMPoint: [ getNode("p2", p2Doc).lastChild, 0 ], 109 point: [ getNode("p2", p2Doc), 2 ], 110 pointList: [ [ p2Doc, 0 ] ], 111 }, 112 { // after 'c' 113 DOMPoint: [ getNode("p2", p2Doc).lastChild, 1 ], 114 point: [ getNode("p2", p2Doc), 3 ], 115 pointList: [ [ p2Doc, 0 ] ], 116 }, 117 ]; 118 queueTraversalList(traversalList, getNode("p2", p2Doc)); 119 120 gQueue.onFinish = function() { 121 turnCaretBrowsing(false); 122 }; 123 124 gQueue.invoke(); // Will call SimpleTest.finish(); 125 } 126 127 SimpleTest.waitForExplicitFinish(); 128 addA11yLoadEvent(doTests); 129 </script> 130 </head> 131 132 <body> 133 134 <a target="_blank" 135 href="https://bugzilla.mozilla.org/show_bug.cgi?id=448744" 136 title="caretOffset should return -1 if the system caret is not currently with in that particular object"> 137 Bug 448744 138 </a> 139 <a target="_blank" 140 href="https://bugzilla.mozilla.org/show_bug.cgi?id=524115" 141 title="HyperText accessible should get focus when the caret is positioned inside of it, text is changed or copied into clipboard by ATs"> 142 Bug 524115 143 </a> 144 <a target="_blank" 145 href="https://bugzilla.mozilla.org/show_bug.cgi?id=546068" 146 title="Position is not being updated when atk_text_set_caret_offset is used"> 147 Bug 546068 148 </a> 149 <a target="_blank" 150 href="https://bugzilla.mozilla.org/show_bug.cgi?id=672717" 151 title="Broken caret when moving into/out of embedded objects with right arrow"> 152 Bug 672717 153 </a> 154 <a target="_blank" 155 href="https://bugzilla.mozilla.org/show_bug.cgi?id=725581" 156 title="caretOffset for textarea should be -1 when textarea doesn't have a focus"> 157 Bug 725581 158 </a> 159 <p id="display"></p> 160 <div id="content" style="display: none"></div> 161 <pre id="test"> 162 </pre> 163 164 <input id="textbox" value="hello"/> 165 <textarea id="textarea">text<br>text</textarea> 166 <p id="p" contentEditable="true"><span>text</span><br/>text</p> 167 <a id="link" href="about:mozilla">about mozilla</a> 168 <h5 id="heading">heading</h5> 169 <iframe id="p2_container" 170 src="data:text/html,<p id='p2' contentEditable='true'>a<a id='p2_a' href='mozilla.org'>b</a>c</p>"></iframe> 171 172 <div id="eventdump"></div> 173 </body> 174 </html>