Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(540)

Side by Side Diff: content/browser/accessibility/browser_accessibility_win_unittest.cc

Issue 1377733002: Fixes for contenteditable caret and selection handling in Windows. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixed some more corner cases, updated tests to make them more resilient and added comments to the c… Created 5 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 963 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
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(1L, 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 anchor 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(0L, 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(0L, 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
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698