4 <script src="../fast/js/resources/js-test-pre.js"></script>
7 This tests that the AXSelection property is correctly reported for non-native text boxes.<br>
8 <div role="textbox" id="ariaTextBox" aria-multiline="false" tabindex="0">Some text in a textbox (34 chars).</div>
9 <div id="console"></div>
11 function assertEvaluatesTo(actual, expected, message) {
14 actualValue = eval(actual);
16 debug("Evaluating " + actual + ": Threw exception " + e);
19 if (actualValue === expected)
20 debug("PASS: " + actual + " is " + expected + (message ? " (" + message + ")" : ""));
22 debug("FAIL: " + actual + " should be " + expected + ", got " + actualValue + (message ? " (" + message + ")" : ""));
25 function assertCorrectAXSelection(element, selection, message) {
27 var selectionValues = /\{(\d+), (\d+)\}/.exec(selection);
28 var selectionStart = eval(selectionValues[1]);
29 var selectionLength = eval(selectionValues[2]);
30 var selectionEnd = selectionStart + selectionLength;
32 window.getSelection().setBaseAndExtent(element.firstChild, selectionStart, element.firstChild, selectionEnd);
33 var axElement = accessibilityController.focusedElement;
34 axSelection = axElement.selectedTextRange;
35 assertEvaluatesTo("axSelection", selection, message);
38 if (window.testRunner && window.accessibilityController) {
39 window.testRunner.dumpAsText();
40 var ariaTextBox = document.getElementById("ariaTextBox");
41 var textLength = ariaTextBox.textContent.length;
43 assertCorrectAXSelection(ariaTextBox, "{0, 0}", "Collapsed selection at start");
44 assertCorrectAXSelection(ariaTextBox, "{" + textLength + ", 0}", "Collapsed selection at end");
45 assertCorrectAXSelection(ariaTextBox, "{15, 0}", "Collapsed selection in the middle");
46 assertCorrectAXSelection(ariaTextBox, "{15, 2}", "Non-collapsed selection in the middle");
47 assertCorrectAXSelection(ariaTextBox, "{0, 15}", "Non-collapsed selection at the start");
48 assertCorrectAXSelection(ariaTextBox, "{15, "+ (textLength - 15) + "}", "Non-collapsed selection at the end");
53 <script src="../fast/js/resources/js-test-post.js"></script>