| 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 "base/memory/scoped_ptr.h" | 5 #include "base/memory/scoped_ptr.h" |
| 6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
| 7 #include "base/win/scoped_bstr.h" | 7 #include "base/win/scoped_bstr.h" |
| 8 #include "base/win/scoped_comptr.h" | 8 #include "base/win/scoped_comptr.h" |
| 9 #include "base/win/scoped_variant.h" | 9 #include "base/win/scoped_variant.h" |
| 10 #include "content/browser/accessibility/browser_accessibility_manager.h" | 10 #include "content/browser/accessibility/browser_accessibility_manager.h" |
| (...skipping 587 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 598 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 598 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 599 } | 599 } |
| 600 | 600 |
| 601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { | 601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { |
| 602 // Try creating an empty document with busy state. Readonly is | 602 // Try creating an empty document with busy state. Readonly is |
| 603 // set automatically. | 603 // set automatically. |
| 604 CountedBrowserAccessibility::reset(); | 604 CountedBrowserAccessibility::reset(); |
| 605 const int32 busy_state = 1 << ui::AX_STATE_BUSY; | 605 const int32 busy_state = 1 << ui::AX_STATE_BUSY; |
| 606 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; | 606 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; |
| 607 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED; | 607 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED; |
| 608 scoped_ptr<content::LegacyRenderWidgetHostHWND> accessible_hwnd( | |
| 609 content::LegacyRenderWidgetHostHWND::Create(GetDesktopWindow())); | |
| 610 scoped_ptr<BrowserAccessibilityManager> manager( | 608 scoped_ptr<BrowserAccessibilityManager> manager( |
| 611 new BrowserAccessibilityManagerWin( | 609 new BrowserAccessibilityManagerWin( |
| 612 accessible_hwnd.get(), | |
| 613 NULL, | |
| 614 BrowserAccessibilityManagerWin::GetEmptyDocument(), | 610 BrowserAccessibilityManagerWin::GetEmptyDocument(), |
| 615 NULL, | 611 NULL, |
| 616 new CountedBrowserAccessibilityFactory())); | 612 new CountedBrowserAccessibilityFactory())); |
| 617 | 613 |
| 618 // Verify the root is as we expect by default. | 614 // Verify the root is as we expect by default. |
| 619 BrowserAccessibility* root = manager->GetRoot(); | 615 BrowserAccessibility* root = manager->GetRoot(); |
| 620 EXPECT_EQ(0, root->GetId()); | 616 EXPECT_EQ(0, root->GetId()); |
| 621 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); | 617 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); |
| 622 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState()); | 618 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState()); |
| 623 | 619 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 676 | 672 |
| 677 // And the new child exists. | 673 // And the new child exists. |
| 678 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole()); | 674 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole()); |
| 679 EXPECT_EQ(3, acc2_2->GetId()); | 675 EXPECT_EQ(3, acc2_2->GetId()); |
| 680 | 676 |
| 681 // Ensure we properly cleaned up. | 677 // Ensure we properly cleaned up. |
| 682 manager.reset(); | 678 manager.reset(); |
| 683 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); | 679 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); |
| 684 } | 680 } |
| 685 | 681 |
| 686 TEST(BrowserAccessibilityManagerWinTest, TestAccessibleHWND) { | |
| 687 HWND desktop_hwnd = GetDesktopWindow(); | |
| 688 base::win::ScopedComPtr<IAccessible> desktop_hwnd_iaccessible; | |
| 689 ASSERT_EQ(S_OK, AccessibleObjectFromWindow( | |
| 690 desktop_hwnd, OBJID_CLIENT, | |
| 691 IID_IAccessible, | |
| 692 reinterpret_cast<void**>(desktop_hwnd_iaccessible.Receive()))); | |
| 693 | |
| 694 scoped_ptr<content::LegacyRenderWidgetHostHWND> accessible_hwnd( | |
| 695 content::LegacyRenderWidgetHostHWND::Create(GetDesktopWindow())); | |
| 696 | |
| 697 scoped_ptr<BrowserAccessibilityManagerWin> manager( | |
| 698 new BrowserAccessibilityManagerWin( | |
| 699 accessible_hwnd.get(), | |
| 700 desktop_hwnd_iaccessible, | |
| 701 BrowserAccessibilityManagerWin::GetEmptyDocument(), | |
| 702 NULL)); | |
| 703 ASSERT_EQ(desktop_hwnd, manager->parent_hwnd()); | |
| 704 | |
| 705 // Enabling screen reader support and calling MaybeCallNotifyWinEvent | |
| 706 // should trigger creating the AccessibleHWND, and we should now get a | |
| 707 // new parent_hwnd with the right window class to fool older screen | |
| 708 // readers. | |
| 709 BrowserAccessibilityStateImpl::GetInstance()->OnScreenReaderDetected(); | |
| 710 manager->MaybeCallNotifyWinEvent(0, 0); | |
| 711 HWND new_parent_hwnd = manager->parent_hwnd(); | |
| 712 ASSERT_NE(desktop_hwnd, new_parent_hwnd); | |
| 713 WCHAR hwnd_class_name[256]; | |
| 714 ASSERT_NE(0, GetClassName(new_parent_hwnd, hwnd_class_name, 256)); | |
| 715 ASSERT_STREQ(L"Chrome_RenderWidgetHostHWND", hwnd_class_name); | |
| 716 | |
| 717 // Destroy the hwnd explicitly; that should trigger clearing parent_hwnd(). | |
| 718 DestroyWindow(new_parent_hwnd); | |
| 719 ASSERT_EQ(NULL, manager->parent_hwnd()); | |
| 720 | |
| 721 // Now create it again. | |
| 722 accessible_hwnd = content::LegacyRenderWidgetHostHWND::Create( | |
| 723 GetDesktopWindow()); | |
| 724 manager.reset( | |
| 725 new BrowserAccessibilityManagerWin( | |
| 726 accessible_hwnd.get(), | |
| 727 desktop_hwnd_iaccessible, | |
| 728 BrowserAccessibilityManagerWin::GetEmptyDocument(), | |
| 729 NULL)); | |
| 730 manager->MaybeCallNotifyWinEvent(0, 0); | |
| 731 new_parent_hwnd = manager->parent_hwnd(); | |
| 732 ASSERT_FALSE(NULL == new_parent_hwnd); | |
| 733 | |
| 734 // This time, destroy the manager first, make sure the AccessibleHWND doesn't | |
| 735 // crash on destruction (to be caught by SyzyASAN or other tools). | |
| 736 manager.reset(NULL); | |
| 737 } | |
| 738 | |
| 739 } // namespace content | 682 } // namespace content |
| OLD | NEW |