| OLD | NEW |
| (Empty) |
| 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. | |
| 4 | |
| 5 #include <oleacc.h> | |
| 6 | |
| 7 #include "base/utf_string_conversions.h" | |
| 8 #include "base/win/scoped_comptr.h" | |
| 9 #include "chrome/browser/ui/browser.h" | |
| 10 #include "chrome/browser/ui/browser_window.h" | |
| 11 #include "chrome/browser/ui/view_ids.h" | |
| 12 #include "chrome/browser/ui/views/bookmarks/bookmark_bar_view.h" | |
| 13 #include "chrome/browser/ui/views/frame/browser_view.h" | |
| 14 #include "chrome/browser/ui/views/toolbar_view.h" | |
| 15 #include "chrome/common/url_constants.h" | |
| 16 #include "chrome/test/base/in_process_browser_test.h" | |
| 17 #include "chrome/test/base/ui_test_utils.h" | |
| 18 #include "grit/chromium_strings.h" | |
| 19 #include "grit/generated_resources.h" | |
| 20 #include "ui/base/accessibility/accessibility_types.h" | |
| 21 #include "ui/base/l10n/l10n_util.h" | |
| 22 #include "ui/base/win/atl_module.h" | |
| 23 #include "ui/views/accessibility/native_view_accessibility_win.h" | |
| 24 #include "ui/views/widget/widget.h" | |
| 25 | |
| 26 namespace { | |
| 27 | |
| 28 VARIANT id_self = {VT_I4, CHILDID_SELF}; | |
| 29 | |
| 30 } // namespace | |
| 31 | |
| 32 class BrowserViewsAccessibilityTest : public InProcessBrowserTest { | |
| 33 public: | |
| 34 BrowserViewsAccessibilityTest() { | |
| 35 ui::win::CreateATLModuleIfNeeded(); | |
| 36 ::CoInitialize(NULL); | |
| 37 } | |
| 38 | |
| 39 ~BrowserViewsAccessibilityTest() { | |
| 40 ::CoUninitialize(); | |
| 41 } | |
| 42 | |
| 43 // Retrieves an instance of BrowserWindowTesting | |
| 44 BrowserWindowTesting* GetBrowserWindowTesting() { | |
| 45 BrowserWindow* browser_window = browser()->window(); | |
| 46 | |
| 47 if (!browser_window) | |
| 48 return NULL; | |
| 49 | |
| 50 return browser_window->GetBrowserWindowTesting(); | |
| 51 } | |
| 52 | |
| 53 // Retrieve an instance of BrowserView | |
| 54 BrowserView* GetBrowserView() { | |
| 55 return BrowserView::GetBrowserViewForBrowser(browser()); | |
| 56 } | |
| 57 | |
| 58 // Retrieves and initializes an instance of ToolbarView. | |
| 59 ToolbarView* GetToolbarView() { | |
| 60 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting(); | |
| 61 | |
| 62 if (!browser_window_testing) | |
| 63 return NULL; | |
| 64 | |
| 65 return browser_window_testing->GetToolbarView(); | |
| 66 } | |
| 67 | |
| 68 // Retrieves and initializes an instance of BookmarkBarView. | |
| 69 BookmarkBarView* GetBookmarkBarView() { | |
| 70 BrowserWindowTesting* browser_window_testing = GetBrowserWindowTesting(); | |
| 71 | |
| 72 if (!browser_window_testing) | |
| 73 return NULL; | |
| 74 | |
| 75 return browser_window_testing->GetBookmarkBarView(); | |
| 76 } | |
| 77 | |
| 78 // Retrieves and verifies the accessibility object for the given View. | |
| 79 void TestViewAccessibilityObject(views::View* view, std::wstring name, | |
| 80 int32 role) { | |
| 81 ASSERT_TRUE(NULL != view); | |
| 82 | |
| 83 TestAccessibilityInfo(view->GetNativeViewAccessible(), name, role); | |
| 84 } | |
| 85 | |
| 86 | |
| 87 // Verifies MSAA Name and Role properties of the given IAccessible. | |
| 88 void TestAccessibilityInfo(IAccessible* acc_obj, std::wstring name, | |
| 89 int32 role) { | |
| 90 // Verify MSAA Name property. | |
| 91 BSTR acc_name; | |
| 92 | |
| 93 HRESULT hr = acc_obj->get_accName(id_self, &acc_name); | |
| 94 ASSERT_EQ(S_OK, hr); | |
| 95 EXPECT_STREQ(acc_name, name.c_str()); | |
| 96 | |
| 97 // Verify MSAA Role property. | |
| 98 VARIANT acc_role; | |
| 99 ::VariantInit(&acc_role); | |
| 100 | |
| 101 hr = acc_obj->get_accRole(id_self, &acc_role); | |
| 102 ASSERT_EQ(S_OK, hr); | |
| 103 EXPECT_EQ(VT_I4, acc_role.vt); | |
| 104 EXPECT_EQ(role, acc_role.lVal); | |
| 105 | |
| 106 ::VariantClear(&acc_role); | |
| 107 ::SysFreeString(acc_name); | |
| 108 } | |
| 109 }; | |
| 110 | |
| 111 // Retrieve accessibility object for main window and verify accessibility info. | |
| 112 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 113 TestChromeWindowAccObj) { | |
| 114 BrowserWindow* browser_window = browser()->window(); | |
| 115 ASSERT_TRUE(NULL != browser_window); | |
| 116 | |
| 117 HWND hwnd = browser_window->GetNativeHandle(); | |
| 118 ASSERT_TRUE(NULL != hwnd); | |
| 119 | |
| 120 // Get accessibility object. | |
| 121 base::win::ScopedComPtr<IAccessible> acc_obj; | |
| 122 HRESULT hr = ::AccessibleObjectFromWindow(hwnd, OBJID_WINDOW, IID_IAccessible, | |
| 123 reinterpret_cast<void**>(&acc_obj)); | |
| 124 ASSERT_EQ(S_OK, hr); | |
| 125 ASSERT_TRUE(NULL != acc_obj); | |
| 126 | |
| 127 ui_test_utils::NavigateToURL(browser(), GURL(chrome::kAboutBlankURL)); | |
| 128 std::wstring title = UTF16ToWide(l10n_util::GetStringFUTF16( | |
| 129 IDS_BROWSER_WINDOW_TITLE_FORMAT, | |
| 130 ASCIIToUTF16(chrome::kAboutBlankURL))); | |
| 131 TestAccessibilityInfo(acc_obj, title, ROLE_SYSTEM_WINDOW); | |
| 132 } | |
| 133 | |
| 134 // Retrieve accessibility object for non client view and verify accessibility | |
| 135 // info. | |
| 136 // http://crbug.com/104132 | |
| 137 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 138 DISABLED_TestNonClientViewAccObj) { | |
| 139 views::View* non_client_view = | |
| 140 GetBrowserView()->GetWidget()->non_client_view(); | |
| 141 | |
| 142 TestViewAccessibilityObject(non_client_view, | |
| 143 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), | |
| 144 ROLE_SYSTEM_WINDOW); | |
| 145 } | |
| 146 | |
| 147 // Retrieve accessibility object for browser root view and verify | |
| 148 // accessibility info. | |
| 149 // http://crbug.com/104132 | |
| 150 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 151 DISABLED_TestBrowserRootViewAccObj) { | |
| 152 views::View* browser_root_view = GetBrowserView()->frame()->GetRootView(); | |
| 153 | |
| 154 TestViewAccessibilityObject( | |
| 155 browser_root_view, | |
| 156 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), | |
| 157 ROLE_SYSTEM_APPLICATION); | |
| 158 } | |
| 159 | |
| 160 // Retrieve accessibility object for browser view and verify accessibility info. | |
| 161 // http://crbug.com/104132 | |
| 162 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 163 DISABLED_TestBrowserViewAccObj) { | |
| 164 // Verify root view MSAA name and role. | |
| 165 TestViewAccessibilityObject( | |
| 166 GetBrowserView(), | |
| 167 UTF16ToWide(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME)), | |
| 168 ROLE_SYSTEM_CLIENT); | |
| 169 } | |
| 170 | |
| 171 // Retrieve accessibility object for toolbar view and verify accessibility info. | |
| 172 // http://crbug.com/104132 | |
| 173 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 174 DISABLED_TestToolbarViewAccObj) { | |
| 175 // Verify toolbar MSAA name and role. | |
| 176 TestViewAccessibilityObject( | |
| 177 GetToolbarView(), | |
| 178 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_TOOLBAR)), | |
| 179 ROLE_SYSTEM_TOOLBAR); | |
| 180 } | |
| 181 | |
| 182 // Retrieve accessibility object for Back button and verify accessibility info. | |
| 183 // http://crbug.com/104132 | |
| 184 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 185 DISABLED_TestBackButtonAccObj) { | |
| 186 // Verify Back button MSAA name and role. | |
| 187 TestViewAccessibilityObject( | |
| 188 GetToolbarView()->GetViewByID(VIEW_ID_BACK_BUTTON), | |
| 189 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BACK)), | |
| 190 ROLE_SYSTEM_BUTTONDROPDOWN); | |
| 191 } | |
| 192 | |
| 193 // Retrieve accessibility object for Forward button and verify accessibility | |
| 194 // info. | |
| 195 // http://crbug.com/104132 | |
| 196 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 197 DISABLED_TestForwardButtonAccObj) { | |
| 198 // Verify Forward button MSAA name and role. | |
| 199 TestViewAccessibilityObject( | |
| 200 GetToolbarView()->GetViewByID(VIEW_ID_FORWARD_BUTTON), | |
| 201 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_FORWARD)), | |
| 202 ROLE_SYSTEM_BUTTONDROPDOWN); | |
| 203 } | |
| 204 | |
| 205 // Retrieve accessibility object for Reload button and verify accessibility | |
| 206 // info. | |
| 207 // http://crbug.com/104132 | |
| 208 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 209 DISABLED_TestReloadButtonAccObj) { | |
| 210 // Verify Reload button MSAA name and role. | |
| 211 TestViewAccessibilityObject( | |
| 212 GetToolbarView()->GetViewByID(VIEW_ID_RELOAD_BUTTON), | |
| 213 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_RELOAD)), | |
| 214 ROLE_SYSTEM_PUSHBUTTON); | |
| 215 } | |
| 216 | |
| 217 // Retrieve accessibility object for Home button and verify accessibility info. | |
| 218 // http://crbug.com/104132 | |
| 219 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 220 DISABLED_TestHomeButtonAccObj) { | |
| 221 // Verify Home button MSAA name and role. | |
| 222 TestViewAccessibilityObject( | |
| 223 GetToolbarView()->GetViewByID(VIEW_ID_HOME_BUTTON), | |
| 224 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_HOME)), | |
| 225 ROLE_SYSTEM_PUSHBUTTON); | |
| 226 } | |
| 227 | |
| 228 // Retrieve accessibility object for Star button and verify accessibility info. | |
| 229 // http://crbug.com/104132 | |
| 230 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 231 DISABLED_TestStarButtonAccObj) { | |
| 232 // Verify Star button MSAA name and role. | |
| 233 TestViewAccessibilityObject( | |
| 234 GetToolbarView()->GetViewByID(VIEW_ID_STAR_BUTTON), | |
| 235 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_STAR)), | |
| 236 ROLE_SYSTEM_PUSHBUTTON); | |
| 237 } | |
| 238 | |
| 239 // Retrieve accessibility object for App menu button and verify accessibility | |
| 240 // info. | |
| 241 // http://crbug.com/104132 | |
| 242 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 243 DISABLED_TestAppMenuAccObj) { | |
| 244 // Verify App menu button MSAA name and role. | |
| 245 TestViewAccessibilityObject( | |
| 246 GetToolbarView()->GetViewByID(VIEW_ID_APP_MENU), | |
| 247 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_APP)), | |
| 248 ROLE_SYSTEM_BUTTONMENU); | |
| 249 } | |
| 250 | |
| 251 // http://crbug.com/104132 | |
| 252 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 253 DISABLED_TestBookmarkBarViewAccObj) { | |
| 254 TestViewAccessibilityObject( | |
| 255 GetBookmarkBarView(), | |
| 256 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ACCNAME_BOOKMARKS)), | |
| 257 ROLE_SYSTEM_TOOLBAR); | |
| 258 } | |
| 259 | |
| 260 IN_PROC_BROWSER_TEST_F(BrowserViewsAccessibilityTest, | |
| 261 TestAboutChromeViewAccObj) { | |
| 262 // Firstly, test that the WindowDelegate got updated. | |
| 263 views::Widget* about_chrome_window = | |
| 264 GetBrowserView()->DoShowAboutChromeDialog(); | |
| 265 EXPECT_STREQ( | |
| 266 about_chrome_window->widget_delegate()->GetWindowTitle().c_str(), | |
| 267 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ABOUT_CHROME_TITLE)).c_str()); | |
| 268 EXPECT_EQ(about_chrome_window->widget_delegate()->GetAccessibleWindowRole(), | |
| 269 ui::AccessibilityTypes::ROLE_DIALOG); | |
| 270 | |
| 271 // Also test the accessibility object directly. | |
| 272 IAccessible* acc_obj = NULL; | |
| 273 HRESULT hr = | |
| 274 ::AccessibleObjectFromWindow(about_chrome_window->GetNativeWindow(), | |
| 275 OBJID_CLIENT, | |
| 276 IID_IAccessible, | |
| 277 reinterpret_cast<void**>(&acc_obj)); | |
| 278 ASSERT_EQ(S_OK, hr); | |
| 279 ASSERT_TRUE(NULL != acc_obj); | |
| 280 | |
| 281 TestAccessibilityInfo( | |
| 282 acc_obj, | |
| 283 UTF16ToWide(l10n_util::GetStringUTF16(IDS_ABOUT_CHROME_TITLE)), | |
| 284 ROLE_SYSTEM_DIALOG); | |
| 285 | |
| 286 acc_obj->Release(); | |
| 287 } | |
| OLD | NEW |