Add a minor text member to ui::MenuModel.
[chromium-blink-merge.git] / chrome / browser / ui / views / accessibility / browser_views_accessibility_browsertest.cc
blobca7270c064c73ec33e7701f154959c92262ecd22
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.
5 #include <oleacc.h>
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 class BrowserViewsAccessibilityTest : public InProcessBrowserTest {
30 public:
31 BrowserViewsAccessibilityTest();
32 virtual ~BrowserViewsAccessibilityTest();
34 // Retrieves an instance of BrowserWindowTesting.
35 BrowserWindowTesting* GetBrowserWindowTesting();
37 // Retrieve an instance of BrowserView.
38 BrowserView* GetBrowserView();
40 // Retrieves and initializes an instance of ToolbarView.
41 ToolbarView* GetToolbarView();
43 // Retrieves and initializes an instance of BookmarkBarView.
44 BookmarkBarView* GetBookmarkBarView();
46 // Retrieves and verifies the accessibility object for the given View.
47 void TestViewAccessibilityObject(views::View* view,
48 std::wstring name,
49 int32 role);
51 // Verifies MSAA Name and Role properties of the given IAccessible.
52 void TestAccessibilityInfo(IAccessible* acc_obj,
53 std::wstring name,
54 int32 role);
56 private:
57 base::win::ScopedCOMInitializer com_initializer_;
59 DISALLOW_COPY_AND_ASSIGN(BrowserViewsAccessibilityTest);
62 BrowserViewsAccessibilityTest::BrowserViewsAccessibilityTest() {
63 ui::win::CreateATLModuleIfNeeded();
66 BrowserViewsAccessibilityTest::~BrowserViewsAccessibilityTest() {
69 BrowserWindowTesting* BrowserViewsAccessibilityTest::GetBrowserWindowTesting() {
70 BrowserWindow* browser_window = browser()->window();
71 return browser_window ? browser_window->GetBrowserWindowTesting() : NULL;
74 BrowserView* BrowserViewsAccessibilityTest::GetBrowserView() {
75 return BrowserView::GetBrowserViewForBrowser(browser());
78 ToolbarView* BrowserViewsAccessibilityTest::GetToolbarView() {
79 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
80 return browser_window_testing ?
81 browser_window_testing->GetToolbarView() : NULL;
84 BookmarkBarView* BrowserViewsAccessibilityTest::GetBookmarkBarView() {
85 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting();
86 return browser_window_testing ?
87 browser_window_testing->GetBookmarkBarView() : NULL;
90 void BrowserViewsAccessibilityTest::TestViewAccessibilityObject(
91 views::View* view,
92 std::wstring name,
93 int32 role) {
94 ASSERT_TRUE(view != NULL);
95 TestAccessibilityInfo(view->GetNativeViewAccessible(), name, role);
98 void BrowserViewsAccessibilityTest::TestAccessibilityInfo(IAccessible* acc_obj,
99 std::wstring name,
100 int32 role) {
101 // Verify MSAA Name property.
102 base::win::ScopedVariant childid_self(CHILDID_SELF);
103 base::win::ScopedBstr acc_name;
104 ASSERT_EQ(S_OK, acc_obj->get_accName(childid_self, acc_name.Receive()));
105 EXPECT_EQ(name, string16(acc_name));
107 // Verify MSAA Role property.
108 base::win::ScopedVariant acc_role;
109 ASSERT_EQ(S_OK, acc_obj->get_accRole(childid_self, acc_role.Receive()));
110 EXPECT_EQ(VT_I4, acc_role.type());
111 EXPECT_EQ(role, V_I4(&acc_role));
114 // Retrieve accessibility object for main window and verify accessibility info.
115 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
116 TestChromeWindowAccObj) {
117 BrowserWindow* browser_window = browser()->window();
118 ASSERT_TRUE(NULL != browser_window);
120 HWND hwnd = browser_window->GetNativeWindow();
121 ASSERT_TRUE(NULL != hwnd);
123 // Get accessibility object.
124 base::win::ScopedComPtr<IAccessible> acc_obj;
125 HRESULT hr = ::AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAccessible,
126 reinterpret_cast<void**>(&acc_obj));
127 ASSERT_EQ(S_OK, hr);
128 ASSERT_TRUE(NULL != acc_obj);
130 ui_test_utils::NavigateToURL(browser(), GURL(content::kAboutBlankURL));
131 std::wstring title = UTF16ToWide(l10n_util::GetStringFUTF16(
132 IDS_BROWSER_WINDOW_TITLE_FORMAT,
133 ASCIIToUTF16(content::kAboutBlankURL)));
134 TestAccessibilityInfo(acc_obj, title, ROLE_SYSTEM_WINDOW);
137 // Retrieve accessibility object for non client view and verify accessibility
138 // info.
139 // TODO(pkasting): Disabled pending resolution of whether this should be
140 // ROLE_SYSTEM_CLIENT or ROLE_SYSTEM_WINDOW.
141 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
142 DISABLED_TestNonClientViewAccObj) {
143 TestViewAccessibilityObject(
144 GetBrowserView()->GetWidget()->non_client_view(),
145 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
146 ROLE_SYSTEM_WINDOW);
149 // Retrieve accessibility object for browser root view and verify accessibility
150 // info.
151 // TODO(pkasting): Disabled pending resolution of whether this should be
152 // ROLE_SYSTEM_WINDOW or ROLE_SYSTEM_APPLICATION, as well as what the name
153 // should be.
154 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
155 DISABLED_TestBrowserRootViewAccObj) {
156 TestViewAccessibilityObject(
157 GetBrowserView()->frame()->GetRootView(),
158 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
159 ROLE_SYSTEM_APPLICATION);
162 // Retrieve accessibility object for browser view and verify accessibility info.
163 // TODO(pkasting): Disabled pending resolution of whether this object should
164 // have an accessible name.
165 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
166 DISABLED_TestBrowserViewAccObj) {
167 TestViewAccessibilityObject(
168 GetBrowserView(),
169 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)),
170 ROLE_SYSTEM_CLIENT);
173 // Retrieve accessibility object for toolbar view and verify accessibility info.
174 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestToolbarViewAccObj) {
175 TestViewAccessibilityObject(
176 GetToolbarView(),
177 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLBAR)),
178 ROLE_SYSTEM_TOOLBAR);
181 // Retrieve accessibility object for Back button and verify accessibility info.
182 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestBackButtonAccObj) {
183 TestViewAccessibilityObject(
184 GetToolbarView()->GetViewByID(VIEW_ID_BACK_BUTTON),
185 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)),
186 ROLE_SYSTEM_BUTTONDROPDOWN);
189 // Retrieve accessibility object for Forward button and verify accessibility
190 // info.
191 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestForwardButtonAccObj) {
192 TestViewAccessibilityObject(
193 GetToolbarView()->GetViewByID(VIEW_ID_FORWARD_BUTTON),
194 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)),
195 ROLE_SYSTEM_BUTTONDROPDOWN);
198 // Retrieve accessibility object for Reload button and verify accessibility
199 // info.
200 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestReloadButtonAccObj) {
201 TestViewAccessibilityObject(
202 GetToolbarView()->GetViewByID(VIEW_ID_RELOAD_BUTTON),
203 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)),
204 ROLE_SYSTEM_PUSHBUTTON);
207 // Retrieve accessibility object for Home button and verify accessibility info.
208 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestHomeButtonAccObj) {
209 TestViewAccessibilityObject(
210 GetToolbarView()->GetViewByID(VIEW_ID_HOME_BUTTON),
211 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)),
212 ROLE_SYSTEM_PUSHBUTTON);
215 // Retrieve accessibility object for Star button and verify accessibility info.
216 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestStarButtonAccObj) {
217 TestViewAccessibilityObject(
218 GetToolbarView()->GetViewByID(VIEW_ID_STAR_BUTTON),
219 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_STAR)),
220 ROLE_SYSTEM_PUSHBUTTON);
223 // Retrieve accessibility object for Mic search button and verify accessibility
224 // info.
225 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
226 TestMicSearchButtonViewAccObj) {
227 TestViewAccessibilityObject(
228 GetToolbarView()->GetViewByID(VIEW_ID_MIC_SEARCH_BUTTON),
229 UTF16ToWide(l10n_util::GetStringUTF16(IDS_TOOLTIP_MIC_SEARCH)),
230 ROLE_SYSTEM_PUSHBUTTON);
233 // Retrieve accessibility object for App menu button and verify accessibility
234 // info.
235 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, TestAppMenuAccObj) {
236 TestViewAccessibilityObject(
237 GetToolbarView()->GetViewByID(VIEW_ID_APP_MENU),
238 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)),
239 ROLE_SYSTEM_BUTTONMENU);
242 // Retrieve accessibility object for bookmark bar and verify accessibility info.
243 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest,
244 TestBookmarkBarViewAccObj) {
245 TestViewAccessibilityObject(
246 GetBookmarkBarView(),
247 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS)),
248 ROLE_SYSTEM_TOOLBAR);