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;
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
27 * @param aAttrs the map of text attributes (name/value pairs)
28 * @param aStartOffset the start offset where text attributes are
30 * @param aEndOffset the end offset where text attribute are applied
31 * @param aDefAttrs the list of default text attributes (name/value
34 function testTextAttrs(aID, aOffset,
35 aAttrs, aStartOffset, aEndOffset, aDefAttrs)
37 var node = document.getElementById(aID);
39 ok(false,
"Can't get the element with ID " + aID);
43 var accessible = null;
45 accessible = gAccRetrieval.getAccessibleFor(node);
46 accessible.QueryInterface(nsIAccessibleText);
51 ok(false,
"Can't query nsIAccessibleText interface for " + aID);
55 var startOffset = { value: -
1 };
56 var endOffset = { value: -
1 };
59 attrs = accessible.getTextAttributes(false,
61 startOffset, endOffset);
66 ok(false,
"Can't get text attributes for " + aID);
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);
80 defAttrs = accessible.defaultTextAttributes;
85 ok(false,
"Can't get default attributes for " + aID);
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))
101 "Unexpected attribute '" + prop.key +
"'" + aErrorMsg);
103 is(prop.value, aExpectedAttrs[prop.key],
104 "Attribute '" + prop.key +
"' has wrong value" + aErrorMsg);
107 for (var name in aExpectedAttrs) {
110 value = aAttrs.getStringProperty(name);
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")
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",
150 var node = document.getElementById(ID);
153 var editor = node.QueryInterface(nsIDOMNSEditableElement).editor;
154 var spellchecker = editor.getInlineSpellChecker(true);
155 spellchecker.enableRealTimeSpell = true;
157 window.setTimeout(function()
160 "font-style":
"normal",
161 "text-align":
"start",
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,
194 gAccRetrieval = Components.classes[
"@mozilla.org/accessibleRetrieval;1"].
195 getService(nsIAccessibleRetrieval);
197 //////////////////////////////////////////////////////////////////////////
201 "font-style":
"normal",
202 "text-align":
"start",
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"
213 testTextAttrs(ID,
0, attrs,
0,
7, defAttrs);
215 attrs = {
"font-weight":
"401"};
216 testTextAttrs(ID,
7, attrs,
7,
11, defAttrs);
219 testTextAttrs(ID,
12, attrs,
11,
18, defAttrs);
221 //////////////////////////////////////////////////////////////////////////
225 "font-style":
"normal",
226 "text-align":
"start",
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"
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);
249 testTextAttrs(ID,
24, attrs,
23,
30, defAttrs);
251 //////////////////////////////////////////////////////////////////////////
255 "font-style":
"normal",
256 "text-align":
"start",
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 //////////////////////////////////////////////////////////////////////////
279 "font-style":
"normal",
280 "text-align":
"start",
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 //////////////////////////////////////////////////////////////////////////
303 "font-style":
"normal",
304 "text-align":
"start",
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);
318 testTextAttrs(ID,
7, attrs,
5,
8, defAttrs);
320 attrs = {
"color":
"rgb(255, 0, 0)"};
321 testTextAttrs(ID,
9, attrs,
8,
11, defAttrs);
324 testTextAttrs(ID,
11, attrs,
11,
18, defAttrs);
326 //////////////////////////////////////////////////////////////////////////
327 // area6 (CSS vertical-align property, bug
445938)
330 "font-style":
"normal",
331 "text-align":
"start",
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"
342 testTextAttrs(ID,
0, attrs,
0,
5, defAttrs);
344 attrs = {
"text-position":
"super",
"font-size":
"13px" };
345 testTextAttrs(ID,
5, attrs,
5,
13, defAttrs);
348 testTextAttrs(ID,
13, attrs,
13,
27, defAttrs);
350 attrs = {
"text-position":
"super" };
351 testTextAttrs(ID,
27, attrs,
27,
35, defAttrs);
354 testTextAttrs(ID,
35, attrs,
35,
39, defAttrs);
356 attrs = {
"text-position":
"sub",
"font-size":
"13px" };
357 testTextAttrs(ID,
39, attrs,
39,
50, defAttrs);
360 testTextAttrs(ID,
50, attrs,
50,
55, defAttrs);
362 attrs = {
"text-position":
"sub" };
363 testTextAttrs(ID,
55, attrs,
55,
64, defAttrs);
365 //////////////////////////////////////////////////////////////////////////
369 "font-style":
"normal",
370 "text-align":
"start",
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);
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);
422 href=
"https://bugzilla.mozilla.org/show_bug.cgi?id=345759"
423 title=
"Implement text attributes">
427 <div id=
"content" style=
"display: none"></div>
431 <p id=
"area1">Normal
<b>Bold
</b> Normal
</p>
432 <p id=
"area2">Normal
<b>Bold
<i>Italic
</i>Bold
</b> Normal
</p>
434 <span style=
"color: green">
436 <span style=
"color: red">but children are red
</span>
437 </span><span style=
"color: green">
438 Another green section.
442 <span style=
"color: green">
444 </span><span style=
"color: green">
446 <span style=
"color: red">with red children
</span>
451 <span style=
"color: green">Green
</span>
452 <img src=
"moz.png" alt=
"image"/>
453 <span style=
"color: red">Red
</span>Normal
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>
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>
468 <span style=
"color: magenta">Magenta
<b>Bold
</b>Magenta
</span>
472 <input id=
"area8" value=
"valid text inalid tixt"/>