1 <!DOCTYPE HTML PUBLIC
"-//IETF//DTD HTML//EN">
5 <script src=
"../resources/js-test.js"></script>
9 <p id=
"paragraph" style=
"width: 30em;">
10 The Hitchhiker's Guide to the
12 Galaxy has a few things to say on the subject of resumés.
13 A resumé, it says, is about the most massively useful thing an interstellar hitch hiker can have.
16 <p id=
"description"></p>
18 <div id=
"console"></div>
22 description("Tests that we can compute the bounds of a range of text from the accessibility tree.");
24 if (window
.accessibilityController
) {
25 var axParagraph
= accessibilityController
.accessibleElementById('paragraph');
26 var axStaticText
= axParagraph
.childAtIndex(0);
28 // The first characters of stringValue are 'AXValue: ' - use substr to get rid of those.
29 // The accessible text shouldn't have any spaces.
30 var text
= axStaticText
.stringValue
.substr(9);
31 shouldBe("text.length", "185");
32 debug("Accessible text: \"" + text
+ "\"");
34 // Append the text from all of the inline text boxes and make sure we get the same text.
35 var appendedInlineText
= '';
36 for (var i
= 0; i
< axStaticText
.childrenCount
; i
++) {
37 var axInlineTextBox
= axStaticText
.childAtIndex(i
);
38 appendedInlineText
+= axInlineTextBox
.stringValue
.substr(9);
40 shouldBe("appendedInlineText", "text");
42 // For several possible words in the text, get the bounds of the word in the accessibility
43 // tree, and also in the DOM, and assert that they're the same, within one pixel.
44 var paragraph
= document
.getElementById('paragraph');
45 var domText
= paragraph
.innerHTML
;
46 function testWord(word
) {
47 debug('\nTesting bounds of word: ' + word
);
49 // Get the bounds from the accessibility tree.
50 window
.wordAxIndex
= text
.indexOf(word
);
51 eval('window.axBounds = ' + axStaticText
.boundsForRange(wordAxIndex
, wordAxIndex
+ word
.length
) + ';');
53 // Get the bounds from the DOM.
54 window
.domIndex
= domText
.indexOf(word
);
55 var range
= new Range();
56 range
.setStart(paragraph
.firstChild
, domIndex
);
57 range
.setEnd(paragraph
.firstChild
, domIndex
+ word
.length
);
58 window
.rangeBounds
= range
.getBoundingClientRect();
60 // Make sure they're the same, within one pixel.
61 shouldBeCloseTo("axBounds.x", rangeBounds
.left
, 1);
62 shouldBeCloseTo("axBounds.y", rangeBounds
.top
, 1);
63 shouldBeCloseTo("axBounds.width", rangeBounds
.width
, 1);
64 shouldBeCloseTo("axBounds.height", rangeBounds
.height
, 1);
67 testWord('Hitchhiker');
69 testWord('interstellar');