blob: 2596568c9766e0c24407e1b71bc853897ecc8cd2 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<meta charset="utf-8">
<script src="../../resources/js-test-pre.js"></script>
</head>
<body id="body">
<div id="text">
Test1
Test2 Test3
</div>
<p id="description"></p>
<div id="console"></div>
<script>
description("This tests that word navigation is working correctly with collapsed whitespaces.");
if (window.accessibilityController) {
var text = accessibilityController.accessibleElementById("text");
// Get the actual text node.
text = text.childAtIndex(0);
// Check that we can get the second word "Test2"
var textMarkerRange = text.textMarkerRangeForElement(text);
var startMarker = text.startTextMarkerForTextMarkerRange(textMarkerRange);
var currentMarker = advanceAndVerify(startMarker, 5, text);
currentMarker = advanceAndVerify(currentMarker, 1, text);
// Check that we can get the third word "Test3"
currentMarker = advanceAndVerify(currentMarker, 5, text);
currentMarker = advanceAndVerify(currentMarker, 1, text);
function advanceAndVerify(currentMarker, offset, obj) {
var previousMarker = currentMarker;
for (var i = 0; i < offset; i++) {
previousMarker = currentMarker;
currentMarker = obj.nextTextMarker(previousMarker);
}
verifyWordRangeForTextMarker(previousMarker, currentMarker, obj);
return currentMarker;
}
function replaceAttachmentInString(str) {
var newline = '\n';
str = str.replace(String.fromCharCode(65532), "[ATTACHMENT]");
str = str.replace(newline, "'line break'");
return str;
}
function verifyWordRangeForTextMarker(preMarker, textMarker, obj) {
var markerRange = obj.textMarkerRangeForMarkers(preMarker, textMarker);
var currentCharacter = obj.stringForTextMarkerRange(markerRange);
debug("Current character is: " + currentCharacter);
var previousWordRange = obj.leftWordTextMarkerRangeForTextMarker(textMarker);
var nextWordRange = obj.rightWordTextMarkerRangeForTextMarker(textMarker);
var preWord = obj.stringForTextMarkerRange(previousWordRange);
var nextWord = obj.stringForTextMarkerRange(nextWordRange);
debug("Left word is: " + preWord);
debug("Right word is: " + nextWord);
var preWordStart = obj.previousWordStartTextMarkerForTextMarker(textMarker);
var nextWordEnd = obj.nextWordEndTextMarkerForTextMarker(textMarker);
var preAndNextWordRange = obj.textMarkerRangeForMarkers(preWordStart, nextWordEnd);
var preAndNextWord = obj.stringForTextMarkerRange(preAndNextWordRange);
debug("Pre word start to next word end: " + preAndNextWord + "\n");
}
}
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>