Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(195)

Side by Side Diff: ui/accessibility/platform/ax_platform_node_win_unittest.cc

Issue 2942413003: Forward BrowserAccessibility::get_accSelection to AXPlatformNode. (Closed)
Patch Set: Break up tests and add a case for mutiple selection Created 3 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "ui/accessibility/platform/ax_platform_node.h" 5 #include "ui/accessibility/platform/ax_platform_node.h"
6 6
7 #include <atlbase.h> 7 #include <atlbase.h>
8 #include <atlcom.h> 8 #include <atlcom.h>
9 #include <oleacc.h> 9 #include <oleacc.h>
10 10
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 void Init(const AXNodeData& node1, 67 void Init(const AXNodeData& node1,
68 const AXNodeData& node2, 68 const AXNodeData& node2,
69 const AXNodeData& node3) { 69 const AXNodeData& node3) {
70 AXTreeUpdate update; 70 AXTreeUpdate update;
71 update.root_id = node1.id; 71 update.root_id = node1.id;
72 update.nodes.push_back(node1); 72 update.nodes.push_back(node1);
73 update.nodes.push_back(node2); 73 update.nodes.push_back(node2);
74 update.nodes.push_back(node3); 74 update.nodes.push_back(node3);
75 Init(update); 75 Init(update);
76 } 76 }
77 void Init(const AXNodeData& node1,
78 const AXNodeData& node2,
79 const AXNodeData& node3,
80 const AXNodeData& node4) {
81 AXTreeUpdate update;
82 update.root_id = node1.id;
83 update.nodes.push_back(node1);
84 update.nodes.push_back(node2);
85 update.nodes.push_back(node3);
86 update.nodes.push_back(node4);
87 Init(update);
88 }
77 89
78 protected: 90 protected:
79 AXNode* GetRootNode() { 91 AXNode* GetRootNode() {
80 return tree_->root(); 92 return tree_->root();
81 } 93 }
82 94
83 ScopedComPtr<IAccessible> IAccessibleFromNode(AXNode* node) { 95 ScopedComPtr<IAccessible> IAccessibleFromNode(AXNode* node) {
84 TestAXNodeWrapper* wrapper = 96 TestAXNodeWrapper* wrapper =
85 TestAXNodeWrapper::GetOrCreate(tree_.get(), node); 97 TestAXNodeWrapper::GetOrCreate(tree_.get(), node);
86 if (!wrapper) 98 if (!wrapper)
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after
186 EXPECT_EQ(S_OK, root_obj->get_accKeyboardShortcut(SELF, shortcut.Receive())); 198 EXPECT_EQ(S_OK, root_obj->get_accKeyboardShortcut(SELF, shortcut.Receive()));
187 EXPECT_STREQ(L"Shortcut", shortcut); 199 EXPECT_STREQ(L"Shortcut", shortcut);
188 200
189 EXPECT_EQ(E_INVALIDARG, root_obj->get_accKeyboardShortcut(SELF, nullptr)); 201 EXPECT_EQ(E_INVALIDARG, root_obj->get_accKeyboardShortcut(SELF, nullptr));
190 ScopedVariant bad_id(999); 202 ScopedVariant bad_id(999);
191 ScopedBstr k2; 203 ScopedBstr k2;
192 EXPECT_EQ(E_INVALIDARG, 204 EXPECT_EQ(E_INVALIDARG,
193 root_obj->get_accKeyboardShortcut(bad_id, k2.Receive())); 205 root_obj->get_accKeyboardShortcut(bad_id, k2.Receive()));
194 } 206 }
195 207
208 TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionNotListBox) {
209 // We only support AX_ROLE_LIST_BOX as this point, so, this should return
210 // not implemented. We're choosing AX_ROLE_ALERT, but it could be anything
211 // but AX_ROLE_LIST_BOX_OPTION.
212
213 AXNodeData not_supported;
214 not_supported.id = 0;
215 not_supported.role = AX_ROLE_ALERT;
216
217 Init(not_supported);
218 ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
219
220 ScopedVariant selection;
221 EXPECT_EQ(E_NOTIMPL, root_obj->get_accSelection(selection.Receive()));
222 }
223
224 TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionNothingSelected) {
225 // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 2 options with
226 // nothing selected
227 AXNodeData list;
228 list.id = 0;
229 list.role = AX_ROLE_LIST_BOX;
230
231 list.child_ids.push_back(2);
232 list.child_ids.push_back(3);
233
234 AXNodeData list_item_2;
235 list_item_2.id = 2;
236 list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
237 list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
238
239 AXNodeData list_item_3;
240 list_item_3.id = 3;
241 list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
242 list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
243
244 // Nothing is selected. This should return S_OK and the selection should
245 // be VT_EMPTY.
246
247 Init(list, list_item_2, list_item_3);
248 ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
249
250 ScopedVariant selection;
251 EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
252 EXPECT_EQ(VT_EMPTY, selection.type());
253 }
254
255 TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionOneSelected) {
256 // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 2 options with
257 // one selected.
258 AXNodeData list;
259 list.id = 0;
260 list.role = AX_ROLE_LIST_BOX;
261
262 list.child_ids.push_back(2);
263 list.child_ids.push_back(3);
264
265 AXNodeData list_item_2;
266 list_item_2.id = 2;
267 list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
268 list_item_2.state = 1 << ui::AX_STATE_SELECTED;
269 list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
270
271 AXNodeData list_item_3;
272 list_item_3.id = 3;
273 list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
274 list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
275
276 Init(list, list_item_2, list_item_3);
277
278 ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
279
280 ScopedVariant selection;
281 EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
282 ASSERT_NE(nullptr, selection.ptr());
283
284 // We got something back, make sure that it has the correct name.
285 base::win::ScopedComPtr<IAccessible> accessible;
286 HRESULT hr =
287 V_DISPATCH(selection.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
288 EXPECT_EQ(S_OK, hr);
289 ScopedBstr name;
290 EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
291 EXPECT_STREQ(L"Name2", name);
292 }
293
294 TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionMultipleSelected) {
295 // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 3 options with
296 // two selected.
297 AXNodeData list;
298 list.id = 0;
299 list.role = AX_ROLE_LIST_BOX;
300
301 list.child_ids.push_back(2);
302 list.child_ids.push_back(3);
303 list.child_ids.push_back(4);
304
305 AXNodeData list_item_2;
306 list_item_2.id = 2;
307 list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
308 list_item_2.state = 1 << ui::AX_STATE_SELECTED;
309 list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
310
311 AXNodeData list_item_3;
312 list_item_3.id = 3;
313 list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
314 list_item_3.state = 1 << ui::AX_STATE_SELECTED;
315 list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
316
317 AXNodeData list_item_4;
318 list_item_4.id = 4;
319 list_item_4.role = AX_ROLE_LIST_BOX_OPTION;
320 list_item_4.AddStringAttribute(AX_ATTR_NAME, "Name4");
321 Init(list, list_item_2, list_item_3, list_item_4);
322
323 ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
324
325 ScopedVariant selection;
326 EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
327 ASSERT_NE(nullptr, selection.ptr());
328
329 // We got something back, make sure that it has the corrent name.
330 base::win::ScopedComPtr<IEnumVARIANT> accessibles;
331 HRESULT hr =
332 V_DISPATCH(selection.ptr())->QueryInterface(IID_PPV_ARGS(&accessibles));
333 EXPECT_EQ(S_OK, hr);
334 ULONG ignore;
335
336 // Check out the first selected item.
337 {
338 ScopedVariant item;
339 hr = accessibles->Next(1, item.Receive(), &ignore);
340 EXPECT_EQ(S_OK, hr);
341
342 base::win::ScopedComPtr<IAccessible> accessible;
dmazzoni 2017/06/26 16:58:31 Not necessary for this change, but I wonder if the
dougt 2017/06/26 22:19:11 Agreed. At the very least, if we continue adding s
343 HRESULT hr =
344 V_DISPATCH(item.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
345 EXPECT_EQ(S_OK, hr);
346 ScopedBstr name;
347 EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
348 EXPECT_STREQ(L"Name2", name);
349 }
350
351 // and the second selected element.
352 {
353 ScopedVariant item;
354 hr = accessibles->Next(1, item.Receive(), &ignore);
355 EXPECT_EQ(S_OK, hr);
356
357 base::win::ScopedComPtr<IAccessible> accessible;
358 HRESULT hr =
359 V_DISPATCH(item.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
360 EXPECT_EQ(S_OK, hr);
361 ScopedBstr name;
362 EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
363 EXPECT_STREQ(L"Name3", name);
364 }
365
366 // There shouldn't be any more selected.
367 {
368 ScopedVariant item;
369 hr = accessibles->Next(1, item.Receive(), &ignore);
370 EXPECT_EQ(S_FALSE, hr);
371 }
372 }
373
196 TEST_F(AXPlatformNodeWinTest, TestIAccessibleRole) { 374 TEST_F(AXPlatformNodeWinTest, TestIAccessibleRole) {
197 AXNodeData root; 375 AXNodeData root;
198 root.id = 1; 376 root.id = 1;
199 root.child_ids.push_back(2); 377 root.child_ids.push_back(2);
200 378
201 AXNodeData child; 379 AXNodeData child;
202 child.id = 2; 380 child.id = 2;
203 381
204 Init(root, child); 382 Init(root, child);
205 AXNode* child_node = GetRootNode()->children()[0]; 383 AXNode* child_node = GetRootNode()->children()[0];
(...skipping 307 matching lines...) Expand 10 before | Expand all | Expand 10 after
513 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 1, 0)); 691 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 1, 0));
514 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 2, 2)); 692 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 2, 2));
515 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, IA2_TEXT_OFFSET_CARET, 693 EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, IA2_TEXT_OFFSET_CARET,
516 IA2_TEXT_OFFSET_LENGTH)); 694 IA2_TEXT_OFFSET_LENGTH));
517 695
518 EXPECT_HRESULT_FAILED(text_field->setSelection(1, 0, 0)); 696 EXPECT_HRESULT_FAILED(text_field->setSelection(1, 0, 0));
519 EXPECT_HRESULT_FAILED(text_field->setSelection(0, 0, 5)); 697 EXPECT_HRESULT_FAILED(text_field->setSelection(0, 0, 5));
520 } 698 }
521 699
522 } // namespace ui 700 } // namespace ui
OLDNEW
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698