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

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

Issue 1598583002: Fixed algorithms that compute bounding rectangles and word start offsets to take into account IA2 h… (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 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 <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/macros.h" 10 #include "base/macros.h"
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
56 56
57 protected: 57 protected:
58 class AccessibleChecker; 58 class AccessibleChecker;
59 void LoadInitialAccessibilityTreeFromHtml(const std::string& html); 59 void LoadInitialAccessibilityTreeFromHtml(const std::string& html);
60 IAccessible* GetRendererAccessible(); 60 IAccessible* GetRendererAccessible();
61 void ExecuteScript(const std::wstring& script); 61 void ExecuteScript(const std::wstring& script);
62 void SetUpInputField( 62 void SetUpInputField(
63 base::win::ScopedComPtr<IAccessibleText>* input_text); 63 base::win::ScopedComPtr<IAccessibleText>* input_text);
64 void SetUpTextareaField( 64 void SetUpTextareaField(
65 base::win::ScopedComPtr<IAccessibleText>* textarea_text); 65 base::win::ScopedComPtr<IAccessibleText>* textarea_text);
66 void SetUpSampleParagraph(
67 base::win::ScopedComPtr<IAccessibleText>* paragraph_text);
66 68
67 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant( 69 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant(
68 IAccessible* parent, 70 IAccessible* parent,
69 VARIANT* var); 71 VARIANT* var);
70 static HRESULT QueryIAccessible2(IAccessible* accessible, 72 static HRESULT QueryIAccessible2(IAccessible* accessible,
71 IAccessible2** accessible2); 73 IAccessible2** accessible2);
72 static void FindNodeInAccessibilityTree(IAccessible* node, 74 static void FindNodeInAccessibilityTree(IAccessible* node,
73 int32_t expected_role, 75 int32_t expected_role,
74 const std::wstring& expected_name, 76 const std::wstring& expected_name,
75 int32_t depth, 77 int32_t depth,
76 bool* found); 78 bool* found);
77 static void CheckTextAtOffset( 79 static void CheckTextAtOffset(
78 base::win::ScopedComPtr<IAccessibleText>& element, 80 base::win::ScopedComPtr<IAccessibleText>& object,
79 LONG offset, 81 LONG offset,
80 IA2TextBoundaryType boundary_type, 82 IA2TextBoundaryType boundary_type,
81 LONG expected_start_offset, 83 LONG expected_start_offset,
82 LONG expected_end_offset, 84 LONG expected_end_offset,
83 const std::wstring& expected_text); 85 const std::wstring& expected_text);
84 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren( 86 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren(
85 IAccessible* element); 87 IAccessible* element);
86 88
87 private: 89 private:
88 DISALLOW_COPY_AND_ASSIGN(AccessibilityWinBrowserTest); 90 DISALLOW_COPY_AND_ASSIGN(AccessibilityWinBrowserTest);
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after
126 net::EscapeQueryParamValue(INPUT_CONTENTS, false) + std::string( 128 net::EscapeQueryParamValue(INPUT_CONTENTS, false) + std::string(
127 "'></form></body></html>")); 129 "'></form></body></html>"));
128 130
129 // Retrieve the IAccessible interface for the web page. 131 // Retrieve the IAccessible interface for the web page.
130 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); 132 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
131 std::vector<base::win::ScopedVariant> document_children = 133 std::vector<base::win::ScopedVariant> document_children =
132 GetAllAccessibleChildren(document.get()); 134 GetAllAccessibleChildren(document.get());
133 ASSERT_EQ(1u, document_children.size()); 135 ASSERT_EQ(1u, document_children.size());
134 136
135 base::win::ScopedComPtr<IAccessible2> form; 137 base::win::ScopedComPtr<IAccessible2> form;
136 HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( 138 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
137 document.get(), document_children[0].AsInput()).get(), form.Receive()); 139 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
138 ASSERT_EQ(S_OK, hr); 140 .get(),
141 form.Receive()));
139 std::vector<base::win::ScopedVariant> form_children = 142 std::vector<base::win::ScopedVariant> form_children =
140 GetAllAccessibleChildren(form.get()); 143 GetAllAccessibleChildren(form.get());
141 ASSERT_EQ(2u, form_children.size()); 144 ASSERT_EQ(2u, form_children.size());
142 145
143 // Find the input text field. 146 // Find the input text field.
144 base::win::ScopedComPtr<IAccessible2> input; 147 base::win::ScopedComPtr<IAccessible2> input;
145 hr = QueryIAccessible2(GetAccessibleFromVariant( 148 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
146 form.get(), form_children[1].AsInput()).get(), input.Receive()); 149 GetAccessibleFromVariant(form.get(), form_children[1].AsInput()).get(),
147 ASSERT_EQ(S_OK, hr); 150 input.Receive()));
148 LONG input_role = 0; 151 LONG input_role = 0;
149 hr = input->role(&input_role); 152 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role));
150 ASSERT_EQ(S_OK, hr);
151 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role); 153 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role);
152 154
153 // Retrieve the IAccessibleText interface for the field. 155 // Retrieve the IAccessibleText interface for the field.
154 hr = input.QueryInterface(input_text->Receive()); 156 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive()));
155 ASSERT_EQ(S_OK, hr);
156 157
157 // Set the caret on the last character. 158 // Set the caret on the last character.
158 AccessibilityNotificationWaiter waiter( 159 AccessibilityNotificationWaiter waiter(
159 shell(), AccessibilityModeComplete, 160 shell(), AccessibilityModeComplete,
160 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 161 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
161 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 162 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
162 static_cast<int>(CONTENTS_LENGTH - 1))); 163 static_cast<int>(CONTENTS_LENGTH - 1)));
163 ExecuteScript(std::wstring( 164 ExecuteScript(std::wstring(
164 L"var textField = document.getElementById('textField');" 165 L"var textField = document.getElementById('textField');"
165 L"textField.focus();" 166 L"textField.focus();"
(...skipping 12 matching lines...) Expand all
178 net::EscapeQueryParamValue(TEXTAREA_CONTENTS, false) + std::string( 179 net::EscapeQueryParamValue(TEXTAREA_CONTENTS, false) + std::string(
179 "</textarea></body></html>")); 180 "</textarea></body></html>"));
180 181
181 // Retrieve the IAccessible interface for the web page. 182 // Retrieve the IAccessible interface for the web page.
182 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); 183 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
183 std::vector<base::win::ScopedVariant> document_children = 184 std::vector<base::win::ScopedVariant> document_children =
184 GetAllAccessibleChildren(document.get()); 185 GetAllAccessibleChildren(document.get());
185 ASSERT_EQ(1u, document_children.size()); 186 ASSERT_EQ(1u, document_children.size());
186 187
187 base::win::ScopedComPtr<IAccessible2> section; 188 base::win::ScopedComPtr<IAccessible2> section;
188 HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( 189 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
189 document.get(), document_children[0].AsInput()).get(), section.Receive()); 190 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
190 ASSERT_EQ(S_OK, hr); 191 .get(),
192 section.Receive()));
191 std::vector<base::win::ScopedVariant> section_children = 193 std::vector<base::win::ScopedVariant> section_children =
192 GetAllAccessibleChildren(section.get()); 194 GetAllAccessibleChildren(section.get());
193 ASSERT_EQ(1u, section_children.size()); 195 ASSERT_EQ(1u, section_children.size());
194 196
195 // Find the textarea text field. 197 // Find the textarea text field.
196 base::win::ScopedComPtr<IAccessible2> textarea; 198 base::win::ScopedComPtr<IAccessible2> textarea;
197 hr = QueryIAccessible2(GetAccessibleFromVariant( 199 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
198 section.get(), section_children[0].AsInput()).get(), textarea.Receive()); 200 GetAccessibleFromVariant(section.get(), section_children[0].AsInput())
199 ASSERT_EQ(S_OK, hr); 201 .get(),
202 textarea.Receive()));
200 LONG textarea_role = 0; 203 LONG textarea_role = 0;
201 hr = textarea->role(&textarea_role); 204 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role));
202 ASSERT_EQ(S_OK, hr);
203 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role); 205 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role);
204 206
205 // Retrieve the IAccessibleText interface for the field. 207 // Retrieve the IAccessibleText interface for the field.
206 hr = textarea.QueryInterface(textarea_text->Receive()); 208 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive()));
207 ASSERT_EQ(S_OK, hr);
208 209
209 // Set the caret on the last character. 210 // Set the caret on the last character.
210 AccessibilityNotificationWaiter waiter( 211 AccessibilityNotificationWaiter waiter(
211 shell(), AccessibilityModeComplete, 212 shell(), AccessibilityModeComplete,
212 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 213 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
213 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 214 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
214 static_cast<int>(CONTENTS_LENGTH - 1))); 215 static_cast<int>(CONTENTS_LENGTH - 1)));
215 ExecuteScript(std::wstring( 216 ExecuteScript(std::wstring(
216 L"var textField = document.getElementById('textField');" 217 L"var textField = document.getElementById('textField');"
217 L"textField.focus();" 218 L"textField.focus();"
218 L"textField.setSelectionRange(") + 219 L"textField.setSelectionRange(") +
219 caret_offset + L"," + caret_offset + L");"); 220 caret_offset + L"," + caret_offset + L");");
220 waiter.WaitForNotification(); 221 waiter.WaitForNotification();
221 } 222 }
222 223
224 // Loads a page with a paragraph of sample text.
225 // (This is an actual test case provided by Freedom Scientific as part of a bug
226 // report.)
227 void AccessibilityWinBrowserTest::SetUpSampleParagraph(
228 base::win::ScopedComPtr<IAccessibleText>* paragraph_text) {
229 ASSERT_NE(nullptr, paragraph_text);
230 LoadInitialAccessibilityTreeFromHtml(std::string(
231 "<!DOCTYPE html><html><body>"
232 "<p><b>Game theory</b> is \"the study of "
233 "<a href=\"#\" title=\"Mathematical model\">mathematical models</a> "
234 "of conflict and<br>cooperation between intelligent rational "
235 "decision-makers.\"</p></body></html>"));
236
237 // Retrieve the IAccessible interface for the web page.
238 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
239 std::vector<base::win::ScopedVariant> document_children =
240 GetAllAccessibleChildren(document.get());
241 ASSERT_EQ(1u, document_children.size());
242
243 base::win::ScopedComPtr<IAccessible2> paragraph;
244 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
245 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
246 .get(),
247 paragraph.Receive()));
248 LONG paragraph_role = 0;
249 ASSERT_HRESULT_SUCCEEDED(paragraph->role(&paragraph_role));
250 ASSERT_EQ(IA2_ROLE_PARAGRAPH, paragraph_role);
251 ASSERT_HRESULT_SUCCEEDED(paragraph.QueryInterface(paragraph_text->Receive()));
252 }
223 253
224 // Static helpers ------------------------------------------------ 254 // Static helpers ------------------------------------------------
225 255
226 base::win::ScopedComPtr<IAccessible> 256 base::win::ScopedComPtr<IAccessible>
227 AccessibilityWinBrowserTest::GetAccessibleFromVariant( 257 AccessibilityWinBrowserTest::GetAccessibleFromVariant(
228 IAccessible* parent, 258 IAccessible* parent,
229 VARIANT* var) { 259 VARIANT* var) {
230 base::win::ScopedComPtr<IAccessible> ptr; 260 base::win::ScopedComPtr<IAccessible> ptr;
231 switch (V_VT(var)) { 261 switch (V_VT(var)) {
232 case VT_DISPATCH: { 262 case VT_DISPATCH: {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 found); 330 found);
301 if (*found) 331 if (*found)
302 return; 332 return;
303 } 333 }
304 } 334 }
305 } 335 }
306 336
307 // Ensures that the text and the start and end offsets retrieved using 337 // Ensures that the text and the start and end offsets retrieved using
308 // get_textAtOffset match the expected values. 338 // get_textAtOffset match the expected values.
309 void AccessibilityWinBrowserTest::CheckTextAtOffset( 339 void AccessibilityWinBrowserTest::CheckTextAtOffset(
310 base::win::ScopedComPtr<IAccessibleText>& element, 340 base::win::ScopedComPtr<IAccessibleText>& object,
311 LONG offset, 341 LONG offset,
312 IA2TextBoundaryType boundary_type, 342 IA2TextBoundaryType boundary_type,
313 LONG expected_start_offset, 343 LONG expected_start_offset,
314 LONG expected_end_offset, 344 LONG expected_end_offset,
315 const std::wstring& expected_text) { 345 const std::wstring& expected_text) {
316 testing::Message message; 346 testing::Message message;
317 message << "While checking for \'" << expected_text << "\' at " << 347 message << "While checking for \'" << expected_text << "\' at " <<
318 expected_start_offset << '-' << expected_end_offset << '.'; 348 expected_start_offset << '-' << expected_end_offset << '.';
319 SCOPED_TRACE(message); 349 SCOPED_TRACE(message);
320 350
321 LONG start_offset = 0; 351 LONG start_offset = 0;
322 LONG end_offset = 0; 352 LONG end_offset = 0;
323 base::win::ScopedBstr text; 353 base::win::ScopedBstr text;
324 HRESULT hr = element->get_textAtOffset( 354 HRESULT hr = object->get_textAtOffset(offset, boundary_type, &start_offset,
325 offset, boundary_type, 355 &end_offset, text.Receive());
326 &start_offset, &end_offset, text.Receive());
327 EXPECT_EQ(S_OK, hr); 356 EXPECT_EQ(S_OK, hr);
328 EXPECT_EQ(expected_start_offset, start_offset); 357 EXPECT_EQ(expected_start_offset, start_offset);
329 EXPECT_EQ(expected_end_offset, end_offset); 358 EXPECT_EQ(expected_end_offset, end_offset);
330 EXPECT_EQ(expected_text, std::wstring(text, text.Length())); 359 EXPECT_EQ(expected_text, std::wstring(text, text.Length()));
331 } 360 }
332 361
333 std::vector<base::win::ScopedVariant> 362 std::vector<base::win::ScopedVariant>
334 AccessibilityWinBrowserTest::GetAllAccessibleChildren( 363 AccessibilityWinBrowserTest::GetAllAccessibleChildren(
335 IAccessible* element) { 364 IAccessible* element) {
336 LONG child_count = 0; 365 LONG child_count = 0;
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after
947 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING, 976 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
948 std::wstring()); 977 std::wstring());
949 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 978 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
950 std::wstring()); 979 std::wstring());
951 document_checker.AppendExpectedChild(&grouping1_checker); 980 document_checker.AppendExpectedChild(&grouping1_checker);
952 document_checker.AppendExpectedChild(&grouping2_checker); 981 document_checker.AppendExpectedChild(&grouping2_checker);
953 document_checker.CheckAccessible(GetRendererAccessible()); 982 document_checker.CheckAccessible(GetRendererAccessible());
954 } 983 }
955 984
956 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 985 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
957 TestSetCaretOffset) { 986 TestCharacterExtentsWithInvalidArguments) {
987 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
988 SetUpSampleParagraph(&paragraph_text);
989
990 LONG invalid_offset = -3;
991 LONG x = -1, y = -1;
992 LONG width = -1, height = -1;
993
994 HRESULT hr = paragraph_text->get_characterExtents(
995 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height);
996 EXPECT_EQ(E_INVALIDARG, hr);
997 EXPECT_EQ(-1, x);
998 EXPECT_EQ(-1, y);
999 EXPECT_EQ(-1, width);
1000 EXPECT_EQ(-1, height);
1001 hr = paragraph_text->get_characterExtents(
1002 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height);
1003 EXPECT_EQ(E_INVALIDARG, hr);
1004 EXPECT_EQ(-1, x);
1005 EXPECT_EQ(-1, y);
1006 EXPECT_EQ(-1, width);
1007 EXPECT_EQ(-1, height);
1008
1009 LONG n_characters;
1010 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters));
1011 ASSERT_LT(0, n_characters);
1012
1013 invalid_offset = n_characters + 1;
1014 hr = paragraph_text->get_characterExtents(
1015 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height);
1016 EXPECT_EQ(E_INVALIDARG, hr);
1017 EXPECT_EQ(-1, x);
1018 EXPECT_EQ(-1, y);
1019 EXPECT_EQ(-1, width);
1020 EXPECT_EQ(-1, height);
1021 hr = paragraph_text->get_characterExtents(
1022 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height);
1023 EXPECT_EQ(E_INVALIDARG, hr);
1024 EXPECT_EQ(-1, x);
1025 EXPECT_EQ(-1, y);
1026 EXPECT_EQ(-1, width);
1027 EXPECT_EQ(-1, height);
1028 }
1029
1030 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestCharacterExtents) {
1031 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
1032 SetUpSampleParagraph(&paragraph_text);
1033
1034 const LONG newline_offset = 46;
1035 LONG n_characters;
1036 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters));
1037 ASSERT_LT(0, n_characters);
1038
1039 IA2CoordinateType coordinate_type = IA2_COORDTYPE_SCREEN_RELATIVE;
1040 LONG x, y, width, height;
1041 LONG previous_x, previous_y;
1042
1043 for (int test_case = 0; test_case < 1; ++test_case) {
dmazzoni 2016/01/20 01:10:43 Delete this loop since there's only 1 test case no
1044 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1045 0, coordinate_type, &x, &y, &width, &height));
1046 EXPECT_LT(0, x) << "at offset 0";
1047 EXPECT_LT(0, y) << "at offset 0";
1048 EXPECT_LT(0, width) << "at offset 0";
1049 EXPECT_LT(0, height) << "at offset 0";
1050
1051 for (LONG offset = 1; offset < newline_offset; ++offset) {
1052 previous_x = x;
1053 previous_y = y;
1054
1055 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1056 offset, coordinate_type, &x, &y, &width, &height));
1057 EXPECT_LT(previous_x, x) << "at offset " << offset;
1058 EXPECT_EQ(previous_y, y) << "at offset " << offset;
1059 EXPECT_LT(0, width) << "at offset " << offset;
1060 EXPECT_LT(0, height) << "at offset " << offset;
1061 }
1062
1063 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1064 newline_offset + 1, coordinate_type, &x, &y, &width, &height));
1065 EXPECT_LT(0, x) << "at offset 0";
dmazzoni 2016/01/20 01:10:43 Do you also want to assert that this is actually o
1066 EXPECT_LT(0, y) << "at offset 0";
1067 EXPECT_LT(0, width) << "at offset 0";
1068 EXPECT_LT(0, height) << "at offset 0";
1069
1070 for (LONG offset = newline_offset + 2; offset < n_characters; ++offset) {
1071 previous_x = x;
1072 previous_y = y;
1073
1074 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1075 offset, coordinate_type, &x, &y, &width, &height));
1076 EXPECT_LT(previous_x, x) << "at offset " << offset;
1077 EXPECT_EQ(previous_y, y) << "at offset " << offset;
1078 EXPECT_LT(0, width) << "at offset " << offset;
1079 EXPECT_LT(0, height) << "at offset " << offset;
1080 }
1081
1082 coordinate_type = IA2_COORDTYPE_PARENT_RELATIVE;
1083 }
1084 }
1085
1086 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) {
958 base::win::ScopedComPtr<IAccessibleText> input_text; 1087 base::win::ScopedComPtr<IAccessibleText> input_text;
959 SetUpInputField(&input_text); 1088 SetUpInputField(&input_text);
960 1089
961 LONG caret_offset = 0; 1090 LONG caret_offset = 0;
962 HRESULT hr = input_text->get_caretOffset(&caret_offset); 1091 HRESULT hr = input_text->get_caretOffset(&caret_offset);
963 EXPECT_EQ(S_OK, hr); 1092 EXPECT_EQ(S_OK, hr);
964 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1093 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
965 1094
966 AccessibilityNotificationWaiter waiter( 1095 AccessibilityNotificationWaiter waiter(
967 shell(), AccessibilityModeComplete, 1096 shell(), AccessibilityModeComplete,
(...skipping 25 matching lines...) Expand all
993 hr = textarea_text->setCaretOffset(caret_offset); 1122 hr = textarea_text->setCaretOffset(caret_offset);
994 EXPECT_EQ(S_OK, hr); 1123 EXPECT_EQ(S_OK, hr);
995 waiter.WaitForNotification(); 1124 waiter.WaitForNotification();
996 1125
997 hr = textarea_text->get_caretOffset(&caret_offset); 1126 hr = textarea_text->get_caretOffset(&caret_offset);
998 EXPECT_EQ(S_OK, hr); 1127 EXPECT_EQ(S_OK, hr);
999 EXPECT_EQ(0, caret_offset); 1128 EXPECT_EQ(0, caret_offset);
1000 } 1129 }
1001 1130
1002 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1131 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1003 TestTextAtOffsetWithInvalidArgs) { 1132 TestTextAtOffsetWithInvalidArguments) {
1004 base::win::ScopedComPtr<IAccessibleText> input_text; 1133 base::win::ScopedComPtr<IAccessibleText> input_text;
1005 SetUpInputField(&input_text); 1134 SetUpInputField(&input_text);
1006 HRESULT hr = input_text->get_textAtOffset( 1135 HRESULT hr = input_text->get_textAtOffset(
1007 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); 1136 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL);
1008 EXPECT_EQ(E_INVALIDARG, hr); 1137 EXPECT_EQ(E_INVALIDARG, hr);
1009 1138
1010 // Test invalid offset. 1139 // Test invalid offset.
1011 LONG start_offset = 0; 1140 LONG start_offset = 0;
1012 LONG end_offset = 0; 1141 LONG end_offset = 0;
1013 base::win::ScopedBstr text; 1142 base::win::ScopedBstr text;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 hr = input_text->get_textAtOffset( 1215 hr = input_text->get_textAtOffset(
1087 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL, 1216 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL,
1088 &start_offset, &end_offset, text.Receive()); 1217 &start_offset, &end_offset, text.Receive());
1089 EXPECT_EQ(S_FALSE, hr); 1218 EXPECT_EQ(S_FALSE, hr);
1090 EXPECT_EQ(0, start_offset); 1219 EXPECT_EQ(0, start_offset);
1091 EXPECT_EQ(0, end_offset); 1220 EXPECT_EQ(0, end_offset);
1092 EXPECT_EQ(nullptr, static_cast<BSTR>(text)); 1221 EXPECT_EQ(nullptr, static_cast<BSTR>(text));
1093 } 1222 }
1094 1223
1095 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1224 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1096 TestMultiLineTextAtOffsetWithInvalidArgs) { 1225 TestMultiLineTextAtOffsetWithInvalidArguments) {
1097 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1226 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1098 SetUpTextareaField(&textarea_text); 1227 SetUpTextareaField(&textarea_text);
1099 HRESULT hr = textarea_text->get_textAtOffset( 1228 HRESULT hr = textarea_text->get_textAtOffset(
1100 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); 1229 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL);
1101 EXPECT_EQ(E_INVALIDARG, hr); 1230 EXPECT_EQ(E_INVALIDARG, hr);
1102 1231
1103 // Test invalid offset. 1232 // Test invalid offset.
1104 LONG start_offset = 0; 1233 LONG start_offset = 0;
1105 LONG end_offset = 0; 1234 LONG end_offset = 0;
1106 base::win::ScopedBstr text; 1235 base::win::ScopedBstr text;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 40, CONTENTS_LENGTH, L"like\"."); 1500 40, CONTENTS_LENGTH, L"like\".");
1372 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD, 1501 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD,
1373 40, CONTENTS_LENGTH, L"like\"."); 1502 40, CONTENTS_LENGTH, L"like\".");
1374 1503
1375 // Test special offsets. 1504 // Test special offsets.
1376 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET, 1505 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET,
1377 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\"."); 1506 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\".");
1378 } 1507 }
1379 1508
1380 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1509 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1510 TestStaticTextAtOffsetWithBoundaryWord) {
1511 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
1512 SetUpSampleParagraph(&paragraph_text);
1513 const std::vector<std::wstring> words{
1514 L"Game ", L"theory ", L"is \"", L"the ",
1515 L"study ", L"of \xfffc ", L"of ", L"conflict ",
1516 L"and\n", L"cooperation ", L"between ", L"intelligent ",
1517 L"rational ", L"decision-makers.\""};
1518
1519 // Try to retrieve one word after another.
1520 // (This is an actual test case provided by Freedom Scientific as part of a
1521 // bug report.)
1522 LONG word_start_offset = 0;
1523 for (auto& word : words) {
1524 LONG word_end_offset = word_start_offset + word.size();
1525 CheckTextAtOffset(paragraph_text, word_start_offset, IA2_TEXT_BOUNDARY_WORD,
1526 word_start_offset, word_end_offset, word);
1527 word_start_offset = word_end_offset;
1528 }
1529 }
1530
1531 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1381 TestTextAtOffsetWithBoundarySentence) { 1532 TestTextAtOffsetWithBoundarySentence) {
1382 base::win::ScopedComPtr<IAccessibleText> input_text; 1533 base::win::ScopedComPtr<IAccessibleText> input_text;
1383 SetUpInputField(&input_text); 1534 SetUpInputField(&input_text);
1384 1535
1385 // Sentence navigation is not currently implemented. 1536 // Sentence navigation is not currently implemented.
1386 LONG start_offset = 0; 1537 LONG start_offset = 0;
1387 LONG end_offset = 0; 1538 LONG end_offset = 0;
1388 base::win::ScopedBstr text; 1539 base::win::ScopedBstr text;
1389 HRESULT hr = input_text->get_textAtOffset( 1540 HRESULT hr = input_text->get_textAtOffset(
1390 5, IA2_TEXT_BOUNDARY_SENTENCE, 1541 5, IA2_TEXT_BOUNDARY_SENTENCE,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1613 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1463 TestMultiLineTextAtOffsetWithBoundaryAll) { 1614 TestMultiLineTextAtOffsetWithBoundaryAll) {
1464 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1615 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1465 SetUpTextareaField(&textarea_text); 1616 SetUpTextareaField(&textarea_text);
1466 1617
1467 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, 1618 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL,
1468 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); 1619 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS));
1469 } 1620 }
1470 1621
1471 } // namespace content 1622 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698