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