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 1064 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1075 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1075 root_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
1076 ASSERT_NE(nullptr, text_field_accessible); | 1076 ASSERT_NE(nullptr, text_field_accessible); |
1077 | 1077 |
1078 // -2 is never a valid offset. | 1078 // -2 is never a valid offset. |
1079 LONG caret_offset = -2; | 1079 LONG caret_offset = -2; |
1080 LONG n_selections = -2; | 1080 LONG n_selections = -2; |
1081 LONG selection_start = -2; | 1081 LONG selection_start = -2; |
1082 LONG selection_end = -2; | 1082 LONG selection_end = -2; |
1083 | 1083 |
1084 // Test get_caretOffset. | 1084 // Test get_caretOffset. |
1085 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset);; | 1085 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset); |
1086 EXPECT_EQ(S_OK, hr); | 1086 EXPECT_EQ(S_OK, hr); |
1087 EXPECT_EQ(1L, caret_offset); | 1087 EXPECT_EQ(1L, caret_offset); |
1088 // The caret should be at the end of the selection. | 1088 // The caret should be at the end of the selection. |
1089 hr = text_field_accessible->get_caretOffset(&caret_offset);; | 1089 hr = text_field_accessible->get_caretOffset(&caret_offset); |
1090 EXPECT_EQ(S_OK, hr); | 1090 EXPECT_EQ(S_OK, hr); |
1091 EXPECT_EQ(2L, caret_offset); | 1091 EXPECT_EQ(2L, caret_offset); |
1092 | 1092 |
1093 // Move the focus to the text field. | 1093 // Move the focus to the text field. |
1094 combo_box.state &= ~(1 << ui::AX_STATE_FOCUSED); | 1094 combo_box.state &= ~(1 << ui::AX_STATE_FOCUSED); |
1095 text_field.state |= 1 << ui::AX_STATE_FOCUSED; | 1095 text_field.state |= 1 << ui::AX_STATE_FOCUSED; |
1096 manager->SetFocus(text_field_accessible, false /* notify */); | 1096 manager->SetFocus(text_field_accessible, false /* notify */); |
1097 ASSERT_EQ(text_field_accessible, | 1097 ASSERT_EQ(text_field_accessible, |
1098 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1098 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
1099 | 1099 |
1100 // The caret should not have moved. | 1100 // The caret should not have moved. |
1101 hr = text_field_accessible->get_caretOffset(&caret_offset);; | 1101 hr = text_field_accessible->get_caretOffset(&caret_offset); |
1102 EXPECT_EQ(S_OK, hr); | 1102 EXPECT_EQ(S_OK, hr); |
1103 EXPECT_EQ(2L, caret_offset); | 1103 EXPECT_EQ(2L, caret_offset); |
1104 | 1104 |
1105 // Test get_nSelections. | 1105 // Test get_nSelections. |
1106 hr = combo_box_accessible->get_nSelections(&n_selections);; | 1106 hr = combo_box_accessible->get_nSelections(&n_selections); |
1107 EXPECT_EQ(S_OK, hr); | 1107 EXPECT_EQ(S_OK, hr); |
1108 EXPECT_EQ(0L, n_selections); | 1108 EXPECT_EQ(0L, n_selections); |
1109 hr = text_field_accessible->get_nSelections(&n_selections);; | 1109 hr = text_field_accessible->get_nSelections(&n_selections); |
1110 EXPECT_EQ(S_OK, hr); | 1110 EXPECT_EQ(S_OK, hr); |
1111 EXPECT_EQ(1L, n_selections); | 1111 EXPECT_EQ(1L, n_selections); |
1112 | 1112 |
1113 // Test get_selection. | 1113 // Test get_selection. |
1114 hr = combo_box_accessible->get_selection( | 1114 hr = combo_box_accessible->get_selection( |
1115 0L /* selection_index */, &selection_start, &selection_end);; | 1115 0L /* selection_index */, &selection_start, &selection_end); |
1116 EXPECT_EQ(E_INVALIDARG, hr); // No selections available. | 1116 EXPECT_EQ(E_INVALIDARG, hr); // No selections available. |
1117 // Invalid in_args should not modify out_args. | 1117 // Invalid in_args should not modify out_args. |
1118 EXPECT_EQ(-2L, selection_start); | 1118 EXPECT_EQ(-2L, selection_start); |
1119 EXPECT_EQ(-2L, selection_end); | 1119 EXPECT_EQ(-2L, selection_end); |
1120 hr = text_field_accessible->get_selection( | 1120 hr = text_field_accessible->get_selection( |
1121 0L /* selection_index */, &selection_start, &selection_end);; | 1121 0L /* selection_index */, &selection_start, &selection_end); |
1122 EXPECT_EQ(S_OK, hr); | 1122 EXPECT_EQ(S_OK, hr); |
1123 EXPECT_EQ(1L, selection_start); | 1123 EXPECT_EQ(1L, selection_start); |
1124 EXPECT_EQ(2L, selection_end); | 1124 EXPECT_EQ(2L, selection_end); |
1125 | 1125 |
1126 manager.reset(); | 1126 manager.reset(); |
1127 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1127 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1128 } | 1128 } |
1129 | 1129 |
1130 TEST_F(BrowserAccessibilityTest, TestCaretInContentEditables) { | 1130 TEST_F(BrowserAccessibilityTest, TestCaretInContentEditables) { |
1131 ui::AXNodeData root; | 1131 ui::AXNodeData root; |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1221 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); | 1221 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); |
1222 | 1222 |
1223 BrowserAccessibilityWin* link_text_accessible = | 1223 BrowserAccessibilityWin* link_text_accessible = |
1224 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1224 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
1225 ASSERT_NE(nullptr, link_text_accessible); | 1225 ASSERT_NE(nullptr, link_text_accessible); |
1226 | 1226 |
1227 // The caret should not have moved. | 1227 // The caret should not have moved. |
1228 hr = div_editable_accessible->get_nSelections(&n_selections); | 1228 hr = div_editable_accessible->get_nSelections(&n_selections); |
1229 EXPECT_EQ(S_OK, hr); | 1229 EXPECT_EQ(S_OK, hr); |
1230 EXPECT_EQ(0L, n_selections); | 1230 EXPECT_EQ(0L, n_selections); |
1231 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1231 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
1232 EXPECT_EQ(S_OK, hr); | 1232 EXPECT_EQ(S_OK, hr); |
1233 EXPECT_EQ(6L, caret_offset); | 1233 EXPECT_EQ(6L, caret_offset); |
1234 | 1234 |
1235 hr = link_accessible->get_nSelections(&n_selections); | 1235 hr = link_accessible->get_nSelections(&n_selections); |
1236 EXPECT_EQ(S_OK, hr); | 1236 EXPECT_EQ(S_OK, hr); |
1237 EXPECT_EQ(0L, n_selections); | 1237 EXPECT_EQ(0L, n_selections); |
1238 hr = link_text_accessible->get_nSelections(&n_selections); | 1238 hr = link_text_accessible->get_nSelections(&n_selections); |
1239 EXPECT_EQ(S_OK, hr); | 1239 EXPECT_EQ(S_OK, hr); |
1240 EXPECT_EQ(0L, n_selections); | 1240 EXPECT_EQ(0L, n_selections); |
1241 | 1241 |
1242 hr = link_accessible->get_caretOffset(&caret_offset);; | 1242 hr = link_accessible->get_caretOffset(&caret_offset); |
1243 EXPECT_EQ(S_OK, hr); | 1243 EXPECT_EQ(S_OK, hr); |
1244 EXPECT_EQ(1L, caret_offset); | 1244 EXPECT_EQ(1L, caret_offset); |
1245 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1245 hr = link_text_accessible->get_caretOffset(&caret_offset); |
1246 EXPECT_EQ(S_OK, hr); | 1246 EXPECT_EQ(S_OK, hr); |
1247 EXPECT_EQ(1L, caret_offset); | 1247 EXPECT_EQ(1L, caret_offset); |
1248 | 1248 |
1249 manager.reset(); | 1249 manager.reset(); |
1250 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1250 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1251 } | 1251 } |
1252 | 1252 |
1253 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) { | 1253 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) { |
1254 ui::AXNodeData root; | 1254 ui::AXNodeData root; |
1255 root.id = 1; | 1255 root.id = 1; |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1323 BrowserAccessibilityWin* link_accessible = | 1323 BrowserAccessibilityWin* link_accessible = |
1324 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1324 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
1325 ASSERT_NE(nullptr, link_accessible); | 1325 ASSERT_NE(nullptr, link_accessible); |
1326 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); | 1326 ASSERT_EQ(1U, link_accessible->PlatformChildCount()); |
1327 | 1327 |
1328 BrowserAccessibilityWin* link_text_accessible = | 1328 BrowserAccessibilityWin* link_text_accessible = |
1329 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1329 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
1330 ASSERT_NE(nullptr, link_text_accessible); | 1330 ASSERT_NE(nullptr, link_text_accessible); |
1331 | 1331 |
1332 // get_nSelections should work on all objects. | 1332 // get_nSelections should work on all objects. |
1333 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections);; | 1333 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); |
1334 EXPECT_EQ(S_OK, hr); | 1334 EXPECT_EQ(S_OK, hr); |
1335 EXPECT_EQ(1L, n_selections); | 1335 EXPECT_EQ(1L, n_selections); |
1336 hr = text_accessible->get_nSelections(&n_selections);; | 1336 hr = text_accessible->get_nSelections(&n_selections); |
1337 EXPECT_EQ(S_OK, hr); | 1337 EXPECT_EQ(S_OK, hr); |
1338 EXPECT_EQ(1L, n_selections); | 1338 EXPECT_EQ(1L, n_selections); |
1339 hr = link_accessible->get_nSelections(&n_selections);; | 1339 hr = link_accessible->get_nSelections(&n_selections); |
1340 EXPECT_EQ(S_OK, hr); | 1340 EXPECT_EQ(S_OK, hr); |
1341 EXPECT_EQ(1L, n_selections); | 1341 EXPECT_EQ(1L, n_selections); |
1342 hr = link_text_accessible->get_nSelections(&n_selections);; | 1342 hr = link_text_accessible->get_nSelections(&n_selections); |
1343 EXPECT_EQ(S_OK, hr); | 1343 EXPECT_EQ(S_OK, hr); |
1344 EXPECT_EQ(1L, n_selections); | 1344 EXPECT_EQ(1L, n_selections); |
1345 | 1345 |
1346 // get_selection should be unaffected by focus placement. | 1346 // get_selection should be unaffected by focus placement. |
1347 hr = div_editable_accessible->get_selection( | 1347 hr = div_editable_accessible->get_selection( |
1348 0L /* selection_index */, &selection_start, &selection_end);; | 1348 0L /* selection_index */, &selection_start, &selection_end); |
1349 EXPECT_EQ(S_OK, hr); | 1349 EXPECT_EQ(S_OK, hr); |
1350 EXPECT_EQ(1L, selection_start); | 1350 EXPECT_EQ(1L, selection_start); |
1351 // selection_end should be after embedded object character. | 1351 // selection_end should be after embedded object character. |
1352 EXPECT_EQ(7L, selection_end); | 1352 EXPECT_EQ(7L, selection_end); |
1353 | 1353 |
1354 hr = text_accessible->get_selection( | 1354 hr = text_accessible->get_selection( |
1355 0L /* selection_index */, &selection_start, &selection_end);; | 1355 0L /* selection_index */, &selection_start, &selection_end); |
1356 EXPECT_EQ(S_OK, hr); | 1356 EXPECT_EQ(S_OK, hr); |
1357 EXPECT_EQ(1L, selection_start); | 1357 EXPECT_EQ(1L, selection_start); |
1358 // No embedded character on this object, only the first part of the text. | 1358 // No embedded character on this object, only the first part of the text. |
1359 EXPECT_EQ(6L, selection_end); | 1359 EXPECT_EQ(6L, selection_end); |
1360 hr = link_accessible->get_selection( | 1360 hr = link_accessible->get_selection( |
1361 0L /* selection_index */, &selection_start, &selection_end);; | 1361 0L /* selection_index */, &selection_start, &selection_end); |
1362 EXPECT_EQ(S_OK, hr); | 1362 EXPECT_EQ(S_OK, hr); |
1363 EXPECT_EQ(0L, selection_start); | 1363 EXPECT_EQ(0L, selection_start); |
1364 EXPECT_EQ(4L, selection_end); | 1364 EXPECT_EQ(4L, selection_end); |
1365 hr = link_text_accessible->get_selection( | 1365 hr = link_text_accessible->get_selection( |
1366 0L /* selection_index */, &selection_start, &selection_end);; | 1366 0L /* selection_index */, &selection_start, &selection_end); |
1367 EXPECT_EQ(S_OK, hr); | 1367 EXPECT_EQ(S_OK, hr); |
1368 EXPECT_EQ(0L, selection_start); | 1368 EXPECT_EQ(0L, selection_start); |
1369 EXPECT_EQ(4L, selection_end); | 1369 EXPECT_EQ(4L, selection_end); |
1370 | 1370 |
1371 // The caret should be at the focus (the end) of the selection. | 1371 // The caret should be at the focus (the end) of the selection. |
1372 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1372 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
1373 EXPECT_EQ(S_OK, hr); | 1373 EXPECT_EQ(S_OK, hr); |
1374 EXPECT_EQ(7L, caret_offset); | 1374 EXPECT_EQ(7L, caret_offset); |
1375 | 1375 |
1376 // Move the focus to the content editable. | 1376 // Move the focus to the content editable. |
1377 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 1377 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; |
1378 manager->SetFocus(div_editable_accessible, false /* notify */); | 1378 manager->SetFocus(div_editable_accessible, false /* notify */); |
1379 ASSERT_EQ(div_editable_accessible, | 1379 ASSERT_EQ(div_editable_accessible, |
1380 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1380 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
1381 | 1381 |
1382 // The caret should not have moved. | 1382 // The caret should not have moved. |
1383 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1383 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
1384 EXPECT_EQ(S_OK, hr); | 1384 EXPECT_EQ(S_OK, hr); |
1385 EXPECT_EQ(7L, caret_offset); | 1385 EXPECT_EQ(7L, caret_offset); |
1386 | 1386 |
1387 // The caret offset should reflect the position of the selection's focus in | 1387 // The caret offset should reflect the position of the selection's focus in |
1388 // any given object. | 1388 // any given object. |
1389 hr = link_accessible->get_caretOffset(&caret_offset);; | 1389 hr = link_accessible->get_caretOffset(&caret_offset); |
1390 EXPECT_EQ(S_OK, hr); | 1390 EXPECT_EQ(S_OK, hr); |
1391 EXPECT_EQ(4L, caret_offset); | 1391 EXPECT_EQ(4L, caret_offset); |
1392 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1392 hr = link_text_accessible->get_caretOffset(&caret_offset); |
1393 EXPECT_EQ(S_OK, hr); | 1393 EXPECT_EQ(S_OK, hr); |
1394 EXPECT_EQ(4L, caret_offset); | 1394 EXPECT_EQ(4L, caret_offset); |
1395 | 1395 |
1396 hr = div_editable_accessible->get_selection( | 1396 hr = div_editable_accessible->get_selection( |
1397 0L /* selection_index */, &selection_start, &selection_end);; | 1397 0L /* selection_index */, &selection_start, &selection_end); |
1398 EXPECT_EQ(S_OK, hr); | 1398 EXPECT_EQ(S_OK, hr); |
1399 EXPECT_EQ(1L, selection_start); | 1399 EXPECT_EQ(1L, selection_start); |
1400 EXPECT_EQ(7L, selection_end); | 1400 EXPECT_EQ(7L, selection_end); |
1401 | 1401 |
1402 manager.reset(); | 1402 manager.reset(); |
1403 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1403 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1404 } | 1404 } |
1405 | 1405 |
1406 TEST_F(BrowserAccessibilityTest, TestIAccessibleHyperlink) { | 1406 TEST_F(BrowserAccessibilityTest, TestIAccessibleHyperlink) { |
1407 ui::AXNodeData root; | 1407 ui::AXNodeData root; |
(...skipping 266 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1674 EXPECT_EQ(S_OK, hr); | 1674 EXPECT_EQ(S_OK, hr); |
1675 | 1675 |
1676 base::win::ScopedVariant new_child_variant(child_unique_id_2); | 1676 base::win::ScopedVariant new_child_variant(child_unique_id_2); |
1677 base::win::ScopedComPtr<IDispatch> new_child_dispatch; | 1677 base::win::ScopedComPtr<IDispatch> new_child_dispatch; |
1678 hr = root->ToBrowserAccessibilityWin()->get_accChild( | 1678 hr = root->ToBrowserAccessibilityWin()->get_accChild( |
1679 new_child_variant, new_child_dispatch.Receive()); | 1679 new_child_variant, new_child_dispatch.Receive()); |
1680 EXPECT_EQ(S_OK, hr); | 1680 EXPECT_EQ(S_OK, hr); |
1681 } | 1681 } |
1682 | 1682 |
1683 } // namespace content | 1683 } // namespace content |
OLD | NEW |