1<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN">
2<html>
3<head>
4<script src="../../../resources/js-test-pre.js"></script>
5<script src="../resources/atk-helpers.js"></script>
6</head>
7
8<body id="body">
9<h1 id='firstChild'>A text header</h1>
10
11<p>A paragraph <a href='http://foo.bar.baz/'>with a link</a> in the middle</p>
12
13<ol>
14 <li>A list item</li>
15 <li><span style='display:block;'>Block span in a list item</span><span>Inline span in a list item</span></li>
16 <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>
17</ol>
18
19<select><option selected value='foo'>An option in a combo box</option></select>
20
21<input type='text' name='foo' value='foo bar baz' />
22
23<table>
24 <tr>
25 <td>a table cell</td>
26 <td></td>
27 <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>
28 <td><span style='display:block;'>Block span in a table cell</span><span>Inline span in a table cell</span></td>
29 </tr>
30</table>
31
32<div id="console"></div>
33
34<script>
35var caretMovedData;
36
37function globalListener(object, name, offset)
38{
39 var role = object.role.replace('AXRole: AX', '');
40 if (name == 'AXTextCaretMoved') {
41 caretMovedData += role + '|' + offset;
42 }
43}
44
45function resetCaretOffsetForObject(object, offset)
46{
47 caretMovedData = '';
48 setCaretOffset(object, offset);
49}
50
51if (window.testRunner) {
52 testRunner.overridePreference("WebKitEnableCaretBrowsing", true);
53 testRunner.dumpAsText();
54}
55
56if (window.accessibilityController) {
57 accessibilityController.addNotificationListener(globalListener);
58 root = accessibilityController.accessibleElementById('firstChild').parentElement();
59 shouldBe('root.childrenCount', '5');
60
61 /* It should be possible to place the caret inside a header. */
62 h1 = root.childAtIndex(0);
63 caretMovedData = '';
64 shouldBeTrue('setCaretOffset(h1, 5)');
65 shouldBeEqualToString('caretMovedData', 'Heading|5');
66
67 /* It should be possible to place the caret inside a paragraph and a link. */
68 p1 = root.childAtIndex(1);
69 resetCaretOffsetForObject(p1, 5);
70 shouldBeEqualToString('caretMovedData', 'Paragraph|5');
71 resetCaretOffsetForObject(p1, 20);
72 shouldBeEqualToString('caretMovedData', 'Paragraph|20');
73 resetCaretOffsetForObject(p1, 30);
74 shouldBeEqualToString('caretMovedData', 'Paragraph|30');
75 link = p1.childAtIndex(0);
76 caretMovedData = '';
77 shouldBeTrue('setCaretOffset(link, 5)');
78 /* Positions inside links are reported relative to the paragraph. */
79 shouldBeEqualToString('caretMovedData', 'Paragraph|17');
80
81 list = root.childAtIndex(2);
82 shouldBeEqualToString('list.role', 'AXRole: AXList');
83 shouldBe('list.childrenCount', '3');
84 listItem = list.childAtIndex(2);
85 /* It's not possible to place the caret inside an item's marker. */
86 shouldBe('setCaretOffset(listItem, 1)', 'false');
87 /* It should be possible to place the caret inside an item's text. */
88 caretMovedData = '';
89 shouldBe('setCaretOffset(listItem, 5)', 'true');
90 shouldBeEqualToString('caretMovedData', 'ListItem|2');
91
92 panel = root.childAtIndex(3);
93 comboBox = panel.childAtIndex(0);
94 shouldBeEqualToString('comboBox.role', 'AXRole: AXComboBox');
95 menuPopup = comboBox.childAtIndex(0);
96 shouldBeEqualToString('menuPopup.role', 'AXRole: AXMenu');
97 comboBoxOption = menuPopup.childAtIndex(0);
98 shouldBeEqualToString('comboBoxOption.role', 'AXRole: AXMenuItem');
99 /* It's not possible to place the caret inside an option for a combobox. */
100 shouldBe('setCaretOffset(comboBoxOption, 1)', 'false');
101 textEntry = panel.childAtIndex(1);
102 shouldBeEqualToString('textEntry.role', 'AXRole: AXTextField');
103 resetCaretOffsetForObject(textEntry, 5);
104 shouldBeEqualToString('caretMovedData', 'TextField|5');
105
106 table = root.childAtIndex(4);
107 shouldBeEqualToString('table.role', 'AXRole: AXTable');
108 shouldBe('table.childrenCount', '4');
109 tableCell = table.childAtIndex(0);
110 shouldBeEqualToString('tableCell.role', 'AXRole: AXCell');
111 resetCaretOffsetForObject(tableCell, 2);
112 shouldBeEqualToString('caretMovedData', 'Cell|2');
113}
114
115description("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.");
116
117</script>
118<script src="../../../resources/js-test-post.js"></script>
119</body>
120</html>