haikuwebkit/LayoutTests/accessibility/mac/select-text/select-text-135546.html

74 lines
2.8 KiB
HTML

<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<title>Select Text</title>
</head>
<body>
<p contenteditable="true" id="text">The quick brown fox <span id="target">jumps</span> over the lazy dog. </p>
<p contenteditable="true" id="text2">TEXT2: The quick brown fox jumps over the lazy dog. The quick brown fox jumps over the lazy dog.</p>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests the ability to select and replace text with respect to selection.");
function selectedText() {
return window.getSelection().toString();
}
function selectElementText(element) {
var range = document.createRange();
range.selectNodeContents(element);
var selection = window.getSelection();
selection.removeAllRanges();
selection.addRange(range);
}
if (window.accessibilityController) {
var text = accessibilityController.accessibleElementById("text");
var result = 0;
var selection = 0;
var target = document.getElementById("target");
// [https://bugs.webkit.org/show_bug.cgi?id=135546]
// A matching range before the selection should be selected when searching for closest match.
document.getElementById("text2").focus();
var windowSelection = window.getSelection();
windowSelection.removeAllRanges();
// First find the range before the current selection.
var range = document.createRange();
range.setStart(document.getElementById("text2").firstChild, 20);
range.setEnd(document.getElementById("text2").firstChild, 20);
windowSelection.addRange(range);
var text2 = accessibilityController.accessibleElementById("text2");
result = text2.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "quick");
shouldBe("result", "'quick'");
selection = window.getSelection();
shouldBe("windowSelection.getRangeAt(0).startOffset", "11");
shouldBe("windowSelection.getRangeAt(0).endOffset", "16");
// Move the cursor closer to the second instance in front of the selection.
range = document.createRange();
range.setStart(document.getElementById("text2").firstChild, 48);
range.setEnd(document.getElementById("text2").firstChild, 48);
windowSelection.removeAllRanges();
windowSelection.addRange(range);
result = text2.selectTextWithCriteria("AXSelectTextAmbiguityResolutionClosestToSelection", "quick");
shouldBe("result", "'quick'");
shouldBe("windowSelection.getRangeAt(0).startOffset", "56");
shouldBe("windowSelection.getRangeAt(0).endOffset", "61");
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>