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 EXPECT_EQ(state_, V_I4(&var_state)); | 385 EXPECT_EQ(state_, V_I4(&state)); |
391 if (state_ != V_I4(&var_state)) { | 386 if (state_ != V_I4(&state)) { |
392 LOG(ERROR) << "Expected state: " << | 387 LOG(ERROR) << "Expected state: " << IAccessibleStateToString(state_); |
393 IAccessibleStateToString(state_); | 388 LOG(ERROR) << "Got state: " << IAccessibleStateToString(V_I4(&state)); |
394 LOG(ERROR) << "Got state: " << | |
395 IAccessibleStateToString(V_I4(&var_state)); | |
396 } | 389 } |
397 } | 390 } |
398 | 391 |
399 void AccessibleChecker::CheckAccessibleChildren(IAccessible* parent) { | 392 void AccessibleChecker::CheckAccessibleChildren(IAccessible* parent) { |
400 LONG child_count = 0; | 393 LONG child_count = 0; |
401 HRESULT hr = parent->get_accChildCount(&child_count); | 394 HRESULT hr = parent->get_accChildCount(&child_count); |
402 EXPECT_EQ(S_OK, hr); | 395 EXPECT_EQ(S_OK, hr); |
403 ASSERT_EQ(child_count, children_.size()); | 396 ASSERT_EQ(child_count, children_.size()); |
404 | 397 |
405 auto_ptr<VARIANT> child_array(new VARIANT[child_count]); | 398 scoped_ptr<VARIANT[]> child_array(new VARIANT[child_count]); |
406 LONG obtained_count = 0; | 399 LONG obtained_count = 0; |
407 hr = AccessibleChildren(parent, 0, child_count, | 400 hr = AccessibleChildren(parent, 0, child_count, |
408 child_array.get(), &obtained_count); | 401 child_array.get(), &obtained_count); |
409 ASSERT_EQ(S_OK, hr); | 402 ASSERT_EQ(S_OK, hr); |
410 ASSERT_EQ(child_count, obtained_count); | 403 ASSERT_EQ(child_count, obtained_count); |
411 | 404 |
412 VARIANT* child = child_array.get(); | 405 VARIANT* child = child_array.get(); |
413 for (AccessibleCheckerVector::iterator child_checker = children_.begin(); | 406 for (AccessibleCheckerVector::iterator child_checker = children_.begin(); |
414 child_checker != children_.end(); | 407 child_checker != children_.end(); |
415 ++child_checker, ++child) { | 408 ++child_checker, ++child) { |
416 base::win::ScopedComPtr<IAccessible> child_accessible( | 409 base::win::ScopedComPtr<IAccessible> child_accessible( |
417 GetAccessibleFromResultVariant(parent, child)); | 410 GetAccessibleFromResultVariant(parent, child)); |
418 ASSERT_TRUE(child_accessible.get()); | 411 ASSERT_TRUE(child_accessible.get()); |
419 (*child_checker)->CheckAccessible(child_accessible); | 412 (*child_checker)->CheckAccessible(child_accessible); |
420 } | 413 } |
421 } | 414 } |
422 | 415 |
423 string16 AccessibleChecker::RoleVariantToString( | 416 string16 AccessibleChecker::RoleVariantToString( |
424 const base::win::ScopedVariant& role_variant) { | 417 const base::win::ScopedVariant& role) { |
425 if (role_variant.type() == VT_I4) | 418 if (role.type() == VT_I4) |
426 return IAccessibleRoleToString(V_I4(&role_variant)); | 419 return IAccessibleRoleToString(V_I4(&role)); |
427 else if (role_variant.type() == VT_BSTR) | 420 if (role.type() == VT_BSTR) |
428 return string16(V_BSTR(&role_variant), SysStringLen(V_BSTR(&role_variant))); | 421 return string16(V_BSTR(&role), SysStringLen(V_BSTR(&role))); |
429 return string16(); | 422 return string16(); |
430 } | 423 } |
431 | 424 |
| 425 } // namespace |
| 426 |
| 427 |
| 428 // Tests ---------------------------------------------------------------------- |
| 429 |
432 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 430 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
433 MAYBE(TestBusyAccessibilityTree)) { | 431 MAYBE(TestBusyAccessibilityTree)) { |
434 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); | 432 NavigateToURL(shell(), GURL(chrome::kAboutBlankURL)); |
435 | 433 |
436 // The initial accessible returned should have state STATE_SYSTEM_BUSY while | 434 // The initial accessible returned should have state STATE_SYSTEM_BUSY while |
437 // the accessibility tree is being requested from the renderer. | 435 // the accessibility tree is being requested from the renderer. |
438 AccessibleChecker document1_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 436 AccessibleChecker document1_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 437 std::wstring()); |
439 document1_checker.SetExpectedState( | 438 document1_checker.SetExpectedState( |
440 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED | | 439 STATE_SYSTEM_READONLY | STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_FOCUSED | |
441 STATE_SYSTEM_BUSY); | 440 STATE_SYSTEM_BUSY); |
442 document1_checker.CheckAccessible(GetRendererAccessible()); | 441 document1_checker.CheckAccessible(GetRendererAccessible()); |
443 } | 442 } |
444 | 443 |
445 // Flaky, http://crbug.com/167320 . | 444 // Flaky, http://crbug.com/167320 . |
446 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 445 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
447 DISABLED_TestRendererAccessibilityTree) { | 446 DISABLED_TestRendererAccessibilityTree) { |
448 LoadInitialAccessibilityTreeFromHtml( | 447 LoadInitialAccessibilityTreeFromHtml( |
449 "<html><head><title>Accessibility Win Test</title></head>" | 448 "<html><head><title>Accessibility Win Test</title></head>" |
450 "<body><input type='button' value='push' /><input type='checkbox' />" | 449 "<body><input type='button' value='push' /><input type='checkbox' />" |
451 "</body></html>"); | 450 "</body></html>"); |
452 | 451 |
453 // Check the browser's copy of the renderer accessibility tree. | 452 // Check the browser's copy of the renderer accessibility tree. |
454 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON, L""); | 453 AccessibleChecker button_checker(L"push", ROLE_SYSTEM_PUSHBUTTON, |
455 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON, L""); | 454 std::wstring()); |
456 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 455 AccessibleChecker checkbox_checker(std::wstring(), ROLE_SYSTEM_CHECKBUTTON, |
457 AccessibleChecker document2_checker( | 456 std::wstring()); |
458 L"Accessibility Win Test", ROLE_SYSTEM_DOCUMENT, L""); | 457 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
| 458 std::wstring()); |
| 459 AccessibleChecker document2_checker(L"Accessibility Win Test", |
| 460 ROLE_SYSTEM_DOCUMENT, std::wstring()); |
459 body_checker.AppendExpectedChild(&button_checker); | 461 body_checker.AppendExpectedChild(&button_checker); |
460 body_checker.AppendExpectedChild(&checkbox_checker); | 462 body_checker.AppendExpectedChild(&checkbox_checker); |
461 document2_checker.AppendExpectedChild(&body_checker); | 463 document2_checker.AppendExpectedChild(&body_checker); |
462 document2_checker.CheckAccessible(GetRendererAccessible()); | 464 document2_checker.CheckAccessible(GetRendererAccessible()); |
463 | 465 |
464 // Check that document accessible has a parent accessible. | 466 // Check that document accessible has a parent accessible. |
465 base::win::ScopedComPtr<IAccessible> document_accessible( | 467 base::win::ScopedComPtr<IAccessible> document_accessible( |
466 GetRendererAccessible()); | 468 GetRendererAccessible()); |
467 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); | 469 ASSERT_NE(document_accessible.get(), reinterpret_cast<IAccessible*>(NULL)); |
468 base::win::ScopedComPtr<IDispatch> parent_dispatch; | 470 base::win::ScopedComPtr<IDispatch> parent_dispatch; |
(...skipping 14 matching lines...) Expand all Loading... |
483 } | 485 } |
484 | 486 |
485 // Periodically failing. See crbug.com/145537 | 487 // Periodically failing. See crbug.com/145537 |
486 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 488 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
487 DISABLED_TestNotificationActiveDescendantChanged) { | 489 DISABLED_TestNotificationActiveDescendantChanged) { |
488 LoadInitialAccessibilityTreeFromHtml( | 490 LoadInitialAccessibilityTreeFromHtml( |
489 "<ul tabindex='-1' role='radiogroup' aria-label='ul'>" | 491 "<ul tabindex='-1' role='radiogroup' aria-label='ul'>" |
490 "<li id='li'>li</li></ul>"); | 492 "<li id='li'>li</li></ul>"); |
491 | 493 |
492 // Check the browser's copy of the renderer accessibility tree. | 494 // Check the browser's copy of the renderer accessibility tree. |
493 AccessibleChecker list_marker_checker(L"\x2022", ROLE_SYSTEM_TEXT, L""); | 495 AccessibleChecker list_marker_checker(L"\x2022", ROLE_SYSTEM_TEXT, |
494 AccessibleChecker static_text_checker(L"li", ROLE_SYSTEM_TEXT, L""); | 496 std::wstring()); |
495 AccessibleChecker list_item_checker(L"", ROLE_SYSTEM_LISTITEM, L""); | 497 AccessibleChecker static_text_checker(L"li", ROLE_SYSTEM_TEXT, |
496 list_item_checker.SetExpectedState( | 498 std::wstring()); |
497 STATE_SYSTEM_READONLY); | 499 AccessibleChecker list_item_checker(std::wstring(), ROLE_SYSTEM_LISTITEM, |
| 500 std::wstring()); |
| 501 list_item_checker.SetExpectedState(STATE_SYSTEM_READONLY); |
498 AccessibleChecker radio_group_checker(L"ul", ROLE_SYSTEM_GROUPING, | 502 AccessibleChecker radio_group_checker(L"ul", ROLE_SYSTEM_GROUPING, |
499 IA2_ROLE_SECTION, L""); | 503 IA2_ROLE_SECTION, std::wstring()); |
500 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 504 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
501 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 505 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 506 std::wstring()); |
502 list_item_checker.AppendExpectedChild(&list_marker_checker); | 507 list_item_checker.AppendExpectedChild(&list_marker_checker); |
503 list_item_checker.AppendExpectedChild(&static_text_checker); | 508 list_item_checker.AppendExpectedChild(&static_text_checker); |
504 radio_group_checker.AppendExpectedChild(&list_item_checker); | 509 radio_group_checker.AppendExpectedChild(&list_item_checker); |
505 document_checker.AppendExpectedChild(&radio_group_checker); | 510 document_checker.AppendExpectedChild(&radio_group_checker); |
506 document_checker.CheckAccessible(GetRendererAccessible()); | 511 document_checker.CheckAccessible(GetRendererAccessible()); |
507 | 512 |
508 // Set focus to the radio group. | 513 // Set focus to the radio group. |
509 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 514 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
510 WebContents* web_contents = shell()->web_contents(); | 515 WebContents* web_contents = shell()->web_contents(); |
511 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 516 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
(...skipping 22 matching lines...) Expand all Loading... |
534 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 539 radio_group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
535 document_checker.CheckAccessible(GetRendererAccessible()); | 540 document_checker.CheckAccessible(GetRendererAccessible()); |
536 } | 541 } |
537 | 542 |
538 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 543 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
539 MAYBE(TestNotificationCheckedStateChanged)) { | 544 MAYBE(TestNotificationCheckedStateChanged)) { |
540 LoadInitialAccessibilityTreeFromHtml( | 545 LoadInitialAccessibilityTreeFromHtml( |
541 "<body><input type='checkbox' /></body>"); | 546 "<body><input type='checkbox' /></body>"); |
542 | 547 |
543 // Check the browser's copy of the renderer accessibility tree. | 548 // Check the browser's copy of the renderer accessibility tree. |
544 AccessibleChecker checkbox_checker(L"", ROLE_SYSTEM_CHECKBUTTON, L""); | 549 AccessibleChecker checkbox_checker(std::wstring(), ROLE_SYSTEM_CHECKBUTTON, |
| 550 std::wstring()); |
545 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 551 checkbox_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
546 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 552 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
547 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 553 std::wstring()); |
| 554 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 555 std::wstring()); |
548 body_checker.AppendExpectedChild(&checkbox_checker); | 556 body_checker.AppendExpectedChild(&checkbox_checker); |
549 document_checker.AppendExpectedChild(&body_checker); | 557 document_checker.AppendExpectedChild(&body_checker); |
550 document_checker.CheckAccessible(GetRendererAccessible()); | 558 document_checker.CheckAccessible(GetRendererAccessible()); |
551 | 559 |
552 // Check the checkbox. | 560 // Check the checkbox. |
553 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 561 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
554 WebContents* web_contents = shell()->web_contents(); | 562 WebContents* web_contents = shell()->web_contents(); |
555 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 563 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
556 web_contents->GetRenderViewHost()); | 564 web_contents->GetRenderViewHost()); |
557 view_host->SetAccessibilityOtherCallbackForTesting( | 565 view_host->SetAccessibilityOtherCallbackForTesting( |
558 loop_runner->QuitClosure()); | 566 loop_runner->QuitClosure()); |
559 ExecuteScript(L"document.body.children[0].checked=true"); | 567 ExecuteScript(L"document.body.children[0].checked=true"); |
560 loop_runner->Run(); | 568 loop_runner->Run(); |
561 | 569 |
562 // Check that the accessibility tree of the browser has been updated. | 570 // Check that the accessibility tree of the browser has been updated. |
563 checkbox_checker.SetExpectedState( | 571 checkbox_checker.SetExpectedState( |
564 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); | 572 STATE_SYSTEM_CHECKED | STATE_SYSTEM_FOCUSABLE); |
565 document_checker.CheckAccessible(GetRendererAccessible()); | 573 document_checker.CheckAccessible(GetRendererAccessible()); |
566 } | 574 } |
567 | 575 |
568 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 576 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
569 MAYBE(TestNotificationChildrenChanged)) { | 577 MAYBE(TestNotificationChildrenChanged)) { |
570 // The role attribute causes the node to be in the accessibility tree. | 578 // The role attribute causes the node to be in the accessibility tree. |
571 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); | 579 LoadInitialAccessibilityTreeFromHtml("<body role=group></body>"); |
572 | 580 |
573 // Check the browser's copy of the renderer accessibility tree. | 581 // Check the browser's copy of the renderer accessibility tree. |
574 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 582 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
575 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 583 std::wstring()); |
| 584 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 585 std::wstring()); |
576 document_checker.AppendExpectedChild(&group_checker); | 586 document_checker.AppendExpectedChild(&group_checker); |
577 document_checker.CheckAccessible(GetRendererAccessible()); | 587 document_checker.CheckAccessible(GetRendererAccessible()); |
578 | 588 |
579 // Change the children of the document body. | 589 // Change the children of the document body. |
580 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 590 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
581 WebContents* web_contents = shell()->web_contents(); | 591 WebContents* web_contents = shell()->web_contents(); |
582 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 592 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
583 web_contents->GetRenderViewHost()); | 593 web_contents->GetRenderViewHost()); |
584 view_host->SetAccessibilityOtherCallbackForTesting( | 594 view_host->SetAccessibilityOtherCallbackForTesting( |
585 loop_runner->QuitClosure()); | 595 loop_runner->QuitClosure()); |
586 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); | 596 ExecuteScript(L"document.body.innerHTML='<b>new text</b>'"); |
587 loop_runner->Run(); | 597 loop_runner->Run(); |
588 | 598 |
589 // Check that the accessibility tree of the browser has been updated. | 599 // Check that the accessibility tree of the browser has been updated. |
590 AccessibleChecker text_checker(L"new text", ROLE_SYSTEM_TEXT, L""); | 600 AccessibleChecker text_checker(L"new text", ROLE_SYSTEM_TEXT, std::wstring()); |
591 group_checker.AppendExpectedChild(&text_checker); | 601 group_checker.AppendExpectedChild(&text_checker); |
592 document_checker.CheckAccessible(GetRendererAccessible()); | 602 document_checker.CheckAccessible(GetRendererAccessible()); |
593 } | 603 } |
594 | 604 |
595 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 605 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
596 MAYBE(TestNotificationChildrenChanged2)) { | 606 MAYBE(TestNotificationChildrenChanged2)) { |
597 // The role attribute causes the node to be in the accessibility tree. | 607 // The role attribute causes the node to be in the accessibility tree. |
598 LoadInitialAccessibilityTreeFromHtml( | 608 LoadInitialAccessibilityTreeFromHtml( |
599 "<div role=group style='visibility: hidden'>text</div>"); | 609 "<div role=group style='visibility: hidden'>text</div>"); |
600 | 610 |
601 // Check the accessible tree of the browser. | 611 // Check the accessible tree of the browser. |
602 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 612 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 613 std::wstring()); |
603 document_checker.CheckAccessible(GetRendererAccessible()); | 614 document_checker.CheckAccessible(GetRendererAccessible()); |
604 | 615 |
605 // Change the children of the document body. | 616 // Change the children of the document body. |
606 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 617 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
607 WebContents* web_contents = shell()->web_contents(); | 618 WebContents* web_contents = shell()->web_contents(); |
608 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 619 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
609 web_contents->GetRenderViewHost()); | 620 web_contents->GetRenderViewHost()); |
610 view_host->SetAccessibilityOtherCallbackForTesting( | 621 view_host->SetAccessibilityOtherCallbackForTesting( |
611 loop_runner->QuitClosure()); | 622 loop_runner->QuitClosure()); |
612 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); | 623 ExecuteScript(L"document.body.children[0].style.visibility='visible'"); |
613 loop_runner->Run(); | 624 loop_runner->Run(); |
614 | 625 |
615 // Check that the accessibility tree of the browser has been updated. | 626 // Check that the accessibility tree of the browser has been updated. |
616 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_TEXT, L""); | 627 AccessibleChecker static_text_checker(L"text", ROLE_SYSTEM_TEXT, |
617 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 628 std::wstring()); |
| 629 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 630 std::wstring()); |
618 document_checker.AppendExpectedChild(&group_checker); | 631 document_checker.AppendExpectedChild(&group_checker); |
619 group_checker.AppendExpectedChild(&static_text_checker); | 632 group_checker.AppendExpectedChild(&static_text_checker); |
620 document_checker.CheckAccessible(GetRendererAccessible()); | 633 document_checker.CheckAccessible(GetRendererAccessible()); |
621 } | 634 } |
622 | 635 |
623 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 636 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
624 MAYBE(TestNotificationFocusChanged)) { | 637 MAYBE(TestNotificationFocusChanged)) { |
625 // The role attribute causes the node to be in the accessibility tree. | 638 // The role attribute causes the node to be in the accessibility tree. |
626 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>"); | 639 LoadInitialAccessibilityTreeFromHtml("<div role=group tabindex='-1'></div>"); |
627 | 640 |
628 // Check the browser's copy of the renderer accessibility tree. | 641 // Check the browser's copy of the renderer accessibility tree. |
629 SCOPED_TRACE("Check initial tree"); | 642 SCOPED_TRACE("Check initial tree"); |
630 AccessibleChecker group_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 643 AccessibleChecker group_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 644 std::wstring()); |
631 group_checker.SetExpectedState( | 645 group_checker.SetExpectedState( |
632 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_OFFSCREEN); | 646 STATE_SYSTEM_FOCUSABLE | STATE_SYSTEM_OFFSCREEN); |
633 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 647 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 648 std::wstring()); |
634 document_checker.AppendExpectedChild(&group_checker); | 649 document_checker.AppendExpectedChild(&group_checker); |
635 document_checker.CheckAccessible(GetRendererAccessible()); | 650 document_checker.CheckAccessible(GetRendererAccessible()); |
636 | 651 |
637 // Focus the div in the document | 652 // Focus the div in the document |
638 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 653 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
639 WebContents* web_contents = shell()->web_contents(); | 654 WebContents* web_contents = shell()->web_contents(); |
640 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 655 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
641 web_contents->GetRenderViewHost()); | 656 web_contents->GetRenderViewHost()); |
642 view_host->SetAccessibilityOtherCallbackForTesting( | 657 view_host->SetAccessibilityOtherCallbackForTesting( |
643 loop_runner->QuitClosure()); | 658 loop_runner->QuitClosure()); |
(...skipping 23 matching lines...) Expand all Loading... |
667 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 682 group_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
668 document_checker.CheckAccessible(GetRendererAccessible()); | 683 document_checker.CheckAccessible(GetRendererAccessible()); |
669 } | 684 } |
670 | 685 |
671 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 686 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
672 MAYBE(TestNotificationValueChanged)) { | 687 MAYBE(TestNotificationValueChanged)) { |
673 LoadInitialAccessibilityTreeFromHtml( | 688 LoadInitialAccessibilityTreeFromHtml( |
674 "<body><input type='text' value='old value'/></body>"); | 689 "<body><input type='text' value='old value'/></body>"); |
675 | 690 |
676 // Check the browser's copy of the renderer accessibility tree. | 691 // Check the browser's copy of the renderer accessibility tree. |
677 AccessibleChecker text_field_checker(L"", ROLE_SYSTEM_TEXT, L"old value"); | 692 AccessibleChecker text_field_checker(std::wstring(), ROLE_SYSTEM_TEXT, |
| 693 L"old value"); |
678 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); | 694 text_field_checker.SetExpectedState(STATE_SYSTEM_FOCUSABLE); |
679 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 695 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
680 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 696 std::wstring()); |
| 697 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 698 std::wstring()); |
681 body_checker.AppendExpectedChild(&text_field_checker); | 699 body_checker.AppendExpectedChild(&text_field_checker); |
682 document_checker.AppendExpectedChild(&body_checker); | 700 document_checker.AppendExpectedChild(&body_checker); |
683 document_checker.CheckAccessible(GetRendererAccessible()); | 701 document_checker.CheckAccessible(GetRendererAccessible()); |
684 | 702 |
685 // Set the value of the text control | 703 // Set the value of the text control |
686 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); | 704 scoped_refptr<MessageLoopRunner> loop_runner(new MessageLoopRunner); |
687 WebContents* web_contents = shell()->web_contents(); | 705 WebContents* web_contents = shell()->web_contents(); |
688 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( | 706 RenderViewHostImpl* view_host = static_cast<RenderViewHostImpl*>( |
689 web_contents->GetRenderViewHost()); | 707 web_contents->GetRenderViewHost()); |
690 view_host->SetAccessibilityOtherCallbackForTesting( | 708 view_host->SetAccessibilityOtherCallbackForTesting( |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 RecursiveFindNodeInAccessibilityTree( | 743 RecursiveFindNodeInAccessibilityTree( |
726 browser_accessible.get(), ROLE_SYSTEM_DOCUMENT, L"MyDocument", 0, &found); | 744 browser_accessible.get(), ROLE_SYSTEM_DOCUMENT, L"MyDocument", 0, &found); |
727 ASSERT_EQ(found, true); | 745 ASSERT_EQ(found, true); |
728 } | 746 } |
729 | 747 |
730 // Disabled because of http://crbug.com/144390. | 748 // Disabled because of http://crbug.com/144390. |
731 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, | 749 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, |
732 DISABLED_TestToggleButtonRoleAndStates) { | 750 DISABLED_TestToggleButtonRoleAndStates) { |
733 AccessibleChecker* button_checker; | 751 AccessibleChecker* button_checker; |
734 std::string button_html("data:text/html,"); | 752 std::string button_html("data:text/html,"); |
735 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 753 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
736 AccessibleChecker body_checker(L"", L"body", IA2_ROLE_SECTION, L""); | 754 std::wstring()); |
| 755 AccessibleChecker body_checker(std::wstring(), L"body", IA2_ROLE_SECTION, |
| 756 std::wstring()); |
737 document_checker.AppendExpectedChild(&body_checker); | 757 document_checker.AppendExpectedChild(&body_checker); |
738 | 758 |
739 // Temporary macro | 759 // Temporary macro |
740 #define ADD_BUTTON(html, ia2_role, state) \ | 760 #define ADD_BUTTON(html, ia2_role, state) \ |
741 button_html += html; \ | 761 button_html += html; \ |
742 button_checker = new AccessibleChecker(L"x", ROLE_SYSTEM_PUSHBUTTON, \ | 762 button_checker = new AccessibleChecker(L"x", ROLE_SYSTEM_PUSHBUTTON, \ |
743 ia2_role, L""); \ | 763 ia2_role, std::wstring()); \ |
744 button_checker->SetExpectedState(state); \ | 764 button_checker->SetExpectedState(state); \ |
745 body_checker.AppendExpectedChild(button_checker) | 765 body_checker.AppendExpectedChild(button_checker) |
746 | 766 |
747 // If aria-pressed is 'undefined', empty or not present, use PUSHBUTTON | 767 // If aria-pressed is 'undefined', empty or not present, use PUSHBUTTON |
748 // Otherwise use TOGGLE_BUTTON, even if the value is invalid. | 768 // Otherwise use TOGGLE_BUTTON, even if the value is invalid. |
749 // The spec does this in an attempt future-proof in case new values are added. | 769 // The spec does this in an attempt future-proof in case new values are added. |
750 ADD_BUTTON("<span role='button' aria-pressed='false'>x</span>", | 770 ADD_BUTTON("<span role='button' aria-pressed='false'>x</span>", |
751 IA2_ROLE_TOGGLE_BUTTON, 0); | 771 IA2_ROLE_TOGGLE_BUTTON, 0); |
752 ADD_BUTTON("<span role='button' aria-pressed='true'>x</span>", | 772 ADD_BUTTON("<span role='button' aria-pressed='true'>x</span>", |
753 IA2_ROLE_TOGGLE_BUTTON, STATE_SYSTEM_PRESSED); | 773 IA2_ROLE_TOGGLE_BUTTON, STATE_SYSTEM_PRESSED); |
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
839 node_value.Reset(); | 859 node_value.Reset(); |
840 | 860 |
841 base::win::ScopedComPtr<ISimpleDOMNode> body_isimpledomnode; | 861 base::win::ScopedComPtr<ISimpleDOMNode> body_isimpledomnode; |
842 hr = document_isimpledomnode->get_firstChild( | 862 hr = document_isimpledomnode->get_firstChild( |
843 body_isimpledomnode.Receive()); | 863 body_isimpledomnode.Receive()); |
844 ASSERT_EQ(S_OK, hr); | 864 ASSERT_EQ(S_OK, hr); |
845 hr = body_isimpledomnode->get_nodeInfo( | 865 hr = body_isimpledomnode->get_nodeInfo( |
846 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, | 866 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, |
847 &unique_id, &node_type); | 867 &unique_id, &node_type); |
848 ASSERT_EQ(S_OK, hr); | 868 ASSERT_EQ(S_OK, hr); |
849 EXPECT_STREQ(L"body", wstring(node_name, node_name.Length()).c_str()); | 869 EXPECT_EQ(L"body", std::wstring(node_name, node_name.Length())); |
850 EXPECT_EQ(NODETYPE_ELEMENT, node_type); | 870 EXPECT_EQ(NODETYPE_ELEMENT, node_type); |
851 EXPECT_EQ(1, num_children); | 871 EXPECT_EQ(1, num_children); |
852 node_name.Reset(); | 872 node_name.Reset(); |
853 node_value.Reset(); | 873 node_value.Reset(); |
854 | 874 |
855 base::win::ScopedComPtr<ISimpleDOMNode> checkbox_isimpledomnode; | 875 base::win::ScopedComPtr<ISimpleDOMNode> checkbox_isimpledomnode; |
856 hr = body_isimpledomnode->get_firstChild( | 876 hr = body_isimpledomnode->get_firstChild( |
857 checkbox_isimpledomnode.Receive()); | 877 checkbox_isimpledomnode.Receive()); |
858 ASSERT_EQ(S_OK, hr); | 878 ASSERT_EQ(S_OK, hr); |
859 hr = checkbox_isimpledomnode->get_nodeInfo( | 879 hr = checkbox_isimpledomnode->get_nodeInfo( |
860 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, | 880 node_name.Receive(), &name_space_id, node_value.Receive(), &num_children, |
861 &unique_id, &node_type); | 881 &unique_id, &node_type); |
862 ASSERT_EQ(S_OK, hr); | 882 ASSERT_EQ(S_OK, hr); |
863 EXPECT_STREQ(L"input", wstring(node_name, node_name.Length()).c_str()); | 883 EXPECT_EQ(L"input", std::wstring(node_name, node_name.Length())); |
864 EXPECT_EQ(NODETYPE_ELEMENT, node_type); | 884 EXPECT_EQ(NODETYPE_ELEMENT, node_type); |
865 EXPECT_EQ(0, num_children); | 885 EXPECT_EQ(0, num_children); |
866 } | 886 } |
867 | 887 |
868 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, MAYBE(TestRoleGroup)) { | 888 IN_PROC_BROWSER_TEST_F(AccessibilityWinBrowserTest, MAYBE(TestRoleGroup)) { |
869 LoadInitialAccessibilityTreeFromHtml( | 889 LoadInitialAccessibilityTreeFromHtml( |
870 "<fieldset></fieldset><div role=group></div>"); | 890 "<fieldset></fieldset><div role=group></div>"); |
871 | 891 |
872 // Check the browser's copy of the renderer accessibility tree. | 892 // Check the browser's copy of the renderer accessibility tree. |
873 AccessibleChecker grouping1_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 893 AccessibleChecker grouping1_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
874 AccessibleChecker grouping2_checker(L"", ROLE_SYSTEM_GROUPING, L""); | 894 std::wstring()); |
875 AccessibleChecker document_checker(L"", ROLE_SYSTEM_DOCUMENT, L""); | 895 AccessibleChecker grouping2_checker(std::wstring(), ROLE_SYSTEM_GROUPING, |
| 896 std::wstring()); |
| 897 AccessibleChecker document_checker(std::wstring(), ROLE_SYSTEM_DOCUMENT, |
| 898 std::wstring()); |
876 document_checker.AppendExpectedChild(&grouping1_checker); | 899 document_checker.AppendExpectedChild(&grouping1_checker); |
877 document_checker.AppendExpectedChild(&grouping2_checker); | 900 document_checker.AppendExpectedChild(&grouping2_checker); |
878 document_checker.CheckAccessible(GetRendererAccessible()); | 901 document_checker.CheckAccessible(GetRendererAccessible()); |
879 } | 902 } |
880 } // namespace. | |
881 | 903 |
882 } // namespace content | 904 } // namespace content |
OLD | NEW |