blob: 39a7c7ef97a7c7ef7751f820bd1284abbd499063 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta charset="utf-8">
<script src="../resources/js-test.js"></script>
</head>
<body>
<p id="paragraph" style="width: 30em;">
The Hitchhiker's Guide to the
Galaxy has a few things to say on the subject of resumés.
A resumé, it says, is about the most massively useful thing an interstellar hitch hiker can have.
</p>
<p id="description"></p>
<div id="console"></div>
<script>
description("Tests that we can compute the bounds of a range of text from the accessibility tree.");
if (window.accessibilityController) {
var axParagraph = accessibilityController.accessibleElementById('paragraph');
var axStaticText = axParagraph.childAtIndex(0);
var text = axStaticText.name;
shouldBe("text.length", "185");
debug("Accessible text: \"" + text + "\"");
// Append the text from all of the inline text boxes and make sure we get the same text.
var appendedInlineText = '';
for (var i = 0; i < axStaticText.childrenCount; i++) {
var axInlineTextBox = axStaticText.childAtIndex(i);
appendedInlineText += axInlineTextBox.name;
}
shouldBe("appendedInlineText", "text");
// For several possible words in the text, get the bounds of the word in the accessibility
// tree, and also in the DOM, and assert that they're the same, within one pixel.
var paragraph = document.getElementById('paragraph');
var domText = paragraph.innerHTML;
function testWord(word) {
debug('\nTesting bounds of word: ' + word);
// Get the bounds from the accessibility tree.
window.wordAxIndex = text.indexOf(word);
eval('window.axBounds = ' + axStaticText.boundsForRange(wordAxIndex, wordAxIndex + word.length) + ';');
// Get the bounds from the DOM.
window.domIndex = domText.indexOf(word);
var range = new Range();
range.setStart(paragraph.firstChild, domIndex);
range.setEnd(paragraph.firstChild, domIndex + word.length);
window.rangeBounds = range.getBoundingClientRect();
// Make sure they're the same, within one pixel.
shouldBeCloseTo("axBounds.x", rangeBounds.left, 1);
shouldBeCloseTo("axBounds.y", rangeBounds.top, 1);
shouldBeCloseTo("axBounds.width", rangeBounds.width, 1);
shouldBeCloseTo("axBounds.height", rangeBounds.height, 1);
}
testWord('The');
testWord('Hitchhiker');
testWord('Guide');
testWord('interstellar');
}
</script>
</body>
</html>