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
3 // found in the LICENSE file.
7 #include "base/strings/utf_string_conversions.h"
8 #include "base/win/scoped_bstr.h"
9 #include "base/win/scoped_com_initializer.h"
10 #include "base/win/scoped_comptr.h"
11 #include "base/win/scoped_variant.h"
12 #include "chrome/browser/ui/browser.h"
13 #include "chrome/browser/ui/browser_window.h"
14 #include "chrome/browser/ui/view_ids.h"
15 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h"
16 #include "chrome/browser/ui/views/frame/browser_view.h"
17 #include "chrome/browser/ui/views/toolbar_view.h"
18 #include "chrome/common/url_constants.h"
19 #include "chrome/test/base/in_process_browser_test.h"
20 #include "chrome/test/base/ui_test_utils.h"
21 #include "grit/chromium_strings.h"
22 #include "grit/generated_resources.h"
23 #include "ui/base/accessibility/accessibility_types.h"
24 #include "ui/base/l10n/l10n_util.h"
25 #include "ui/base/win/atl_module.h"
26 #include "ui/views/accessibility/native_view_accessibility_win.h"
27 #include "ui/views/widget/widget.h"
29 using base::UTF16ToWide
;
31 class BrowserViewsAccessibilityTest
: public InProcessBrowserTest
{
33 BrowserViewsAccessibilityTest();
34 virtual ~BrowserViewsAccessibilityTest();
36 // Retrieves an instance of BrowserWindowTesting.
37 BrowserWindowTesting
* GetBrowserWindowTesting();
39 // Retrieve an instance of BrowserView.
40 BrowserView
* GetBrowserView();
42 // Retrieves and initializes an instance of ToolbarView.
43 ToolbarView
* GetToolbarView();
45 // Retrieves and initializes an instance of BookmarkBarView.
46 BookmarkBarView
* GetBookmarkBarView();
48 // Retrieves and verifies the accessibility object for the given View.
49 void TestViewAccessibilityObject(views::View
* view
,
53 // Verifies MSAA Name and Role properties of the given IAccessible.
54 void TestAccessibilityInfo(IAccessible
* acc_obj
,
59 base::win::ScopedCOMInitializer com_initializer_
;
61 DISALLOW_COPY_AND_ASSIGN(BrowserViewsAccessibilityTest
);
64 BrowserViewsAccessibilityTest::BrowserViewsAccessibilityTest() {
65 ui::win::CreateATLModuleIfNeeded();
68 BrowserViewsAccessibilityTest::~BrowserViewsAccessibilityTest() {
71 BrowserWindowTesting
* BrowserViewsAccessibilityTest::GetBrowserWindowTesting() {
72 BrowserWindow
* browser_window
= browser()->window();
73 return browser_window
? browser_window
->GetBrowserWindowTesting() : NULL
;
76 BrowserView
* BrowserViewsAccessibilityTest::GetBrowserView() {
77 return BrowserView::GetBrowserViewForBrowser(browser());
80 ToolbarView
* BrowserViewsAccessibilityTest::GetToolbarView() {
81 BrowserWindowTesting
* browser_window_testing
= GetBrowserWindowTesting();
82 return browser_window_testing
?
83 browser_window_testing
->GetToolbarView() : NULL
;
86 BookmarkBarView
* BrowserViewsAccessibilityTest::GetBookmarkBarView() {
87 BrowserWindowTesting
* browser_window_testing
= GetBrowserWindowTesting();
88 return browser_window_testing
?
89 browser_window_testing
->GetBookmarkBarView() : NULL
;
92 void BrowserViewsAccessibilityTest::TestViewAccessibilityObject(
96 ASSERT_TRUE(view
!= NULL
);
97 TestAccessibilityInfo(view
->GetNativeViewAccessible(), name
, role
);
100 void BrowserViewsAccessibilityTest::TestAccessibilityInfo(IAccessible
* acc_obj
,
103 // Verify MSAA Name property.
104 base::win::ScopedVariant
childid_self(CHILDID_SELF
);
105 base::win::ScopedBstr acc_name
;
106 ASSERT_EQ(S_OK
, acc_obj
->get_accName(childid_self
, acc_name
.Receive()));
107 EXPECT_EQ(name
, base::string16(acc_name
));
109 // Verify MSAA Role property.
110 base::win::ScopedVariant acc_role
;
111 ASSERT_EQ(S_OK
, acc_obj
->get_accRole(childid_self
, acc_role
.Receive()));
112 EXPECT_EQ(VT_I4
, acc_role
.type());
113 EXPECT_EQ(role
, V_I4(&acc_role
));
116 // Retrieve accessibility object for main window and verify accessibility info.
117 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
118 TestChromeWindowAccObj
) {
119 BrowserWindow
* browser_window
= browser()->window();
120 ASSERT_TRUE(NULL
!= browser_window
);
122 HWND hwnd
= browser_window
->GetNativeWindow();
123 ASSERT_TRUE(NULL
!= hwnd
);
125 // Get accessibility object.
126 base::win::ScopedComPtr
<IAccessible
> acc_obj
;
127 HRESULT hr
= ::AccessibleObjectFromWindow(hwnd
, OBJID_WINDOW
, IID_IAccessible
,
128 reinterpret_cast<void**>(&acc_obj
));
130 ASSERT_TRUE(NULL
!= acc_obj
);
132 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL
));
133 std::wstring title
= UTF16ToWide(l10n_util::GetStringFUTF16(
134 IDS_BROWSER_WINDOW_TITLE_FORMAT
,
135 base::ASCIIToUTF16(content::kAboutBlankURL
)));
136 TestAccessibilityInfo(acc_obj
, title
, ROLE_SYSTEM_WINDOW
);
139 // Retrieve accessibility object for non client view and verify accessibility
141 // TODO(pkasting): Disabled pending resolution of whether this should be
142 // ROLE_SYSTEM_CLIENT or ROLE_SYSTEM_WINDOW.
143 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
144 DISABLED_TestNonClientViewAccObj
) {
145 TestViewAccessibilityObject(
146 GetBrowserView()->GetWidget()->non_client_view(),
147 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)),
151 // Retrieve accessibility object for browser root view and verify accessibility
153 // TODO(pkasting): Disabled pending resolution of whether this should be
154 // ROLE_SYSTEM_WINDOW or ROLE_SYSTEM_APPLICATION, as well as what the name
156 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
157 DISABLED_TestBrowserRootViewAccObj
) {
158 TestViewAccessibilityObject(
159 GetBrowserView()->frame()->GetRootView(),
160 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)),
161 ROLE_SYSTEM_APPLICATION
);
164 // Retrieve accessibility object for browser view and verify accessibility info.
165 // TODO(pkasting): Disabled pending resolution of whether this object should
166 // have an accessible name.
167 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
168 DISABLED_TestBrowserViewAccObj
) {
169 TestViewAccessibilityObject(
171 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME
)),
175 // Retrieve accessibility object for toolbar view and verify accessibility info.
176 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestToolbarViewAccObj
) {
177 TestViewAccessibilityObject(
179 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLBAR
)),
180 ROLE_SYSTEM_TOOLBAR
);
183 // Retrieve accessibility object for Back button and verify accessibility info.
184 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestBackButtonAccObj
) {
185 TestViewAccessibilityObject(
186 GetToolbarView()->GetViewByID(VIEW_ID_BACK_BUTTON
),
187 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK
)),
188 ROLE_SYSTEM_BUTTONDROPDOWN
);
191 // Retrieve accessibility object for Forward button and verify accessibility
193 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestForwardButtonAccObj
) {
194 TestViewAccessibilityObject(
195 GetToolbarView()->GetViewByID(VIEW_ID_FORWARD_BUTTON
),
196 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD
)),
197 ROLE_SYSTEM_BUTTONDROPDOWN
);
200 // Retrieve accessibility object for Reload button and verify accessibility
202 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestReloadButtonAccObj
) {
203 TestViewAccessibilityObject(
204 GetToolbarView()->GetViewByID(VIEW_ID_RELOAD_BUTTON
),
205 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD
)),
206 ROLE_SYSTEM_PUSHBUTTON
);
209 // Retrieve accessibility object for Home button and verify accessibility info.
210 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestHomeButtonAccObj
) {
211 TestViewAccessibilityObject(
212 GetToolbarView()->GetViewByID(VIEW_ID_HOME_BUTTON
),
213 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME
)),
214 ROLE_SYSTEM_PUSHBUTTON
);
217 // Retrieve accessibility object for Star button and verify accessibility info.
218 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestStarButtonAccObj
) {
219 TestViewAccessibilityObject(
220 GetToolbarView()->GetViewByID(VIEW_ID_STAR_BUTTON
),
221 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_STAR
)),
222 ROLE_SYSTEM_PUSHBUTTON
);
225 // Retrieve accessibility object for Mic search button and verify accessibility
227 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
228 TestMicSearchButtonViewAccObj
) {
229 TestViewAccessibilityObject(
230 GetToolbarView()->GetViewByID(VIEW_ID_MIC_SEARCH_BUTTON
),
231 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH
)),
232 ROLE_SYSTEM_PUSHBUTTON
);
235 // Retrieve accessibility object for App menu button and verify accessibility
237 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
, TestAppMenuAccObj
) {
238 TestViewAccessibilityObject(
239 GetToolbarView()->GetViewByID(VIEW_ID_APP_MENU
),
240 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_APP
)),
241 ROLE_SYSTEM_BUTTONMENU
);
244 // Retrieve accessibility object for bookmark bar and verify accessibility info.
245 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest
,
246 TestBookmarkBarViewAccObj
) {
247 TestViewAccessibilityObject(
248 GetBookmarkBarView(),
249 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS
)),
250 ROLE_SYSTEM_TOOLBAR
);