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 <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 Loading... | |
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 Loading... | |
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 Loading... | |
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 void AccessibilityWinBrowserTest::SetUpSampleParagraph( | |
226 base::win::ScopedComPtr<IAccessibleText>* paragraph_text) { | |
227 ASSERT_NE(nullptr, paragraph_text); | |
228 LoadInitialAccessibilityTreeFromHtml(std::string( | |
229 "<!DOCTYPE html><html><body>" | |
230 "<p><b>Game theory</b> is \"the study of " | |
231 "<a href=\"#\" title=\"Mathematical model\">mathematical models</a> " | |
232 "of conflict and<br>cooperation between intelligent rational " | |
233 "decision-makers.\"</p></body></html>")); | |
234 | |
235 // Retrieve the IAccessible interface for the web page. | |
236 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); | |
237 std::vector<base::win::ScopedVariant> document_children = | |
238 GetAllAccessibleChildren(document.get()); | |
239 ASSERT_EQ(1u, document_children.size()); | |
240 | |
241 base::win::ScopedComPtr<IAccessible2> paragraph; | |
242 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2( | |
243 GetAccessibleFromVariant(document.get(), document_children[0].AsInput()) | |
244 .get(), | |
245 paragraph.Receive())); | |
246 LONG paragraph_role = 0; | |
247 ASSERT_HRESULT_SUCCEEDED(paragraph->role(¶graph_role)); | |
248 ASSERT_EQ(IA2_ROLE_PARAGRAPH, paragraph_role); | |
249 ASSERT_HRESULT_SUCCEEDED(paragraph.QueryInterface(paragraph_text->Receive())); | |
250 } | |
223 | 251 |
224 // Static helpers ------------------------------------------------ | 252 // Static helpers ------------------------------------------------ |
225 | 253 |
226 base::win::ScopedComPtr<IAccessible> | 254 base::win::ScopedComPtr<IAccessible> |
227 AccessibilityWinBrowserTest::GetAccessibleFromVariant( | 255 AccessibilityWinBrowserTest::GetAccessibleFromVariant( |
228 IAccessible* parent, | 256 IAccessible* parent, |
229 VARIANT* var) { | 257 VARIANT* var) { |
230 base::win::ScopedComPtr<IAccessible> ptr; | 258 base::win::ScopedComPtr<IAccessible> ptr; |
231 switch (V_VT(var)) { | 259 switch (V_VT(var)) { |
232 case VT_DISPATCH: { | 260 case VT_DISPATCH: { |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
300 found); | 328 found); |
301 if (*found) | 329 if (*found) |
302 return; | 330 return; |
303 } | 331 } |
304 } | 332 } |
305 } | 333 } |
306 | 334 |
307 // Ensures that the text and the start and end offsets retrieved using | 335 // Ensures that the text and the start and end offsets retrieved using |
308 // get_textAtOffset match the expected values. | 336 // get_textAtOffset match the expected values. |
309 void AccessibilityWinBrowserTest::CheckTextAtOffset( | 337 void AccessibilityWinBrowserTest::CheckTextAtOffset( |
310 base::win::ScopedComPtr<IAccessibleText>& element, | 338 base::win::ScopedComPtr<IAccessibleText>& object, |
311 LONG offset, | 339 LONG offset, |
312 IA2TextBoundaryType boundary_type, | 340 IA2TextBoundaryType boundary_type, |
313 LONG expected_start_offset, | 341 LONG expected_start_offset, |
314 LONG expected_end_offset, | 342 LONG expected_end_offset, |
315 const std::wstring& expected_text) { | 343 const std::wstring& expected_text) { |
316 testing::Message message; | 344 testing::Message message; |
317 message << "While checking for \'" << expected_text << "\' at " << | 345 message << "While checking for \'" << expected_text << "\' at " << |
318 expected_start_offset << '-' << expected_end_offset << '.'; | 346 expected_start_offset << '-' << expected_end_offset << '.'; |
319 SCOPED_TRACE(message); | 347 SCOPED_TRACE(message); |
320 | 348 |
321 LONG start_offset = 0; | 349 LONG start_offset = 0; |
322 LONG end_offset = 0; | 350 LONG end_offset = 0; |
323 base::win::ScopedBstr text; | 351 base::win::ScopedBstr text; |
324 HRESULT hr = element->get_textAtOffset( | 352 HRESULT hr = object->get_textAtOffset(offset, boundary_type, &start_offset, |
325 offset, boundary_type, | 353 &end_offset, text.Receive()); |
326 &start_offset, &end_offset, text.Receive()); | |
327 EXPECT_EQ(S_OK, hr); | 354 EXPECT_EQ(S_OK, hr); |
328 EXPECT_EQ(expected_start_offset, start_offset); | 355 EXPECT_EQ(expected_start_offset, start_offset); |
329 EXPECT_EQ(expected_end_offset, end_offset); | 356 EXPECT_EQ(expected_end_offset, end_offset); |
330 EXPECT_EQ(expected_text, std::wstring(text, text.Length())); | 357 EXPECT_EQ(expected_text, std::wstring(text, text.Length())); |
331 } | 358 } |
332 | 359 |
333 std::vector<base::win::ScopedVariant> | 360 std::vector<base::win::ScopedVariant> |
334 AccessibilityWinBrowserTest::GetAllAccessibleChildren( | 361 AccessibilityWinBrowserTest::GetAllAccessibleChildren( |
335 IAccessible* element) { | 362 IAccessible* element) { |
336 LONG child_count = 0; | 363 LONG child_count = 0; |
(...skipping 610 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
947 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING, | 974 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
948 std::wstring()); | 975 std::wstring()); |
949 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, | 976 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
950 std::wstring()); | 977 std::wstring()); |
951 document_checker.AppendExpectedChild(&grouping1_checker); | 978 document_checker.AppendExpectedChild(&grouping1_checker); |
952 document_checker.AppendExpectedChild(&grouping2_checker); | 979 document_checker.AppendExpectedChild(&grouping2_checker); |
953 document_checker.CheckAccessible(GetRendererAccessible()); | 980 document_checker.CheckAccessible(GetRendererAccessible()); |
954 } | 981 } |
955 | 982 |
956 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 983 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
957 TestSetCaretOffset) { | 984 TestCharacterExtentsWithInvalidArguments) { |
985 base::win::ScopedComPtr<IAccessibleText> paragraph_text; | |
986 SetUpSampleParagraph(¶graph_text); | |
987 | |
988 LONG invalid_offset = -3; | |
989 LONG x = -1, y = -1; | |
990 LONG width = -1, height = -1; | |
991 | |
992 HRESULT hr = paragraph_text->get_characterExtents( | |
993 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height); | |
994 EXPECT_EQ(E_INVALIDARG, hr); | |
995 EXPECT_EQ(-1, x); | |
996 EXPECT_EQ(-1, y); | |
997 EXPECT_EQ(-1, width); | |
998 EXPECT_EQ(-1, height); | |
999 hr = paragraph_text->get_characterExtents( | |
1000 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height); | |
1001 EXPECT_EQ(E_INVALIDARG, hr); | |
1002 EXPECT_EQ(-1, x); | |
1003 EXPECT_EQ(-1, y); | |
1004 EXPECT_EQ(-1, width); | |
1005 EXPECT_EQ(-1, height); | |
1006 | |
1007 LONG n_characters; | |
1008 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters)); | |
1009 ASSERT_LT(0, n_characters); | |
1010 | |
1011 invalid_offset = n_characters + 1; | |
1012 hr = paragraph_text->get_characterExtents( | |
1013 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height); | |
1014 EXPECT_EQ(E_INVALIDARG, hr); | |
1015 EXPECT_EQ(-1, x); | |
1016 EXPECT_EQ(-1, y); | |
1017 EXPECT_EQ(-1, width); | |
1018 EXPECT_EQ(-1, height); | |
1019 hr = paragraph_text->get_characterExtents( | |
1020 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height); | |
1021 EXPECT_EQ(E_INVALIDARG, hr); | |
1022 EXPECT_EQ(-1, x); | |
1023 EXPECT_EQ(-1, y); | |
1024 EXPECT_EQ(-1, width); | |
1025 EXPECT_EQ(-1, height); | |
1026 } | |
1027 | |
1028 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestCharacterExtents) { | |
1029 base::win::ScopedComPtr<IAccessibleText> paragraph_text; | |
1030 SetUpSampleParagraph(¶graph_text); | |
1031 | |
1032 const LONG newline_offset = 46; | |
1033 LONG n_characters; | |
1034 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters)); | |
1035 ASSERT_LT(0, n_characters); | |
1036 | |
1037 LONG x, y, width, height; | |
1038 LONG previous_x, previous_y; | |
1039 | |
1040 for (int i = IA2_COORDTYPE_SCREEN_RELATIVE; i < IA2_COORDTYPE_PARENT_RELATIVE; | |
dmazzoni
2016/01/20 19:44:41
This still isn't correct, if you want to test both
| |
1041 ++i) { | |
1042 auto coordinate_type = static_cast<IA2CoordinateType>(i); | |
1043 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( | |
1044 0, coordinate_type, &x, &y, &width, &height)); | |
1045 EXPECT_LE(0, x) << "at offset 0"; | |
1046 EXPECT_LE(0, y) << "at offset 0"; | |
1047 EXPECT_LT(0, width) << "at offset 0"; | |
1048 EXPECT_LT(0, height) << "at offset 0"; | |
1049 | |
1050 for (LONG offset = 1; offset < newline_offset; ++offset) { | |
1051 previous_x = x; | |
1052 previous_y = y; | |
1053 | |
1054 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( | |
1055 offset, coordinate_type, &x, &y, &width, &height)); | |
1056 EXPECT_LT(previous_x, x) << "at offset " << offset; | |
1057 EXPECT_EQ(previous_y, y) << "at offset " << offset; | |
1058 EXPECT_LT(0, width) << "at offset " << offset; | |
1059 EXPECT_LT(0, height) << "at offset " << offset; | |
1060 } | |
1061 | |
1062 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents( | |
1063 newline_offset + 1, coordinate_type, &x, &y, &width, &height)); | |
1064 EXPECT_LT(0, x) << "at offset " << newline_offset + 1; | |
1065 EXPECT_GT(previous_x, x) << "at offset " << newline_offset + 1; | |
1066 EXPECT_LT(previous_y, y) << "at offset " << newline_offset + 1; | |
1067 EXPECT_LT(0, width) << "at offset " << newline_offset + 1; | |
1068 EXPECT_LT(0, height) << "at offset " << newline_offset + 1; | |
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 } | |
1083 | |
1084 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) { | |
958 base::win::ScopedComPtr<IAccessibleText> input_text; | 1085 base::win::ScopedComPtr<IAccessibleText> input_text; |
959 SetUpInputField(&input_text); | 1086 SetUpInputField(&input_text); |
960 | 1087 |
961 LONG caret_offset = 0; | 1088 LONG caret_offset = 0; |
962 HRESULT hr = input_text->get_caretOffset(&caret_offset); | 1089 HRESULT hr = input_text->get_caretOffset(&caret_offset); |
963 EXPECT_EQ(S_OK, hr); | 1090 EXPECT_EQ(S_OK, hr); |
964 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); | 1091 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); |
965 | 1092 |
966 AccessibilityNotificationWaiter waiter( | 1093 AccessibilityNotificationWaiter waiter( |
967 shell(), AccessibilityModeComplete, | 1094 shell(), AccessibilityModeComplete, |
(...skipping 25 matching lines...) Expand all Loading... | |
993 hr = textarea_text->setCaretOffset(caret_offset); | 1120 hr = textarea_text->setCaretOffset(caret_offset); |
994 EXPECT_EQ(S_OK, hr); | 1121 EXPECT_EQ(S_OK, hr); |
995 waiter.WaitForNotification(); | 1122 waiter.WaitForNotification(); |
996 | 1123 |
997 hr = textarea_text->get_caretOffset(&caret_offset); | 1124 hr = textarea_text->get_caretOffset(&caret_offset); |
998 EXPECT_EQ(S_OK, hr); | 1125 EXPECT_EQ(S_OK, hr); |
999 EXPECT_EQ(0, caret_offset); | 1126 EXPECT_EQ(0, caret_offset); |
1000 } | 1127 } |
1001 | 1128 |
1002 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 1129 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
1003 TestTextAtOffsetWithInvalidArgs) { | 1130 TestTextAtOffsetWithInvalidArguments) { |
1004 base::win::ScopedComPtr<IAccessibleText> input_text; | 1131 base::win::ScopedComPtr<IAccessibleText> input_text; |
1005 SetUpInputField(&input_text); | 1132 SetUpInputField(&input_text); |
1006 HRESULT hr = input_text->get_textAtOffset( | 1133 HRESULT hr = input_text->get_textAtOffset( |
1007 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); | 1134 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); |
1008 EXPECT_EQ(E_INVALIDARG, hr); | 1135 EXPECT_EQ(E_INVALIDARG, hr); |
1009 | 1136 |
1010 // Test invalid offset. | 1137 // Test invalid offset. |
1011 LONG start_offset = 0; | 1138 LONG start_offset = 0; |
1012 LONG end_offset = 0; | 1139 LONG end_offset = 0; |
1013 base::win::ScopedBstr text; | 1140 base::win::ScopedBstr text; |
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1086 hr = input_text->get_textAtOffset( | 1213 hr = input_text->get_textAtOffset( |
1087 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL, | 1214 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL, |
1088 &start_offset, &end_offset, text.Receive()); | 1215 &start_offset, &end_offset, text.Receive()); |
1089 EXPECT_EQ(S_FALSE, hr); | 1216 EXPECT_EQ(S_FALSE, hr); |
1090 EXPECT_EQ(0, start_offset); | 1217 EXPECT_EQ(0, start_offset); |
1091 EXPECT_EQ(0, end_offset); | 1218 EXPECT_EQ(0, end_offset); |
1092 EXPECT_EQ(nullptr, static_cast<BSTR>(text)); | 1219 EXPECT_EQ(nullptr, static_cast<BSTR>(text)); |
1093 } | 1220 } |
1094 | 1221 |
1095 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 1222 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
1096 TestMultiLineTextAtOffsetWithInvalidArgs) { | 1223 TestMultiLineTextAtOffsetWithInvalidArguments) { |
1097 base::win::ScopedComPtr<IAccessibleText> textarea_text; | 1224 base::win::ScopedComPtr<IAccessibleText> textarea_text; |
1098 SetUpTextareaField(&textarea_text); | 1225 SetUpTextareaField(&textarea_text); |
1099 HRESULT hr = textarea_text->get_textAtOffset( | 1226 HRESULT hr = textarea_text->get_textAtOffset( |
1100 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); | 1227 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); |
1101 EXPECT_EQ(E_INVALIDARG, hr); | 1228 EXPECT_EQ(E_INVALIDARG, hr); |
1102 | 1229 |
1103 // Test invalid offset. | 1230 // Test invalid offset. |
1104 LONG start_offset = 0; | 1231 LONG start_offset = 0; |
1105 LONG end_offset = 0; | 1232 LONG end_offset = 0; |
1106 base::win::ScopedBstr text; | 1233 base::win::ScopedBstr text; |
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1371 40, CONTENTS_LENGTH, L"like\"."); | 1498 40, CONTENTS_LENGTH, L"like\"."); |
1372 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD, | 1499 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD, |
1373 40, CONTENTS_LENGTH, L"like\"."); | 1500 40, CONTENTS_LENGTH, L"like\"."); |
1374 | 1501 |
1375 // Test special offsets. | 1502 // Test special offsets. |
1376 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET, | 1503 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET, |
1377 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\"."); | 1504 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\"."); |
1378 } | 1505 } |
1379 | 1506 |
1380 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 1507 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
1508 TestStaticTextAtOffsetWithBoundaryWord) { | |
1509 base::win::ScopedComPtr<IAccessibleText> paragraph_text; | |
1510 SetUpSampleParagraph(¶graph_text); | |
1511 std::vector<std::wstring> words; | |
1512 words.push_back(L"Game "); | |
1513 words.push_back(L"theory "); | |
1514 words.push_back(L"is \""); | |
1515 words.push_back(L"the "); | |
1516 words.push_back(L"study "); | |
1517 words.push_back(L"of \xfffc "); | |
1518 words.push_back(L"of "); | |
1519 words.push_back(L"conflict "); | |
1520 words.push_back(L"and\n"); | |
1521 words.push_back(L"cooperation "); | |
1522 words.push_back(L"between "); | |
1523 words.push_back(L"intelligent "); | |
1524 words.push_back(L"rational "); | |
1525 words.push_back(L"decision-"); | |
1526 words.push_back(L"makers.\""); | |
1527 | |
1528 // Try to retrieve one word after another. | |
1529 LONG word_start_offset = 0; | |
1530 for (auto& word : words) { | |
1531 LONG word_end_offset = word_start_offset + word.size(); | |
1532 CheckTextAtOffset(paragraph_text, word_start_offset, IA2_TEXT_BOUNDARY_WORD, | |
1533 word_start_offset, word_end_offset, word); | |
1534 word_start_offset = word_end_offset; | |
1535 } | |
1536 } | |
1537 | |
1538 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | |
1381 TestTextAtOffsetWithBoundarySentence) { | 1539 TestTextAtOffsetWithBoundarySentence) { |
1382 base::win::ScopedComPtr<IAccessibleText> input_text; | 1540 base::win::ScopedComPtr<IAccessibleText> input_text; |
1383 SetUpInputField(&input_text); | 1541 SetUpInputField(&input_text); |
1384 | 1542 |
1385 // Sentence navigation is not currently implemented. | 1543 // Sentence navigation is not currently implemented. |
1386 LONG start_offset = 0; | 1544 LONG start_offset = 0; |
1387 LONG end_offset = 0; | 1545 LONG end_offset = 0; |
1388 base::win::ScopedBstr text; | 1546 base::win::ScopedBstr text; |
1389 HRESULT hr = input_text->get_textAtOffset( | 1547 HRESULT hr = input_text->get_textAtOffset( |
1390 5, IA2_TEXT_BOUNDARY_SENTENCE, | 1548 5, IA2_TEXT_BOUNDARY_SENTENCE, |
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1462 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 1620 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
1463 TestMultiLineTextAtOffsetWithBoundaryAll) { | 1621 TestMultiLineTextAtOffsetWithBoundaryAll) { |
1464 base::win::ScopedComPtr<IAccessibleText> textarea_text; | 1622 base::win::ScopedComPtr<IAccessibleText> textarea_text; |
1465 SetUpTextareaField(&textarea_text); | 1623 SetUpTextareaField(&textarea_text); |
1466 | 1624 |
1467 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, | 1625 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, |
1468 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); | 1626 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); |
1469 } | 1627 } |
1470 | 1628 |
1471 } // namespace content | 1629 } // namespace content |
OLD | NEW |