OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 <vector> | 5 #include <vector> |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/stringprintf.h" | |
9 #include "base/utf_string_conversions.h" | 8 #include "base/utf_string_conversions.h" |
10 #include "base/win/scoped_bstr.h" | 9 #include "base/win/scoped_bstr.h" |
11 #include "base/win/scoped_comptr.h" | 10 #include "base/win/scoped_comptr.h" |
12 #include "base/win/scoped_variant.h" | 11 #include "base/win/scoped_variant.h" |
13 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" | 12 #include "content/browser/accessibility/accessibility_tree_formatter_utils_win.h
" |
14 #include "content/browser/renderer_host/render_view_host_impl.h" | 13 #include "content/browser/renderer_host/render_view_host_impl.h" |
15 #include "content/public/browser/notification_service.h" | 14 #include "content/public/browser/notification_service.h" |
16 #include "content/public/browser/notification_types.h" | 15 #include "content/public/browser/notification_types.h" |
17 #include "content/public/browser/render_view_host.h" | 16 #include "content/public/browser/render_view_host.h" |
18 #include "content/public/browser/render_widget_host_view.h" | 17 #include "content/public/browser/render_widget_host_view.h" |
19 #include "content/public/browser/web_contents.h" | 18 #include "content/public/browser/web_contents.h" |
20 #include "content/public/common/url_constants.h" | 19 #include "content/public/common/url_constants.h" |
21 #include "content/public/test/test_utils.h" | 20 #include "content/public/test/test_utils.h" |
22 #include "content/shell/shell.h" | 21 #include "content/shell/shell.h" |
23 #include "content/test/content_browser_test.h" | 22 #include "content/test/content_browser_test.h" |
24 #include "content/test/content_browser_test_utils.h" | 23 #include "content/test/content_browser_test_utils.h" |
25 #include "third_party/iaccessible2/ia2_api_all.h" | 24 #include "third_party/iaccessible2/ia2_api_all.h" |
26 #include "third_party/isimpledom/ISimpleDOMNode.h" | 25 #include "third_party/isimpledom/ISimpleDOMNode.h" |
27 | 26 |
28 using std::auto_ptr; | |
29 using std::string; | |
30 using std::vector; | |
31 using std::wstring; | |
32 | |
33 // TODO(dmazzoni): Disabled accessibility tests on Win64. crbug.com/179717 | 27 // TODO(dmazzoni): Disabled accessibility tests on Win64. crbug.com/179717 |
34 #if defined(ARCH_CPU_X86_64) | 28 #if defined(ARCH_CPU_X86_64) |
35 #define MAYBE(x) DISABLED_##x | 29 #define MAYBE(x) DISABLED_##x |
36 #else | 30 #else |
37 #define MAYBE(x) x | 31 #define MAYBE(x) x |
38 #endif | 32 #endif |
39 | 33 |
40 namespace content { | 34 namespace content { |
41 | 35 |
42 namespace { | 36 namespace { |
43 | 37 |
44 class AccessibilityWinBrowserTest : public ContentBrowserTest { | |
45 public: | |
46 AccessibilityWinBrowserTest() {} | |
47 | 38 |
48 protected: | 39 // Helpers -------------------------------------------------------------------- |
49 void LoadInitialAccessibilityTreeFromHtml(string html); | |
50 IAccessible* GetRendererAccessible(); | |
51 void ExecuteScript(wstring script); | |
52 }; | |
53 | |
54 class AccessibleChecker { | |
55 public: | |
56 AccessibleChecker( | |
57 wstring expected_name, | |
58 int32 expected_role, | |
59 wstring expected_value); | |
60 AccessibleChecker( | |
61 wstring expected_name, | |
62 wstring expected_role, | |
63 int32 expected_ia2_role, | |
64 wstring expected_value); | |
65 AccessibleChecker( | |
66 wstring expected_name, | |
67 int32 expected_role, | |
68 int32 expected_ia2_role, | |
69 wstring expected_value); | |
70 | |
71 // Append an AccessibleChecker that verifies accessibility information for | |
72 // a child IAccessible. Order is important. | |
73 void AppendExpectedChild(AccessibleChecker* expected_child); | |
74 | |
75 // Check that the name and role of the given IAccessible instance and its | |
76 // descendants match the expected names and roles that this object was | |
77 // initialized with. | |
78 void CheckAccessible(IAccessible* accessible); | |
79 | |
80 // Set the expected value for this AccessibleChecker. | |
81 void SetExpectedValue(wstring expected_value); | |
82 | |
83 // Set the expected state for this AccessibleChecker. | |
84 void SetExpectedState(LONG expected_state); | |
85 | |
86 private: | |
87 void CheckAccessibleName(IAccessible* accessible); | |
88 void CheckAccessibleRole(IAccessible* accessible); | |
89 void CheckIA2Role(IAccessible* accessible); | |
90 void CheckAccessibleValue(IAccessible* accessible); | |
91 void CheckAccessibleState(IAccessible* accessible); | |
92 void CheckAccessibleChildren(IAccessible* accessible); | |
93 string16 RoleVariantToString(const base::win::ScopedVariant& role_variant); | |
94 | |
95 private: | |
96 typedef vector<AccessibleChecker*> AccessibleCheckerVector; | |
97 | |
98 // Expected accessible name. Checked against IAccessible::get_accName. | |
99 wstring name_; | |
100 | |
101 // Expected accessible role. Checked against IAccessible::get_accRole. | |
102 base::win::ScopedVariant role_; | |
103 | |
104 // Expected IAccessible2 role. Checked against IAccessible2::role. | |
105 int32 ia2_role_; | |
106 | |
107 // Expected accessible value. Checked against IAccessible::get_accValue. | |
108 wstring value_; | |
109 | |
110 // Expected accessible state. Checked against IAccessible::get_accState. | |
111 LONG state_; | |
112 | |
113 // Expected accessible children. Checked using IAccessible::get_accChildCount | |
114 // and ::AccessibleChildren. | |
115 AccessibleCheckerVector children_; | |
116 }; | |
117 | 40 |
118 base::win::ScopedComPtr<IAccessible> GetAccessibleFromResultVariant( | 41 base::win::ScopedComPtr<IAccessible> GetAccessibleFromResultVariant( |
119 IAccessible* parent, | 42 IAccessible* parent, |
120 VARIANT *var) { | 43 VARIANT* var) { |
121 base::win::ScopedComPtr<IAccessible> ptr; | 44 base::win::ScopedComPtr<IAccessible> ptr; |
122 switch (V_VT(var)) { | 45 switch (V_VT(var)) { |
123 case VT_DISPATCH: { | 46 case VT_DISPATCH: { |
124 IDispatch* dispatch = V_DISPATCH(var); | 47 IDispatch* dispatch = V_DISPATCH(var); |
125 if (dispatch) | 48 if (dispatch) |
126 ptr.QueryFrom(dispatch); | 49 ptr.QueryFrom(dispatch); |
127 break; | 50 break; |
128 } | 51 } |
129 | 52 |
130 case VT_I4: { | 53 case VT_I4: { |
131 base::win::ScopedComPtr<IDispatch> dispatch; | 54 base::win::ScopedComPtr<IDispatch> dispatch; |
132 HRESULT hr = parent->get_accChild(*var, dispatch.Receive()); | 55 HRESULT hr = parent->get_accChild(*var, dispatch.Receive()); |
133 EXPECT_TRUE(SUCCEEDED(hr)); | 56 EXPECT_TRUE(SUCCEEDED(hr)); |
134 if (dispatch.get()) | 57 if (dispatch.get()) |
135 dispatch.QueryInterface(ptr.Receive()); | 58 dispatch.QueryInterface(ptr.Receive()); |
136 break; | 59 break; |
137 } | 60 } |
138 } | 61 } |
139 return ptr; | 62 return ptr; |
140 } | 63 } |
141 | 64 |
142 HRESULT QueryIAccessible2(IAccessible* accessible, IAccessible2** accessible2) { | 65 HRESULT QueryIAccessible2(IAccessible* accessible, IAccessible2** accessible2) { |
143 // TODO(ctguil): For some reason querying the IAccessible2 interface from | 66 // TODO(ctguil): For some reason querying the IAccessible2 interface from |
144 // IAccessible fails. | 67 // IAccessible fails. |
145 base::win::ScopedComPtr<IServiceProvider> service_provider; | 68 base::win::ScopedComPtr<IServiceProvider> service_provider; |
146 HRESULT hr = accessible->QueryInterface(service_provider.Receive()); | 69 HRESULT hr = accessible->QueryInterface(service_provider.Receive()); |
147 if (FAILED(hr)) | 70 return SUCCEEDED(hr) ? |
148 return hr; | 71 service_provider->QueryService(IID_IAccessible2, accessible2) : hr; |
149 | |
150 hr = service_provider->QueryService(IID_IAccessible2, accessible2); | |
151 return hr; | |
152 } | 72 } |
153 | 73 |
154 // Recursively search through all of the descendants reachable from an | 74 // Recursively search through all of the descendants reachable from an |
155 // IAccessible node and return true if we find one with the given role | 75 // IAccessible node and return true if we find one with the given role |
156 // and name. | 76 // and name. |
157 void RecursiveFindNodeInAccessibilityTree( | 77 void RecursiveFindNodeInAccessibilityTree(IAccessible* node, |
158 IAccessible* node, | 78 int32 expected_role, |
159 int32 expected_role, | 79 const std::wstring& expected_name, |
160 const wstring& expected_name, | 80 int32 depth, |
161 int32 depth, | 81 bool* found) { |
162 bool* found) { | |
163 base::win::ScopedBstr name_bstr; | 82 base::win::ScopedBstr name_bstr; |
164 base::win::ScopedVariant childid_self(CHILDID_SELF); | 83 base::win::ScopedVariant childid_self(CHILDID_SELF); |
165 node->get_accName(childid_self, name_bstr.Receive()); | 84 node->get_accName(childid_self, name_bstr.Receive()); |
166 wstring name(name_bstr, name_bstr.Length()); | 85 std::wstring name(name_bstr, name_bstr.Length()); |
167 base::win::ScopedVariant role; | 86 base::win::ScopedVariant role; |
168 node->get_accRole(childid_self, role.Receive()); | 87 node->get_accRole(childid_self, role.Receive()); |
169 ASSERT_EQ(VT_I4, role.type()); | 88 ASSERT_EQ(VT_I4, role.type()); |
170 | 89 |
171 // Print the accessibility tree as we go, because if this test fails | 90 // Print the accessibility tree as we go, because if this test fails |
172 // on the bots, this is really helpful in figuring out why. | 91 // on the bots, this is really helpful in figuring out why. |
173 for (int i = 0; i < depth; i++) { | 92 for (int i = 0; i < depth; i++) |
174 printf(" "); | 93 printf(" "); |
175 } | |
176 printf("role=%d name=%s\n", V_I4(&role), WideToUTF8(name).c_str()); | 94 printf("role=%d name=%s\n", V_I4(&role), WideToUTF8(name).c_str()); |
177 | 95 |
178 if (expected_role == V_I4(&role) && expected_name == name) { | 96 if (expected_role == V_I4(&role) && expected_name == name) { |
179 *found = true; | 97 *found = true; |
180 return; | 98 return; |
181 } | 99 } |
182 | 100 |
183 LONG child_count = 0; | 101 LONG child_count = 0; |
184 HRESULT hr = node->get_accChildCount(&child_count); | 102 HRESULT hr = node->get_accChildCount(&child_count); |
185 ASSERT_EQ(S_OK, hr); | 103 ASSERT_EQ(S_OK, hr); |
(...skipping 11 matching lines...) Expand all Loading... |
197 if (child_accessible.get()) { | 115 if (child_accessible.get()) { |
198 RecursiveFindNodeInAccessibilityTree( | 116 RecursiveFindNodeInAccessibilityTree( |
199 child_accessible.get(), expected_role, expected_name, depth + 1, | 117 child_accessible.get(), expected_role, expected_name, depth + 1, |
200 found); | 118 found); |
201 if (*found) | 119 if (*found) |
202 return; | 120 return; |
203 } | 121 } |
204 } | 122 } |
205 } | 123 } |
206 | 124 |
| 125 |
| 126 // AccessibilityWinBrowserTest ------------------------------------------------ |
| 127 |
| 128 class AccessibilityWinBrowserTest : public ContentBrowserTest { |
| 129 public: |
| 130 AccessibilityWinBrowserTest(); |
| 131 virtual ~AccessibilityWinBrowserTest(); |
| 132 |
| 133 protected: |
| 134 void LoadInitialAccessibilityTreeFromHtml(const std::string& html); |
| 135 IAccessible* GetRendererAccessible(); |
| 136 void ExecuteScript(const std::wstring& script); |
| 137 |
| 138 private: |
| 139 DISALLOW_COPY_AND_ASSIGN(AccessibilityWinBrowserTest); |
| 140 }; |
| 141 |
| 142 AccessibilityWinBrowserTest::AccessibilityWinBrowserTest() { |
| 143 } |
| 144 |
| 145 AccessibilityWinBrowserTest::~AccessibilityWinBrowserTest() { |
| 146 } |
| 147 |
207 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml( | 148 void AccessibilityWinBrowserTest::LoadInitialAccessibilityTreeFromHtml( |
208 string html) { | 149 const std::string& html) { |
209 // Load the html using a data url and wait for the navigation to finish. | 150 // Load the html using a data url and wait for the navigation to finish. |
210 GURL html_data_url(string("data:text/html,") + html); | 151 GURL html_data_url("data:text/html," + html); |
211 NavigateToURL(shell(), html_data_url); | 152 NavigateToURL(shell(), html_data_url); |
212 | 153 |
213 // At this point, renderer accessibility is off and the page has completed | 154 // At this point, renderer accessibility is off and the page has completed |
214 // loading. (Both of these must be strictly true or there will be test | 155 // loading. (Both of these must be strictly true or there will be test |
215 // flakiness.) Now call GetRendererAccessible, which will trigger | 156 // flakiness.) Now call GetRendererAccessible, which will trigger |
216 // changing the accessibility mode to AccessibilityModeComplete. When | 157 // changing the accessibility mode to AccessibilityModeComplete. When |
217 // the renderer switches accessibility on, it will send a Layout Complete | 158 // the renderer switches accessibility on, it will send a Layout Complete |
218 // accessibility notification containing the full accessibility tree, which | 159 // accessibility notification containing the full accessibility tree, which |
219 // we can wait for. | 160 // we can wait for. |
220 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 161 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
221 WebContents* web_contents = shell()->web_contents(); | 162 WebContents* web_contents = shell()->web_contents(); |
222 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 163 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
223 web_contents->GetRenderViewHost()); | 164 web_contents->GetRenderViewHost()); |
224 view_host->SetAccessibilityLayoutCompleteCallbackForTesting( | 165 view_host->SetAccessibilityLayoutCompleteCallbackForTesting( |
225 loop_runner->QuitClosure()); | 166 loop_runner->QuitClosure()); |
226 GetRendererAccessible(); | 167 GetRendererAccessible(); |
227 loop_runner->Run(); | 168 loop_runner->Run(); |
228 } | 169 } |
229 | 170 |
230 // Retrieve the MSAA client accessibility object for the Render Widget Host View | 171 // Retrieve the MSAA client accessibility object for the Render Widget Host View |
231 // of the selected tab. | 172 // of the selected tab. |
232 IAccessible* | 173 IAccessible* AccessibilityWinBrowserTest::GetRendererAccessible() { |
233 AccessibilityWinBrowserTest::GetRendererAccessible() { | |
234 HWND hwnd_render_widget_host_view = | 174 HWND hwnd_render_widget_host_view = |
235 shell()->web_contents()->GetRenderWidgetHostView()->GetNativeView(); | 175 shell()->web_contents()->GetRenderWidgetHostView()->GetNativeView(); |
236 | 176 |
237 // Invoke windows screen reader detection by sending the WM_GETOBJECT message | 177 // Invoke windows screen reader detection by sending the WM_GETOBJECT message |
238 // with kIdCustom as the LPARAM. | 178 // with kIdCustom as the LPARAM. |
239 const int32 kIdCustom = 1; | 179 const int32 kIdCustom = 1; |
240 SendMessage( | 180 SendMessage( |
241 hwnd_render_widget_host_view, WM_GETOBJECT, OBJID_CLIENT, kIdCustom); | 181 hwnd_render_widget_host_view, WM_GETOBJECT, OBJID_CLIENT, kIdCustom); |
242 | 182 |
243 IAccessible* accessible; | 183 IAccessible* accessible; |
244 HRESULT hr = AccessibleObjectFromWindow( | 184 HRESULT hr = AccessibleObjectFromWindow( |
245 hwnd_render_widget_host_view, OBJID_CLIENT, | 185 hwnd_render_widget_host_view, OBJID_CLIENT, |
246 IID_IAccessible, reinterpret_cast<void**>(&accessible)); | 186 IID_IAccessible, reinterpret_cast<void**>(&accessible)); |
247 | 187 |
248 EXPECT_EQ(S_OK, hr); | 188 EXPECT_EQ(S_OK, hr); |
249 EXPECT_NE(accessible, reinterpret_cast<IAccessible*>(NULL)); | 189 EXPECT_NE(accessible, reinterpret_cast<IAccessible*>(NULL)); |
250 | 190 |
251 return accessible; | 191 return accessible; |
252 } | 192 } |
253 | 193 |
254 void AccessibilityWinBrowserTest::ExecuteScript(wstring script) { | 194 void AccessibilityWinBrowserTest::ExecuteScript(const std::wstring& script) { |
255 shell()->web_contents()->GetRenderViewHost()-> | 195 shell()->web_contents()->GetRenderViewHost()->ExecuteJavascriptInWebFrame( |
256 ExecuteJavascriptInWebFrame(L"", script); | 196 std::wstring(), script); |
257 } | 197 } |
258 | 198 |
259 // This constructor can be used if IA2 role will be the same as MSAA role | 199 |
260 AccessibleChecker::AccessibleChecker( | 200 // AccessibleChecker ---------------------------------------------------------- |
261 wstring expected_name, int32 expected_role, wstring expected_value) : | 201 |
262 name_(expected_name), | 202 class AccessibleChecker { |
263 role_(expected_role), | 203 public: |
264 ia2_role_(expected_role), | 204 // This constructor can be used if the IA2 role will be the same as the MSAA |
265 value_(expected_value), | 205 // role. |
266 state_(-1) { | 206 AccessibleChecker(const std::wstring& expected_name, |
| 207 int32 expected_role, |
| 208 const std::wstring& expected_value); |
| 209 AccessibleChecker(const std::wstring& expected_name, |
| 210 int32 expected_role, |
| 211 int32 expected_ia2_role, |
| 212 const std::wstring& expected_value); |
| 213 AccessibleChecker(const std::wstring& expected_name, |
| 214 const std::wstring& expected_role, |
| 215 int32 expected_ia2_role, |
| 216 const std::wstring& expected_value); |
| 217 |
| 218 // Append an AccessibleChecker that verifies accessibility information for |
| 219 // a child IAccessible. Order is important. |
| 220 void AppendExpectedChild(AccessibleChecker* expected_child); |
| 221 |
| 222 // Check that the name and role of the given IAccessible instance and its |
| 223 // descendants match the expected names and roles that this object was |
| 224 // initialized with. |
| 225 void CheckAccessible(IAccessible* accessible); |
| 226 |
| 227 // Set the expected value for this AccessibleChecker. |
| 228 void SetExpectedValue(const std::wstring& expected_value); |
| 229 |
| 230 // Set the expected state for this AccessibleChecker. |
| 231 void SetExpectedState(LONG expected_state); |
| 232 |
| 233 private: |
| 234 typedef std::vector<AccessibleChecker*> AccessibleCheckerVector; |
| 235 |
| 236 void CheckAccessibleName(IAccessible* accessible); |
| 237 void CheckAccessibleRole(IAccessible* accessible); |
| 238 void CheckIA2Role(IAccessible* accessible); |
| 239 void CheckAccessibleValue(IAccessible* accessible); |
| 240 void CheckAccessibleState(IAccessible* accessible); |
| 241 void CheckAccessibleChildren(IAccessible* accessible); |
| 242 string16 RoleVariantToString(const base::win::ScopedVariant& role); |
| 243 |
| 244 // Expected accessible name. Checked against IAccessible::get_accName. |
| 245 std::wstring name_; |
| 246 |
| 247 // Expected accessible role. Checked against IAccessible::get_accRole. |
| 248 base::win::ScopedVariant role_; |
| 249 |
| 250 // Expected IAccessible2 role. Checked against IAccessible2::role. |
| 251 int32 ia2_role_; |
| 252 |
| 253 // Expected accessible value. Checked against IAccessible::get_accValue. |
| 254 std::wstring value_; |
| 255 |
| 256 // Expected accessible state. Checked against IAccessible::get_accState. |
| 257 LONG state_; |
| 258 |
| 259 // Expected accessible children. Checked using IAccessible::get_accChildCount |
| 260 // and ::AccessibleChildren. |
| 261 AccessibleCheckerVector children_; |
| 262 }; |
| 263 |
| 264 AccessibleChecker::AccessibleChecker(const std::wstring& expected_name, |
| 265 int32 expected_role, |
| 266 const std::wstring& expected_value) |
| 267 : name_(expected_name), |
| 268 role_(expected_role), |
| 269 ia2_role_(expected_role), |
| 270 value_(expected_value), |
| 271 state_(-1) { |
267 } | 272 } |
268 | 273 |
269 AccessibleChecker::AccessibleChecker(wstring expected_name, | 274 AccessibleChecker::AccessibleChecker(const std::wstring& expected_name, |
270 int32 expected_role, | 275 int32 expected_role, |
271 int32 expected_ia2_role, | 276 int32 expected_ia2_role, |
272 wstring expected_value) : | 277 const std::wstring& expected_value) |
273 name_(expected_name), | 278 : name_(expected_name), |
274 role_(expected_role), | 279 role_(expected_role), |
275 ia2_role_(expected_ia2_role), | 280 ia2_role_(expected_ia2_role), |
276 value_(expected_value), | 281 value_(expected_value), |
277 state_(-1) { | 282 state_(-1) { |
278 } | 283 } |
279 | 284 |
280 AccessibleChecker::AccessibleChecker(wstring expected_name, | 285 AccessibleChecker::AccessibleChecker(const std::wstring& expected_name, |
281 wstring expected_role, | 286 const std::wstring& expected_role, |
282 int32 expected_ia2_role, | 287 int32 expected_ia2_role, |
283 wstring expected_value) : | 288 const std::wstring& expected_value) |
284 name_(expected_name), | 289 : name_(expected_name), |
285 role_(expected_role.c_str()), | 290 role_(expected_role.c_str()), |
286 ia2_role_(expected_ia2_role), | 291 ia2_role_(expected_ia2_role), |
287 value_(expected_value), | 292 value_(expected_value), |
288 state_(-1) { | 293 state_(-1) { |
289 } | 294 } |
290 | 295 |
291 void AccessibleChecker::AppendExpectedChild( | 296 void AccessibleChecker::AppendExpectedChild( |
292 AccessibleChecker* expected_child) { | 297 AccessibleChecker* expected_child) { |
293 children_.push_back(expected_child); | 298 children_.push_back(expected_child); |
294 } | 299 } |
295 | 300 |
296 void AccessibleChecker::CheckAccessible(IAccessible* accessible) { | 301 void AccessibleChecker::CheckAccessible(IAccessible* accessible) { |
297 SCOPED_TRACE(base::StringPrintf( | 302 SCOPED_TRACE("while checking " + UTF16ToUTF8(RoleVariantToString(role_))); |
298 "while checking %s", | |
299 UTF16ToUTF8(RoleVariantToString(role_)).c_str())); | |
300 CheckAccessibleName(accessible); | 303 CheckAccessibleName(accessible); |
301 CheckAccessibleRole(accessible); | 304 CheckAccessibleRole(accessible); |
302 CheckIA2Role(accessible); | 305 CheckIA2Role(accessible); |
303 CheckAccessibleValue(accessible); | 306 CheckAccessibleValue(accessible); |
304 CheckAccessibleState(accessible); | 307 CheckAccessibleState(accessible); |
305 CheckAccessibleChildren(accessible); | 308 CheckAccessibleChildren(accessible); |
306 } | 309 } |
307 | 310 |
308 void AccessibleChecker::SetExpectedValue(wstring expected_value) { | 311 void AccessibleChecker::SetExpectedValue(const std::wstring& expected_value) { |
309 value_ = expected_value; | 312 value_ = expected_value; |
310 } | 313 } |
311 | 314 |
312 void AccessibleChecker::SetExpectedState(LONG expected_state) { | 315 void AccessibleChecker::SetExpectedState(LONG expected_state) { |
313 state_ = expected_state; | 316 state_ = expected_state; |
314 } | 317 } |
315 | 318 |
316 void AccessibleChecker::CheckAccessibleName(IAccessible* accessible) { | 319 void AccessibleChecker::CheckAccessibleName(IAccessible* accessible) { |
317 base::win::ScopedBstr name; | 320 base::win::ScopedBstr name; |
318 base::win::ScopedVariant childid_self(CHILDID_SELF); | 321 base::win::ScopedVariant childid_self(CHILDID_SELF); |
319 HRESULT hr = accessible->get_accName(childid_self, name.Receive()); | 322 HRESULT hr = accessible->get_accName(childid_self, name.Receive()); |
320 | 323 |
321 if (name_.empty()) { | 324 if (name_.empty()) { |
322 // If the object doesn't have name S_FALSE should be returned. | 325 // If the object doesn't have name S_FALSE should be returned. |
323 EXPECT_EQ(hr, S_FALSE); | 326 EXPECT_EQ(S_FALSE, hr); |
324 } else { | 327 } else { |
325 // Test that the correct string was returned. | 328 // Test that the correct string was returned. |
326 EXPECT_EQ(S_OK, hr); | 329 EXPECT_EQ(S_OK, hr); |
327 EXPECT_STREQ(name_.c_str(), | 330 EXPECT_EQ(name_, std::wstring(name, name.Length())); |
328 wstring(name, name.Length()).c_str()); | |
329 } | 331 } |
330 } | 332 } |
331 | 333 |
332 void AccessibleChecker::CheckAccessibleRole(IAccessible* accessible) { | 334 void AccessibleChecker::CheckAccessibleRole(IAccessible* accessible) { |
333 base::win::ScopedVariant var_role; | 335 base::win::ScopedVariant role; |
334 base::win::ScopedVariant childid_self(CHILDID_SELF); | 336 base::win::ScopedVariant childid_self(CHILDID_SELF); |
335 HRESULT hr = accessible->get_accRole(childid_self, var_role.Receive()); | 337 HRESULT hr = accessible->get_accRole(childid_self, role.Receive()); |
336 ASSERT_EQ(S_OK, hr); | 338 ASSERT_EQ(S_OK, hr); |
337 EXPECT_EQ(0, role_.Compare(var_role)) | 339 EXPECT_EQ(0, role_.Compare(role)) |
338 << "Expected role: " << RoleVariantToString(role_) | 340 << "Expected role: " << RoleVariantToString(role_) |
339 << "\nGot role: " << RoleVariantToString(var_role); | 341 << "\nGot role: " << RoleVariantToString(role); |
340 } | 342 } |
341 | 343 |
342 void AccessibleChecker::CheckIA2Role(IAccessible* accessible) { | 344 void AccessibleChecker::CheckIA2Role(IAccessible* accessible) { |
343 base::win::ScopedComPtr<IAccessible2> accessible2; | 345 base::win::ScopedComPtr<IAccessible2> accessible2; |
344 HRESULT hr = QueryIAccessible2(accessible, accessible2.Receive()); | 346 HRESULT hr = QueryIAccessible2(accessible, accessible2.Receive()); |
345 ASSERT_EQ(S_OK, hr); | 347 ASSERT_EQ(S_OK, hr); |
346 long ia2_role = 0; | 348 long ia2_role = 0; |
347 hr = accessible2->role(&ia2_role); | 349 hr = accessible2->role(&ia2_role); |
348 ASSERT_EQ(S_OK, hr); | 350 ASSERT_EQ(S_OK, hr); |
349 EXPECT_EQ(ia2_role_, ia2_role); | 351 EXPECT_EQ(ia2_role_, ia2_role) |
350 if (ia2_role_ != ia2_role) { | 352 << "Expected ia2 role: " << IAccessible2RoleToString(ia2_role_) |
351 LOG(ERROR) << "Expected ia2 role: " << | 353 << "\nGot ia2 role: " << IAccessible2RoleToString(ia2_role); |
352 IAccessible2RoleToString(ia2_role_); | |
353 LOG(ERROR) << "Got ia2 role: " << | |
354 IAccessible2RoleToString(ia2_role); | |
355 } | |
356 } | 354 } |
357 | 355 |
358 void AccessibleChecker::CheckAccessibleValue(IAccessible* accessible) { | 356 void AccessibleChecker::CheckAccessibleValue(IAccessible* accessible) { |
359 // Don't check the value if if's a DOCUMENT role, because the value | 357 // Don't check the value if if's a DOCUMENT role, because the value |
360 // is supposed to be the url (and we don't keep track of that in the | 358 // is supposed to be the url (and we don't keep track of that in the |
361 // test expectations). | 359 // test expectations). |
362 base::win::ScopedVariant var_role; | 360 base::win::ScopedVariant role; |
363 base::win::ScopedVariant childid_self(CHILDID_SELF); | 361 base::win::ScopedVariant childid_self(CHILDID_SELF); |
364 HRESULT hr = accessible->get_accRole(childid_self, var_role.Receive()); | 362 HRESULT hr = accessible->get_accRole(childid_self, role.Receive()); |
365 ASSERT_EQ(S_OK, hr); | 363 ASSERT_EQ(S_OK, hr); |
366 if (var_role.type() == VT_I4 && | 364 if (role.type() == VT_I4 && V_I4(&role) == ROLE_SYSTEM_DOCUMENT) |
367 V_I4(&var_role) == ROLE_SYSTEM_DOCUMENT) { | |
368 return; | 365 return; |
369 } | |
370 | 366 |
371 // Get the value. | 367 // Get the value. |
372 base::win::ScopedBstr value; | 368 base::win::ScopedBstr value; |
373 hr = accessible->get_accValue(childid_self, value.Receive()); | 369 hr = accessible->get_accValue(childid_self, value.Receive()); |
374 EXPECT_EQ(S_OK, hr); | 370 EXPECT_EQ(S_OK, hr); |
375 | 371 |
376 // Test that the correct string was returned. | 372 // Test that the correct string was returned. |
377 EXPECT_STREQ(value_.c_str(), | 373 EXPECT_EQ(value_, std::wstring(value, value.Length())); |
378 wstring(value, value.Length()).c_str()); | |
379 } | 374 } |
380 | 375 |
381 void AccessibleChecker::CheckAccessibleState(IAccessible* accessible) { | 376 void AccessibleChecker::CheckAccessibleState(IAccessible* accessible) { |
382 if (state_ < 0) | 377 if (state_ < 0) |
383 return; | 378 return; |
384 | 379 |
385 base::win::ScopedVariant var_state; | 380 base::win::ScopedVariant state; |
386 base::win::ScopedVariant childid_self(CHILDID_SELF); | 381 base::win::ScopedVariant childid_self(CHILDID_SELF); |
387 HRESULT hr = accessible->get_accState(childid_self, var_state.Receive()); | 382 HRESULT hr = accessible->get_accState(childid_self, state.Receive()); |
388 EXPECT_EQ(S_OK, hr); | 383 EXPECT_EQ(S_OK, hr); |
389 ASSERT_EQ(VT_I4, var_state.type()); | 384 ASSERT_EQ(VT_I4, state.type()); |
390 LONG obj_state = V_I4(&var_state); | 385 LONG obj_state = V_I4(&state); |
391 // Avoid flakiness. The "offscreen" state depends on whether the browser | 386 // Avoid flakiness. The "offscreen" state depends on whether the browser |
392 // window is frontmost or not, and "hottracked" depends on whether the | 387 // window is frontmost or not, and "hottracked" depends on whether the |
393 // mouse cursor happens to be over the element. | 388 // mouse cursor happens to be over the element. |
394 obj_state &= ~STATE_SYSTEM_OFFSCREEN; | 389 obj_state &= ~(STATE_SYSTEM_OFFSCREEN | STATE_SYSTEM_HOTTRACKED); |
395 obj_state &= ~STATE_SYSTEM_HOTTRACKED; | 390 EXPECT_EQ(state_, obj_state) |
396 EXPECT_EQ(state_, obj_state); | 391 << "Expected state: " << IAccessibleStateToString(state_) |
397 if (state_ != obj_state) { | 392 << "\nGot state: " << IAccessibleStateToString(obj_state); |
398 LOG(ERROR) << "Expected state: " << IAccessibleStateToString(state_); | |
399 LOG(ERROR) << "Got state: " << IAccessibleStateToString(V_I4(&var_state)); | |
400 } | |
401 } | 393 } |
402 | 394 |
403 void AccessibleChecker::CheckAccessibleChildren(IAccessible* parent) { | 395 void AccessibleChecker::CheckAccessibleChildren(IAccessible* parent) { |
404 LONG child_count = 0; | 396 LONG child_count = 0; |
405 HRESULT hr = parent->get_accChildCount(&child_count); | 397 HRESULT hr = parent->get_accChildCount(&child_count); |
406 EXPECT_EQ(S_OK, hr); | 398 EXPECT_EQ(S_OK, hr); |
407 ASSERT_EQ(child_count, children_.size()); | 399 ASSERT_EQ(child_count, children_.size()); |
408 | 400 |
409 auto_ptr<VARIANT> child_array(new VARIANT[child_count]); | 401 scoped_ptr<VARIANT[]> child_array(new VARIANT[child_count]); |
410 LONG obtained_count = 0; | 402 LONG obtained_count = 0; |
411 hr = AccessibleChildren(parent, 0, child_count, | 403 hr = AccessibleChildren(parent, 0, child_count, |
412 child_array.get(), &obtained_count); | 404 child_array.get(), &obtained_count); |
413 ASSERT_EQ(S_OK, hr); | 405 ASSERT_EQ(S_OK, hr); |
414 ASSERT_EQ(child_count, obtained_count); | 406 ASSERT_EQ(child_count, obtained_count); |
415 | 407 |
416 VARIANT* child = child_array.get(); | 408 VARIANT* child = child_array.get(); |
417 for (AccessibleCheckerVector::iterator child_checker = children_.begin(); | 409 for (AccessibleCheckerVector::iterator child_checker = children_.begin(); |
418 child_checker != children_.end(); | 410 child_checker != children_.end(); |
419 ++child_checker, ++child) { | 411 ++child_checker, ++child) { |
420 base::win::ScopedComPtr<IAccessible> child_accessible( | 412 base::win::ScopedComPtr<IAccessible> child_accessible( |
421 GetAccessibleFromResultVariant(parent, child)); | 413 GetAccessibleFromResultVariant(parent, child)); |
422 ASSERT_TRUE(child_accessible.get()); | 414 ASSERT_TRUE(child_accessible.get()); |
423 (*child_checker)->CheckAccessible(child_accessible); | 415 (*child_checker)->CheckAccessible(child_accessible); |
424 } | 416 } |
425 } | 417 } |
426 | 418 |
427 string16 AccessibleChecker::RoleVariantToString( | 419 string16 AccessibleChecker::RoleVariantToString( |
428 const base::win::ScopedVariant& role_variant) { | 420 const base::win::ScopedVariant& role) { |
429 if (role_variant.type() == VT_I4) | 421 if (role.type() == VT_I4) |
430 return IAccessibleRoleToString(V_I4(&role_variant)); | 422 return IAccessibleRoleToString(V_I4(&role)); |
431 else if (role_variant.type() == VT_BSTR) | 423 if (role.type() == VT_BSTR) |
432 return string16(V_BSTR(&role_variant), SysStringLen(V_BSTR(&role_variant))); | 424 return string16(V_BSTR(&role), SysStringLen(V_BSTR(&role))); |
433 return string16(); | 425 return string16(); |
434 } | 426 } |
435 | 427 |
| 428 } // namespace |
| 429 |
| 430 |
| 431 // Tests ---------------------------------------------------------------------- |
| 432 |
436 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 433 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
437 MAYBE(TestBusyAccessibilityTree)) { | 434 MAYBE(TestBusyAccessibilityTree)) { |
438 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | 435 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); |
439 | 436 |
440 // The initial accessible returned should have state STATE_SYSTEM_BUSY while | 437 // The initial accessible returned should have state STATE_SYSTEM_BUSY while |
441 // the accessibility tree is being requested from the renderer. | 438 // the accessibility tree is being requested from the renderer. |
442 AccessibleChecker document1_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 439 AccessibleChecker document1_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 440 std::wstring()); |
443 document1_checker.SetExpectedState( | 441 document1_checker.SetExpectedState( |
444 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED | | 442 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED | |
445 STATE_SYSTEM_BUSY); | 443 STATE_SYSTEM_BUSY); |
446 document1_checker.CheckAccessible(GetRendererAccessible()); | 444 document1_checker.CheckAccessible(GetRendererAccessible()); |
447 } | 445 } |
448 | 446 |
449 // Flaky, http://crbug.com/167320 . | 447 // Flaky, http://crbug.com/167320 . |
450 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 448 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
451 DISABLED_TestRendererAccessibilityTree) { | 449 DISABLED_TestRendererAccessibilityTree) { |
452 LoadInitialAccessibilityTreeFromHtml( | 450 LoadInitialAccessibilityTreeFromHtml( |
453 "<html><head><title>Accessibility Win Test</title></head>" | 451 "<html><head><title>Accessibility Win Test</title></head>" |
454 "<body><input type='button' value='push' /><input type='checkbox' />" | 452 "<body><input type='button' value='push' /><input type='checkbox' />" |
455 "</body></html>"); | 453 "</body></html>"); |
456 | 454 |
457 // Check the browser's copy of the renderer accessibility tree. | 455 // Check the browser's copy of the renderer accessibility tree. |
458 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON, L""); | 456 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON, |
459 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON, L""); | 457 std::wstring()); |
460 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 458 AccessibleChecker checkbox_checker(std::wstring(), ROLE_SYSTEM_CHECKBUTTON, |
461 AccessibleChecker document2_checker( | 459 std::wstring()); |
462 L"Accessibility Win Test", ROLE_SYSTEM_DOCUMENT, L""); | 460 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
| 461 std::wstring()); |
| 462 AccessibleChecker document2_checker(L"Accessibility Win Test", |
| 463 ROLE_SYSTEM_DOCUMENT, std::wstring()); |
463 body_checker.AppendExpectedChild(&button_checker); | 464 body_checker.AppendExpectedChild(&button_checker); |
464 body_checker.AppendExpectedChild(&checkbox_checker); | 465 body_checker.AppendExpectedChild(&checkbox_checker); |
465 document2_checker.AppendExpectedChild(&body_checker); | 466 document2_checker.AppendExpectedChild(&body_checker); |
466 document2_checker.CheckAccessible(GetRendererAccessible()); | 467 document2_checker.CheckAccessible(GetRendererAccessible()); |
467 | 468 |
468 // Check that document accessible has a parent accessible. | 469 // Check that document accessible has a parent accessible. |
469 base::win::ScopedComPtr<IAccessible> document_accessible( | 470 base::win::ScopedComPtr<IAccessible> document_accessible( |
470 GetRendererAccessible()); | 471 GetRendererAccessible()); |
471 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); | 472 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); |
472 base::win::ScopedComPtr<IDispatch> parent_dispatch; | 473 base::win::ScopedComPtr<IDispatch> parent_dispatch; |
(...skipping 14 matching lines...) Expand all Loading... |
487 } | 488 } |
488 | 489 |
489 // Periodically failing. See crbug.com/145537 | 490 // Periodically failing. See crbug.com/145537 |
490 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 491 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
491 DISABLED_TestNotificationActiveDescendantChanged) { | 492 DISABLED_TestNotificationActiveDescendantChanged) { |
492 LoadInitialAccessibilityTreeFromHtml( | 493 LoadInitialAccessibilityTreeFromHtml( |
493 "<ul tabindex='-1' role='radiogroup' aria-label='ul'>" | 494 "<ul tabindex='-1' role='radiogroup' aria-label='ul'>" |
494 "<li id='li'>li</li></ul>"); | 495 "<li id='li'>li</li></ul>"); |
495 | 496 |
496 // Check the browser's copy of the renderer accessibility tree. | 497 // Check the browser's copy of the renderer accessibility tree. |
497 AccessibleChecker list_marker_checker(L"\x2022", ROLE_SYSTEM_TEXT, L""); | 498 AccessibleChecker list_marker_checker(L"\x2022", ROLE_SYSTEM_TEXT, |
498 AccessibleChecker static_text_checker(L"li", ROLE_SYSTEM_TEXT, L""); | 499 std::wstring()); |
499 AccessibleChecker list_item_checker(L"", ROLE_SYSTEM_LISTITEM, L""); | 500 AccessibleChecker static_text_checker(L"li", ROLE_SYSTEM_TEXT, |
500 list_item_checker.SetExpectedState( | 501 std::wstring()); |
501 STATE_SYSTEM_READONLY); | 502 AccessibleChecker list_item_checker(std::wstring(), ROLE_SYSTEM_LISTITEM, |
| 503 std::wstring()); |
| 504 list_item_checker.SetExpectedState(STATE_SYSTEM_READONLY); |
502 AccessibleChecker radio_group_checker(L"ul", ROLE_SYSTEM_GROUPING, | 505 AccessibleChecker radio_group_checker(L"ul", ROLE_SYSTEM_GROUPING, |
503 IA2_ROLE_SECTION, L""); | 506 IA2_ROLE_SECTION, std::wstring()); |
504 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 507 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
505 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 508 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 509 std::wstring()); |
506 list_item_checker.AppendExpectedChild(&list_marker_checker); | 510 list_item_checker.AppendExpectedChild(&list_marker_checker); |
507 list_item_checker.AppendExpectedChild(&static_text_checker); | 511 list_item_checker.AppendExpectedChild(&static_text_checker); |
508 radio_group_checker.AppendExpectedChild(&list_item_checker); | 512 radio_group_checker.AppendExpectedChild(&list_item_checker); |
509 document_checker.AppendExpectedChild(&radio_group_checker); | 513 document_checker.AppendExpectedChild(&radio_group_checker); |
510 document_checker.CheckAccessible(GetRendererAccessible()); | 514 document_checker.CheckAccessible(GetRendererAccessible()); |
511 | 515 |
512 // Set focus to the radio group. | 516 // Set focus to the radio group. |
513 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 517 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
514 WebContents* web_contents = shell()->web_contents(); | 518 WebContents* web_contents = shell()->web_contents(); |
515 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 519 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
(...skipping 22 matching lines...) Expand all Loading... |
538 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 542 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
539 document_checker.CheckAccessible(GetRendererAccessible()); | 543 document_checker.CheckAccessible(GetRendererAccessible()); |
540 } | 544 } |
541 | 545 |
542 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 546 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
543 MAYBE(TestNotificationCheckedStateChanged)) { | 547 MAYBE(TestNotificationCheckedStateChanged)) { |
544 LoadInitialAccessibilityTreeFromHtml( | 548 LoadInitialAccessibilityTreeFromHtml( |
545 "<body><input type='checkbox' /></body>"); | 549 "<body><input type='checkbox' /></body>"); |
546 | 550 |
547 // Check the browser's copy of the renderer accessibility tree. | 551 // Check the browser's copy of the renderer accessibility tree. |
548 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON, L""); | 552 AccessibleChecker checkbox_checker(std::wstring(), ROLE_SYSTEM_CHECKBUTTON, |
| 553 std::wstring()); |
549 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 554 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
550 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 555 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
551 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 556 std::wstring()); |
| 557 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 558 std::wstring()); |
552 body_checker.AppendExpectedChild(&checkbox_checker); | 559 body_checker.AppendExpectedChild(&checkbox_checker); |
553 document_checker.AppendExpectedChild(&body_checker); | 560 document_checker.AppendExpectedChild(&body_checker); |
554 document_checker.CheckAccessible(GetRendererAccessible()); | 561 document_checker.CheckAccessible(GetRendererAccessible()); |
555 | 562 |
556 // Check the checkbox. | 563 // Check the checkbox. |
557 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 564 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
558 WebContents* web_contents = shell()->web_contents(); | 565 WebContents* web_contents = shell()->web_contents(); |
559 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 566 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
560 web_contents->GetRenderViewHost()); | 567 web_contents->GetRenderViewHost()); |
561 view_host->SetAccessibilityOtherCallbackForTesting( | 568 view_host->SetAccessibilityOtherCallbackForTesting( |
562 loop_runner->QuitClosure()); | 569 loop_runner->QuitClosure()); |
563 ExecuteScript(L"document.body.children[0].checked=true"); | 570 ExecuteScript(L"document.body.children[0].checked=true"); |
564 loop_runner->Run(); | 571 loop_runner->Run(); |
565 | 572 |
566 // Check that the accessibility tree of the browser has been updated. | 573 // Check that the accessibility tree of the browser has been updated. |
567 checkbox_checker.SetExpectedState( | 574 checkbox_checker.SetExpectedState( |
568 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); | 575 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); |
569 document_checker.CheckAccessible(GetRendererAccessible()); | 576 document_checker.CheckAccessible(GetRendererAccessible()); |
570 } | 577 } |
571 | 578 |
572 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 579 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
573 MAYBE(TestNotificationChildrenChanged)) { | 580 MAYBE(TestNotificationChildrenChanged)) { |
574 // The role attribute causes the node to be in the accessibility tree. | 581 // The role attribute causes the node to be in the accessibility tree. |
575 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); | 582 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); |
576 | 583 |
577 // Check the browser's copy of the renderer accessibility tree. | 584 // Check the browser's copy of the renderer accessibility tree. |
578 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 585 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
579 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 586 std::wstring()); |
| 587 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 588 std::wstring()); |
580 document_checker.AppendExpectedChild(&group_checker); | 589 document_checker.AppendExpectedChild(&group_checker); |
581 document_checker.CheckAccessible(GetRendererAccessible()); | 590 document_checker.CheckAccessible(GetRendererAccessible()); |
582 | 591 |
583 // Change the children of the document body. | 592 // Change the children of the document body. |
584 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 593 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
585 WebContents* web_contents = shell()->web_contents(); | 594 WebContents* web_contents = shell()->web_contents(); |
586 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 595 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
587 web_contents->GetRenderViewHost()); | 596 web_contents->GetRenderViewHost()); |
588 view_host->SetAccessibilityOtherCallbackForTesting( | 597 view_host->SetAccessibilityOtherCallbackForTesting( |
589 loop_runner->QuitClosure()); | 598 loop_runner->QuitClosure()); |
590 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); | 599 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); |
591 loop_runner->Run(); | 600 loop_runner->Run(); |
592 | 601 |
593 // Check that the accessibility tree of the browser has been updated. | 602 // Check that the accessibility tree of the browser has been updated. |
594 AccessibleChecker text_checker(L"new text", ROLE_SYSTEM_TEXT, L""); | 603 AccessibleChecker text_checker(L"new text", ROLE_SYSTEM_TEXT, std::wstring()); |
595 group_checker.AppendExpectedChild(&text_checker); | 604 group_checker.AppendExpectedChild(&text_checker); |
596 document_checker.CheckAccessible(GetRendererAccessible()); | 605 document_checker.CheckAccessible(GetRendererAccessible()); |
597 } | 606 } |
598 | 607 |
599 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 608 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
600 MAYBE(TestNotificationChildrenChanged2)) { | 609 MAYBE(TestNotificationChildrenChanged2)) { |
601 // The role attribute causes the node to be in the accessibility tree. | 610 // The role attribute causes the node to be in the accessibility tree. |
602 LoadInitialAccessibilityTreeFromHtml( | 611 LoadInitialAccessibilityTreeFromHtml( |
603 "<div role=group style='visibility: hidden'>text</div>"); | 612 "<div role=group style='visibility: hidden'>text</div>"); |
604 | 613 |
605 // Check the accessible tree of the browser. | 614 // Check the accessible tree of the browser. |
606 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 615 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 616 std::wstring()); |
607 document_checker.CheckAccessible(GetRendererAccessible()); | 617 document_checker.CheckAccessible(GetRendererAccessible()); |
608 | 618 |
609 // Change the children of the document body. | 619 // Change the children of the document body. |
610 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 620 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
611 WebContents* web_contents = shell()->web_contents(); | 621 WebContents* web_contents = shell()->web_contents(); |
612 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 622 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
613 web_contents->GetRenderViewHost()); | 623 web_contents->GetRenderViewHost()); |
614 view_host->SetAccessibilityOtherCallbackForTesting( | 624 view_host->SetAccessibilityOtherCallbackForTesting( |
615 loop_runner->QuitClosure()); | 625 loop_runner->QuitClosure()); |
616 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); | 626 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); |
617 loop_runner->Run(); | 627 loop_runner->Run(); |
618 | 628 |
619 // Check that the accessibility tree of the browser has been updated. | 629 // Check that the accessibility tree of the browser has been updated. |
620 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_TEXT, L""); | 630 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_TEXT, |
621 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 631 std::wstring()); |
| 632 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 633 std::wstring()); |
622 document_checker.AppendExpectedChild(&group_checker); | 634 document_checker.AppendExpectedChild(&group_checker); |
623 group_checker.AppendExpectedChild(&static_text_checker); | 635 group_checker.AppendExpectedChild(&static_text_checker); |
624 document_checker.CheckAccessible(GetRendererAccessible()); | 636 document_checker.CheckAccessible(GetRendererAccessible()); |
625 } | 637 } |
626 | 638 |
627 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 639 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
628 MAYBE(TestNotificationFocusChanged)) { | 640 MAYBE(TestNotificationFocusChanged)) { |
629 // The role attribute causes the node to be in the accessibility tree. | 641 // The role attribute causes the node to be in the accessibility tree. |
630 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>"); | 642 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>"); |
631 | 643 |
632 // Check the browser's copy of the renderer accessibility tree. | 644 // Check the browser's copy of the renderer accessibility tree. |
633 SCOPED_TRACE("Check initial tree"); | 645 SCOPED_TRACE("Check initial tree"); |
634 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 646 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 647 std::wstring()); |
635 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 648 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
636 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 649 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 650 std::wstring()); |
637 document_checker.AppendExpectedChild(&group_checker); | 651 document_checker.AppendExpectedChild(&group_checker); |
638 document_checker.CheckAccessible(GetRendererAccessible()); | 652 document_checker.CheckAccessible(GetRendererAccessible()); |
639 | 653 |
640 // Focus the div in the document | 654 // Focus the div in the document |
641 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 655 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
642 WebContents* web_contents = shell()->web_contents(); | 656 WebContents* web_contents = shell()->web_contents(); |
643 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 657 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
644 web_contents->GetRenderViewHost()); | 658 web_contents->GetRenderViewHost()); |
645 view_host->SetAccessibilityOtherCallbackForTesting( | 659 view_host->SetAccessibilityOtherCallbackForTesting( |
646 loop_runner->QuitClosure()); | 660 loop_runner->QuitClosure()); |
(...skipping 23 matching lines...) Expand all Loading... |
670 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 684 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
671 document_checker.CheckAccessible(GetRendererAccessible()); | 685 document_checker.CheckAccessible(GetRendererAccessible()); |
672 } | 686 } |
673 | 687 |
674 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 688 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
675 MAYBE(TestNotificationValueChanged)) { | 689 MAYBE(TestNotificationValueChanged)) { |
676 LoadInitialAccessibilityTreeFromHtml( | 690 LoadInitialAccessibilityTreeFromHtml( |
677 "<body><input type='text' value='old value'/></body>"); | 691 "<body><input type='text' value='old value'/></body>"); |
678 | 692 |
679 // Check the browser's copy of the renderer accessibility tree. | 693 // Check the browser's copy of the renderer accessibility tree. |
680 AccessibleChecker text_field_checker(L"", ROLE_SYSTEM_TEXT, L"old value"); | 694 AccessibleChecker text_field_checker(std::wstring(), ROLE_SYSTEM_TEXT, |
| 695 L"old value"); |
681 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 696 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
682 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 697 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
683 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 698 std::wstring()); |
| 699 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 700 std::wstring()); |
684 body_checker.AppendExpectedChild(&text_field_checker); | 701 body_checker.AppendExpectedChild(&text_field_checker); |
685 document_checker.AppendExpectedChild(&body_checker); | 702 document_checker.AppendExpectedChild(&body_checker); |
686 document_checker.CheckAccessible(GetRendererAccessible()); | 703 document_checker.CheckAccessible(GetRendererAccessible()); |
687 | 704 |
688 // Set the value of the text control | 705 // Set the value of the text control |
689 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 706 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
690 WebContents* web_contents = shell()->web_contents(); | 707 WebContents* web_contents = shell()->web_contents(); |
691 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 708 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
692 web_contents->GetRenderViewHost()); | 709 web_contents->GetRenderViewHost()); |
693 view_host->SetAccessibilityOtherCallbackForTesting( | 710 view_host->SetAccessibilityOtherCallbackForTesting( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
728 RecursiveFindNodeInAccessibilityTree( | 745 RecursiveFindNodeInAccessibilityTree( |
729 browser_accessible.get(), ROLE_SYSTEM_DOCUMENT, L"MyDocument", 0, &found); | 746 browser_accessible.get(), ROLE_SYSTEM_DOCUMENT, L"MyDocument", 0, &found); |
730 ASSERT_EQ(found, true); | 747 ASSERT_EQ(found, true); |
731 } | 748 } |
732 | 749 |
733 // Disabled because of http://crbug.com/144390. | 750 // Disabled because of http://crbug.com/144390. |
734 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 751 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
735 DISABLED_TestToggleButtonRoleAndStates) { | 752 DISABLED_TestToggleButtonRoleAndStates) { |
736 AccessibleChecker* button_checker; | 753 AccessibleChecker* button_checker; |
737 std::string button_html("data:text/html,"); | 754 std::string button_html("data:text/html,"); |
738 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 755 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
739 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 756 std::wstring()); |
| 757 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
| 758 std::wstring()); |
740 document_checker.AppendExpectedChild(&body_checker); | 759 document_checker.AppendExpectedChild(&body_checker); |
741 | 760 |
742 // Temporary macro | 761 // Temporary macro |
743 #define ADD_BUTTON(html, ia2_role, state) \ | 762 #define ADD_BUTTON(html, ia2_role, state) \ |
744 button_html += html; \ | 763 button_html += html; \ |
745 button_checker = new AccessibleChecker(L"x", ROLE_SYSTEM_PUSHBUTTON, \ | 764 button_checker = new AccessibleChecker(L"x", ROLE_SYSTEM_PUSHBUTTON, \ |
746 ia2_role, L""); \ | 765 ia2_role, std::wstring()); \ |
747 button_checker->SetExpectedState(state); \ | 766 button_checker->SetExpectedState(state); \ |
748 body_checker.AppendExpectedChild(button_checker) | 767 body_checker.AppendExpectedChild(button_checker) |
749 | 768 |
750 // If aria-pressed is 'undefined', empty or not present, use PUSHBUTTON | 769 // If aria-pressed is 'undefined', empty or not present, use PUSHBUTTON |
751 // Otherwise use TOGGLE_BUTTON, even if the value is invalid. | 770 // Otherwise use TOGGLE_BUTTON, even if the value is invalid. |
752 // The spec does this in an attempt future-proof in case new values are added. | 771 // The spec does this in an attempt future-proof in case new values are added. |
753 ADD_BUTTON("<span role='button' aria-pressed='false'>x</span>", | 772 ADD_BUTTON("<span role='button' aria-pressed='false'>x</span>", |
754 IA2_ROLE_TOGGLE_BUTTON, 0); | 773 IA2_ROLE_TOGGLE_BUTTON, 0); |
755 ADD_BUTTON("<span role='button' aria-pressed='true'>x</span>", | 774 ADD_BUTTON("<span role='button' aria-pressed='true'>x</span>", |
756 IA2_ROLE_TOGGLE_BUTTON, STATE_SYSTEM_PRESSED); | 775 IA2_ROLE_TOGGLE_BUTTON, STATE_SYSTEM_PRESSED); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
842 node_value.Reset(); | 861 node_value.Reset(); |
843 | 862 |
844 base::win::ScopedComPtr<ISimpleDOMNode> body_isimpledomnode; | 863 base::win::ScopedComPtr<ISimpleDOMNode> body_isimpledomnode; |
845 hr = document_isimpledomnode->get_firstChild( | 864 hr = document_isimpledomnode->get_firstChild( |
846 body_isimpledomnode.Receive()); | 865 body_isimpledomnode.Receive()); |
847 ASSERT_EQ(S_OK, hr); | 866 ASSERT_EQ(S_OK, hr); |
848 hr = body_isimpledomnode->get_nodeInfo( | 867 hr = body_isimpledomnode->get_nodeInfo( |
849 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, | 868 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, |
850 &unique_id, &node_type); | 869 &unique_id, &node_type); |
851 ASSERT_EQ(S_OK, hr); | 870 ASSERT_EQ(S_OK, hr); |
852 EXPECT_STREQ(L"body", wstring(node_name, node_name.Length()).c_str()); | 871 EXPECT_EQ(L"body", std::wstring(node_name, node_name.Length())); |
853 EXPECT_EQ(NODETYPE_ELEMENT, node_type); | 872 EXPECT_EQ(NODETYPE_ELEMENT, node_type); |
854 EXPECT_EQ(1, num_children); | 873 EXPECT_EQ(1, num_children); |
855 node_name.Reset(); | 874 node_name.Reset(); |
856 node_value.Reset(); | 875 node_value.Reset(); |
857 | 876 |
858 base::win::ScopedComPtr<ISimpleDOMNode> checkbox_isimpledomnode; | 877 base::win::ScopedComPtr<ISimpleDOMNode> checkbox_isimpledomnode; |
859 hr = body_isimpledomnode->get_firstChild( | 878 hr = body_isimpledomnode->get_firstChild( |
860 checkbox_isimpledomnode.Receive()); | 879 checkbox_isimpledomnode.Receive()); |
861 ASSERT_EQ(S_OK, hr); | 880 ASSERT_EQ(S_OK, hr); |
862 hr = checkbox_isimpledomnode->get_nodeInfo( | 881 hr = checkbox_isimpledomnode->get_nodeInfo( |
863 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, | 882 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, |
864 &unique_id, &node_type); | 883 &unique_id, &node_type); |
865 ASSERT_EQ(S_OK, hr); | 884 ASSERT_EQ(S_OK, hr); |
866 EXPECT_STREQ(L"input", wstring(node_name, node_name.Length()).c_str()); | 885 EXPECT_EQ(L"input", std::wstring(node_name, node_name.Length())); |
867 EXPECT_EQ(NODETYPE_ELEMENT, node_type); | 886 EXPECT_EQ(NODETYPE_ELEMENT, node_type); |
868 EXPECT_EQ(0, num_children); | 887 EXPECT_EQ(0, num_children); |
869 } | 888 } |
870 | 889 |
871 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, MAYBE(TestRoleGroup)) { | 890 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, MAYBE(TestRoleGroup)) { |
872 LoadInitialAccessibilityTreeFromHtml( | 891 LoadInitialAccessibilityTreeFromHtml( |
873 "<fieldset></fieldset><div role=group></div>"); | 892 "<fieldset></fieldset><div role=group></div>"); |
874 | 893 |
875 // Check the browser's copy of the renderer accessibility tree. | 894 // Check the browser's copy of the renderer accessibility tree. |
876 AccessibleChecker grouping1_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 895 AccessibleChecker grouping1_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
877 AccessibleChecker grouping2_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 896 std::wstring()); |
878 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 897 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 898 std::wstring()); |
| 899 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 900 std::wstring()); |
879 document_checker.AppendExpectedChild(&grouping1_checker); | 901 document_checker.AppendExpectedChild(&grouping1_checker); |
880 document_checker.AppendExpectedChild(&grouping2_checker); | 902 document_checker.AppendExpectedChild(&grouping2_checker); |
881 document_checker.CheckAccessible(GetRendererAccessible()); | 903 document_checker.CheckAccessible(GetRendererAccessible()); |
882 } | 904 } |
883 } // namespace. | |
884 | 905 |
885 } // namespace content | 906 } // namespace content |
OLD | NEW |