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

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

Issue 415633002: Simplify access to LegacyRenderWidgetHostHWND. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@render_frame_ax_4
Patch Set: Rebase and fix style issue Created 6 years, 5 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 "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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
72 72
73 BrowserAccessibility* CountedBrowserAccessibilityFactory::Create() { 73 BrowserAccessibility* CountedBrowserAccessibilityFactory::Create() {
74 CComObject<CountedBrowserAccessibility>* instance; 74 CComObject<CountedBrowserAccessibility>* instance;
75 HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance( 75 HRESULT hr = CComObject<CountedBrowserAccessibility>::CreateInstance(
76 &instance); 76 &instance);
77 DCHECK(SUCCEEDED(hr)); 77 DCHECK(SUCCEEDED(hr));
78 instance->AddRef(); 78 instance->AddRef();
79 return instance; 79 return instance;
80 } 80 }
81 81
82 // Provides functionality for creating the accessible hwnd and ensures that
83 // the hwnd along with the LegacyRenderWidgetHostHWND instance is destroyed
84 // when this instance is destroyed.
85 class TestLegacyRenderWidgetHostHWND {
86 public:
87 TestLegacyRenderWidgetHostHWND()
88 : accessible_hwnd_(NULL) {}
89
90 ~TestLegacyRenderWidgetHostHWND() {
91 if (accessible_hwnd())
92 ::DestroyWindow(accessible_hwnd()->hwnd());
93 }
94
95 bool Initialize(HWND parent) {
96 accessible_hwnd_ = LegacyRenderWidgetHostHWND::Create(parent);
97 EXPECT_NE(accessible_hwnd_,
98 static_cast<LegacyRenderWidgetHostHWND*>(NULL));
99 return accessible_hwnd_ != NULL;
100 }
101
102 LegacyRenderWidgetHostHWND* accessible_hwnd() {
103 return accessible_hwnd_;
104 }
105
106 private:
107 LegacyRenderWidgetHostHWND* accessible_hwnd_;
108 };
109
110 } // namespace 82 } // namespace
111 83
112 84
113 // BrowserAccessibilityTest --------------------------------------------------- 85 // BrowserAccessibilityTest ---------------------------------------------------
114 86
115 class BrowserAccessibilityTest : public testing::Test { 87 class BrowserAccessibilityTest : public testing::Test {
116 public: 88 public:
117 BrowserAccessibilityTest(); 89 BrowserAccessibilityTest();
118 virtual ~BrowserAccessibilityTest(); 90 virtual ~BrowserAccessibilityTest();
119 91
(...skipping 506 matching lines...) Expand 10 before | Expand all | Expand 10 after
626 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 598 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
627 } 599 }
628 600
629 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { 601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) {
630 // Try creating an empty document with busy state. Readonly is 602 // Try creating an empty document with busy state. Readonly is
631 // set automatically. 603 // set automatically.
632 CountedBrowserAccessibility::reset(); 604 CountedBrowserAccessibility::reset();
633 const int32 busy_state = 1 << ui::AX_STATE_BUSY; 605 const int32 busy_state = 1 << ui::AX_STATE_BUSY;
634 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY; 606 const int32 readonly_state = 1 << ui::AX_STATE_READ_ONLY;
635 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED; 607 const int32 enabled_state = 1 << ui::AX_STATE_ENABLED;
636 scoped_ptr<TestLegacyRenderWidgetHostHWND> accessibility_test
637 (new TestLegacyRenderWidgetHostHWND);
638 EXPECT_EQ(accessibility_test->Initialize(GetDesktopWindow()), true);
639 scoped_ptr<BrowserAccessibilityManager> manager( 608 scoped_ptr<BrowserAccessibilityManager> manager(
640 new BrowserAccessibilityManagerWin( 609 new BrowserAccessibilityManagerWin(
641 accessibility_test->accessible_hwnd(),
642 NULL,
643 BrowserAccessibilityManagerWin::GetEmptyDocument(), 610 BrowserAccessibilityManagerWin::GetEmptyDocument(),
644 NULL, 611 NULL,
645 new CountedBrowserAccessibilityFactory())); 612 new CountedBrowserAccessibilityFactory()));
646 613
647 // Verify the root is as we expect by default. 614 // Verify the root is as we expect by default.
648 BrowserAccessibility* root = manager->GetRoot(); 615 BrowserAccessibility* root = manager->GetRoot();
649 EXPECT_EQ(0, root->GetId()); 616 EXPECT_EQ(0, root->GetId());
650 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole()); 617 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->GetRole());
651 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState()); 618 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->GetState());
652 619
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 672
706 // And the new child exists. 673 // And the new child exists.
707 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole()); 674 EXPECT_EQ(ui::AX_ROLE_BUTTON, acc2_2->GetRole());
708 EXPECT_EQ(3, acc2_2->GetId()); 675 EXPECT_EQ(3, acc2_2->GetId());
709 676
710 // Ensure we properly cleaned up. 677 // Ensure we properly cleaned up.
711 manager.reset(); 678 manager.reset();
712 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 679 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
713 } 680 }
714 681
715 TEST(BrowserAccessibilityManagerWinTest, TestAccessibleHWND) {
716 HWND desktop_hwnd = GetDesktopWindow();
717 base::win::ScopedComPtr<IAccessible> desktop_hwnd_iaccessible;
718 ASSERT_EQ(S_OK, AccessibleObjectFromWindow(
719 desktop_hwnd, static_cast<DWORD>(OBJID_CLIENT),
720 IID_IAccessible,
721 reinterpret_cast<void**>(desktop_hwnd_iaccessible.Receive())));
722
723 scoped_ptr<TestLegacyRenderWidgetHostHWND> accessibility_test
724 (new TestLegacyRenderWidgetHostHWND);
725 EXPECT_EQ(accessibility_test->Initialize(GetDesktopWindow()), true);
726
727 scoped_ptr<BrowserAccessibilityManagerWin> manager(
728 new BrowserAccessibilityManagerWin(
729 accessibility_test->accessible_hwnd(),
730 desktop_hwnd_iaccessible,
731 BrowserAccessibilityManagerWin::GetEmptyDocument(),
732 NULL));
733 ASSERT_EQ(desktop_hwnd, manager->parent_hwnd());
734
735 // Enabling screen reader support and calling MaybeCallNotifyWinEvent
736 // should trigger creating the AccessibleHWND, and we should now get a
737 // new parent_hwnd with the right window class to fool older screen
738 // readers.
739 BrowserAccessibilityStateImpl::GetInstance()->OnScreenReaderDetected();
740 manager->MaybeCallNotifyWinEvent(0, 0);
741 HWND new_parent_hwnd = manager->parent_hwnd();
742 ASSERT_NE(desktop_hwnd, new_parent_hwnd);
743 WCHAR hwnd_class_name[256];
744 ASSERT_NE(0, GetClassName(new_parent_hwnd, hwnd_class_name, 256));
745 ASSERT_STREQ(L"Chrome_RenderWidgetHostHWND", hwnd_class_name);
746
747 // Destroy the TestLegacyRenderWidgetHostHWND instance. That should in turn
748 // destroy the hwnd, which should clear the parent_hwnd().
749 accessibility_test.reset(NULL);
750 ASSERT_EQ(FALSE, ::IsWindow(new_parent_hwnd));
751 ASSERT_EQ(NULL, manager->parent_hwnd());
752
753 // Now create it again.
754 accessibility_test.reset(new TestLegacyRenderWidgetHostHWND);
755 EXPECT_EQ(accessibility_test->Initialize(::GetDesktopWindow()), true);
756 manager.reset(
757 new BrowserAccessibilityManagerWin(
758 accessibility_test->accessible_hwnd(),
759 desktop_hwnd_iaccessible,
760 BrowserAccessibilityManagerWin::GetEmptyDocument(),
761 NULL));
762 manager->MaybeCallNotifyWinEvent(0, 0);
763 new_parent_hwnd = manager->parent_hwnd();
764 ASSERT_FALSE(NULL == new_parent_hwnd);
765
766 // This time, destroy the manager first, make sure the AccessibleHWND doesn't
767 // crash on destruction (to be caught by SyzyASAN or other tools).
768 manager.reset(NULL);
769 }
770
771 } // namespace content 682 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/accessibility/browser_accessibility_win.cc ('k') | content/browser/frame_host/render_frame_host_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698