blob: 5725b3f6078f259475a421d6941c8ad61b9e71c8 [file] [log] [blame] [edit]
<html><!-- webkit-test-runner [ IsAccessibilityIsolatedTreeEnabled=true ] -->
<head>
<script src="../../resources/accessibility-helper.js"></script>
<script src="../../resources/js-test.js"></script>
</head>
<body id="body" role="group">
<div id="text1">Alpha Bravo</div>
<div id="text2"> Charlie Delta </div>
<script>
var output = "This tests the intersectionWithSelectionRange API, which returns the range of characters in an AX element that are part of the document selection, if any.\n\n";
// Selects the specified range via DOM calls and returns the DOM selection object..
async function selectNodeRange(nodeId0, offset0, nodeId1, offset1) {
let selection = window.getSelection();
let range = document.createRange();
range.setStart(document.getElementById(nodeId0).firstChild, offset0);
range.setEnd(document.getElementById(nodeId1).firstChild, offset1);
selection.removeAllRanges();
selection.addRange(range);
return selection;
}
async function runTest(nodeId0, offset0, nodeId1, offset1, expectedSelection, axElementId) {
output += `Selecting: ${nodeId0}:${offset0} - ${nodeId1}:${offset1}\n`;
selection = await selectNodeRange(nodeId0, offset0, nodeId1, offset1);
output += `Selected text: '${selection.toString().replace("\n", "\\n")}'\n`;
// FIXME: change the await for notification listening.
webarea = accessibilityController.accessibleElementById("body");
await waitFor(() => webarea.stringForTextMarkerRange(webarea.selectedTextMarkerRange()) == expectedSelection);
axElement = accessibilityController.accessibleElementById(axElementId);
axChild = axElement.childAtIndex(0);
range = axChild.textMarkerRangeForElement(axChild);
output += `${axElementId} range: '${axChild.stringForTextMarkerRange(range)}'\n`;
intersection = axChild.intersectionWithSelectionRange;
output += `Intersection: '${axChild.stringForTextMarkerRange(intersection)}'\n\n`;
}
if (window.accessibilityController) {
window.jsTestIsAsync = true;
setTimeout(async () => {
await runTest("text1", 0, "text1", 5, "Alpha", "text1");
await runTest("text1", 6, "text1", 11, "Bravo", "text1");
await runTest("text2", 2, "text2", 9, "Charlie", "text2");
await runTest("text2", 11, "text2", 16, "Delta", "text2");
await runTest("text1", 6, "text2", 9, "Bravo\nCharlie", "text1");
await runTest("text1", 0, "text1", 5, "Alpha", "text2");
await runTest("text1", 6, "text2", 9, "Bravo\nCharlie", "text2");
debug(output);
finishJSTest();
}, 0);
}
</script>
</body>
</html>