| <!DOCTYPE HTML PUBLIC> |
| <html> |
| <head> |
| <script src="../resources/js-test.js"></script> |
| </head> |
| <body> |
| This tests that the AXSelection property is correctly reported for non-native text boxes.<br> |
| <div role="textbox" id="ariaTextBox" aria-multiline="false" tabindex="0">Some text in a textbox (34 chars).</div> |
| <div id="console"></div> |
| <script> |
| function assertEvaluatesTo(actual, expected, message) { |
| var actualValue = 0; |
| try { |
| actualValue = eval(actual); |
| } catch (e) { |
| debug("Evaluating " + actual + ": Threw exception " + e); |
| return; |
| } |
| if (actualValue === expected) |
| debug("PASS: " + actual + " is " + expected + (message ? " (" + message + ")" : "")); |
| else |
| debug("FAIL: " + actual + " should be " + expected + ", got " + actualValue + (message ? " (" + message + ")" : "")); |
| } |
| |
| function assertCorrectAXSelection(element, selection, message) { |
| element.focus(); |
| var selectionValues = /\{(\d+), (\d+)\}/.exec(selection); |
| var selectionStart = eval(selectionValues[1]); |
| var selectionLength = eval(selectionValues[2]); |
| var selectionEnd = selectionStart + selectionLength; |
| |
| window.getSelection().setBaseAndExtent(element.firstChild, selectionStart, element.firstChild, selectionEnd); |
| var axElement = accessibilityController.focusedElement; |
| axSelection = axElement.selectedTextRange; |
| assertEvaluatesTo("axSelection", selection, message); |
| } |
| |
| if (window.testRunner && window.accessibilityController) { |
| var ariaTextBox = document.getElementById("ariaTextBox"); |
| var textLength = ariaTextBox.textContent.length; |
| |
| assertCorrectAXSelection(ariaTextBox, "{0, 0}", "Collapsed selection at start"); |
| assertCorrectAXSelection(ariaTextBox, "{" + textLength + ", 0}", "Collapsed selection at end"); |
| assertCorrectAXSelection(ariaTextBox, "{15, 0}", "Collapsed selection in the middle"); |
| assertCorrectAXSelection(ariaTextBox, "{15, 2}", "Non-collapsed selection in the middle"); |
| assertCorrectAXSelection(ariaTextBox, "{0, 15}", "Non-collapsed selection at the start"); |
| assertCorrectAXSelection(ariaTextBox, "{15, "+ (textLength - 15) + "}", "Non-collapsed selection at the end"); |
| } |
| |
| </script> |
| </body> |
| </html> |