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

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

Issue 151083002: Create a visible window with class name Chrome_RenderWidgetHostHWND which corresponds to the bounds… (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 6 years, 10 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 | Annotate | Revision Log
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"
11 #include "content/browser/accessibility/browser_accessibility_manager_win.h" 11 #include "content/browser/accessibility/browser_accessibility_manager_win.h"
12 #include "content/browser/accessibility/browser_accessibility_state_impl.h" 12 #include "content/browser/accessibility/browser_accessibility_state_impl.h"
13 #include "content/browser/accessibility/browser_accessibility_win.h" 13 #include "content/browser/accessibility/browser_accessibility_win.h"
14 #include "content/browser/renderer_host/legacy_render_widget_host_win.h"
14 #include "content/common/accessibility_messages.h" 15 #include "content/common/accessibility_messages.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/base/win/atl_module.h" 17 #include "ui/base/win/atl_module.h"
17 18
18 namespace content { 19 namespace content {
19 namespace { 20 namespace {
20 21
21 22
22 // CountedBrowserAccessibility ------------------------------------------------ 23 // CountedBrowserAccessibility ------------------------------------------------
23 24
(...skipping 574 matching lines...) Expand 10 before | Expand all | Expand 10 after
598 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances()); 599 ASSERT_EQ(0, CountedBrowserAccessibility::num_instances());
599 } 600 }
600 601
601 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) { 602 TEST_F(BrowserAccessibilityTest, TestCreateEmptyDocument) {
602 // Try creating an empty document with busy state. Readonly is 603 // Try creating an empty document with busy state. Readonly is
603 // set automatically. 604 // set automatically.
604 CountedBrowserAccessibility::reset(); 605 CountedBrowserAccessibility::reset();
605 const int32 busy_state = 1 << ui::AX_STATE_BUSY; 606 const int32 busy_state = 1 << ui::AX_STATE_BUSY;
606 const int32 readonly_state = 1 << ui::AX_STATE_READONLY; 607 const int32 readonly_state = 1 << ui::AX_STATE_READONLY;
607 const int32 enabled_state = 1 << blink::WebAXStateEnabled; 608 const int32 enabled_state = 1 << blink::WebAXStateEnabled;
609 scoped_ptr<content::LegacyRenderWidgetHostHWND> accessible_hwnd(
610 content::LegacyRenderWidgetHostHWND::Create(GetDesktopWindow()));
608 scoped_ptr<BrowserAccessibilityManager> manager( 611 scoped_ptr<BrowserAccessibilityManager> manager(
609 new BrowserAccessibilityManagerWin( 612 new BrowserAccessibilityManagerWin(
610 GetDesktopWindow(), 613 accessible_hwnd.get(),
611 NULL, 614 NULL,
612 BrowserAccessibilityManagerWin::GetEmptyDocument(), 615 BrowserAccessibilityManagerWin::GetEmptyDocument(),
613 NULL, 616 NULL,
614 new CountedBrowserAccessibilityFactory())); 617 new CountedBrowserAccessibilityFactory()));
615 618
616 // Verify the root is as we expect by default. 619 // Verify the root is as we expect by default.
617 BrowserAccessibility* root = manager->GetRoot(); 620 BrowserAccessibility* root = manager->GetRoot();
618 EXPECT_EQ(0, root->renderer_id()); 621 EXPECT_EQ(0, root->renderer_id());
619 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->role()); 622 EXPECT_EQ(ui::AX_ROLE_ROOT_WEB_AREA, root->role());
620 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->state()); 623 EXPECT_EQ(busy_state | readonly_state | enabled_state, root->state());
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after
682 } 685 }
683 686
684 TEST(BrowserAccessibilityManagerWinTest, TestAccessibleHWND) { 687 TEST(BrowserAccessibilityManagerWinTest, TestAccessibleHWND) {
685 HWND desktop_hwnd = GetDesktopWindow(); 688 HWND desktop_hwnd = GetDesktopWindow();
686 base::win::ScopedComPtr<IAccessible> desktop_hwnd_iaccessible; 689 base::win::ScopedComPtr<IAccessible> desktop_hwnd_iaccessible;
687 ASSERT_EQ(S_OK, AccessibleObjectFromWindow( 690 ASSERT_EQ(S_OK, AccessibleObjectFromWindow(
688 desktop_hwnd, OBJID_CLIENT, 691 desktop_hwnd, OBJID_CLIENT,
689 IID_IAccessible, 692 IID_IAccessible,
690 reinterpret_cast<void**>(desktop_hwnd_iaccessible.Receive()))); 693 reinterpret_cast<void**>(desktop_hwnd_iaccessible.Receive())));
691 694
695 scoped_ptr<content::LegacyRenderWidgetHostHWND> accessible_hwnd(
696 content::LegacyRenderWidgetHostHWND::Create(GetDesktopWindow()));
697
692 scoped_ptr<BrowserAccessibilityManagerWin> manager( 698 scoped_ptr<BrowserAccessibilityManagerWin> manager(
693 new BrowserAccessibilityManagerWin( 699 new BrowserAccessibilityManagerWin(
694 desktop_hwnd, 700 accessible_hwnd.get(),
695 desktop_hwnd_iaccessible, 701 desktop_hwnd_iaccessible,
696 BrowserAccessibilityManagerWin::GetEmptyDocument(), 702 BrowserAccessibilityManagerWin::GetEmptyDocument(),
697 NULL)); 703 NULL));
698 ASSERT_EQ(desktop_hwnd, manager->parent_hwnd()); 704 ASSERT_EQ(desktop_hwnd, manager->parent_hwnd());
699 705
700 // Enabling screen reader support and calling MaybeCallNotifyWinEvent 706 // Enabling screen reader support and calling MaybeCallNotifyWinEvent
701 // should trigger creating the AccessibleHWND, and we should now get a 707 // should trigger creating the AccessibleHWND, and we should now get a
702 // new parent_hwnd with the right window class to fool older screen 708 // new parent_hwnd with the right window class to fool older screen
703 // readers. 709 // readers.
704 BrowserAccessibilityStateImpl::GetInstance()->OnScreenReaderDetected(); 710 BrowserAccessibilityStateImpl::GetInstance()->OnScreenReaderDetected();
705 manager->MaybeCallNotifyWinEvent(0, 0); 711 manager->MaybeCallNotifyWinEvent(0, 0);
706 HWND new_parent_hwnd = manager->parent_hwnd(); 712 HWND new_parent_hwnd = manager->parent_hwnd();
707 ASSERT_NE(desktop_hwnd, new_parent_hwnd); 713 ASSERT_NE(desktop_hwnd, new_parent_hwnd);
708 WCHAR hwnd_class_name[256]; 714 WCHAR hwnd_class_name[256];
709 ASSERT_NE(0, GetClassName(new_parent_hwnd, hwnd_class_name, 256)); 715 ASSERT_NE(0, GetClassName(new_parent_hwnd, hwnd_class_name, 256));
710 ASSERT_STREQ(L"Chrome_RenderWidgetHostHWND", hwnd_class_name); 716 ASSERT_STREQ(L"Chrome_RenderWidgetHostHWND", hwnd_class_name);
711 717
712 // Destroy the hwnd explicitly; that should trigger clearing parent_hwnd(). 718 // Destroy the hwnd explicitly; that should trigger clearing parent_hwnd().
713 DestroyWindow(new_parent_hwnd); 719 DestroyWindow(new_parent_hwnd);
714 ASSERT_EQ(NULL, manager->parent_hwnd()); 720 ASSERT_EQ(NULL, manager->parent_hwnd());
715 721
716 // Now create it again. 722 // Now create it again.
723 accessible_hwnd = content::LegacyRenderWidgetHostHWND::Create(
724 GetDesktopWindow());
717 manager.reset( 725 manager.reset(
718 new BrowserAccessibilityManagerWin( 726 new BrowserAccessibilityManagerWin(
719 desktop_hwnd, 727 accessible_hwnd.get(),
720 desktop_hwnd_iaccessible, 728 desktop_hwnd_iaccessible,
721 BrowserAccessibilityManagerWin::GetEmptyDocument(), 729 BrowserAccessibilityManagerWin::GetEmptyDocument(),
722 NULL)); 730 NULL));
723 manager->MaybeCallNotifyWinEvent(0, 0); 731 manager->MaybeCallNotifyWinEvent(0, 0);
724 new_parent_hwnd = manager->parent_hwnd(); 732 new_parent_hwnd = manager->parent_hwnd();
725 ASSERT_FALSE(NULL == new_parent_hwnd); 733 ASSERT_FALSE(NULL == new_parent_hwnd);
726 734
727 // This time, destroy the manager first, make sure the AccessibleHWND doesn't 735 // This time, destroy the manager first, make sure the AccessibleHWND doesn't
728 // crash on destruction (to be caught by SyzyASAN or other tools). 736 // crash on destruction (to be caught by SyzyASAN or other tools).
729 manager.reset(NULL); 737 manager.reset(NULL);
730 } 738 }
731 739
732 } // namespace content 740 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698