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

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: Added a TODO to investigate test failure on Linux. 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
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/sys_string_conversions.h" 13 #include "base/strings/sys_string_conversions.h"
14 #include "base/win/scoped_bstr.h" 14 #include "base/win/scoped_bstr.h"
15 #include "base/win/scoped_comptr.h" 15 #include "base/win/scoped_comptr.h"
16 #include "base/win/scoped_variant.h" 16 #include "base/win/scoped_variant.h"
17 #include "content/browser/accessibility/accessibility_mode_helper.h" 17 #include "content/browser/accessibility/accessibility_mode_helper.h"
18 #include "content/browser/accessibility/accessibility_tree_formatter.h" 18 #include "content/browser/accessibility/accessibility_tree_formatter.h"
19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h " 19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h "
20 #include "content/browser/accessibility/browser_accessibility_win.h"
20 #include "content/browser/renderer_host/render_view_host_impl.h" 21 #include "content/browser/renderer_host/render_view_host_impl.h"
21 #include "content/public/browser/notification_service.h" 22 #include "content/public/browser/notification_service.h"
22 #include "content/public/browser/notification_types.h" 23 #include "content/public/browser/notification_types.h"
23 #include "content/public/browser/render_frame_host.h" 24 #include "content/public/browser/render_frame_host.h"
24 #include "content/public/browser/render_widget_host_view.h" 25 #include "content/public/browser/render_widget_host_view.h"
25 #include "content/public/browser/web_contents.h" 26 #include "content/public/browser/web_contents.h"
26 #include "content/public/common/url_constants.h" 27 #include "content/public/common/url_constants.h"
27 #include "content/public/test/content_browser_test.h" 28 #include "content/public/test/content_browser_test.h"
28 #include "content/public/test/content_browser_test_utils.h" 29 #include "content/public/test/content_browser_test_utils.h"
29 #include "content/shell/browser/shell.h" 30 #include "content/shell/browser/shell.h"
(...skipping 26 matching lines...) Expand all
56 57
57 protected: 58 protected:
58 class AccessibleChecker; 59 class AccessibleChecker;
59 void LoadInitialAccessibilityTreeFromHtml(const std::string& html); 60 void LoadInitialAccessibilityTreeFromHtml(const std::string& html);
60 IAccessible* GetRendererAccessible(); 61 IAccessible* GetRendererAccessible();
61 void ExecuteScript(const std::wstring& script); 62 void ExecuteScript(const std::wstring& script);
62 void SetUpInputField( 63 void SetUpInputField(
63 base::win::ScopedComPtr<IAccessibleText>* input_text); 64 base::win::ScopedComPtr<IAccessibleText>* input_text);
64 void SetUpTextareaField( 65 void SetUpTextareaField(
65 base::win::ScopedComPtr<IAccessibleText>* textarea_text); 66 base::win::ScopedComPtr<IAccessibleText>* textarea_text);
67 void SetUpSampleParagraph(
68 base::win::ScopedComPtr<IAccessibleText>* paragraph_text);
66 69
67 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant( 70 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant(
68 IAccessible* parent, 71 IAccessible* parent,
69 VARIANT* var); 72 VARIANT* var);
70 static HRESULT QueryIAccessible2(IAccessible* accessible, 73 static HRESULT QueryIAccessible2(IAccessible* accessible,
71 IAccessible2** accessible2); 74 IAccessible2** accessible2);
72 static void FindNodeInAccessibilityTree(IAccessible* node, 75 static void FindNodeInAccessibilityTree(IAccessible* node,
73 int32_t expected_role, 76 int32_t expected_role,
74 const std::wstring& expected_name, 77 const std::wstring& expected_name,
75 int32_t depth, 78 int32_t depth,
76 bool* found); 79 bool* found);
77 static void CheckTextAtOffset( 80 static void CheckTextAtOffset(
78 base::win::ScopedComPtr<IAccessibleText>& element, 81 base::win::ScopedComPtr<IAccessibleText>& object,
79 LONG offset, 82 LONG offset,
80 IA2TextBoundaryType boundary_type, 83 IA2TextBoundaryType boundary_type,
81 LONG expected_start_offset, 84 LONG expected_start_offset,
82 LONG expected_end_offset, 85 LONG expected_end_offset,
83 const std::wstring& expected_text); 86 const std::wstring& expected_text);
84 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren( 87 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren(
85 IAccessible* element); 88 IAccessible* element);
86 89
87 private: 90 private:
88 DISALLOW_COPY_AND_ASSIGN(AccessibilityWinBrowserTest); 91 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( 129 net::EscapeQueryParamValue(INPUT_CONTENTS, false) + std::string(
127 "'></form></body></html>")); 130 "'></form></body></html>"));
128 131
129 // Retrieve the IAccessible interface for the web page. 132 // Retrieve the IAccessible interface for the web page.
130 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); 133 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
131 std::vector<base::win::ScopedVariant> document_children = 134 std::vector<base::win::ScopedVariant> document_children =
132 GetAllAccessibleChildren(document.get()); 135 GetAllAccessibleChildren(document.get());
133 ASSERT_EQ(1u, document_children.size()); 136 ASSERT_EQ(1u, document_children.size());
134 137
135 base::win::ScopedComPtr<IAccessible2> form; 138 base::win::ScopedComPtr<IAccessible2> form;
136 HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( 139 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
137 document.get(), document_children[0].AsInput()).get(), form.Receive()); 140 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
138 ASSERT_EQ(S_OK, hr); 141 .get(),
142 form.Receive()));
139 std::vector<base::win::ScopedVariant> form_children = 143 std::vector<base::win::ScopedVariant> form_children =
140 GetAllAccessibleChildren(form.get()); 144 GetAllAccessibleChildren(form.get());
141 ASSERT_EQ(2u, form_children.size()); 145 ASSERT_EQ(2u, form_children.size());
142 146
143 // Find the input text field. 147 // Find the input text field.
144 base::win::ScopedComPtr<IAccessible2> input; 148 base::win::ScopedComPtr<IAccessible2> input;
145 hr = QueryIAccessible2(GetAccessibleFromVariant( 149 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
146 form.get(), form_children[1].AsInput()).get(), input.Receive()); 150 GetAccessibleFromVariant(form.get(), form_children[1].AsInput()).get(),
147 ASSERT_EQ(S_OK, hr); 151 input.Receive()));
148 LONG input_role = 0; 152 LONG input_role = 0;
149 hr = input->role(&input_role); 153 ASSERT_HRESULT_SUCCEEDED(input->role(&input_role));
150 ASSERT_EQ(S_OK, hr);
151 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role); 154 ASSERT_EQ(ROLE_SYSTEM_TEXT, input_role);
152 155
153 // Retrieve the IAccessibleText interface for the field. 156 // Retrieve the IAccessibleText interface for the field.
154 hr = input.QueryInterface(input_text->Receive()); 157 ASSERT_HRESULT_SUCCEEDED(input.QueryInterface(input_text->Receive()));
155 ASSERT_EQ(S_OK, hr);
156 158
157 // Set the caret on the last character. 159 // Set the caret on the last character.
158 AccessibilityNotificationWaiter waiter( 160 AccessibilityNotificationWaiter waiter(
159 shell(), AccessibilityModeComplete, 161 shell(), AccessibilityModeComplete,
160 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 162 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
161 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 163 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
162 static_cast<int>(CONTENTS_LENGTH - 1))); 164 static_cast<int>(CONTENTS_LENGTH - 1)));
163 ExecuteScript(std::wstring( 165 ExecuteScript(std::wstring(
164 L"var textField = document.getElementById('textField');" 166 L"var textField = document.getElementById('textField');"
165 L"textField.focus();" 167 L"textField.focus();"
(...skipping 12 matching lines...) Expand all
178 net::EscapeQueryParamValue(TEXTAREA_CONTENTS, false) + std::string( 180 net::EscapeQueryParamValue(TEXTAREA_CONTENTS, false) + std::string(
179 "</textarea></body></html>")); 181 "</textarea></body></html>"));
180 182
181 // Retrieve the IAccessible interface for the web page. 183 // Retrieve the IAccessible interface for the web page.
182 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible()); 184 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
183 std::vector<base::win::ScopedVariant> document_children = 185 std::vector<base::win::ScopedVariant> document_children =
184 GetAllAccessibleChildren(document.get()); 186 GetAllAccessibleChildren(document.get());
185 ASSERT_EQ(1u, document_children.size()); 187 ASSERT_EQ(1u, document_children.size());
186 188
187 base::win::ScopedComPtr<IAccessible2> section; 189 base::win::ScopedComPtr<IAccessible2> section;
188 HRESULT hr = QueryIAccessible2(GetAccessibleFromVariant( 190 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
189 document.get(), document_children[0].AsInput()).get(), section.Receive()); 191 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
190 ASSERT_EQ(S_OK, hr); 192 .get(),
193 section.Receive()));
191 std::vector<base::win::ScopedVariant> section_children = 194 std::vector<base::win::ScopedVariant> section_children =
192 GetAllAccessibleChildren(section.get()); 195 GetAllAccessibleChildren(section.get());
193 ASSERT_EQ(1u, section_children.size()); 196 ASSERT_EQ(1u, section_children.size());
194 197
195 // Find the textarea text field. 198 // Find the textarea text field.
196 base::win::ScopedComPtr<IAccessible2> textarea; 199 base::win::ScopedComPtr<IAccessible2> textarea;
197 hr = QueryIAccessible2(GetAccessibleFromVariant( 200 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
198 section.get(), section_children[0].AsInput()).get(), textarea.Receive()); 201 GetAccessibleFromVariant(section.get(), section_children[0].AsInput())
199 ASSERT_EQ(S_OK, hr); 202 .get(),
203 textarea.Receive()));
200 LONG textarea_role = 0; 204 LONG textarea_role = 0;
201 hr = textarea->role(&textarea_role); 205 ASSERT_HRESULT_SUCCEEDED(textarea->role(&textarea_role));
202 ASSERT_EQ(S_OK, hr);
203 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role); 206 ASSERT_EQ(ROLE_SYSTEM_TEXT, textarea_role);
204 207
205 // Retrieve the IAccessibleText interface for the field. 208 // Retrieve the IAccessibleText interface for the field.
206 hr = textarea.QueryInterface(textarea_text->Receive()); 209 ASSERT_HRESULT_SUCCEEDED(textarea.QueryInterface(textarea_text->Receive()));
207 ASSERT_EQ(S_OK, hr);
208 210
209 // Set the caret on the last character. 211 // Set the caret on the last character.
210 AccessibilityNotificationWaiter waiter( 212 AccessibilityNotificationWaiter waiter(
211 shell(), AccessibilityModeComplete, 213 shell(), AccessibilityModeComplete,
212 ui::AX_EVENT_TEXT_SELECTION_CHANGED); 214 ui::AX_EVENT_TEXT_SELECTION_CHANGED);
213 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16( 215 std::wstring caret_offset = base::UTF16ToWide(base::IntToString16(
214 static_cast<int>(CONTENTS_LENGTH - 1))); 216 static_cast<int>(CONTENTS_LENGTH - 1)));
215 ExecuteScript(std::wstring( 217 ExecuteScript(std::wstring(
216 L"var textField = document.getElementById('textField');" 218 L"var textField = document.getElementById('textField');"
217 L"textField.focus();" 219 L"textField.focus();"
218 L"textField.setSelectionRange(") + 220 L"textField.setSelectionRange(") +
219 caret_offset + L"," + caret_offset + L");"); 221 caret_offset + L"," + caret_offset + L");");
220 waiter.WaitForNotification(); 222 waiter.WaitForNotification();
221 } 223 }
222 224
225 // Loads a page with a paragraph of sample text.
226 void AccessibilityWinBrowserTest::SetUpSampleParagraph(
227 base::win::ScopedComPtr<IAccessibleText>* paragraph_text) {
228 ASSERT_NE(nullptr, paragraph_text);
229 LoadInitialAccessibilityTreeFromHtml(std::string(
230 "<!DOCTYPE html><html><body>"
231 "<p><b>Game theory</b> is \"the study of "
232 "<a href=\"#\" title=\"Mathematical model\">mathematical models</a> "
233 "of conflict and<br>cooperation between intelligent rational "
234 "decision-makers.\"</p></body></html>"));
235
236 // Retrieve the IAccessible interface for the web page.
237 base::win::ScopedComPtr<IAccessible> document(GetRendererAccessible());
238 std::vector<base::win::ScopedVariant> document_children =
239 GetAllAccessibleChildren(document.get());
240 ASSERT_EQ(1u, document_children.size());
241
242 base::win::ScopedComPtr<IAccessible2> paragraph;
243 ASSERT_HRESULT_SUCCEEDED(QueryIAccessible2(
244 GetAccessibleFromVariant(document.get(), document_children[0].AsInput())
245 .get(),
246 paragraph.Receive()));
247 LONG paragraph_role = 0;
248 ASSERT_HRESULT_SUCCEEDED(paragraph->role(&paragraph_role));
249 ASSERT_EQ(IA2_ROLE_PARAGRAPH, paragraph_role);
250 ASSERT_HRESULT_SUCCEEDED(paragraph.QueryInterface(paragraph_text->Receive()));
251 }
223 252
224 // Static helpers ------------------------------------------------ 253 // Static helpers ------------------------------------------------
225 254
226 base::win::ScopedComPtr<IAccessible> 255 base::win::ScopedComPtr<IAccessible>
227 AccessibilityWinBrowserTest::GetAccessibleFromVariant( 256 AccessibilityWinBrowserTest::GetAccessibleFromVariant(
228 IAccessible* parent, 257 IAccessible* parent,
229 VARIANT* var) { 258 VARIANT* var) {
230 base::win::ScopedComPtr<IAccessible> ptr; 259 base::win::ScopedComPtr<IAccessible> ptr;
231 switch (V_VT(var)) { 260 switch (V_VT(var)) {
232 case VT_DISPATCH: { 261 case VT_DISPATCH: {
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 found); 329 found);
301 if (*found) 330 if (*found)
302 return; 331 return;
303 } 332 }
304 } 333 }
305 } 334 }
306 335
307 // Ensures that the text and the start and end offsets retrieved using 336 // Ensures that the text and the start and end offsets retrieved using
308 // get_textAtOffset match the expected values. 337 // get_textAtOffset match the expected values.
309 void AccessibilityWinBrowserTest::CheckTextAtOffset( 338 void AccessibilityWinBrowserTest::CheckTextAtOffset(
310 base::win::ScopedComPtr<IAccessibleText>& element, 339 base::win::ScopedComPtr<IAccessibleText>& object,
311 LONG offset, 340 LONG offset,
312 IA2TextBoundaryType boundary_type, 341 IA2TextBoundaryType boundary_type,
313 LONG expected_start_offset, 342 LONG expected_start_offset,
314 LONG expected_end_offset, 343 LONG expected_end_offset,
315 const std::wstring& expected_text) { 344 const std::wstring& expected_text) {
316 testing::Message message; 345 testing::Message message;
317 message << "While checking for \'" << expected_text << "\' at " << 346 message << "While checking for \'" << expected_text << "\' at " <<
318 expected_start_offset << '-' << expected_end_offset << '.'; 347 expected_start_offset << '-' << expected_end_offset << '.';
319 SCOPED_TRACE(message); 348 SCOPED_TRACE(message);
320 349
321 LONG start_offset = 0; 350 LONG start_offset = 0;
322 LONG end_offset = 0; 351 LONG end_offset = 0;
323 base::win::ScopedBstr text; 352 base::win::ScopedBstr text;
324 HRESULT hr = element->get_textAtOffset( 353 HRESULT hr = object->get_textAtOffset(offset, boundary_type, &start_offset,
325 offset, boundary_type, 354 &end_offset, text.Receive());
326 &start_offset, &end_offset, text.Receive());
327 EXPECT_EQ(S_OK, hr); 355 EXPECT_EQ(S_OK, hr);
328 EXPECT_EQ(expected_start_offset, start_offset); 356 EXPECT_EQ(expected_start_offset, start_offset);
329 EXPECT_EQ(expected_end_offset, end_offset); 357 EXPECT_EQ(expected_end_offset, end_offset);
330 EXPECT_EQ(expected_text, std::wstring(text, text.Length())); 358 EXPECT_EQ(expected_text, std::wstring(text, text.Length()));
331 } 359 }
332 360
333 std::vector<base::win::ScopedVariant> 361 std::vector<base::win::ScopedVariant>
334 AccessibilityWinBrowserTest::GetAllAccessibleChildren( 362 AccessibilityWinBrowserTest::GetAllAccessibleChildren(
335 IAccessible* element) { 363 IAccessible* element) {
336 LONG child_count = 0; 364 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, 975 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING,
948 std::wstring()); 976 std::wstring());
949 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, 977 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT,
950 std::wstring()); 978 std::wstring());
951 document_checker.AppendExpectedChild(&grouping1_checker); 979 document_checker.AppendExpectedChild(&grouping1_checker);
952 document_checker.AppendExpectedChild(&grouping2_checker); 980 document_checker.AppendExpectedChild(&grouping2_checker);
953 document_checker.CheckAccessible(GetRendererAccessible()); 981 document_checker.CheckAccessible(GetRendererAccessible());
954 } 982 }
955 983
956 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 984 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
957 TestSetCaretOffset) { 985 TestCharacterExtentsWithInvalidArguments) {
986 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
987 SetUpSampleParagraph(&paragraph_text);
988
989 LONG invalid_offset = -3;
990 LONG x = -1, y = -1;
991 LONG width = -1, height = -1;
992
993 HRESULT hr = paragraph_text->get_characterExtents(
994 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height);
995 EXPECT_EQ(E_INVALIDARG, hr);
996 EXPECT_EQ(-1, x);
997 EXPECT_EQ(-1, y);
998 EXPECT_EQ(-1, width);
999 EXPECT_EQ(-1, height);
1000 hr = paragraph_text->get_characterExtents(
1001 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height);
1002 EXPECT_EQ(E_INVALIDARG, hr);
1003 EXPECT_EQ(-1, x);
1004 EXPECT_EQ(-1, y);
1005 EXPECT_EQ(-1, width);
1006 EXPECT_EQ(-1, height);
1007
1008 LONG n_characters;
1009 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters));
1010 ASSERT_LT(0, n_characters);
1011
1012 invalid_offset = n_characters + 1;
1013 hr = paragraph_text->get_characterExtents(
1014 invalid_offset, IA2_COORDTYPE_SCREEN_RELATIVE, &x, &y, &width, &height);
1015 EXPECT_EQ(E_INVALIDARG, hr);
1016 EXPECT_EQ(-1, x);
1017 EXPECT_EQ(-1, y);
1018 EXPECT_EQ(-1, width);
1019 EXPECT_EQ(-1, height);
1020 hr = paragraph_text->get_characterExtents(
1021 invalid_offset, IA2_COORDTYPE_PARENT_RELATIVE, &x, &y, &width, &height);
1022 EXPECT_EQ(E_INVALIDARG, hr);
1023 EXPECT_EQ(-1, x);
1024 EXPECT_EQ(-1, y);
1025 EXPECT_EQ(-1, width);
1026 EXPECT_EQ(-1, height);
1027 }
1028
1029 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestCharacterExtents) {
1030 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
1031 SetUpSampleParagraph(&paragraph_text);
1032
1033 const LONG newline_offset = 46;
1034 LONG n_characters;
1035 ASSERT_HRESULT_SUCCEEDED(paragraph_text->get_nCharacters(&n_characters));
1036 ASSERT_LT(0, n_characters);
1037
1038 LONG x, y, width, height;
1039 LONG previous_x, previous_y;
1040
1041 for (int coordinate = IA2_COORDTYPE_SCREEN_RELATIVE;
1042 coordinate <= IA2_COORDTYPE_PARENT_RELATIVE; ++coordinate) {
1043 auto coordinate_type = static_cast<IA2CoordinateType>(coordinate);
1044 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1045 0, coordinate_type, &x, &y, &width, &height));
1046 EXPECT_LE(0, x) << "at offset 0";
1047 EXPECT_LE(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_LE(0, x) << "at offset " << newline_offset + 1;
1066 EXPECT_GT(previous_x, x) << "at offset " << newline_offset + 1;
1067 EXPECT_LT(previous_y, y) << "at offset " << newline_offset + 1;
1068 EXPECT_LT(0, width) << "at offset " << newline_offset + 1;
1069 EXPECT_LT(0, height) << "at offset " << newline_offset + 1;
1070
1071 for (LONG offset = newline_offset + 2; offset < n_characters; ++offset) {
1072 previous_x = x;
1073 previous_y = y;
1074
1075 EXPECT_HRESULT_SUCCEEDED(paragraph_text->get_characterExtents(
1076 offset, coordinate_type, &x, &y, &width, &height));
1077 EXPECT_LT(previous_x, x) << "at offset " << offset;
1078 EXPECT_EQ(previous_y, y) << "at offset " << offset;
1079 EXPECT_LT(0, width) << "at offset " << offset;
1080 EXPECT_LT(0, height) << "at offset " << offset;
1081 }
1082 }
1083 }
1084
1085 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, TestSetCaretOffset) {
958 base::win::ScopedComPtr<IAccessibleText> input_text; 1086 base::win::ScopedComPtr<IAccessibleText> input_text;
959 SetUpInputField(&input_text); 1087 SetUpInputField(&input_text);
960 1088
961 LONG caret_offset = 0; 1089 LONG caret_offset = 0;
962 HRESULT hr = input_text->get_caretOffset(&caret_offset); 1090 HRESULT hr = input_text->get_caretOffset(&caret_offset);
963 EXPECT_EQ(S_OK, hr); 1091 EXPECT_EQ(S_OK, hr);
964 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset); 1092 EXPECT_EQ(CONTENTS_LENGTH - 1, caret_offset);
965 1093
966 AccessibilityNotificationWaiter waiter( 1094 AccessibilityNotificationWaiter waiter(
967 shell(), AccessibilityModeComplete, 1095 shell(), AccessibilityModeComplete,
(...skipping 25 matching lines...) Expand all
993 hr = textarea_text->setCaretOffset(caret_offset); 1121 hr = textarea_text->setCaretOffset(caret_offset);
994 EXPECT_EQ(S_OK, hr); 1122 EXPECT_EQ(S_OK, hr);
995 waiter.WaitForNotification(); 1123 waiter.WaitForNotification();
996 1124
997 hr = textarea_text->get_caretOffset(&caret_offset); 1125 hr = textarea_text->get_caretOffset(&caret_offset);
998 EXPECT_EQ(S_OK, hr); 1126 EXPECT_EQ(S_OK, hr);
999 EXPECT_EQ(0, caret_offset); 1127 EXPECT_EQ(0, caret_offset);
1000 } 1128 }
1001 1129
1002 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1130 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1003 TestTextAtOffsetWithInvalidArgs) { 1131 TestTextAtOffsetWithInvalidArguments) {
1004 base::win::ScopedComPtr<IAccessibleText> input_text; 1132 base::win::ScopedComPtr<IAccessibleText> input_text;
1005 SetUpInputField(&input_text); 1133 SetUpInputField(&input_text);
1006 HRESULT hr = input_text->get_textAtOffset( 1134 HRESULT hr = input_text->get_textAtOffset(
1007 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); 1135 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL);
1008 EXPECT_EQ(E_INVALIDARG, hr); 1136 EXPECT_EQ(E_INVALIDARG, hr);
1009 1137
1010 // Test invalid offset. 1138 // Test invalid offset.
1011 LONG start_offset = 0; 1139 LONG start_offset = 0;
1012 LONG end_offset = 0; 1140 LONG end_offset = 0;
1013 base::win::ScopedBstr text; 1141 base::win::ScopedBstr text;
(...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after
1086 hr = input_text->get_textAtOffset( 1214 hr = input_text->get_textAtOffset(
1087 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL, 1215 IA2_TEXT_OFFSET_LENGTH, IA2_TEXT_BOUNDARY_ALL,
1088 &start_offset, &end_offset, text.Receive()); 1216 &start_offset, &end_offset, text.Receive());
1089 EXPECT_EQ(S_FALSE, hr); 1217 EXPECT_EQ(S_FALSE, hr);
1090 EXPECT_EQ(0, start_offset); 1218 EXPECT_EQ(0, start_offset);
1091 EXPECT_EQ(0, end_offset); 1219 EXPECT_EQ(0, end_offset);
1092 EXPECT_EQ(nullptr, static_cast<BSTR>(text)); 1220 EXPECT_EQ(nullptr, static_cast<BSTR>(text));
1093 } 1221 }
1094 1222
1095 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1223 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1096 TestMultiLineTextAtOffsetWithInvalidArgs) { 1224 TestMultiLineTextAtOffsetWithInvalidArguments) {
1097 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1225 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1098 SetUpTextareaField(&textarea_text); 1226 SetUpTextareaField(&textarea_text);
1099 HRESULT hr = textarea_text->get_textAtOffset( 1227 HRESULT hr = textarea_text->get_textAtOffset(
1100 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL); 1228 0, IA2_TEXT_BOUNDARY_CHAR, NULL, NULL, NULL);
1101 EXPECT_EQ(E_INVALIDARG, hr); 1229 EXPECT_EQ(E_INVALIDARG, hr);
1102 1230
1103 // Test invalid offset. 1231 // Test invalid offset.
1104 LONG start_offset = 0; 1232 LONG start_offset = 0;
1105 LONG end_offset = 0; 1233 LONG end_offset = 0;
1106 base::win::ScopedBstr text; 1234 base::win::ScopedBstr text;
(...skipping 264 matching lines...) Expand 10 before | Expand all | Expand 10 after
1371 40, CONTENTS_LENGTH, L"like\"."); 1499 40, CONTENTS_LENGTH, L"like\".");
1372 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD, 1500 CheckTextAtOffset(textarea_text, 45, IA2_TEXT_BOUNDARY_WORD,
1373 40, CONTENTS_LENGTH, L"like\"."); 1501 40, CONTENTS_LENGTH, L"like\".");
1374 1502
1375 // Test special offsets. 1503 // Test special offsets.
1376 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET, 1504 CheckTextAtOffset(textarea_text, IA2_TEXT_OFFSET_CARET,
1377 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\"."); 1505 IA2_TEXT_BOUNDARY_WORD, 40, CONTENTS_LENGTH, L"like\".");
1378 } 1506 }
1379 1507
1380 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1508 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1509 TestStaticTextAtOffsetWithBoundaryWord) {
1510 base::win::ScopedComPtr<IAccessibleText> paragraph_text;
1511 SetUpSampleParagraph(&paragraph_text);
1512 base::string16 embedded_character(
1513 1, BrowserAccessibilityWin::kEmbeddedCharacter);
1514 std::vector<std::wstring> words;
1515 words.push_back(L"Game ");
1516 words.push_back(L"theory ");
1517 words.push_back(L"is \"");
1518 words.push_back(L"the ");
1519 words.push_back(L"study ");
1520 words.push_back(L"of " + embedded_character + L' ');
1521 words.push_back(L"of ");
1522 words.push_back(L"conflict ");
1523 words.push_back(L"and\n");
1524 words.push_back(L"cooperation ");
1525 words.push_back(L"between ");
1526 words.push_back(L"intelligent ");
1527 words.push_back(L"rational ");
1528 words.push_back(L"decision-");
1529 words.push_back(L"makers.\"");
1530
1531 // Try to retrieve one word after another.
1532 LONG word_start_offset = 0;
1533 for (auto& word : words) {
1534 LONG word_end_offset = word_start_offset + word.size();
1535 CheckTextAtOffset(paragraph_text, word_start_offset, IA2_TEXT_BOUNDARY_WORD,
1536 word_start_offset, word_end_offset, word);
1537 word_start_offset = word_end_offset;
1538 }
1539 }
1540
1541 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1381 TestTextAtOffsetWithBoundarySentence) { 1542 TestTextAtOffsetWithBoundarySentence) {
1382 base::win::ScopedComPtr<IAccessibleText> input_text; 1543 base::win::ScopedComPtr<IAccessibleText> input_text;
1383 SetUpInputField(&input_text); 1544 SetUpInputField(&input_text);
1384 1545
1385 // Sentence navigation is not currently implemented. 1546 // Sentence navigation is not currently implemented.
1386 LONG start_offset = 0; 1547 LONG start_offset = 0;
1387 LONG end_offset = 0; 1548 LONG end_offset = 0;
1388 base::win::ScopedBstr text; 1549 base::win::ScopedBstr text;
1389 HRESULT hr = input_text->get_textAtOffset( 1550 HRESULT hr = input_text->get_textAtOffset(
1390 5, IA2_TEXT_BOUNDARY_SENTENCE, 1551 5, IA2_TEXT_BOUNDARY_SENTENCE,
(...skipping 71 matching lines...) Expand 10 before | Expand all | Expand 10 after
1462 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, 1623 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest,
1463 TestMultiLineTextAtOffsetWithBoundaryAll) { 1624 TestMultiLineTextAtOffsetWithBoundaryAll) {
1464 base::win::ScopedComPtr<IAccessibleText> textarea_text; 1625 base::win::ScopedComPtr<IAccessibleText> textarea_text;
1465 SetUpTextareaField(&textarea_text); 1626 SetUpTextareaField(&textarea_text);
1466 1627
1467 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, 1628 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL,
1468 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); 1629 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS));
1469 } 1630 }
1470 1631
1471 } // namespace content 1632 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | content/browser/accessibility/browser_accessibility.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698