blob: 3a9aa69400b790ccde8c158422236a66e38cb90c [file]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../resources/accessibility-helper.js"></script>
<script src="../resources/js-test.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>
<script>
var output = "This tests that lineNumberForPosition is reported correctly for textarea and contenteditable elements.\n\n";
if (window.accessibilityController) {
window.jsTestIsAsync = true;
var currentLine, area1AXUIElement, area2AXUIElement, contenteditableAXUIElement, textareaAXUIElement;
setTimeout(async function() {
area1AXUIElement = await waitForFocus("area1");
// Set the insertion point to the beginning of each line in area1 and
// check that accessibility returns the correct line number.
for (currentLine = 0; currentLine < 3; currentLine++) {
area1.selectionStart = currentLine * 7;
area1.selectionEnd = currentLine * 7;
output += await expectAsync("area1AXUIElement.insertionPointLineNumber", "currentLine");
}
// area2 is an empty textarea so the insertion point line number should be 0.
area2AXUIElement = await waitForFocus("area2");
output += expect("area2AXUIElement.insertionPointLineNumber", "0");
// Set focus to the contenteditable-div element and set the insertion
// point in each of the children lines.
contenteditableAXUIElement = await waitForFocus("contenteditable-div");
var contenteditableLine1 = document.getElementById("contenteditable-line1");
window.getSelection().setBaseAndExtent(contenteditableLine1, 1, contenteditableLine1, 1);
output += expect("contenteditableAXUIElement.insertionPointLineNumber", "0");
var contenteditableLine2 = document.getElementById("contenteditable-line2");
window.getSelection().setBaseAndExtent(contenteditableLine2, 1, contenteditableLine2, 1);
output += expect("contenteditableAXUIElement.insertionPointLineNumber", "1");
var contenteditableLine3 = document.getElementById("contenteditable-line3");
window.getSelection().setBaseAndExtent(contenteditableLine3, 1, contenteditableLine3, 1);
output += expect("contenteditableAXUIElement.insertionPointLineNumber", "2");
// Set focus to line 2 and get the insertion point line number relative
// to the nested textarea, which should be 0.
textareaAXUIElement = await waitForFocus("contenteditable-line2");
output += await expectAsync("textareaAXUIElement.insertionPointLineNumber", "0");
debug(output);
finishJSTest();
}, 0);
}
</script>
</body>
</html>