| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include "base/macros.h" | 7 #include "base/macros.h" |
| 8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
| 10 #include "base/win/scoped_bstr.h" | 10 #include "base/win/scoped_bstr.h" |
| (...skipping 881 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 892 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); | 892 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); |
| 893 | 893 |
| 894 ui::AXNodeData combo_box, combo_box_text; | 894 ui::AXNodeData combo_box, combo_box_text; |
| 895 combo_box.id = 2; | 895 combo_box.id = 2; |
| 896 combo_box_text.id = 3; | 896 combo_box_text.id = 3; |
| 897 combo_box.SetName("Combo box:"); | 897 combo_box.SetName("Combo box:"); |
| 898 combo_box_text.SetName("Combo box text"); | 898 combo_box_text.SetName("Combo box text"); |
| 899 combo_box.role = ui::AX_ROLE_COMBO_BOX; | 899 combo_box.role = ui::AX_ROLE_COMBO_BOX; |
| 900 combo_box_text.role = ui::AX_ROLE_STATIC_TEXT; | 900 combo_box_text.role = ui::AX_ROLE_STATIC_TEXT; |
| 901 combo_box.state = (1 << ui::AX_STATE_EDITABLE) | | 901 combo_box.state = (1 << ui::AX_STATE_EDITABLE) | |
| 902 (1 << ui::AX_STATE_FOCUSABLE) | (1 << ui::AX_STATE_FOCUSED); | 902 (1 << ui::AX_STATE_FOCUSABLE); |
| 903 combo_box_text.state = 1 << ui::AX_STATE_EDITABLE; | 903 combo_box_text.state = 1 << ui::AX_STATE_EDITABLE; |
| 904 combo_box.child_ids.push_back(combo_box_text.id); | 904 combo_box.child_ids.push_back(combo_box_text.id); |
| 905 | 905 |
| 906 ui::AXNodeData search_box, search_box_text, new_line; | 906 ui::AXNodeData search_box, search_box_text, new_line; |
| 907 search_box.id = 4; | 907 search_box.id = 4; |
| 908 search_box_text.id = 5; | 908 search_box_text.id = 5; |
| 909 new_line.id = 6; | 909 new_line.id = 6; |
| 910 search_box.SetName("Search for:"); | 910 search_box.SetName("Search for:"); |
| 911 search_box_text.SetName("Search box text"); | 911 search_box_text.SetName("Search box text"); |
| 912 new_line.SetName("\n"); | 912 new_line.SetName("\n"); |
| 913 search_box.role = ui::AX_ROLE_SEARCH_BOX; | 913 search_box.role = ui::AX_ROLE_SEARCH_BOX; |
| 914 search_box_text.role = ui::AX_ROLE_STATIC_TEXT; | 914 search_box_text.role = ui::AX_ROLE_STATIC_TEXT; |
| 915 new_line.role = ui::AX_ROLE_LINE_BREAK; | 915 new_line.role = ui::AX_ROLE_LINE_BREAK; |
| 916 search_box.state = (1 << ui::AX_STATE_EDITABLE) | | 916 search_box.state = (1 << ui::AX_STATE_EDITABLE) | |
| 917 (1 << ui::AX_STATE_FOCUSABLE) | | 917 (1 << ui::AX_STATE_FOCUSABLE); |
| 918 (1 << ui::AX_STATE_FOCUSED); | |
| 919 search_box_text.state = new_line.state = 1 << ui::AX_STATE_EDITABLE; | 918 search_box_text.state = new_line.state = 1 << ui::AX_STATE_EDITABLE; |
| 920 search_box.child_ids.push_back(search_box_text.id); | 919 search_box.child_ids.push_back(search_box_text.id); |
| 921 search_box.child_ids.push_back(new_line.id); | 920 search_box.child_ids.push_back(new_line.id); |
| 922 | 921 |
| 923 ui::AXNodeData text_field; | 922 ui::AXNodeData text_field; |
| 924 text_field.id = 7; | 923 text_field.id = 7; |
| 925 text_field.role = ui::AX_ROLE_TEXT_FIELD; | 924 text_field.role = ui::AX_ROLE_TEXT_FIELD; |
| 926 text_field.state = | 925 text_field.state = |
| 927 (1 << ui::AX_STATE_EDITABLE) | (1 << ui::AX_STATE_FOCUSABLE); | 926 (1 << ui::AX_STATE_EDITABLE) | (1 << ui::AX_STATE_FOCUSABLE); |
| 928 text_field.SetValue("Text field text"); | 927 text_field.SetValue("Text field text"); |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 963 | 962 |
| 964 ASSERT_NE(nullptr, manager->GetRoot()); | 963 ASSERT_NE(nullptr, manager->GetRoot()); |
| 965 BrowserAccessibilityWin* root_accessible = | 964 BrowserAccessibilityWin* root_accessible = |
| 966 manager->GetRoot()->ToBrowserAccessibilityWin(); | 965 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 967 ASSERT_NE(nullptr, root_accessible); | 966 ASSERT_NE(nullptr, root_accessible); |
| 968 ASSERT_EQ(5U, root_accessible->PlatformChildCount()); | 967 ASSERT_EQ(5U, root_accessible->PlatformChildCount()); |
| 969 | 968 |
| 970 BrowserAccessibilityWin* combo_box_accessible = | 969 BrowserAccessibilityWin* combo_box_accessible = |
| 971 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 970 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
| 972 ASSERT_NE(nullptr, combo_box_accessible); | 971 ASSERT_NE(nullptr, combo_box_accessible); |
| 973 manager->SetFocus(combo_box_accessible, false /* notify */); | 972 manager->SetFocusLocallyForTesting(combo_box_accessible); |
| 974 ASSERT_EQ(combo_box_accessible, | 973 ASSERT_EQ(combo_box_accessible, |
| 975 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 974 manager->GetFocus()->ToBrowserAccessibilityWin()); |
| 976 BrowserAccessibilityWin* search_box_accessible = | 975 BrowserAccessibilityWin* search_box_accessible = |
| 977 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 976 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
| 978 ASSERT_NE(nullptr, search_box_accessible); | 977 ASSERT_NE(nullptr, search_box_accessible); |
| 979 BrowserAccessibilityWin* text_field_accessible = | 978 BrowserAccessibilityWin* text_field_accessible = |
| 980 root_accessible->PlatformGetChild(2)->ToBrowserAccessibilityWin(); | 979 root_accessible->PlatformGetChild(2)->ToBrowserAccessibilityWin(); |
| 981 ASSERT_NE(nullptr, text_field_accessible); | 980 ASSERT_NE(nullptr, text_field_accessible); |
| 982 BrowserAccessibilityWin* link_accessible = | 981 BrowserAccessibilityWin* link_accessible = |
| 983 root_accessible->PlatformGetChild(3)->ToBrowserAccessibilityWin(); | 982 root_accessible->PlatformGetChild(3)->ToBrowserAccessibilityWin(); |
| 984 ASSERT_NE(nullptr, link_accessible); | 983 ASSERT_NE(nullptr, link_accessible); |
| 985 BrowserAccessibilityWin* slider_accessible = | 984 BrowserAccessibilityWin* slider_accessible = |
| (...skipping 203 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1189 TEST_F(BrowserAccessibilityTest, TestCaretAndSelectionInSimpleFields) { | 1188 TEST_F(BrowserAccessibilityTest, TestCaretAndSelectionInSimpleFields) { |
| 1190 ui::AXNodeData root; | 1189 ui::AXNodeData root; |
| 1191 root.id = 1; | 1190 root.id = 1; |
| 1192 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1191 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
| 1193 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); | 1192 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); |
| 1194 | 1193 |
| 1195 ui::AXNodeData combo_box; | 1194 ui::AXNodeData combo_box; |
| 1196 combo_box.id = 2; | 1195 combo_box.id = 2; |
| 1197 combo_box.role = ui::AX_ROLE_COMBO_BOX; | 1196 combo_box.role = ui::AX_ROLE_COMBO_BOX; |
| 1198 combo_box.state = (1 << ui::AX_STATE_EDITABLE) | | 1197 combo_box.state = (1 << ui::AX_STATE_EDITABLE) | |
| 1199 (1 << ui::AX_STATE_FOCUSABLE) | (1 << ui::AX_STATE_FOCUSED); | 1198 (1 << ui::AX_STATE_FOCUSABLE); |
| 1200 combo_box.SetValue("Test1"); | 1199 combo_box.SetValue("Test1"); |
| 1201 // Place the caret between 't' and 'e'. | 1200 // Place the caret between 't' and 'e'. |
| 1202 combo_box.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, 1); | 1201 combo_box.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_START, 1); |
| 1203 combo_box.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, 1); | 1202 combo_box.AddIntAttribute(ui::AX_ATTR_TEXT_SEL_END, 1); |
| 1204 | 1203 |
| 1205 ui::AXNodeData text_field; | 1204 ui::AXNodeData text_field; |
| 1206 text_field.id = 3; | 1205 text_field.id = 3; |
| 1207 text_field.role = ui::AX_ROLE_TEXT_FIELD; | 1206 text_field.role = ui::AX_ROLE_TEXT_FIELD; |
| 1208 text_field.state = (1 << ui::AX_STATE_EDITABLE) | | 1207 text_field.state = (1 << ui::AX_STATE_EDITABLE) | |
| 1209 (1 << ui::AX_STATE_FOCUSABLE); | 1208 (1 << ui::AX_STATE_FOCUSABLE); |
| (...skipping 14 matching lines...) Expand all Loading... |
| 1224 | 1223 |
| 1225 ASSERT_NE(nullptr, manager->GetRoot()); | 1224 ASSERT_NE(nullptr, manager->GetRoot()); |
| 1226 BrowserAccessibilityWin* root_accessible = | 1225 BrowserAccessibilityWin* root_accessible = |
| 1227 manager->GetRoot()->ToBrowserAccessibilityWin(); | 1226 manager->GetRoot()->ToBrowserAccessibilityWin(); |
| 1228 ASSERT_NE(nullptr, root_accessible); | 1227 ASSERT_NE(nullptr, root_accessible); |
| 1229 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); | 1228 ASSERT_EQ(2U, root_accessible->PlatformChildCount()); |
| 1230 | 1229 |
| 1231 BrowserAccessibilityWin* combo_box_accessible = | 1230 BrowserAccessibilityWin* combo_box_accessible = |
| 1232 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1231 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
| 1233 ASSERT_NE(nullptr, combo_box_accessible); | 1232 ASSERT_NE(nullptr, combo_box_accessible); |
| 1234 manager->SetFocus(combo_box_accessible, false /* notify */); | 1233 manager->SetFocusLocallyForTesting(combo_box_accessible); |
| 1235 ASSERT_EQ(combo_box_accessible, | 1234 ASSERT_EQ(combo_box_accessible, |
| 1236 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1235 manager->GetFocus()->ToBrowserAccessibilityWin()); |
| 1237 BrowserAccessibilityWin* text_field_accessible = | 1236 BrowserAccessibilityWin* text_field_accessible = |
| 1238 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1237 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
| 1239 ASSERT_NE(nullptr, text_field_accessible); | 1238 ASSERT_NE(nullptr, text_field_accessible); |
| 1240 | 1239 |
| 1241 // -2 is never a valid offset. | 1240 // -2 is never a valid offset. |
| 1242 LONG caret_offset = -2; | 1241 LONG caret_offset = -2; |
| 1243 LONG n_selections = -2; | 1242 LONG n_selections = -2; |
| 1244 LONG selection_start = -2; | 1243 LONG selection_start = -2; |
| 1245 LONG selection_end = -2; | 1244 LONG selection_end = -2; |
| 1246 | 1245 |
| 1247 // Test get_caretOffset. | 1246 // Test get_caretOffset. |
| 1248 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset); | 1247 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset); |
| 1249 EXPECT_EQ(S_OK, hr); | 1248 EXPECT_EQ(S_OK, hr); |
| 1250 EXPECT_EQ(1L, caret_offset); | 1249 EXPECT_EQ(1L, caret_offset); |
| 1251 // The caret should be at the end of the selection. | 1250 // The caret should be at the end of the selection. |
| 1252 hr = text_field_accessible->get_caretOffset(&caret_offset); | 1251 hr = text_field_accessible->get_caretOffset(&caret_offset); |
| 1253 EXPECT_EQ(S_OK, hr); | 1252 EXPECT_EQ(S_OK, hr); |
| 1254 EXPECT_EQ(2L, caret_offset); | 1253 EXPECT_EQ(2L, caret_offset); |
| 1255 | 1254 |
| 1256 // Move the focus to the text field. | 1255 // Move the focus to the text field. |
| 1257 combo_box.state &= ~(1 << ui::AX_STATE_FOCUSED); | 1256 manager->SetFocusLocallyForTesting(text_field_accessible); |
| 1258 text_field.state |= 1 << ui::AX_STATE_FOCUSED; | |
| 1259 manager->SetFocus(text_field_accessible, false /* notify */); | |
| 1260 ASSERT_EQ(text_field_accessible, | 1257 ASSERT_EQ(text_field_accessible, |
| 1261 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1258 manager->GetFocus()->ToBrowserAccessibilityWin()); |
| 1262 | 1259 |
| 1263 // The caret should not have moved. | 1260 // The caret should not have moved. |
| 1264 hr = text_field_accessible->get_caretOffset(&caret_offset); | 1261 hr = text_field_accessible->get_caretOffset(&caret_offset); |
| 1265 EXPECT_EQ(S_OK, hr); | 1262 EXPECT_EQ(S_OK, hr); |
| 1266 EXPECT_EQ(2L, caret_offset); | 1263 EXPECT_EQ(2L, caret_offset); |
| 1267 | 1264 |
| 1268 // Test get_nSelections. | 1265 // Test get_nSelections. |
| 1269 hr = combo_box_accessible->get_nSelections(&n_selections); | 1266 hr = combo_box_accessible->get_nSelections(&n_selections); |
| 1270 EXPECT_EQ(S_OK, hr); | 1267 EXPECT_EQ(S_OK, hr); |
| 1271 EXPECT_EQ(0L, n_selections); | 1268 EXPECT_EQ(0L, n_selections); |
| (...skipping 91 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1363 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); | 1360 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); |
| 1364 EXPECT_EQ(S_OK, hr); | 1361 EXPECT_EQ(S_OK, hr); |
| 1365 EXPECT_EQ(0L, n_selections); | 1362 EXPECT_EQ(0L, n_selections); |
| 1366 | 1363 |
| 1367 // The caret should be on the embedded object character. | 1364 // The caret should be on the embedded object character. |
| 1368 hr = div_editable_accessible->get_caretOffset(&caret_offset); | 1365 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
| 1369 EXPECT_EQ(S_OK, hr); | 1366 EXPECT_EQ(S_OK, hr); |
| 1370 EXPECT_EQ(6L, caret_offset); | 1367 EXPECT_EQ(6L, caret_offset); |
| 1371 | 1368 |
| 1372 // Move the focus to the content editable. | 1369 // Move the focus to the content editable. |
| 1373 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 1370 manager->SetFocusLocallyForTesting(div_editable_accessible); |
| 1374 manager->SetFocus(div_editable_accessible, false /* notify */); | |
| 1375 ASSERT_EQ(div_editable_accessible, | 1371 ASSERT_EQ(div_editable_accessible, |
| 1376 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1372 manager->GetFocus()->ToBrowserAccessibilityWin()); |
| 1377 | 1373 |
| 1378 BrowserAccessibilityWin* text_accessible = | 1374 BrowserAccessibilityWin* text_accessible = |
| 1379 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1375 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
| 1380 ASSERT_NE(nullptr, text_accessible); | 1376 ASSERT_NE(nullptr, text_accessible); |
| 1381 BrowserAccessibilityWin* link_accessible = | 1377 BrowserAccessibilityWin* link_accessible = |
| 1382 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1378 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
| 1383 ASSERT_NE(nullptr, link_accessible); | 1379 ASSERT_NE(nullptr, link_accessible); |
| 1384 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); | 1380 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); |
| 1385 | 1381 |
| 1386 BrowserAccessibilityWin* link_text_accessible = | 1382 BrowserAccessibilityWin* link_text_accessible = |
| (...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1530 EXPECT_EQ(S_OK, hr); | 1526 EXPECT_EQ(S_OK, hr); |
| 1531 EXPECT_EQ(0L, selection_start); | 1527 EXPECT_EQ(0L, selection_start); |
| 1532 EXPECT_EQ(4L, selection_end); | 1528 EXPECT_EQ(4L, selection_end); |
| 1533 | 1529 |
| 1534 // The caret should be at the focus (the end) of the selection. | 1530 // The caret should be at the focus (the end) of the selection. |
| 1535 hr = div_editable_accessible->get_caretOffset(&caret_offset); | 1531 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
| 1536 EXPECT_EQ(S_OK, hr); | 1532 EXPECT_EQ(S_OK, hr); |
| 1537 EXPECT_EQ(7L, caret_offset); | 1533 EXPECT_EQ(7L, caret_offset); |
| 1538 | 1534 |
| 1539 // Move the focus to the content editable. | 1535 // Move the focus to the content editable. |
| 1540 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 1536 manager->SetFocusLocallyForTesting(div_editable_accessible); |
| 1541 manager->SetFocus(div_editable_accessible, false /* notify */); | |
| 1542 ASSERT_EQ(div_editable_accessible, | 1537 ASSERT_EQ(div_editable_accessible, |
| 1543 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1538 manager->GetFocus()->ToBrowserAccessibilityWin()); |
| 1544 | 1539 |
| 1545 // The caret should not have moved. | 1540 // The caret should not have moved. |
| 1546 hr = div_editable_accessible->get_caretOffset(&caret_offset); | 1541 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
| 1547 EXPECT_EQ(S_OK, hr); | 1542 EXPECT_EQ(S_OK, hr); |
| 1548 EXPECT_EQ(7L, caret_offset); | 1543 EXPECT_EQ(7L, caret_offset); |
| 1549 | 1544 |
| 1550 // The caret offset should reflect the position of the selection's focus in | 1545 // The caret offset should reflect the position of the selection's focus in |
| 1551 // any given object. | 1546 // any given object. |
| 1552 hr = link_accessible->get_caretOffset(&caret_offset); | 1547 hr = link_accessible->get_caretOffset(&caret_offset); |
| 1553 EXPECT_EQ(S_OK, hr); | 1548 EXPECT_EQ(S_OK, hr); |
| (...skipping 283 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1837 EXPECT_EQ(S_OK, hr); | 1832 EXPECT_EQ(S_OK, hr); |
| 1838 | 1833 |
| 1839 base::win::ScopedVariant new_child_variant(child_unique_id_2); | 1834 base::win::ScopedVariant new_child_variant(child_unique_id_2); |
| 1840 base::win::ScopedComPtr<IDispatch> new_child_dispatch; | 1835 base::win::ScopedComPtr<IDispatch> new_child_dispatch; |
| 1841 hr = root->ToBrowserAccessibilityWin()->get_accChild( | 1836 hr = root->ToBrowserAccessibilityWin()->get_accChild( |
| 1842 new_child_variant, new_child_dispatch.Receive()); | 1837 new_child_variant, new_child_dispatch.Receive()); |
| 1843 EXPECT_EQ(S_OK, hr); | 1838 EXPECT_EQ(S_OK, hr); |
| 1844 } | 1839 } |
| 1845 | 1840 |
| 1846 } // namespace content | 1841 } // namespace content |
| OLD | NEW |