1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/accessible/tests/mochitest/events/test_text_alg.html Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,249 @@ 1.4 +<html> 1.5 + 1.6 +<head> 1.7 + <title>Accessible text update algorithm testing</title> 1.8 + 1.9 + <link rel="stylesheet" type="text/css" 1.10 + href="chrome://mochikit/content/tests/SimpleTest/test.css" /> 1.11 + 1.12 + <script type="application/javascript" 1.13 + src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> 1.14 + <script type="application/javascript" 1.15 + src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script> 1.16 + 1.17 + <script type="application/javascript" 1.18 + src="../common.js"></script> 1.19 + <script type="application/javascript" 1.20 + src="../events.js"></script> 1.21 + 1.22 + <script type="application/javascript"> 1.23 + //////////////////////////////////////////////////////////////////////////// 1.24 + // Invokers 1.25 + 1.26 + const kRemoval = 0; 1.27 + const kInsertion = 1; 1.28 + const kUnexpected = true; 1.29 + 1.30 + function changeText(aContainerID, aValue, aEventList) 1.31 + { 1.32 + this.containerNode = getNode(aContainerID); 1.33 + this.textNode = this.containerNode.firstChild; 1.34 + this.textData = this.textNode.data; 1.35 + 1.36 + this.eventSeq = [ ]; 1.37 + this.unexpectedEventSeq = [ ]; 1.38 + 1.39 + for (var i = 0; i < aEventList.length; i++) { 1.40 + var event = aEventList[i]; 1.41 + 1.42 + var isInserted = event[0]; 1.43 + var str = event[1]; 1.44 + var offset = event[2]; 1.45 + var checker = new textChangeChecker(this.containerNode, offset, 1.46 + offset + str.length, str, 1.47 + isInserted); 1.48 + 1.49 + if (event[3] == kUnexpected) 1.50 + this.unexpectedEventSeq.push(checker); 1.51 + else 1.52 + this.eventSeq.push(checker); 1.53 + } 1.54 + 1.55 + this.invoke = function changeText_invoke() 1.56 + { 1.57 + this.textNode.data = aValue; 1.58 + } 1.59 + 1.60 + this.getID = function changeText_getID() 1.61 + { 1.62 + return "change text '" + shortenString(this.textData) + "' -> '" + 1.63 + shortenString(this.textNode.data) + "' for " + 1.64 + prettyName(this.containerNode); 1.65 + } 1.66 + } 1.67 + 1.68 + function expStr(x, doublings) 1.69 + { 1.70 + for (var i = 0; i < doublings; ++i) 1.71 + x = x + x; 1.72 + return x; 1.73 + } 1.74 + 1.75 + //////////////////////////////////////////////////////////////////////////// 1.76 + // Do tests 1.77 + 1.78 + //gA11yEventDumpID = "eventdump"; // debug stuff 1.79 + //gA11yEventDumpToConsole = true; 1.80 + 1.81 + var gQueue = null; 1.82 + function doTests() 1.83 + { 1.84 + gQueue = new eventQueue(); 1.85 + 1.86 + ////////////////////////////////////////////////////////////////////////// 1.87 + // wqrema -> tqb: substitution coalesced with removal 1.88 + 1.89 + var events = [ 1.90 + [ kRemoval, "w", 0 ], // wqrema -> qrema 1.91 + [ kInsertion, "t", 0], // qrema -> tqrema 1.92 + [ kRemoval, "rema", 2 ], // tqrema -> tq 1.93 + [ kInsertion, "b", 2] // tq -> tqb 1.94 + ]; 1.95 + gQueue.push(new changeText("p1", "tqb", events)); 1.96 + 1.97 + ////////////////////////////////////////////////////////////////////////// 1.98 + // b -> insa: substitution coalesced with insertion (complex substitution) 1.99 + 1.100 + events = [ 1.101 + [ kRemoval, "b", 0 ], // b -> 1.102 + [ kInsertion, "insa", 0] // -> insa 1.103 + ]; 1.104 + gQueue.push(new changeText("p2", "insa", events)); 1.105 + 1.106 + ////////////////////////////////////////////////////////////////////////// 1.107 + // abc -> def: coalesced substitutions 1.108 + 1.109 + events = [ 1.110 + [ kRemoval, "abc", 0 ], // abc -> 1.111 + [ kInsertion, "def", 0] // -> def 1.112 + ]; 1.113 + gQueue.push(new changeText("p3", "def", events)); 1.114 + 1.115 + ////////////////////////////////////////////////////////////////////////// 1.116 + // abcabc -> abcDEFabc: coalesced insertions 1.117 + 1.118 + events = [ 1.119 + [ kInsertion, "DEF", 3] // abcabc -> abcDEFabc 1.120 + ]; 1.121 + gQueue.push(new changeText("p4", "abcDEFabc", events)); 1.122 + 1.123 + ////////////////////////////////////////////////////////////////////////// 1.124 + // abc -> defabc: insertion into begin 1.125 + 1.126 + events = [ 1.127 + [ kInsertion, "def", 0] // abc -> defabc 1.128 + ]; 1.129 + gQueue.push(new changeText("p5", "defabc", events)); 1.130 + 1.131 + ////////////////////////////////////////////////////////////////////////// 1.132 + // abc -> abcdef: insertion into end 1.133 + 1.134 + events = [ 1.135 + [ kInsertion, "def", 3] // abc -> abcdef 1.136 + ]; 1.137 + gQueue.push(new changeText("p6", "abcdef", events)); 1.138 + 1.139 + ////////////////////////////////////////////////////////////////////////// 1.140 + // defabc -> abc: removal from begin 1.141 + 1.142 + events = [ 1.143 + [ kRemoval, "def", 0] // defabc -> abc 1.144 + ]; 1.145 + gQueue.push(new changeText("p7", "abc", events)); 1.146 + 1.147 + ////////////////////////////////////////////////////////////////////////// 1.148 + // abcdef -> abc: removal from the end 1.149 + 1.150 + events = [ 1.151 + [ kRemoval, "def", 3] // abcdef -> abc 1.152 + ]; 1.153 + gQueue.push(new changeText("p8", "abc", events)); 1.154 + 1.155 + ////////////////////////////////////////////////////////////////////////// 1.156 + // abcDEFabc -> abcabc: coalesced removals 1.157 + 1.158 + events = [ 1.159 + [ kRemoval, "DEF", 3] // abcDEFabc -> abcabc 1.160 + ]; 1.161 + gQueue.push(new changeText("p9", "abcabc", events)); 1.162 + 1.163 + ////////////////////////////////////////////////////////////////////////// 1.164 + // !abcdef@ -> @axbcef!: insertion, deletion and substitutions 1.165 + 1.166 + events = [ 1.167 + [ kRemoval, "!", 0 ], // !abcdef@ -> abcdef@ 1.168 + [ kInsertion, "@", 0], // abcdef@ -> @abcdef@ 1.169 + [ kInsertion, "x", 2 ], // @abcdef@ -> @axbcdef@ 1.170 + [ kRemoval, "d", 5], // @axbcdef@ -> @axbcef@ 1.171 + [ kRemoval, "@", 7 ], // @axbcef@ -> @axbcef 1.172 + [ kInsertion, "!", 7 ], // @axbcef -> @axbcef! 1.173 + ]; 1.174 + gQueue.push(new changeText("p10", "@axbcef!", events)); 1.175 + 1.176 + ////////////////////////////////////////////////////////////////////////// 1.177 + // meilenstein -> levenshtein: insertion, complex and simple substitutions 1.178 + 1.179 + events = [ 1.180 + [ kRemoval, "m", 0 ], // meilenstein -> eilenstein 1.181 + [ kInsertion, "l", 0], // eilenstein -> leilenstein 1.182 + [ kRemoval, "il", 2 ], // leilenstein -> leenstein 1.183 + [ kInsertion, "v", 2], // leenstein -> levenstein 1.184 + [ kInsertion, "h", 6 ], // levenstein -> levenshtein 1.185 + ]; 1.186 + gQueue.push(new changeText("p11", "levenshtein", events)); 1.187 + 1.188 + ////////////////////////////////////////////////////////////////////////// 1.189 + // long strings, remove/insert pair as the old string was replaced on 1.190 + // new one 1.191 + 1.192 + var longStr1 = expStr("x", 16); 1.193 + var longStr2 = expStr("X", 16); 1.194 + 1.195 + var newStr = "a" + longStr1 + "b", insStr = longStr1, rmStr = ""; 1.196 + events = [ 1.197 + [ kRemoval, rmStr, 1, kUnexpected ], 1.198 + [ kInsertion, insStr, 1 ] 1.199 + ]; 1.200 + gQueue.push(new changeText("p12", newStr, events)); 1.201 + 1.202 + newStr = "a" + longStr2 + "b", insStr = longStr2, rmStr = longStr1; 1.203 + events = [ 1.204 + [ kRemoval, rmStr, 1 ], 1.205 + [ kInsertion, insStr, 1] 1.206 + ]; 1.207 + gQueue.push(new changeText("p12", newStr, events)); 1.208 + 1.209 + newStr = "ab", insStr = "", rmStr = longStr2; 1.210 + events = [ 1.211 + [ kRemoval, rmStr, 1 ], 1.212 + [ kInsertion, insStr, 1, kUnexpected ] 1.213 + ]; 1.214 + gQueue.push(new changeText("p12", newStr, events)); 1.215 + 1.216 + gQueue.invoke(); // Will call SimpleTest.finish(); 1.217 + } 1.218 + 1.219 + SimpleTest.waitForExplicitFinish(); 1.220 + addA11yLoadEvent(doTests); 1.221 + </script> 1.222 +</head> 1.223 + 1.224 +<body> 1.225 + 1.226 + <a target="_blank" 1.227 + href="https://bugzilla.mozilla.org/show_bug.cgi?id=626660" 1.228 + title="Cache rendered text on a11y side"> 1.229 + Mozilla Bug 626660 1.230 + </a> 1.231 + <br> 1.232 + 1.233 + <p id="display"></p> 1.234 + <div id="content" style="display: none"></div> 1.235 + <pre id="test"> 1.236 + </pre> 1.237 + <div id="eventdump"></div> 1.238 + 1.239 + <p id="p1">wqrema</p> 1.240 + <p id="p2">b</p> 1.241 + <p id="p3">abc</p> 1.242 + <p id="p4">abcabc</p> 1.243 + <p id="p5">abc</p> 1.244 + <p id="p6">abc</p> 1.245 + <p id="p7">defabc</p> 1.246 + <p id="p8">abcdef</p> 1.247 + <p id="p9">abcDEFabc</p> 1.248 + <p id="p10">!abcdef@</p> 1.249 + <p id="p11">meilenstein</p> 1.250 + <p id="p12">ab</p> 1.251 +</body> 1.252 +</html>