Backed out changeset db55605b2a4c (relanding bug 121341)
[wine-gecko.git] / accessible / tests / mochitest / test_textattrs.html
blob5880519a7be0bfc3121cc3fd607a4b3765c4e42e
1 <html>
3 <head>
4 <title>Text attributes tests</title>
5 <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css" />
7 <script type="application/javascript" src="chrome://mochikit/content/MochiKit/packed.js"></script>
8 <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
10 <script type="application/javascript">
11 const nsIAccessibleRetrieval = Components.interfaces.nsIAccessibleRetrieval;
12 const nsIAccessibleText = Components.interfaces.nsIAccessibleText;
13 const nsIAccessibleEvent = Components.interfaces.nsIAccessibleEvent;
15 const nsIDOMNSEditableElement =
16 Components.interfaces.nsIDOMNSEditableElement;
17 const nsIObserverService = Components.interfaces.nsIObserverService;
19 var gAccRetrieval = null;
21 /**
22 * Test text attributes.
24 * @param aID the ID of DOM element having text accessible
25 * @param aOffset the offset inside text accessible to fetch
26 * text attributes
27 * @param aAttrs the map of text attributes (name/value pairs)
28 * @param aStartOffset the start offset where text attributes are
29 * applied
30 * @param aEndOffset the end offset where text attribute are applied
31 * @param aDefAttrs the list of default text attributes (name/value
32 * pairs)
34 function testTextAttrs(aID, aOffset,
35 aAttrs, aStartOffset, aEndOffset, aDefAttrs)
37 var node = document.getElementById(aID);
38 if (!node) {
39 ok(false, "Can't get the element with ID " + aID);
40 return;
43 var accessible = null;
44 try {
45 accessible = gAccRetrieval.getAccessibleFor(node);
46 accessible.QueryInterface(nsIAccessibleText);
47 } catch (e) {
50 if (!accessible) {
51 ok(false, "Can't query nsIAccessibleText interface for " + aID);
52 return;
55 var startOffset = { value: -1 };
56 var endOffset = { value: -1 };
57 var attrs = null;
58 try {
59 attrs = accessible.getTextAttributes(false,
60 aOffset,
61 startOffset, endOffset);
62 } catch (e) {
65 if (!attrs) {
66 ok(false, "Can't get text attributes for " + aID);
67 return;
70 var errorMsg = " for " + aID + "at offset " + aOffset;
71 is(startOffset.value, aStartOffset,
72 "Wrong start offset" + errorMsg);
73 is(endOffset.value, aEndOffset,
74 "Wrong end offset" + errorMsg);
76 compareTextAttrs(errorMsg, attrs, aAttrs);
78 var defAttrs = null;
79 try{
80 defAttrs = accessible.defaultTextAttributes;
81 } catch (e) {
84 if (!defAttrs) {
85 ok(false, "Can't get default attributes for " + aID);
86 return;
89 compareTextAttrs(errorMsg, defAttrs, aDefAttrs);
92 function compareTextAttrs(aErrorMsg, aAttrs, aExpectedAttrs)
94 var enumerate = aAttrs.enumerate();
95 while (enumerate.hasMoreElements()) {
96 var prop = enumerate.getNext().
97 QueryInterface(Components.interfaces.nsIPropertyElement);
99 if (!(prop.key in aExpectedAttrs))
100 ok(false,
101 "Unexpected attribute '" + prop.key + "'" + aErrorMsg);
102 else
103 is(prop.value, aExpectedAttrs[prop.key],
104 "Attribute '" + prop.key + "' has wrong value" + aErrorMsg);
107 for (var name in aExpectedAttrs) {
108 var value = "";
109 try {
110 value = aAttrs.getStringProperty(name);
111 } catch(e) {
114 if (!value)
115 ok(false,
116 "There is no expected attribute '" + name + "'" + aErrorMsg);
120 var gObserverService = null;
121 var gA11yEventObserver = null;
123 function testSpellTextAttrs()
125 gA11yEventObserver = {
126 observe: function observe(aSubject, aTopic, aData)
128 if (aTopic != "accessible-event")
129 return;
132 var event = aSubject.QueryInterface(nsIAccessibleEvent);
134 if (event.eventType == nsIAccessibleEvent.EVENT_TEXT_ATTRIBUTE_CHANGED)
135 this.mTextAttrChangedEventCounter++;
138 mTextAttrChangedEventCounter: 0
141 // Add accessibility event listeners
142 var gObserverService = Components.classes["@mozilla.org/observer-service;1"].
143 getService(nsIObserverService);
145 gObserverService.addObserver(gA11yEventObserver, "accessible-event",
146 false);
148 ID = "area8";
150 var node = document.getElementById(ID);
151 node.focus();
153 var editor = node.QueryInterface(nsIDOMNSEditableElement).editor;
154 var spellchecker = editor.getInlineSpellChecker(true);
155 spellchecker.enableRealTimeSpell = true;
157 window.setTimeout(function()
159 var defAttrs = {
160 "font-style": "normal",
161 "text-align": "start",
162 "font-size": "11px",
163 "background-color": "rgb(255, 255, 255)",
164 "font-weight": "400",
165 "text-indent": "0px",
166 "color": "rgb(0, 0, 0)",
167 "font-family": "Lucida Grande",
168 "text-position": "baseline"
171 var attrs = { "background-color": "transparent" };
172 var misspelledAttrs = {
173 "background-color": "transparent",
174 "invalid": "spelling"
177 testTextAttrs(ID, 0, attrs, 0, 11, defAttrs);
178 testTextAttrs(ID, 11, misspelledAttrs, 11, 17, defAttrs);
179 testTextAttrs(ID, 18, misspelledAttrs, 18, 22, defAttrs);
181 is(gA11yEventObserver.mTextAttrChangedEventCounter, 2,
182 "Wrong count of 'text attribute changed' events for " + ID);
184 // Remove a11y events listener
185 gObserverService.removeObserver(gA11yEventObserver,
186 "accessible-event");
188 SimpleTest.finish();
189 }, 0);
192 function doTest()
194 gAccRetrieval = Components.classes["@mozilla.org/accessibleRetrieval;1"].
195 getService(nsIAccessibleRetrieval);
197 //////////////////////////////////////////////////////////////////////////
198 // area1
199 var ID = "area1";
200 var defAttrs = {
201 "font-style": "normal",
202 "text-align": "start",
203 "font-size": "16px",
204 "background-color": "transparent",
205 "font-weight": "400",
206 "text-indent": "0px",
207 "color": "rgb(0, 0, 0)",
208 "font-family": "serif",
209 "text-position": "baseline"
212 var attrs = {};
213 testTextAttrs(ID, 0, attrs, 0, 7, defAttrs);
215 attrs = {"font-weight": "401"};
216 testTextAttrs(ID, 7, attrs, 7, 11, defAttrs);
218 attrs = {};
219 testTextAttrs(ID, 12, attrs, 11, 18, defAttrs);
221 //////////////////////////////////////////////////////////////////////////
222 // area2
223 ID = "area2";
224 defAttrs = {
225 "font-style": "normal",
226 "text-align": "start",
227 "font-size": "16px",
228 "background-color": "transparent",
229 "font-weight": "400",
230 "text-indent": "0px",
231 "color": "rgb(0, 0, 0)",
232 "font-family": "serif",
233 "text-position": "baseline"
236 attrs = {};
237 testTextAttrs(ID, 0, attrs, 0, 7, defAttrs);
239 attrs = {"font-weight": "401"};
240 testTextAttrs(ID, 7, attrs, 7, 12, defAttrs);
242 attrs = {"font-style": "italic", "font-weight": "401"};
243 testTextAttrs(ID, 13, attrs, 12, 19, defAttrs);
245 attrs = {"font-weight": "401"};
246 testTextAttrs(ID, 20, attrs, 19, 23, defAttrs);
248 attrs = {};
249 testTextAttrs(ID, 24, attrs, 23, 30, defAttrs);
251 //////////////////////////////////////////////////////////////////////////
252 // area3
253 ID = "area3";
254 defAttrs = {
255 "font-style": "normal",
256 "text-align": "start",
257 "font-size": "16px",
258 "background-color": "transparent",
259 "font-weight": "400",
260 "text-indent": "0px",
261 "color": "rgb(0, 0, 0)",
262 "font-family": "serif",
263 "text-position": "baseline"
266 attrs = {"color": "rgb(0, 128, 0)"};
267 testTextAttrs(ID, 0, attrs, 0, 6, defAttrs);
269 attrs = {"color": "rgb(255, 0, 0)"};
270 testTextAttrs(ID, 6, attrs, 6, 26, defAttrs);
272 attrs = {"color": "rgb(0, 128, 0)"};
273 testTextAttrs(ID, 26, attrs, 26, 50, defAttrs);
275 //////////////////////////////////////////////////////////////////////////
276 // area4
277 ID = "area4";
278 defAttrs = {
279 "font-style": "normal",
280 "text-align": "start",
281 "font-size": "16px",
282 "background-color": "transparent",
283 "font-weight": "400",
284 "text-indent": "0px",
285 "color": "rgb(0, 0, 0)",
286 "font-family": "serif",
287 "text-position": "baseline"
290 attrs = {"color": "rgb(0, 128, 0)"};
291 testTextAttrs(ID, 0, attrs, 0, 16, defAttrs);
293 attrs = {"color": "rgb(255, 0, 0)"};
294 testTextAttrs(ID, 16, attrs, 16, 33, defAttrs);
296 attrs = {"color": "rgb(0, 128, 0)"};
297 testTextAttrs(ID, 34, attrs, 33, 46, defAttrs);
299 //////////////////////////////////////////////////////////////////////////
300 // area5
301 ID = "area5";
302 defAttrs = {
303 "font-style": "normal",
304 "text-align": "start",
305 "font-size": "16px",
306 "background-color": "transparent",
307 "font-weight": "400",
308 "text-indent": "0px",
309 "color": "rgb(0, 0, 0)",
310 "font-family": "serif",
311 "text-position": "baseline"
314 attrs = {"color": "rgb(0, 128, 0)"};
315 testTextAttrs(ID, 0, attrs, 0, 5, defAttrs);
317 attrs = {};
318 testTextAttrs(ID, 7, attrs, 5, 8, defAttrs);
320 attrs = {"color": "rgb(255, 0, 0)"};
321 testTextAttrs(ID, 9, attrs, 8, 11, defAttrs);
323 attrs = {};
324 testTextAttrs(ID, 11, attrs, 11, 18, defAttrs);
326 //////////////////////////////////////////////////////////////////////////
327 // area6 (CSS vertical-align property, bug 445938)
328 ID = "area6";
329 defAttrs = {
330 "font-style": "normal",
331 "text-align": "start",
332 "font-size": "16px",
333 "background-color": "transparent",
334 "font-weight": "400",
335 "text-indent": "0px",
336 "color": "rgb(0, 0, 0)",
337 "font-family": "serif",
338 "text-position": "baseline"
341 attrs = {};
342 testTextAttrs(ID, 0, attrs, 0, 5, defAttrs);
344 attrs = {"text-position": "super", "font-size": "13px" };
345 testTextAttrs(ID, 5, attrs, 5, 13, defAttrs);
347 attrs = {};
348 testTextAttrs(ID, 13, attrs, 13, 27, defAttrs);
350 attrs = {"text-position": "super" };
351 testTextAttrs(ID, 27, attrs, 27, 35, defAttrs);
353 attrs = {};
354 testTextAttrs(ID, 35, attrs, 35, 39, defAttrs);
356 attrs = {"text-position": "sub", "font-size": "13px" };
357 testTextAttrs(ID, 39, attrs, 39, 50, defAttrs);
359 attrs = {};
360 testTextAttrs(ID, 50, attrs, 50, 55, defAttrs);
362 attrs = {"text-position": "sub" };
363 testTextAttrs(ID, 55, attrs, 55, 64, defAttrs);
365 //////////////////////////////////////////////////////////////////////////
366 // area7
367 ID = "area7";
368 defAttrs = {
369 "font-style": "normal",
370 "text-align": "start",
371 "font-size": "16px",
372 "background-color": "transparent",
373 "font-weight": "400",
374 "text-indent": "0px",
375 "color": "rgb(0, 0, 0)",
376 "font-family": "serif",
377 "text-position": "baseline"
380 attrs = {"language": "ru"};
381 testTextAttrs(ID, 0, attrs, 0, 12, defAttrs);
383 attrs = {"language": "en"};
384 testTextAttrs(ID, 12, attrs, 12, 13, defAttrs);
386 attrs = {"language" :"en", "background-color": "rgb(0, 0, 255)"};
387 testTextAttrs(ID, 13, attrs, 13, 26, defAttrs);
389 attrs = {"language": "en" };
390 testTextAttrs(ID, 26, attrs, 26, 27, defAttrs);
392 attrs = {"language": "de"};
393 testTextAttrs(ID, 27, attrs, 27, 42, defAttrs);
395 attrs = {"language": "en"};
396 testTextAttrs(ID, 42, attrs, 42, 43, defAttrs);
398 attrs = {};
399 testTextAttrs(ID, 43, attrs, 43, 50, defAttrs);
401 attrs = {"color": "rgb(255, 0, 255)"};
402 testTextAttrs(ID, 50, attrs, 50, 57, defAttrs);
404 attrs = {"font-weight": "401", "color": "rgb(255, 0, 255)" };
405 testTextAttrs(ID, 57, attrs, 57, 61, defAttrs);
407 attrs = {"color": "rgb(255, 0, 255)"};
408 testTextAttrs(ID, 61, attrs, 61, 68, defAttrs);
410 //////////////////////////////////////////////////////////////////////////
411 // test spelling text attributes
412 testSpellTextAttrs(); // Will call SimpleTest.finish();
415 SimpleTest.waitForExplicitFinish();
416 addLoadEvent(doTest);
417 </script>
418 </head>
419 <body>
421 <a target="_blank"
422 href="https://bugzilla.mozilla.org/show_bug.cgi?id=345759"
423 title="Implement text attributes">
424 Mozilla Bug 345759
425 </a>
426 <p id="display"></p>
427 <div id="content" style="display: none"></div>
428 <pre id="test">
429 </pre>
431 <p id="area1">Normal <b>Bold</b> Normal</p>
432 <p id="area2">Normal <b>Bold <i>Italic </i>Bold</b> Normal</p>
433 <p id="area3">
434 <span style="color: green">
435 Green
436 <span style="color: red">but children are red</span>
437 </span><span style="color: green">
438 Another green section.
439 </span>
440 </p>
441 <p id="area4">
442 <span style="color: green">
443 Green
444 </span><span style="color: green">
445 Green too
446 <span style="color: red">with red children</span>
447 Green again
448 </span>
449 </p>
450 <p id="area5">
451 <span style="color: green">Green</span>
452 <img src="moz.png" alt="image"/>
453 <span style="color: red">Red</span>Normal
454 </p>
455 <p id="area6">
456 This <sup>sentence</sup> has the word
457 <span style="vertical-align:super;">sentence</span> in
458 <sub>superscript</sub> and
459 <span style="vertical-align:sub;">subscript</span>
460 </p>
462 <p lang="en" id="area7">
463 <span lang="ru">Привет</span>
464 <span style="background-color: blue">Blue BG color</span>
465 <span lang="de">Ich bin/Du bist</span>
466 <span lang="en">
467 Normal
468 <span style="color: magenta">Magenta<b>Bold</b>Magenta</span>
469 </span>
470 </p>
472 <input id="area8" value="valid text inalid tixt"/>
474 <p id="output"/>
475 </body>
476 </html>