blob: 797acca2bfd8b125b603fc7926595d65340f8833 [file] [log] [blame]
<html>
<head>
<script src="../resources/js-test-pre.js"></script>
</head>
<body>
<textarea name="area1" id="area1" rows="5" cols="40">
line 1
line 2
line 3
</textarea>
<textarea name="area2" id="area2" rows="5" cols="40"></textarea>
<div id="contenteditable-div" role="textbox" contenteditable="true" tabindex="0">
<div id="contenteditable-line1">Line1</div>
<textarea id="contenteditable-line2" rows="1" cols="40">Line2</textarea>
<div id="contenteditable-line3">Line3</div>
</div>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests that lineNumberForPosition is reported correctly for textarea and contenteditable elements.");
if (window.accessibilityController) {
var area1 = document.getElementById("area1");
area1.focus();
var area1AXUIElement = accessibilityController.focusedElement;
var lineNumber = -2;
// Set the insertion point to the beginning of each line in area1 and
// check that accessibility returns the correct line number.
for (var currentLine = 0; currentLine < 3; currentLine++) {
area1.selectionStart = currentLine * 7;
area1.selectionEnd = currentLine * 7;
shouldBe("area1AXUIElement.insertionPointLineNumber", "currentLine");
}
// area2 is an empty textarea so the insertion point line number should be 0.
var area2 = document.getElementById("area2");
area2.focus();
var area2AXUIElement = accessibilityController.focusedElement;
shouldBe("area2AXUIElement.insertionPointLineNumber", "0");
// Set focus to the contenteditable-div element and set the insertion
// point in each of the children lines.
var contenteditableDiv = document.getElementById("contenteditable-div");
contenteditableDiv.focus();
var contenteditableAXUIElement = accessibilityController.focusedElement;
var contenteditableLine1 = document.getElementById("contenteditable-line1");
window.getSelection().setBaseAndExtent(contenteditableLine1, 1, contenteditableLine1, 1);
shouldBe("contenteditableAXUIElement.insertionPointLineNumber", "0");
var contenteditableLine2 = document.getElementById("contenteditable-line2");
window.getSelection().setBaseAndExtent(contenteditableLine2, 1, contenteditableLine2, 1);
shouldBe("contenteditableAXUIElement.insertionPointLineNumber", "1");
var contenteditableLine3 = document.getElementById("contenteditable-line3");
window.getSelection().setBaseAndExtent(contenteditableLine3, 1, contenteditableLine3, 1);
shouldBe("contenteditableAXUIElement.insertionPointLineNumber", "2");
// Set focus to line 2 and get the insertion point line number relative
// to the nested textarea, which should be 0.
contenteditableLine2.focus();
var textareaAXUIElement = accessibilityController.focusedElement;
shouldBe("textareaAXUIElement.insertionPointLineNumber", "0");
}
</script>
<script src="../resources/js-test-post.js"></script>
</body>
</html>