OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"> |
| 2 <html> |
| 3 <head> |
| 4 <meta charset="utf-8"> |
| 5 <script src="../fast/js/resources/js-test-pre.js"></script> |
| 6 </head> |
| 7 <body> |
| 8 |
| 9 <p id="paragraph" style="width: 30em;"> |
| 10 The Hitchhiker's Guide to the |
| 11 |
| 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 hitc
h hiker can have. |
| 14 </p> |
| 15 |
| 16 <p id="description"></p> |
| 17 |
| 18 <div id="console"></div> |
| 19 |
| 20 <script> |
| 21 |
| 22 description("Tests that we can compute the bounds of a range of text from th
e accessibility tree."); |
| 23 |
| 24 if (window.accessibilityController) { |
| 25 var axParagraph = accessibilityController.accessibleElementById('paragra
ph'); |
| 26 var axStaticText = axParagraph.childAtIndex(0); |
| 27 |
| 28 // The first characters of stringValue are 'AXValue: ' - use substr to g
et 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 + "\""); |
| 33 |
| 34 // Append the text from all of the inline text boxes and make sure we ge
t 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); |
| 39 } |
| 40 shouldBe("appendedInlineText", "text"); |
| 41 |
| 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 o
ne pixel. |
| 44 var paragraph = document.getElementById('paragraph'); |
| 45 var domText = paragraph.innerHTML; |
| 46 function testWord(word) { |
| 47 debug('\nTesting bounds of word: ' + word); |
| 48 |
| 49 // Get the bounds from the accessibility tree. |
| 50 window.wordAxIndex = text.indexOf(word); |
| 51 eval('window.axBounds = ' + axStaticText.boundsForRange(wordAxIndex,
wordAxIndex + word.length) + ';'); |
| 52 |
| 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(); |
| 59 |
| 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); |
| 65 } |
| 66 testWord('The'); |
| 67 testWord('Hitchhiker'); |
| 68 testWord('Guide'); |
| 69 testWord('interstellar'); |
| 70 } |
| 71 </script> |
| 72 |
| 73 <script src="../fast/js/resources/js-test-post.js"></script> |
| 74 </body> |
| 75 </html> |
OLD | NEW |