blob: 2690d3f9ac0c1ee960df70a51eea3d1686513e7a [file] [log] [blame]
<!DOCTYPE html>
<html>
<head>
<script src="../../../resources/js-test-pre.js"></script>
<title>Search Text 1</title>
</head>
<body id="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 search for text given a starting point and a direction for the search.");
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");
// Select target element.
selectElementText(target);
// Search for text after selection (single search string).
result = text.searchTextWithCriteria("lazy", "AXSearchTextStartFromSelection", "AXSearchTextDirectionForward");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'lazy'");
// Search for text before selection (single search string).
result = text.searchTextWithCriteria("quick", "AXSearchTextStartFromSelection", "AXSearchTextDirectionBackward");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'quick'");
// Search for text closest to selection (single search string).
result = text.searchTextWithCriteria("the", "AXSearchTextStartFromSelection", "AXSearchTextDirectionClosest");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'the'");
// Search from the beginning (single search string).
result = text.searchTextWithCriteria("the", "AXSearchTextStartFromBegin", "AXSearchTextDirectionClosest");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'The'");
// Search for all occurrences from the beginning of document (single search string).
var body = accessibilityController.rootElement.childAtIndex(0);
result = body.searchTextWithCriteria("dog", "AXSearchTextStartFromBegin", "AXSearchTextDirectionAll");
shouldBe("result.length", "3");
for (var i = 0; i < result.length; i++)
shouldBe("body.stringForTextMarkerRange(result[i])", "'dog'");
// Search for all occurrences from the end of document (single search string).
result = body.searchTextWithCriteria("fox", "AXSearchTextStartFromEnd", "AXSearchTextDirectionAll");
shouldBe("result.length", "3");
for (var i = 0; i < result.length; i++)
shouldBe("body.stringForTextMarkerRange(result[i])", "'fox'");
// Search for a non-present string (single search string).
result = body.searchTextWithCriteria("cat", "AXSearchTextStartFromBegin", "AXSearchTextDirectionAll");
shouldBe("typeof result", "'undefined'");
// Search for multiple strings after selection.
result = text.searchTextWithCriteria(["lazy", "over"], "AXSearchTextStartFromSelection", "AXSearchTextDirectionForward");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'over'");
// Search for multiple strings before selection.
result = text.searchTextWithCriteria(["quick", "fox"], "AXSearchTextStartFromSelection", "AXSearchTextDirectionBackward");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'fox'");
// Search for multiple strings closest to selection.
result = text.searchTextWithCriteria(["dog", "fox"], "AXSearchTextStartFromSelection", "AXSearchTextDirectionClosest");
shouldBe("result.length", "1");
shouldBe("text.stringForTextMarkerRange(result[0])", "'fox'");
}
</script>
<script src="../../../resources/js-test-post.js"></script>
</body>
</html>