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 | |
29 protected: | 22 protected: |
30 IAccessible* GetRenderWidgetHostViewClientAccessible(); | 23 IAccessible* GetRenderWidgetHostViewClientAccessible(); |
31 }; | 24 }; |
32 | 25 |
33 class AccessibleChecker { | 26 class AccessibleChecker { |
34 public: | 27 public: |
35 AccessibleChecker(std::wstring expected_name, int32 expected_role); | 28 AccessibleChecker(std::wstring expected_name, int32 expected_role); |
36 AccessibleChecker(std::wstring expected_name, std::wstring expected_role); | 29 AccessibleChecker(std::wstring expected_name, std::wstring expected_role); |
37 | 30 |
38 // Append an AccessibleChecker that verifies accessibility information for | 31 // Append an AccessibleChecker that verifies accessibility information for |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 child_checker != children_.end(); | 167 child_checker != children_.end(); |
175 ++child_checker, ++child) { | 168 ++child_checker, ++child) { |
176 ScopedComPtr<IAccessible> child_accessible; | 169 ScopedComPtr<IAccessible> child_accessible; |
177 child_accessible.Attach(GetAccessibleFromResultVariant(parent, child)); | 170 child_accessible.Attach(GetAccessibleFromResultVariant(parent, child)); |
178 (*child_checker)->CheckAccessible(child_accessible); | 171 (*child_checker)->CheckAccessible(child_accessible); |
179 } | 172 } |
180 } | 173 } |
181 | 174 |
182 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 175 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
183 TestRendererAccessibilityTree) { | 176 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 |
184 GURL tree_url( | 191 GURL tree_url( |
185 "data:text/html,<html><head><title>Accessibility Win Test</title></head>" | 192 "data:text/html,<html><head><title>Accessibility Win Test</title></head>" |
186 "<body><input type='button' value='push' /><input type='checkbox' />" | 193 "<body><input type='button' value='push' /><input type='checkbox' />" |
187 "</body></html>"); | 194 "</body></html>"); |
188 browser()->OpenURL(tree_url, GURL(), CURRENT_TAB, PageTransition::TYPED); | 195 browser()->OpenURL(tree_url, GURL(), CURRENT_TAB, PageTransition::TYPED); |
189 ui_test_utils::WaitForNotification( | 196 ui_test_utils::WaitForNotification( |
190 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED); | 197 NotificationType::RENDER_VIEW_HOST_ACCESSIBILITY_TREE_UPDATED); |
191 | 198 |
192 ScopedComPtr<IAccessible> document_accessible( | 199 document_accessible = GetRenderWidgetHostViewClientAccessible(); |
193 GetRenderWidgetHostViewClientAccessible()); | |
194 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); | 200 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); |
195 | 201 |
196 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON); | 202 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON); |
197 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON); | 203 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON); |
198 | 204 |
199 AccessibleChecker grouping_checker(L"", L"div"); | 205 AccessibleChecker grouping_checker(L"", L"div"); |
200 grouping_checker.AppendExpectedChild(&button_checker); | 206 grouping_checker.AppendExpectedChild(&button_checker); |
201 grouping_checker.AppendExpectedChild(&checkbox_checker); | 207 grouping_checker.AppendExpectedChild(&checkbox_checker); |
202 | 208 |
203 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT); | 209 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT); |
204 document_checker.AppendExpectedChild(&grouping_checker); | 210 document_checker.AppendExpectedChild(&grouping_checker); |
205 | 211 |
206 // Check the accessible tree of the renderer. | 212 // Check the accessible tree of the renderer. |
207 document_checker.CheckAccessible(document_accessible); | 213 document_checker.CheckAccessible(document_accessible); |
208 | 214 |
209 // Check that document accessible has a parent accessible. | 215 // Check that document accessible has a parent accessible. |
210 ScopedComPtr<IDispatch> parent_dispatch; | 216 ScopedComPtr<IDispatch> parent_dispatch; |
211 HRESULT hr = document_accessible->get_accParent(parent_dispatch.Receive()); | 217 hr = document_accessible->get_accParent(parent_dispatch.Receive()); |
212 EXPECT_EQ(hr, S_OK); | 218 EXPECT_EQ(hr, S_OK); |
213 EXPECT_NE(parent_dispatch, reinterpret_cast<IDispatch*>(NULL)); | 219 EXPECT_NE(parent_dispatch, reinterpret_cast<IDispatch*>(NULL)); |
214 | 220 |
215 // Navigate to another page. | 221 // Navigate to another page. |
216 GURL about_url("about:"); | 222 GURL about_url("about:"); |
217 ui_test_utils::NavigateToURL(browser(), about_url); | 223 ui_test_utils::NavigateToURL(browser(), about_url); |
218 | 224 |
219 // Verify that the IAccessible reference still points to a valid object and | 225 // Verify that the IAccessible reference still points to a valid object and |
220 // that it calls to its methods fail since the tree is no longer valid after | 226 // that it calls to its methods fail since the tree is no longer valid after |
221 // the page navagation. | 227 // the page navagation. |
222 // Todo(ctguil): Currently this is giving a false positive because E_FAIL is | 228 // Todo(ctguil): Currently this is giving a false positive because E_FAIL is |
223 // returned when BrowserAccessibilityManager::RequestAccessibilityInfo fails | 229 // returned when BrowserAccessibilityManager::RequestAccessibilityInfo fails |
224 // since the previous render view host connection is lost. Verify that | 230 // since the previous render view host connection is lost. Verify that |
225 // instances are actually marked as invalid once the browse side cache is | 231 // instances are actually marked as invalid once the browse side cache is |
226 // checked in. | 232 // checked in. |
227 CComBSTR name; | 233 CComBSTR name; |
228 hr = document_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); | 234 hr = document_accessible->get_accName(CreateI4Variant(CHILDID_SELF), &name); |
229 ASSERT_EQ(E_FAIL, hr); | 235 ASSERT_EQ(E_FAIL, hr); |
230 } | 236 } |
231 } // namespace. | 237 } // namespace. |
OLD | NEW |