OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <atlbase.h> | 5 #include <atlbase.h> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/file_path.h" | 8 #include "base/file_path.h" |
9 #include "base/scoped_comptr_win.h" | 9 #include "base/scoped_comptr_win.h" |
10 #include "chrome/browser/browser.h" | 10 #include "chrome/browser/browser.h" |
11 #include "chrome/browser/browser_window.h" | 11 #include "chrome/browser/browser_window.h" |
12 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" | 12 #include "chrome/browser/renderer_host/render_widget_host_view_win.h" |
13 #include "chrome/browser/tab_contents/tab_contents.h" | 13 #include "chrome/browser/tab_contents/tab_contents.h" |
14 #include "chrome/common/chrome_switches.h" | 14 #include "chrome/common/chrome_switches.h" |
15 #include "chrome/common/notification_type.h" | 15 #include "chrome/common/notification_type.h" |
16 #include "chrome/test/in_process_browser_test.h" | 16 #include "chrome/test/in_process_browser_test.h" |
17 #include "chrome/test/ui_test_utils.h" | 17 #include "chrome/test/ui_test_utils.h" |
18 | 18 |
19 namespace { | 19 namespace { |
20 | 20 |
21 class AccessibilityWinBrowserTest : public InProcessBrowserTest { | 21 class AccessibilityWinBrowserTest : public InProcessBrowserTest { |
| 22 public: |
| 23 void SetUpCommandLine(CommandLine* command_line) { |
| 24 // Turns on the accessibility in the renderer. Off by default until |
| 25 // http://crbug.com/25564 is fixed. |
| 26 command_line->AppendSwitch(switches::kEnableRendererAccessibility); |
| 27 } |
| 28 |
22 protected: | 29 protected: |
23 IAccessible* GetRenderWidgetHostViewClientAccessible(); | 30 IAccessible* GetRenderWidgetHostViewClientAccessible(); |
24 }; | 31 }; |
25 | 32 |
26 class AccessibleChecker { | 33 class AccessibleChecker { |
27 public: | 34 public: |
28 AccessibleChecker(std::wstring expected_name, int32 expected_role); | 35 AccessibleChecker(std::wstring expected_name, int32 expected_role); |
29 AccessibleChecker(std::wstring expected_name, std::wstring expected_role); | 36 AccessibleChecker(std::wstring expected_name, std::wstring expected_role); |
30 | 37 |
31 // Append an AccessibleChecker that verifies accessibility information for | 38 // Append an AccessibleChecker that verifies accessibility information for |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 child_checker != children_.end(); | 174 child_checker != children_.end(); |
168 ++child_checker, ++child) { | 175 ++child_checker, ++child) { |
169 ScopedComPtr<IAccessible> child_accessible; | 176 ScopedComPtr<IAccessible> child_accessible; |
170 child_accessible.Attach(GetAccessibleFromResultVariant(parent, child)); | 177 child_accessible.Attach(GetAccessibleFromResultVariant(parent, child)); |
171 (*child_checker)->CheckAccessible(child_accessible); | 178 (*child_checker)->CheckAccessible(child_accessible); |
172 } | 179 } |
173 } | 180 } |
174 | 181 |
175 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 182 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
176 TestRendererAccessibilityTree) { | 183 TestRendererAccessibilityTree) { |
177 // By requesting an accessible chrome will believe a screen reader has been | |
178 // detected. | |
179 ScopedComPtr<IAccessible> document_accessible( | |
180 GetRenderWidgetHostViewClientAccessible()); | |
181 | |
182 // The initial accessible returned should have state STATE_SYSTEM_BUSY while | |
183 // the accessibility tree is being requested from the renderer. | |
184 VARIANT var_state; | |
185 HRESULT hr = document_accessible-> | |
186 get_accState(CreateI4Variant(CHILDID_SELF), &var_state); | |
187 EXPECT_EQ(hr, S_OK); | |
188 EXPECT_EQ(V_VT(&var_state), VT_I4); | |
189 EXPECT_EQ(V_I4(&var_state), STATE_SYSTEM_BUSY); | |
190 | |
191 GURL tree_url( | 184 GURL tree_url( |
192 "data:text/html,<html><head><title>Accessibility Win Test</title></head>" | 185 "data:text/html,<html><head><title>Accessibility Win Test</title></head>" |
193 "<body><input type='button' value='push' /><input type='checkbox' />" | 186 "<body><input type='button' value='push' /><input type='checkbox' />" |
194 "</body></html>"); | 187 "</body></html>"); |
195 browser()->OpenURL(tree_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 188 browser()->OpenURL(tree_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
196 ui_test_utils::WaitForNotification( | 189 ui_test_utils::WaitForNotification( |
197 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED); | 190 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED); |
198 | 191 |
199 document_accessible = GetRenderWidgetHostViewClientAccessible(); | 192 ScopedComPtr<IAccessible> document_accessible( |
| 193 GetRenderWidgetHostViewClientAccessible()); |
200 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); | 194 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); |
201 | 195 |
202 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON); | 196 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON); |
203 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON); | 197 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON); |
204 | 198 |
205 AccessibleChecker grouping_checker(L"", L"div"); | 199 AccessibleChecker grouping_checker(L"", L"div"); |
206 grouping_checker.AppendExpectedChild(&button_checker); | 200 grouping_checker.AppendExpectedChild(&button_checker); |
207 grouping_checker.AppendExpectedChild(&checkbox_checker); | 201 grouping_checker.AppendExpectedChild(&checkbox_checker); |
208 | 202 |
209 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT); | 203 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT); |
210 document_checker.AppendExpectedChild(&grouping_checker); | 204 document_checker.AppendExpectedChild(&grouping_checker); |
211 | 205 |
212 // Check the accessible tree of the renderer. | 206 // Check the accessible tree of the renderer. |
213 document_checker.CheckAccessible(document_accessible); | 207 document_checker.CheckAccessible(document_accessible); |
214 | 208 |
215 // Check that document accessible has a parent accessible. | 209 // Check that document accessible has a parent accessible. |
216 ScopedComPtr<IDispatch> parent_dispatch; | 210 ScopedComPtr<IDispatch> parent_dispatch; |
217 hr = document_accessible->get_accParent(parent_dispatch.Receive()); | 211 HRESULT hr = document_accessible->get_accParent(parent_dispatch.Receive()); |
218 EXPECT_EQ(hr, S_OK); | 212 EXPECT_EQ(hr, S_OK); |
219 EXPECT_NE(parent_dispatch, reinterpret_cast<IDispatch*>(NULL)); | 213 EXPECT_NE(parent_dispatch, reinterpret_cast<IDispatch*>(NULL)); |
220 | 214 |
221 // Navigate to another page. | 215 // Navigate to another page. |
222 GURL about_url("about:"); | 216 GURL about_url("about:"); |
223 ui_test_utils::NavigateToURL(browser(), about_url); | 217 ui_test_utils::NavigateToURL(browser(), about_url); |
224 | 218 |
225 // Verify that the IAccessible reference still points to a valid object and | 219 // Verify that the IAccessible reference still points to a valid object and |
226 // that it calls to its methods fail since the tree is no longer valid after | 220 // that it calls to its methods fail since the tree is no longer valid after |
227 // the page navagation. | 221 // the page navagation. |
228 // Todo(ctguil): Currently this is giving a false positive because E_FAIL is | 222 // Todo(ctguil): Currently this is giving a false positive because E_FAIL is |
229 // returned when BrowserAccessibilityManager::RequestAccessibilityInfo fails | 223 // returned when BrowserAccessibilityManager::RequestAccessibilityInfo fails |
230 // since the previous render view host connection is lost. Verify that | 224 // since the previous render view host connection is lost. Verify that |
231 // instances are actually marked as invalid once the browse side cache is | 225 // instances are actually marked as invalid once the browse side cache is |
232 // checked in. | 226 // checked in. |
233 CComBSTR name; | 227 CComBSTR name; |
234 hr = document_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); | 228 hr = document_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); |
235 ASSERT_EQ(E_FAIL, hr); | 229 ASSERT_EQ(E_FAIL, hr); |
236 } | 230 } |
237 } // namespace. | 231 } // namespace. |
OLD | NEW |