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> |
| 6 #include <stdint.h> |
| 7 |
5 #include <vector> | 8 #include <vector> |
6 | 9 |
| 10 #include "base/macros.h" |
7 #include "base/memory/scoped_ptr.h" | 11 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/string_number_conversions.h" | 12 #include "base/strings/string_number_conversions.h" |
9 #include "base/strings/sys_string_conversions.h" | 13 #include "base/strings/sys_string_conversions.h" |
10 #include "base/win/scoped_bstr.h" | 14 #include "base/win/scoped_bstr.h" |
11 #include "base/win/scoped_comptr.h" | 15 #include "base/win/scoped_comptr.h" |
12 #include "base/win/scoped_variant.h" | 16 #include "base/win/scoped_variant.h" |
13 #include "content/browser/accessibility/accessibility_mode_helper.h" | 17 #include "content/browser/accessibility/accessibility_mode_helper.h" |
14 #include "content/browser/accessibility/accessibility_tree_formatter.h" | 18 #include "content/browser/accessibility/accessibility_tree_formatter.h" |
15 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" | 19 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" |
16 #include "content/browser/renderer_host/render_view_host_impl.h" | 20 #include "content/browser/renderer_host/render_view_host_impl.h" |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 base::win::ScopedComPtr<IAccessibleText>* input_text); | 63 base::win::ScopedComPtr<IAccessibleText>* input_text); |
60 void SetUpTextareaField( | 64 void SetUpTextareaField( |
61 base::win::ScopedComPtr<IAccessibleText>* textarea_text); | 65 base::win::ScopedComPtr<IAccessibleText>* textarea_text); |
62 | 66 |
63 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant( | 67 static base::win::ScopedComPtr<IAccessible> GetAccessibleFromVariant( |
64 IAccessible* parent, | 68 IAccessible* parent, |
65 VARIANT* var); | 69 VARIANT* var); |
66 static HRESULT QueryIAccessible2(IAccessible* accessible, | 70 static HRESULT QueryIAccessible2(IAccessible* accessible, |
67 IAccessible2** accessible2); | 71 IAccessible2** accessible2); |
68 static void FindNodeInAccessibilityTree(IAccessible* node, | 72 static void FindNodeInAccessibilityTree(IAccessible* node, |
69 int32 expected_role, | 73 int32_t expected_role, |
70 const std::wstring& expected_name, | 74 const std::wstring& expected_name, |
71 int32 depth, | 75 int32_t depth, |
72 bool* found); | 76 bool* found); |
73 static void CheckTextAtOffset( | 77 static void CheckTextAtOffset( |
74 base::win::ScopedComPtr<IAccessibleText>& element, | 78 base::win::ScopedComPtr<IAccessibleText>& element, |
75 LONG offset, | 79 LONG offset, |
76 IA2TextBoundaryType boundary_type, | 80 IA2TextBoundaryType boundary_type, |
77 LONG expected_start_offset, | 81 LONG expected_start_offset, |
78 LONG expected_end_offset, | 82 LONG expected_end_offset, |
79 const std::wstring& expected_text); | 83 const std::wstring& expected_text); |
80 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren( | 84 static std::vector<base::win::ScopedVariant> GetAllAccessibleChildren( |
81 IAccessible* element); | 85 IAccessible* element); |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
253 HRESULT hr = accessible->QueryInterface(service_provider.Receive()); | 257 HRESULT hr = accessible->QueryInterface(service_provider.Receive()); |
254 return SUCCEEDED(hr) ? | 258 return SUCCEEDED(hr) ? |
255 service_provider->QueryService(IID_IAccessible2, accessible2) : hr; | 259 service_provider->QueryService(IID_IAccessible2, accessible2) : hr; |
256 } | 260 } |
257 | 261 |
258 // Recursively search through all of the descendants reachable from an | 262 // Recursively search through all of the descendants reachable from an |
259 // IAccessible node and return true if we find one with the given role | 263 // IAccessible node and return true if we find one with the given role |
260 // and name. | 264 // and name. |
261 void AccessibilityWinBrowserTest::FindNodeInAccessibilityTree( | 265 void AccessibilityWinBrowserTest::FindNodeInAccessibilityTree( |
262 IAccessible* node, | 266 IAccessible* node, |
263 int32 expected_role, | 267 int32_t expected_role, |
264 const std::wstring& expected_name, | 268 const std::wstring& expected_name, |
265 int32 depth, | 269 int32_t depth, |
266 bool* found) { | 270 bool* found) { |
267 base::win::ScopedBstr name_bstr; | 271 base::win::ScopedBstr name_bstr; |
268 base::win::ScopedVariant childid_self(CHILDID_SELF); | 272 base::win::ScopedVariant childid_self(CHILDID_SELF); |
269 node->get_accName(childid_self, name_bstr.Receive()); | 273 node->get_accName(childid_self, name_bstr.Receive()); |
270 std::wstring name(name_bstr, name_bstr.Length()); | 274 std::wstring name(name_bstr, name_bstr.Length()); |
271 base::win::ScopedVariant role; | 275 base::win::ScopedVariant role; |
272 node->get_accRole(childid_self, role.Receive()); | 276 node->get_accRole(childid_self, role.Receive()); |
273 ASSERT_EQ(VT_I4, role.type()); | 277 ASSERT_EQ(VT_I4, role.type()); |
274 | 278 |
275 // Print the accessibility tree as we go, because if this test fails | 279 // Print the accessibility tree as we go, because if this test fails |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
351 } | 355 } |
352 | 356 |
353 | 357 |
354 // AccessibleChecker ---------------------------------------------------------- | 358 // AccessibleChecker ---------------------------------------------------------- |
355 | 359 |
356 class AccessibilityWinBrowserTest::AccessibleChecker { | 360 class AccessibilityWinBrowserTest::AccessibleChecker { |
357 public: | 361 public: |
358 // This constructor can be used if the IA2 role will be the same as the MSAA | 362 // This constructor can be used if the IA2 role will be the same as the MSAA |
359 // role. | 363 // role. |
360 AccessibleChecker(const std::wstring& expected_name, | 364 AccessibleChecker(const std::wstring& expected_name, |
361 int32 expected_role, | 365 int32_t expected_role, |
362 const std::wstring& expected_value); | 366 const std::wstring& expected_value); |
363 AccessibleChecker(const std::wstring& expected_name, | 367 AccessibleChecker(const std::wstring& expected_name, |
364 int32 expected_role, | 368 int32_t expected_role, |
365 int32 expected_ia2_role, | 369 int32_t expected_ia2_role, |
366 const std::wstring& expected_value); | 370 const std::wstring& expected_value); |
367 AccessibleChecker(const std::wstring& expected_name, | 371 AccessibleChecker(const std::wstring& expected_name, |
368 const std::wstring& expected_role, | 372 const std::wstring& expected_role, |
369 int32 expected_ia2_role, | 373 int32_t expected_ia2_role, |
370 const std::wstring& expected_value); | 374 const std::wstring& expected_value); |
371 | 375 |
372 // Append an AccessibleChecker that verifies accessibility information for | 376 // Append an AccessibleChecker that verifies accessibility information for |
373 // a child IAccessible. Order is important. | 377 // a child IAccessible. Order is important. |
374 void AppendExpectedChild(AccessibleChecker* expected_child); | 378 void AppendExpectedChild(AccessibleChecker* expected_child); |
375 | 379 |
376 // Check that the name and role of the given IAccessible instance and its | 380 // Check that the name and role of the given IAccessible instance and its |
377 // descendants match the expected names and roles that this object was | 381 // descendants match the expected names and roles that this object was |
378 // initialized with. | 382 // initialized with. |
379 void CheckAccessible(IAccessible* accessible); | 383 void CheckAccessible(IAccessible* accessible); |
(...skipping 15 matching lines...) Expand all Loading... |
395 void CheckAccessibleChildren(IAccessible* accessible); | 399 void CheckAccessibleChildren(IAccessible* accessible); |
396 base::string16 RoleVariantToString(const base::win::ScopedVariant& role); | 400 base::string16 RoleVariantToString(const base::win::ScopedVariant& role); |
397 | 401 |
398 // Expected accessible name. Checked against IAccessible::get_accName. | 402 // Expected accessible name. Checked against IAccessible::get_accName. |
399 std::wstring name_; | 403 std::wstring name_; |
400 | 404 |
401 // Expected accessible role. Checked against IAccessible::get_accRole. | 405 // Expected accessible role. Checked against IAccessible::get_accRole. |
402 base::win::ScopedVariant role_; | 406 base::win::ScopedVariant role_; |
403 | 407 |
404 // Expected IAccessible2 role. Checked against IAccessible2::role. | 408 // Expected IAccessible2 role. Checked against IAccessible2::role. |
405 int32 ia2_role_; | 409 int32_t ia2_role_; |
406 | 410 |
407 // Expected accessible value. Checked against IAccessible::get_accValue. | 411 // Expected accessible value. Checked against IAccessible::get_accValue. |
408 std::wstring value_; | 412 std::wstring value_; |
409 | 413 |
410 // Expected accessible state. Checked against IAccessible::get_accState. | 414 // Expected accessible state. Checked against IAccessible::get_accState. |
411 LONG state_; | 415 LONG state_; |
412 | 416 |
413 // Expected accessible children. Checked using IAccessible::get_accChildCount | 417 // Expected accessible children. Checked using IAccessible::get_accChildCount |
414 // and ::AccessibleChildren. | 418 // and ::AccessibleChildren. |
415 AccessibleCheckerVector children_; | 419 AccessibleCheckerVector children_; |
416 }; | 420 }; |
417 | 421 |
418 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( | 422 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( |
419 const std::wstring& expected_name, | 423 const std::wstring& expected_name, |
420 int32 expected_role, | 424 int32_t expected_role, |
421 const std::wstring& expected_value) | 425 const std::wstring& expected_value) |
422 : name_(expected_name), | 426 : name_(expected_name), |
423 role_(expected_role), | 427 role_(expected_role), |
424 ia2_role_(expected_role), | 428 ia2_role_(expected_role), |
425 value_(expected_value), | 429 value_(expected_value), |
426 state_(-1) { | 430 state_(-1) {} |
427 } | |
428 | 431 |
429 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( | 432 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( |
430 const std::wstring& expected_name, | 433 const std::wstring& expected_name, |
431 int32 expected_role, | 434 int32_t expected_role, |
432 int32 expected_ia2_role, | 435 int32_t expected_ia2_role, |
433 const std::wstring& expected_value) | 436 const std::wstring& expected_value) |
434 : name_(expected_name), | 437 : name_(expected_name), |
435 role_(expected_role), | 438 role_(expected_role), |
436 ia2_role_(expected_ia2_role), | 439 ia2_role_(expected_ia2_role), |
437 value_(expected_value), | 440 value_(expected_value), |
438 state_(-1) { | 441 state_(-1) {} |
439 } | |
440 | 442 |
441 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( | 443 AccessibilityWinBrowserTest::AccessibleChecker::AccessibleChecker( |
442 const std::wstring& expected_name, | 444 const std::wstring& expected_name, |
443 const std::wstring& expected_role, | 445 const std::wstring& expected_role, |
444 int32 expected_ia2_role, | 446 int32_t expected_ia2_role, |
445 const std::wstring& expected_value) | 447 const std::wstring& expected_value) |
446 : name_(expected_name), | 448 : name_(expected_name), |
447 role_(expected_role.c_str()), | 449 role_(expected_role.c_str()), |
448 ia2_role_(expected_ia2_role), | 450 ia2_role_(expected_ia2_role), |
449 value_(expected_value), | 451 value_(expected_value), |
450 state_(-1) { | 452 state_(-1) {} |
451 } | |
452 | 453 |
453 void AccessibilityWinBrowserTest::AccessibleChecker::AppendExpectedChild( | 454 void AccessibilityWinBrowserTest::AccessibleChecker::AppendExpectedChild( |
454 AccessibleChecker* expected_child) { | 455 AccessibleChecker* expected_child) { |
455 children_.push_back(expected_child); | 456 children_.push_back(expected_child); |
456 } | 457 } |
457 | 458 |
458 void AccessibilityWinBrowserTest::AccessibleChecker::CheckAccessible( | 459 void AccessibilityWinBrowserTest::AccessibleChecker::CheckAccessible( |
459 IAccessible* accessible) { | 460 IAccessible* accessible) { |
460 SCOPED_TRACE("While checking " | 461 SCOPED_TRACE("While checking " |
461 + base::UTF16ToUTF8(RoleVariantToString(role_))); | 462 + base::UTF16ToUTF8(RoleVariantToString(role_))); |
(...skipping 999 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1461 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 1462 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
1462 TestMultiLineTextAtOffsetWithBoundaryAll) { | 1463 TestMultiLineTextAtOffsetWithBoundaryAll) { |
1463 base::win::ScopedComPtr<IAccessibleText> textarea_text; | 1464 base::win::ScopedComPtr<IAccessibleText> textarea_text; |
1464 SetUpTextareaField(&textarea_text); | 1465 SetUpTextareaField(&textarea_text); |
1465 | 1466 |
1466 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, | 1467 CheckTextAtOffset(textarea_text, CONTENTS_LENGTH - 1, IA2_TEXT_BOUNDARY_ALL, |
1467 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); | 1468 0, CONTENTS_LENGTH, base::SysUTF8ToWide(TEXTAREA_CONTENTS)); |
1468 } | 1469 } |
1469 | 1470 |
1470 } // namespace content | 1471 } // namespace content |
OLD | NEW |