blob: a18b5f7190cd4eea48696fe8582b103bda32a3d4 [file] [log] [blame]
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
<html>
<head>
<script src="../../resources/js-test-pre.js"></script>
<script src="resources/atk-helpers.js"></script>
</head>
<body id="body">
<h1 id='firstChild'>A text header</h1>
<p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p>
<ol>
<li>A list item</li>
<li><span style='display:block;'>Block span in a list item</span><span>Inline span in a list item</span></li>
<li><a href='foo'><span style='display:block;'>Block span in a link in a list item</span><span>Inline span in a link in a list item</span></a></li>
</ol>
<select><option selected value='foo'>An option in a combo box</option></select>
<input type='text' name='foo' value='foo bar baz' />
<table border=1>
<tr>
<td>a table cell</td>
<td></td>
<td><a href='foo'><span style='display:block;'>Block span in a link in a table cell</span><span>Inline span in a link in a table cell</span></a></td>
<td><span style='display:block;'>Block span in a table cell</span><span>Inline span in a table cell</span></td>
</tr>
</table>
<div id="console"></div>
<script>
var caretMovedData;
function globalListener(object, name, offset)
{
var role = object.role.replace('AXRole: AX', '');
if (name == 'AXTextCaretMoved') {
caretMovedData += role + '|' + offset;
}
}
function resetCaretOffsetForObject(object, offset)
{
caretMovedData = '';
setCaretOffset(object, offset);
}
if (window.internals)
internals.settings.setCaretBrowsingEnabled(true);
if (window.testRunner)
testRunner.dumpAsText();
if (window.accessibilityController) {
window.jsTestIsAsync = true;
accessibilityController.addNotificationListener(globalListener);
root = accessibilityController.accessibleElementById('firstChild').parentElement();
shouldBe('root.childrenCount', '5');
/* It should be possible to place the caret inside a header. */
h1 = root.childAtIndex(0);
caretMovedData = '';
shouldBeTrue('setCaretOffset(h1, 5)');
shouldBeEqualToString('caretMovedData', 'Heading|5');
/* It should be possible to place the caret inside a paragraph and a link. */
p1 = root.childAtIndex(1);
resetCaretOffsetForObject(p1, 5);
shouldBeEqualToString('caretMovedData', 'Paragraph|5');
resetCaretOffsetForObject(p1, 20);
shouldBeEqualToString('caretMovedData', 'Paragraph|20');
resetCaretOffsetForObject(p1, 30);
shouldBecomeEqualToString('caretMovedData', 'Paragraph|30', function () {
caretMovedData = '';
link = p1.childAtIndex(0);
shouldBeTrue('setCaretOffset(link, 5)');
/* Positions inside links are reported relative to the paragraph. */
shouldBeEqualToString('caretMovedData', 'Paragraph|17');
list = root.childAtIndex(2);
shouldBeEqualToString('list.role', 'AXRole: AXList');
shouldBe('list.childrenCount', '3');
listItem = list.childAtIndex(2);
/* It's not possible to place the caret inside an item's marker. */
shouldBe('setCaretOffset(listItem, 1)', 'false');
/* It should be possible to place the caret inside an item's text. */
caretMovedData = '';
shouldBe('setCaretOffset(listItem, 5)', 'true');
shouldBeEqualToString('caretMovedData', 'ListItem|5');
panel = root.childAtIndex(3);
comboBox = panel.childAtIndex(0);
shouldBeEqualToString('comboBox.role', 'AXRole: AXComboBox');
menuPopup = comboBox.childAtIndex(0);
shouldBeEqualToString('menuPopup.role', 'AXRole: AXMenu');
comboBoxOption = menuPopup.childAtIndex(0);
shouldBeEqualToString('comboBoxOption.role', 'AXRole: AXMenuItem');
/* It's not possible to place the caret inside an option for a combobox. */
shouldBe('setCaretOffset(comboBoxOption, 1)', 'false');
textEntry = panel.childAtIndex(1);
shouldBeEqualToString('textEntry.role', 'AXRole: AXTextField');
resetCaretOffsetForObject(textEntry, 5);
shouldBeEqualToString('caretMovedData', 'TextField|5');
table = root.childAtIndex(4);
shouldBeEqualToString('table.role', 'AXRole: AXTable');
shouldBe('table.childrenCount', '1');
row = table.childAtIndex(0);
shouldBeEqualToString('row.role', 'AXRole: AXRow');
tableCell = row.childAtIndex(0);
shouldBeEqualToString('tableCell.role', 'AXRole: AXCell');
resetCaretOffsetForObject(tableCell, 2);
shouldBecomeEqualToString('caretMovedData', 'Cell|2', finishJSTest);
});
}
description("This test is replicated from old file testatk.c and tests various scenarios of caret movement: setting caret offset and receiving text-caret-moved signal.");
</script>
<script src="../../resources/js-test-post.js"></script>
</body>
</html>