test_update.html (7105B)
1 <!DOCTYPE html> 2 <html> 3 <head> 4 <title>nsIHyper>TextAccessible in dynamic 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 10 <script type="application/javascript" 11 src="../common.js"></script> 12 <script type="application/javascript" 13 src="../events.js"></script> 14 15 <script type="application/javascript"> 16 const kLinksCount = 128; 17 function addLinks(aContainerID) { 18 this.containerNode = getNode(aContainerID); 19 20 this.eventSeq = [ 21 new invokerChecker(EVENT_REORDER, this.containerNode), 22 ]; 23 24 this.invoke = function addLinks_invoke() { 25 for (var jdx = 0; jdx < kLinksCount; jdx++) { 26 var a = document.createElement("a"); 27 a.setAttribute("href", "mozilla.org"); 28 a.textContent = "mozilla"; 29 this.containerNode.appendChild(a); 30 31 var span = document.createElement("span"); 32 span.textContent = " text "; 33 this.containerNode.appendChild(span); 34 } 35 }; 36 37 this.finalCheck = function addLinks_finalCheck() { 38 // getLinkAt and getLinkIndex. 39 var htAcc = getAccessible(this.containerNode, [nsIAccessibleHyperText]); 40 for (var jdx = 0; jdx < kLinksCount; jdx++) { 41 var link = htAcc.getLinkAt(jdx); 42 ok(link, "No link at index " + jdx + " for '" + aContainerID + "'"); 43 44 var linkIdx = htAcc.getLinkIndex(link); 45 is(linkIdx, jdx, "Wrong link index for '" + aContainerID + "'!"); 46 } 47 }; 48 49 this.getID = function addLinks_getID() { 50 return "Add links for '" + aContainerID + "'"; 51 }; 52 } 53 54 function updateText(aContainerID) { 55 this.containerNode = getNode(aContainerID); 56 this.container = getAccessible(this.containerNode, nsIAccessibleHyperText); 57 this.text = this.container.firstChild; 58 this.textNode = this.text.DOMNode; 59 this.textLen = this.textNode.data.length; 60 61 this.eventSeq = [ 62 new invokerChecker(EVENT_TEXT_INSERTED, this.containerNode), 63 ]; 64 65 this.invoke = function updateText_invoke() { 66 is(this.container.getLinkIndexAtOffset(this.textLen), 0, 67 "Wrong intial text offsets!"); 68 69 this.text.DOMNode.appendData(" my"); 70 }; 71 72 this.finalCheck = function updateText_finalCheck() { 73 is(this.container.getLinkIndexAtOffset(this.textLen), -1, 74 "Text offsets weren't updated!"); 75 }; 76 77 this.getID = function updateText_getID() { 78 return "update text for '" + aContainerID + "'"; 79 }; 80 } 81 82 /** 83 * Text offsets must be updated when hypertext child is removed. 84 */ 85 function removeChild(aContainerID, aChildID, aInitialText, aFinalText) { 86 this.containerNode = getNode(aContainerID); 87 this.container = getAccessible(this.containerNode, nsIAccessibleText); 88 this.childNode = getNode(aChildID); 89 90 // Call first to getText so offsets are cached 91 is(this.container.getText(0, -1), aInitialText, 92 "Wrong text before child removal"); 93 94 this.eventSeq = [ 95 new invokerChecker(EVENT_REORDER, this.containerNode), 96 ]; 97 98 this.invoke = function removeChild_invoke() { 99 this.containerNode.removeChild(this.childNode); 100 }; 101 102 this.finalCheck = function removeChild_finalCheck() { 103 is(this.container.getText(0, -1), aFinalText, 104 "Wrong text after child removal"); 105 is(this.container.characterCount, aFinalText.length, 106 "Wrong text after child removal"); 107 }; 108 109 this.getID = function removeChild_getID() { 110 return "check text after removing child from '" + aContainerID + "'"; 111 }; 112 } 113 114 function removeFirstChild(aContainer) { 115 this.ht = getAccessible(aContainer, [ nsIAccessibleHyperText ]); 116 this.eventSeq = [ 117 new invokerChecker(EVENT_REORDER, aContainer), 118 ]; 119 120 this.invoke = function removeFirstChild_invoke() { 121 is(this.ht.linkCount, 2, "Wrong embedded objects count before removal"); 122 123 getNode(aContainer).removeChild(getNode(aContainer).firstElementChild); 124 }; 125 126 this.finalCheck = function removeFirstChild_finalCheck() { 127 // check list index before link count 128 is(this.ht.getLinkIndex(this.ht.firstChild), 0, "Wrong child index"); 129 is(this.ht.linkCount, 1, "Wrong embedded objects count after removal"); 130 }; 131 132 this.getID = function removeFirstChild_getID() { 133 return "Remove first child and check embedded object indeces"; 134 }; 135 } 136 137 function removeLastChild(aContainer) { 138 this.ht = getAccessible(aContainer, [ nsIAccessibleHyperText ]); 139 this.eventSeq = [ 140 new invokerChecker(EVENT_REORDER, aContainer), 141 ]; 142 143 this.invoke = function removeLastChild_invoke() { 144 is(this.ht.linkCount, 1, "Wrong embedded objects count before removal"); 145 146 getNode(aContainer).removeChild(getNode(aContainer).lastElementChild); 147 }; 148 149 this.finalCheck = function removeLastChild_finalCheck() { 150 is(this.ht.linkCount, 0, "Wrong embedded objects count after removal"); 151 152 var link = null; 153 try { 154 link = this.ht.getLinkAt(0); 155 } catch (e) { } 156 ok(!link, "No embedded object is expected"); 157 }; 158 159 this.getID = function removeLastChild_getID() { 160 return "Remove last child and try its embedded object"; 161 }; 162 } 163 164 // gA11yEventDumpToConsole = true; // debug stuff 165 166 var gQueue = null; 167 function doTest() { 168 gQueue = new eventQueue(); 169 gQueue.push(new addLinks("p1")); 170 gQueue.push(new updateText("p2")); 171 gQueue.push(new removeChild("div1", "div2", 172 "hello my good friend", "hello friend")); 173 gQueue.push(new removeFirstChild("c4")); 174 gQueue.push(new removeLastChild("c5")); 175 176 gQueue.invoke(); // Will call SimpleTest.finish(); 177 } 178 179 SimpleTest.waitForExplicitFinish(); 180 addA11yLoadEvent(doTest); 181 </script> 182 </head> 183 <body> 184 185 <a target="_blank" 186 title="Cache links within hypertext accessible" 187 href="https://bugzilla.mozilla.org/show_bug.cgi?id=572394"> 188 Mozilla Bug 572394 189 </a> 190 <a target="_blank" 191 title="Text offsets don't get updated when text of first child text accessible is changed" 192 href="https://bugzilla.mozilla.org/show_bug.cgi?id=625009"> 193 Mozilla Bug 625009 194 </a> 195 <a target="_blank" 196 title="Crash in nsHyperTextAccessible::GetText()" 197 href="https://bugzilla.mozilla.org/show_bug.cgi?id=630841"> 198 Mozilla Bug 630841 199 </a><br> 200 <p id="display"></p> 201 <div id="content" style="display: none"></div> 202 <pre id="test"> 203 </pre> 204 205 <p id="p1"></p> 206 <p id="p2"><b>hello</b><a>friend</a></p> 207 <div id="div1">hello<span id="div2"> my<span id="div3"> good</span></span> friend</span></div> 208 <form id="c4"> 209 <label for="c4_input">label</label> 210 <input id="c4_input"> 211 </form> 212 <div id="c5">TextLeaf<input id="c5_input"></div> 213 </body> 214 </html>