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 end of the selection. | 879 // The caret should be at the start 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(2L, caret_offset); | 882 EXPECT_EQ(1L, 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(2L, caret_offset); | 894 EXPECT_EQ(1L, 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); | |
990 | 984 |
991 // The caret should be on the embedded object character. | 985 // The caret should be on the embedded object character. |
992 hr = div_editable_accessible->get_caretOffset(&caret_offset); | 986 HRESULT hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
993 EXPECT_EQ(S_OK, hr); | 987 EXPECT_EQ(S_OK, hr); |
994 EXPECT_EQ(6L, caret_offset); | 988 EXPECT_EQ(6L, caret_offset); |
995 | 989 |
996 // Move the focus to the content editable. | 990 // Move the focus to the content editable. |
997 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 991 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; |
998 manager->SetFocus(div_editable_accessible, false /* notify */); | 992 manager->SetFocus(div_editable_accessible, false /* notify */); |
999 ASSERT_EQ(div_editable_accessible, | 993 ASSERT_EQ(div_editable_accessible, |
1000 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 994 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
1001 | 995 |
1002 BrowserAccessibilityWin* text_accessible = | 996 BrowserAccessibilityWin* text_accessible = |
1003 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 997 div_editable_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
1004 ASSERT_NE(nullptr, text_accessible); | 998 ASSERT_NE(nullptr, text_accessible); |
1005 BrowserAccessibilityWin* link_accessible = | 999 BrowserAccessibilityWin* link_accessible = |
1006 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); | 1000 div_editable_accessible->PlatformGetChild(1)->ToBrowserAccessibilityWin(); |
1007 ASSERT_NE(nullptr, link_accessible); | 1001 ASSERT_NE(nullptr, link_accessible); |
1008 ASSERT_EQ(1, link_accessible->PlatformChildCount()); | 1002 ASSERT_EQ(1, link_accessible->PlatformChildCount()); |
1009 | 1003 |
1010 BrowserAccessibilityWin* link_text_accessible = | 1004 BrowserAccessibilityWin* link_text_accessible = |
1011 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); | 1005 link_accessible->PlatformGetChild(0)->ToBrowserAccessibilityWin(); |
1012 ASSERT_NE(nullptr, link_text_accessible); | 1006 ASSERT_NE(nullptr, link_text_accessible); |
1013 | 1007 |
1014 // The caret should not have moved. | 1008 // 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); | |
1018 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1009 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1019 EXPECT_EQ(S_OK, hr); | 1010 EXPECT_EQ(S_OK, hr); |
1020 EXPECT_EQ(6L, caret_offset); | 1011 EXPECT_EQ(6L, caret_offset); |
1021 | 1012 |
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 | |
1029 hr = link_accessible->get_caretOffset(&caret_offset);; | 1013 hr = link_accessible->get_caretOffset(&caret_offset);; |
1030 EXPECT_EQ(S_OK, hr); | 1014 EXPECT_EQ(S_OK, hr); |
1031 EXPECT_EQ(1L, caret_offset); | 1015 EXPECT_EQ(1L, caret_offset); |
1032 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1016 hr = link_text_accessible->get_caretOffset(&caret_offset);; |
1033 EXPECT_EQ(S_OK, hr); | 1017 EXPECT_EQ(S_OK, hr); |
1034 EXPECT_EQ(1L, caret_offset); | 1018 EXPECT_EQ(1L, caret_offset); |
1035 | 1019 |
1036 manager.reset(); | 1020 manager.reset(); |
1037 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1021 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1038 } | 1022 } |
1039 | 1023 |
1040 TEST_F(BrowserAccessibilityTest, TestSelectionInContentEditables) { | 1024 TEST_F(BrowserAccessibilityTest, DISABLED_TestSelectionInContentEditables) { |
1041 ui::AXNodeData root; | 1025 ui::AXNodeData root; |
1042 root.id = 1; | 1026 root.id = 1; |
1043 root.role = ui::AX_ROLE_ROOT_WEB_AREA; | 1027 root.role = ui::AX_ROLE_ROOT_WEB_AREA; |
1044 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); | 1028 root.state = (1 << ui::AX_STATE_READ_ONLY) | (1 << ui::AX_STATE_FOCUSABLE); |
1045 | 1029 |
1046 ui::AXNodeData div_editable; | 1030 ui::AXNodeData div_editable; |
1047 div_editable.id = 2; | 1031 div_editable.id = 2; |
1048 div_editable.role = ui::AX_ROLE_DIV; | 1032 div_editable.role = ui::AX_ROLE_DIV; |
1049 div_editable.state = (1 << ui::AX_STATE_FOCUSABLE); | 1033 div_editable.state = (1 << ui::AX_STATE_FOCUSABLE); |
1050 | 1034 |
(...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1144 0L /* selection_index */, &selection_start, &selection_end);; | 1128 0L /* selection_index */, &selection_start, &selection_end);; |
1145 EXPECT_EQ(S_OK, hr); | 1129 EXPECT_EQ(S_OK, hr); |
1146 EXPECT_EQ(0L, selection_start); | 1130 EXPECT_EQ(0L, selection_start); |
1147 EXPECT_EQ(4L, selection_end); | 1131 EXPECT_EQ(4L, selection_end); |
1148 hr = link_text_accessible->get_selection( | 1132 hr = link_text_accessible->get_selection( |
1149 0L /* selection_index */, &selection_start, &selection_end);; | 1133 0L /* selection_index */, &selection_start, &selection_end);; |
1150 EXPECT_EQ(S_OK, hr); | 1134 EXPECT_EQ(S_OK, hr); |
1151 EXPECT_EQ(0L, selection_start); | 1135 EXPECT_EQ(0L, selection_start); |
1152 EXPECT_EQ(4L, selection_end); | 1136 EXPECT_EQ(4L, selection_end); |
1153 | 1137 |
1154 // The caret should be at the focus (the end) of the selection. | 1138 // The caret should be at the anchor (the start) of the selection. |
1155 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1139 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1156 EXPECT_EQ(S_OK, hr); | 1140 EXPECT_EQ(S_OK, hr); |
1157 EXPECT_EQ(7L, caret_offset); | 1141 EXPECT_EQ(1L, caret_offset); |
1158 | 1142 |
1159 // Move the focus to the content editable. | 1143 // Move the focus to the content editable. |
1160 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; | 1144 div_editable.state |= 1 << ui::AX_STATE_FOCUSED; |
1161 manager->SetFocus(div_editable_accessible, false /* notify */); | 1145 manager->SetFocus(div_editable_accessible, false /* notify */); |
1162 ASSERT_EQ(div_editable_accessible, | 1146 ASSERT_EQ(div_editable_accessible, |
1163 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); | 1147 manager->GetFocus(root_accessible)->ToBrowserAccessibilityWin()); |
1164 | 1148 |
1165 // The caret should not have moved. | 1149 // The caret should not have moved. |
1166 hr = div_editable_accessible->get_caretOffset(&caret_offset);; | 1150 hr = div_editable_accessible->get_caretOffset(&caret_offset);; |
1167 EXPECT_EQ(S_OK, hr); | 1151 EXPECT_EQ(S_OK, hr); |
1168 EXPECT_EQ(7L, caret_offset); | 1152 EXPECT_EQ(1L, caret_offset); |
1169 | 1153 |
1170 // The caret offset should reflect the position of the selection's focus in | 1154 // The HRESULT should be S_FALSE if the caret is not in the given object. |
1171 // any given object. | |
1172 hr = link_accessible->get_caretOffset(&caret_offset);; | 1155 hr = link_accessible->get_caretOffset(&caret_offset);; |
1173 EXPECT_EQ(S_OK, hr); | 1156 EXPECT_EQ(S_FALSE, hr); |
1174 EXPECT_EQ(4L, caret_offset); | 1157 EXPECT_EQ(-1L, caret_offset); |
1175 hr = link_text_accessible->get_caretOffset(&caret_offset);; | 1158 hr = link_text_accessible->get_caretOffset(&caret_offset);; |
1176 EXPECT_EQ(S_OK, hr); | 1159 EXPECT_EQ(S_FALSE, hr); |
1177 EXPECT_EQ(4L, caret_offset); | 1160 EXPECT_EQ(-1L, caret_offset); |
1178 | 1161 |
1179 hr = div_editable_accessible->get_selection( | 1162 hr = div_editable_accessible->get_selection( |
1180 0L /* selection_index */, &selection_start, &selection_end);; | 1163 0L /* selection_index */, &selection_start, &selection_end);; |
1181 EXPECT_EQ(S_OK, hr); | 1164 EXPECT_EQ(S_OK, hr); |
1182 EXPECT_EQ(1L, selection_start); | 1165 EXPECT_EQ(1L, selection_start); |
1183 EXPECT_EQ(7L, selection_end); | 1166 EXPECT_EQ(7L, selection_end); |
1184 | 1167 |
1185 manager.reset(); | 1168 manager.reset(); |
1186 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 1169 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
1187 } | 1170 } |
1188 | 1171 |
1189 } // namespace content | 1172 } // namespace content |
OLD | NEW |