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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "base/win/scoped_bstr.h" | 7 #include "base/win/scoped_bstr.h" |
8 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
9 #include "base/win/scoped_variant.h" | 9 #include "base/win/scoped_variant.h" |
10 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
(...skipping 858 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
869 // -2 is never a valid offset. | 869 // -2 is never a valid offset. |
870 LONG caret_offset = -2; | 870 LONG caret_offset = -2; |
871 LONG n_selections = -2; | 871 LONG n_selections = -2; |
872 LONG selection_start = -2; | 872 LONG selection_start = -2; |
873 LONG selection_end = -2; | 873 LONG selection_end = -2; |
874 | 874 |
875 // Test get_caretOffset. | 875 // Test get_caretOffset. |
876 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset);; | 876 HRESULT hr = combo_box_accessible->get_caretOffset(&caret_offset);; |
877 EXPECT_EQ(S_OK, hr); | 877 EXPECT_EQ(S_OK, hr); |
878 EXPECT_EQ(1L, caret_offset); | 878 EXPECT_EQ(1L, caret_offset); |
879 // The caret should be at the start of the selection. | 879 // The caret should be at the end of the selection. |
880 hr = text_field_accessible->get_caretOffset(&caret_offset);; | 880 hr = text_field_accessible->get_caretOffset(&caret_offset);; |
881 EXPECT_EQ(S_OK, hr); | 881 EXPECT_EQ(S_OK, hr); |
882 EXPECT_EQ(1L, caret_offset); | 882 EXPECT_EQ(2L, caret_offset); |
883 | 883 |
884 // Move the focus to the text field. | 884 // Move the focus to the text field. |
885 combo_box.state &= ~(1 << ui::AX_STATE_FOCUSED); | 885 combo_box.state &= ~(1 << ui::AX_STATE_FOCUSED); |
886 text_field.state |= 1 << ui::AX_STATE_FOCUSED; | 886 text_field.state |= 1 << ui::AX_STATE_FOCUSED; |
887 manager->SetFocus(text_field_accessible, false /* notify */); | 887 manager->SetFocus(text_field_accessible, false /* notify */); |
888 ASSERT_EQ(text_field_accessible, | 888 ASSERT_EQ(text_field_accessible, |
889 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 889 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
890 | 890 |
891 // The caret should not have moved. | 891 // The caret should not have moved. |
892 hr = text_field_accessible->get_caretOffset(&caret_offset);; | 892 hr = text_field_accessible->get_caretOffset(&caret_offset);; |
893 EXPECT_EQ(S_OK, hr); | 893 EXPECT_EQ(S_OK, hr); |
894 EXPECT_EQ(1L, caret_offset); | 894 EXPECT_EQ(2L, caret_offset); |
895 | 895 |
896 // Test get_nSelections. | 896 // Test get_nSelections. |
897 hr = combo_box_accessible->get_nSelections(&n_selections);; | 897 hr = combo_box_accessible->get_nSelections(&n_selections);; |
898 EXPECT_EQ(S_OK, hr); | 898 EXPECT_EQ(S_OK, hr); |
899 EXPECT_EQ(0L, n_selections); | 899 EXPECT_EQ(0L, n_selections); |
900 hr = text_field_accessible->get_nSelections(&n_selections);; | 900 hr = text_field_accessible->get_nSelections(&n_selections);; |
901 EXPECT_EQ(S_OK, hr); | 901 EXPECT_EQ(S_OK, hr); |
902 EXPECT_EQ(1L, n_selections); | 902 EXPECT_EQ(1L, n_selections); |
903 | 903 |
904 // Test get_selection. | 904 // Test get_selection. |
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
974 ASSERT_NE(nullptr, root_accessible); | 974 ASSERT_NE(nullptr, root_accessible); |
975 ASSERT_EQ(1, root_accessible->PlatformChildCount()); | 975 ASSERT_EQ(1, root_accessible->PlatformChildCount()); |
976 | 976 |
977 BrowserAccessibilityWin* div_editable_accessible = | 977 BrowserAccessibilityWin* div_editable_accessible = |
978 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 978 root_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
979 ASSERT_NE(nullptr, div_editable_accessible); | 979 ASSERT_NE(nullptr, div_editable_accessible); |
980 ASSERT_EQ(2, div_editable_accessible->PlatformChildCount()); | 980 ASSERT_EQ(2, div_editable_accessible->PlatformChildCount()); |
981 | 981 |
982 // -2 is never a valid offset. | 982 // -2 is never a valid offset. |
983 LONG caret_offset = -2; | 983 LONG caret_offset = -2; |
| 984 LONG n_selections = -2; |
| 985 |
| 986 // No selection should be present. |
| 987 HRESULT hr = div_editable_accessible->get_nSelections(&n_selections); |
| 988 EXPECT_EQ(S_OK, hr); |
| 989 EXPECT_EQ(0L, n_selections); |
984 | 990 |
985 // The caret should be on the embedded object character. | 991 // The caret should be on the embedded object character. |
986 HRESULT hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 992 hr = div_editable_accessible->get_caretOffset(&caret_offset); |
987 EXPECT_EQ(S_OK, hr); | 993 EXPECT_EQ(S_OK, hr); |
988 EXPECT_EQ(6L, caret_offset); | 994 EXPECT_EQ(6L, caret_offset); |
989 | 995 |
990 // Move the focus to the content editable. | 996 // Move the focus to the content editable. |
991 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 997 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; |
992 manager->SetFocus(div_editable_accessible, false /* notify */); | 998 manager->SetFocus(div_editable_accessible, false /* notify */); |
993 ASSERT_EQ(div_editable_accessible, | 999 ASSERT_EQ(div_editable_accessible, |
994 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1000 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
995 | 1001 |
996 BrowserAccessibilityWin* text_accessible = | 1002 BrowserAccessibilityWin* text_accessible = |
997 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1003 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
998 ASSERT_NE(nullptr, text_accessible); | 1004 ASSERT_NE(nullptr, text_accessible); |
999 BrowserAccessibilityWin* link_accessible = | 1005 BrowserAccessibilityWin* link_accessible = |
1000 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1006 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
1001 ASSERT_NE(nullptr, link_accessible); | 1007 ASSERT_NE(nullptr, link_accessible); |
1002 ASSERT_EQ(1, link_accessible->PlatformChildCount()); | 1008 ASSERT_EQ(1, link_accessible->PlatformChildCount()); |
1003 | 1009 |
1004 BrowserAccessibilityWin* link_text_accessible = | 1010 BrowserAccessibilityWin* link_text_accessible = |
1005 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1011 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
1006 ASSERT_NE(nullptr, link_text_accessible); | 1012 ASSERT_NE(nullptr, link_text_accessible); |
1007 | 1013 |
1008 // The caret should not have moved. | 1014 // The caret should not have moved. |
| 1015 hr = div_editable_accessible->get_nSelections(&n_selections); |
| 1016 EXPECT_EQ(S_OK, hr); |
| 1017 EXPECT_EQ(0L, n_selections); |
1009 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1018 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1010 EXPECT_EQ(S_OK, hr); | 1019 EXPECT_EQ(S_OK, hr); |
1011 EXPECT_EQ(6L, caret_offset); | 1020 EXPECT_EQ(6L, caret_offset); |
1012 | 1021 |
| 1022 hr = link_accessible->get_nSelections(&n_selections); |
| 1023 EXPECT_EQ(S_OK, hr); |
| 1024 EXPECT_EQ(0L, n_selections); |
| 1025 hr = link_text_accessible->get_nSelections(&n_selections); |
| 1026 EXPECT_EQ(S_OK, hr); |
| 1027 EXPECT_EQ(0L, n_selections); |
| 1028 |
1013 hr = link_accessible->get_caretOffset(&caret_offset);; | 1029 hr = link_accessible->get_caretOffset(&caret_offset);; |
1014 EXPECT_EQ(S_OK, hr); | 1030 EXPECT_EQ(S_OK, hr); |
1015 EXPECT_EQ(1L, caret_offset); | 1031 EXPECT_EQ(1L, caret_offset); |
1016 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1032 hr = link_text_accessible->get_caretOffset(&caret_offset);; |
1017 EXPECT_EQ(S_OK, hr); | 1033 EXPECT_EQ(S_OK, hr); |
1018 EXPECT_EQ(1L, caret_offset); | 1034 EXPECT_EQ(1L, caret_offset); |
1019 | 1035 |
1020 manager.reset(); | 1036 manager.reset(); |
1021 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1037 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1022 } | 1038 } |
1023 | 1039 |
1024 TEST_F(BrowserAccessibilityTest, DISABLED_TestSelectionInContentEditables) { | 1040 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) { |
1025 ui::AXNodeData root; | 1041 ui::AXNodeData root; |
1026 root.id = 1; | 1042 root.id = 1; |
1027 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1043 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
1028 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); | 1044 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); |
1029 | 1045 |
1030 ui::AXNodeData div_editable; | 1046 ui::AXNodeData div_editable; |
1031 div_editable.id = 2; | 1047 div_editable.id = 2; |
1032 div_editable.role = ui::AX_ROLE_DIV; | 1048 div_editable.role = ui::AX_ROLE_DIV; |
1033 div_editable.state = (1 << ui::AX_STATE_FOCUSABLE); | 1049 div_editable.state = (1 << ui::AX_STATE_FOCUSABLE); |
1034 | 1050 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1128 0L /* selection_index */, &selection_start, &selection_end);; | 1144 0L /* selection_index */, &selection_start, &selection_end);; |
1129 EXPECT_EQ(S_OK, hr); | 1145 EXPECT_EQ(S_OK, hr); |
1130 EXPECT_EQ(0L, selection_start); | 1146 EXPECT_EQ(0L, selection_start); |
1131 EXPECT_EQ(4L, selection_end); | 1147 EXPECT_EQ(4L, selection_end); |
1132 hr = link_text_accessible->get_selection( | 1148 hr = link_text_accessible->get_selection( |
1133 0L /* selection_index */, &selection_start, &selection_end);; | 1149 0L /* selection_index */, &selection_start, &selection_end);; |
1134 EXPECT_EQ(S_OK, hr); | 1150 EXPECT_EQ(S_OK, hr); |
1135 EXPECT_EQ(0L, selection_start); | 1151 EXPECT_EQ(0L, selection_start); |
1136 EXPECT_EQ(4L, selection_end); | 1152 EXPECT_EQ(4L, selection_end); |
1137 | 1153 |
1138 // The caret should be at the anchor (the start) of the selection. | 1154 // The caret should be at the focus (the end) of the selection. |
1139 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1155 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1140 EXPECT_EQ(S_OK, hr); | 1156 EXPECT_EQ(S_OK, hr); |
1141 EXPECT_EQ(1L, caret_offset); | 1157 EXPECT_EQ(7L, caret_offset); |
1142 | 1158 |
1143 // Move the focus to the content editable. | 1159 // Move the focus to the content editable. |
1144 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 1160 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; |
1145 manager->SetFocus(div_editable_accessible, false /* notify */); | 1161 manager->SetFocus(div_editable_accessible, false /* notify */); |
1146 ASSERT_EQ(div_editable_accessible, | 1162 ASSERT_EQ(div_editable_accessible, |
1147 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1163 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
1148 | 1164 |
1149 // The caret should not have moved. | 1165 // The caret should not have moved. |
1150 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1166 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1151 EXPECT_EQ(S_OK, hr); | 1167 EXPECT_EQ(S_OK, hr); |
1152 EXPECT_EQ(1L, caret_offset); | 1168 EXPECT_EQ(7L, caret_offset); |
1153 | 1169 |
1154 // The HRESULT should be S_FALSE if the caret is not in the given object. | 1170 // The caret offset should reflect the position of the selection's focus in |
| 1171 // any given object. |
1155 hr = link_accessible->get_caretOffset(&caret_offset);; | 1172 hr = link_accessible->get_caretOffset(&caret_offset);; |
1156 EXPECT_EQ(S_FALSE, hr); | 1173 EXPECT_EQ(S_OK, hr); |
1157 EXPECT_EQ(-1L, caret_offset); | 1174 EXPECT_EQ(4L, caret_offset); |
1158 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1175 hr = link_text_accessible->get_caretOffset(&caret_offset);; |
1159 EXPECT_EQ(S_FALSE, hr); | 1176 EXPECT_EQ(S_OK, hr); |
1160 EXPECT_EQ(-1L, caret_offset); | 1177 EXPECT_EQ(4L, caret_offset); |
1161 | 1178 |
1162 hr = div_editable_accessible->get_selection( | 1179 hr = div_editable_accessible->get_selection( |
1163 0L /* selection_index */, &selection_start, &selection_end);; | 1180 0L /* selection_index */, &selection_start, &selection_end);; |
1164 EXPECT_EQ(S_OK, hr); | 1181 EXPECT_EQ(S_OK, hr); |
1165 EXPECT_EQ(1L, selection_start); | 1182 EXPECT_EQ(1L, selection_start); |
1166 EXPECT_EQ(7L, selection_end); | 1183 EXPECT_EQ(7L, selection_end); |
1167 | 1184 |
1168 manager.reset(); | 1185 manager.reset(); |
1169 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1186 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1170 } | 1187 } |
1171 | 1188 |
1172 } // namespace content | 1189 } // namespace content |
OLD | NEW |