Index: LayoutTests/accessibility/inline-text-bounds-for-range.html |
diff --git a/LayoutTests/accessibility/inline-text-bounds-for-range.html b/LayoutTests/accessibility/inline-text-bounds-for-range.html |
new file mode 100644 |
index 0000000000000000000000000000000000000000..88dad3940a56d8ce5433494d02c3edeb4e21d93e |
--- /dev/null |
+++ b/LayoutTests/accessibility/inline-text-bounds-for-range.html |
@@ -0,0 +1,75 @@ |
+<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
+<html> |
+<head> |
+<meta charset="utf-8"> |
+<script src="../fast/js/resources/js-test-pre.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); |
+ |
+ // The first characters of stringValue are 'AXValue: ' - use substr to get rid of those. |
+ // The accessible text shouldn't have any spaces. |
+ var text = axStaticText.stringValue.substr(9); |
+ 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.stringValue.substr(9); |
+ } |
+ 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> |
+ |
+<script src="../fast/js/resources/js-test-post.js"></script> |
+</body> |
+</html> |