accessible/tests/mochitest/events/test_text_alg.html

Fri, 16 Jan 2015 18:13:44 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Fri, 16 Jan 2015 18:13:44 +0100
branch
TOR_BUG_9701
changeset 14
925c144e1f1f
permissions
-rw-r--r--

Integrate suggestion from review to improve consistency with existing code.

michael@0 1 <html>
michael@0 2
michael@0 3 <head>
michael@0 4 <title>Accessible text update algorithm testing</title>
michael@0 5
michael@0 6 <link rel="stylesheet" type="text/css"
michael@0 7 href="chrome://mochikit/content/tests/SimpleTest/test.css" />
michael@0 8
michael@0 9 <script type="application/javascript"
michael@0 10 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
michael@0 11 <script type="application/javascript"
michael@0 12 src="chrome://mochikit/content/tests/SimpleTest/EventUtils.js"></script>
michael@0 13
michael@0 14 <script type="application/javascript"
michael@0 15 src="../common.js"></script>
michael@0 16 <script type="application/javascript"
michael@0 17 src="../events.js"></script>
michael@0 18
michael@0 19 <script type="application/javascript">
michael@0 20 ////////////////////////////////////////////////////////////////////////////
michael@0 21 // Invokers
michael@0 22
michael@0 23 const kRemoval = 0;
michael@0 24 const kInsertion = 1;
michael@0 25 const kUnexpected = true;
michael@0 26
michael@0 27 function changeText(aContainerID, aValue, aEventList)
michael@0 28 {
michael@0 29 this.containerNode = getNode(aContainerID);
michael@0 30 this.textNode = this.containerNode.firstChild;
michael@0 31 this.textData = this.textNode.data;
michael@0 32
michael@0 33 this.eventSeq = [ ];
michael@0 34 this.unexpectedEventSeq = [ ];
michael@0 35
michael@0 36 for (var i = 0; i < aEventList.length; i++) {
michael@0 37 var event = aEventList[i];
michael@0 38
michael@0 39 var isInserted = event[0];
michael@0 40 var str = event[1];
michael@0 41 var offset = event[2];
michael@0 42 var checker = new textChangeChecker(this.containerNode, offset,
michael@0 43 offset + str.length, str,
michael@0 44 isInserted);
michael@0 45
michael@0 46 if (event[3] == kUnexpected)
michael@0 47 this.unexpectedEventSeq.push(checker);
michael@0 48 else
michael@0 49 this.eventSeq.push(checker);
michael@0 50 }
michael@0 51
michael@0 52 this.invoke = function changeText_invoke()
michael@0 53 {
michael@0 54 this.textNode.data = aValue;
michael@0 55 }
michael@0 56
michael@0 57 this.getID = function changeText_getID()
michael@0 58 {
michael@0 59 return "change text '" + shortenString(this.textData) + "' -> '" +
michael@0 60 shortenString(this.textNode.data) + "' for " +
michael@0 61 prettyName(this.containerNode);
michael@0 62 }
michael@0 63 }
michael@0 64
michael@0 65 function expStr(x, doublings)
michael@0 66 {
michael@0 67 for (var i = 0; i < doublings; ++i)
michael@0 68 x = x + x;
michael@0 69 return x;
michael@0 70 }
michael@0 71
michael@0 72 ////////////////////////////////////////////////////////////////////////////
michael@0 73 // Do tests
michael@0 74
michael@0 75 //gA11yEventDumpID = "eventdump"; // debug stuff
michael@0 76 //gA11yEventDumpToConsole = true;
michael@0 77
michael@0 78 var gQueue = null;
michael@0 79 function doTests()
michael@0 80 {
michael@0 81 gQueue = new eventQueue();
michael@0 82
michael@0 83 //////////////////////////////////////////////////////////////////////////
michael@0 84 // wqrema -> tqb: substitution coalesced with removal
michael@0 85
michael@0 86 var events = [
michael@0 87 [ kRemoval, "w", 0 ], // wqrema -> qrema
michael@0 88 [ kInsertion, "t", 0], // qrema -> tqrema
michael@0 89 [ kRemoval, "rema", 2 ], // tqrema -> tq
michael@0 90 [ kInsertion, "b", 2] // tq -> tqb
michael@0 91 ];
michael@0 92 gQueue.push(new changeText("p1", "tqb", events));
michael@0 93
michael@0 94 //////////////////////////////////////////////////////////////////////////
michael@0 95 // b -> insa: substitution coalesced with insertion (complex substitution)
michael@0 96
michael@0 97 events = [
michael@0 98 [ kRemoval, "b", 0 ], // b ->
michael@0 99 [ kInsertion, "insa", 0] // -> insa
michael@0 100 ];
michael@0 101 gQueue.push(new changeText("p2", "insa", events));
michael@0 102
michael@0 103 //////////////////////////////////////////////////////////////////////////
michael@0 104 // abc -> def: coalesced substitutions
michael@0 105
michael@0 106 events = [
michael@0 107 [ kRemoval, "abc", 0 ], // abc ->
michael@0 108 [ kInsertion, "def", 0] // -> def
michael@0 109 ];
michael@0 110 gQueue.push(new changeText("p3", "def", events));
michael@0 111
michael@0 112 //////////////////////////////////////////////////////////////////////////
michael@0 113 // abcabc -> abcDEFabc: coalesced insertions
michael@0 114
michael@0 115 events = [
michael@0 116 [ kInsertion, "DEF", 3] // abcabc -> abcDEFabc
michael@0 117 ];
michael@0 118 gQueue.push(new changeText("p4", "abcDEFabc", events));
michael@0 119
michael@0 120 //////////////////////////////////////////////////////////////////////////
michael@0 121 // abc -> defabc: insertion into begin
michael@0 122
michael@0 123 events = [
michael@0 124 [ kInsertion, "def", 0] // abc -> defabc
michael@0 125 ];
michael@0 126 gQueue.push(new changeText("p5", "defabc", events));
michael@0 127
michael@0 128 //////////////////////////////////////////////////////////////////////////
michael@0 129 // abc -> abcdef: insertion into end
michael@0 130
michael@0 131 events = [
michael@0 132 [ kInsertion, "def", 3] // abc -> abcdef
michael@0 133 ];
michael@0 134 gQueue.push(new changeText("p6", "abcdef", events));
michael@0 135
michael@0 136 //////////////////////////////////////////////////////////////////////////
michael@0 137 // defabc -> abc: removal from begin
michael@0 138
michael@0 139 events = [
michael@0 140 [ kRemoval, "def", 0] // defabc -> abc
michael@0 141 ];
michael@0 142 gQueue.push(new changeText("p7", "abc", events));
michael@0 143
michael@0 144 //////////////////////////////////////////////////////////////////////////
michael@0 145 // abcdef -> abc: removal from the end
michael@0 146
michael@0 147 events = [
michael@0 148 [ kRemoval, "def", 3] // abcdef -> abc
michael@0 149 ];
michael@0 150 gQueue.push(new changeText("p8", "abc", events));
michael@0 151
michael@0 152 //////////////////////////////////////////////////////////////////////////
michael@0 153 // abcDEFabc -> abcabc: coalesced removals
michael@0 154
michael@0 155 events = [
michael@0 156 [ kRemoval, "DEF", 3] // abcDEFabc -> abcabc
michael@0 157 ];
michael@0 158 gQueue.push(new changeText("p9", "abcabc", events));
michael@0 159
michael@0 160 //////////////////////////////////////////////////////////////////////////
michael@0 161 // !abcdef@ -> @axbcef!: insertion, deletion and substitutions
michael@0 162
michael@0 163 events = [
michael@0 164 [ kRemoval, "!", 0 ], // !abcdef@ -> abcdef@
michael@0 165 [ kInsertion, "@", 0], // abcdef@ -> @abcdef@
michael@0 166 [ kInsertion, "x", 2 ], // @abcdef@ -> @axbcdef@
michael@0 167 [ kRemoval, "d", 5], // @axbcdef@ -> @axbcef@
michael@0 168 [ kRemoval, "@", 7 ], // @axbcef@ -> @axbcef
michael@0 169 [ kInsertion, "!", 7 ], // @axbcef -> @axbcef!
michael@0 170 ];
michael@0 171 gQueue.push(new changeText("p10", "@axbcef!", events));
michael@0 172
michael@0 173 //////////////////////////////////////////////////////////////////////////
michael@0 174 // meilenstein -> levenshtein: insertion, complex and simple substitutions
michael@0 175
michael@0 176 events = [
michael@0 177 [ kRemoval, "m", 0 ], // meilenstein -> eilenstein
michael@0 178 [ kInsertion, "l", 0], // eilenstein -> leilenstein
michael@0 179 [ kRemoval, "il", 2 ], // leilenstein -> leenstein
michael@0 180 [ kInsertion, "v", 2], // leenstein -> levenstein
michael@0 181 [ kInsertion, "h", 6 ], // levenstein -> levenshtein
michael@0 182 ];
michael@0 183 gQueue.push(new changeText("p11", "levenshtein", events));
michael@0 184
michael@0 185 //////////////////////////////////////////////////////////////////////////
michael@0 186 // long strings, remove/insert pair as the old string was replaced on
michael@0 187 // new one
michael@0 188
michael@0 189 var longStr1 = expStr("x", 16);
michael@0 190 var longStr2 = expStr("X", 16);
michael@0 191
michael@0 192 var newStr = "a" + longStr1 + "b", insStr = longStr1, rmStr = "";
michael@0 193 events = [
michael@0 194 [ kRemoval, rmStr, 1, kUnexpected ],
michael@0 195 [ kInsertion, insStr, 1 ]
michael@0 196 ];
michael@0 197 gQueue.push(new changeText("p12", newStr, events));
michael@0 198
michael@0 199 newStr = "a" + longStr2 + "b", insStr = longStr2, rmStr = longStr1;
michael@0 200 events = [
michael@0 201 [ kRemoval, rmStr, 1 ],
michael@0 202 [ kInsertion, insStr, 1]
michael@0 203 ];
michael@0 204 gQueue.push(new changeText("p12", newStr, events));
michael@0 205
michael@0 206 newStr = "ab", insStr = "", rmStr = longStr2;
michael@0 207 events = [
michael@0 208 [ kRemoval, rmStr, 1 ],
michael@0 209 [ kInsertion, insStr, 1, kUnexpected ]
michael@0 210 ];
michael@0 211 gQueue.push(new changeText("p12", newStr, events));
michael@0 212
michael@0 213 gQueue.invoke(); // Will call SimpleTest.finish();
michael@0 214 }
michael@0 215
michael@0 216 SimpleTest.waitForExplicitFinish();
michael@0 217 addA11yLoadEvent(doTests);
michael@0 218 </script>
michael@0 219 </head>
michael@0 220
michael@0 221 <body>
michael@0 222
michael@0 223 <a target="_blank"
michael@0 224 href="https://bugzilla.mozilla.org/show_bug.cgi?id=626660"
michael@0 225 title="Cache rendered text on a11y side">
michael@0 226 Mozilla Bug 626660
michael@0 227 </a>
michael@0 228 <br>
michael@0 229
michael@0 230 <p id="display"></p>
michael@0 231 <div id="content" style="display: none"></div>
michael@0 232 <pre id="test">
michael@0 233 </pre>
michael@0 234 <div id="eventdump"></div>
michael@0 235
michael@0 236 <p id="p1">wqrema</p>
michael@0 237 <p id="p2">b</p>
michael@0 238 <p id="p3">abc</p>
michael@0 239 <p id="p4">abcabc</p>
michael@0 240 <p id="p5">abc</p>
michael@0 241 <p id="p6">abc</p>
michael@0 242 <p id="p7">defabc</p>
michael@0 243 <p id="p8">abcdef</p>
michael@0 244 <p id="p9">abcDEFabc</p>
michael@0 245 <p id="p10">!abcdef@</p>
michael@0 246 <p id="p11">meilenstein</p>
michael@0 247 <p id="p12">ab</p>
michael@0 248 </body>
michael@0 249 </html>

mercurial