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

Unified 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, 6 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « ui/accessibility/platform/ax_platform_node_win.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ui/accessibility/platform/ax_platform_node_win_unittest.cc
diff --git a/ui/accessibility/platform/ax_platform_node_win_unittest.cc b/ui/accessibility/platform/ax_platform_node_win_unittest.cc
index 506267ccaa1d5e4eb0a917282f8ec2259c51be91..467a73acac45cf411cbb3b5fb445620c0b180563 100644
--- a/ui/accessibility/platform/ax_platform_node_win_unittest.cc
+++ b/ui/accessibility/platform/ax_platform_node_win_unittest.cc
@@ -74,6 +74,18 @@ class AXPlatformNodeWinTest : public testing::Test {
update.nodes.push_back(node3);
Init(update);
}
+ void Init(const AXNodeData& node1,
+ const AXNodeData& node2,
+ const AXNodeData& node3,
+ const AXNodeData& node4) {
+ AXTreeUpdate update;
+ update.root_id = node1.id;
+ update.nodes.push_back(node1);
+ update.nodes.push_back(node2);
+ update.nodes.push_back(node3);
+ update.nodes.push_back(node4);
+ Init(update);
+ }
protected:
AXNode* GetRootNode() {
@@ -193,6 +205,172 @@ TEST_F(AXPlatformNodeWinTest, TestIAccessibleShortcut) {
root_obj->get_accKeyboardShortcut(bad_id, k2.Receive()));
}
+TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionNotListBox) {
+ // We only support AX_ROLE_LIST_BOX as this point, so, this should return
+ // not implemented. We're choosing AX_ROLE_ALERT, but it could be anything
+ // but AX_ROLE_LIST_BOX_OPTION.
+
+ AXNodeData not_supported;
+ not_supported.id = 0;
+ not_supported.role = AX_ROLE_ALERT;
+
+ Init(not_supported);
+ ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
+
+ ScopedVariant selection;
+ EXPECT_EQ(E_NOTIMPL, root_obj->get_accSelection(selection.Receive()));
+}
+
+TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionNothingSelected) {
+ // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 2 options with
+ // nothing selected
+ AXNodeData list;
+ list.id = 0;
+ list.role = AX_ROLE_LIST_BOX;
+
+ list.child_ids.push_back(2);
+ list.child_ids.push_back(3);
+
+ AXNodeData list_item_2;
+ list_item_2.id = 2;
+ list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
+
+ AXNodeData list_item_3;
+ list_item_3.id = 3;
+ list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
+
+ // Nothing is selected. This should return S_OK and the selection should
+ // be VT_EMPTY.
+
+ Init(list, list_item_2, list_item_3);
+ ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
+
+ ScopedVariant selection;
+ EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
+ EXPECT_EQ(VT_EMPTY, selection.type());
+}
+
+TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionOneSelected) {
+ // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 2 options with
+ // one selected.
+ AXNodeData list;
+ list.id = 0;
+ list.role = AX_ROLE_LIST_BOX;
+
+ list.child_ids.push_back(2);
+ list.child_ids.push_back(3);
+
+ AXNodeData list_item_2;
+ list_item_2.id = 2;
+ list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_2.state = 1 << ui::AX_STATE_SELECTED;
+ list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
+
+ AXNodeData list_item_3;
+ list_item_3.id = 3;
+ list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
+
+ Init(list, list_item_2, list_item_3);
+
+ ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
+
+ ScopedVariant selection;
+ EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
+ ASSERT_NE(nullptr, selection.ptr());
+
+ // We got something back, make sure that it has the correct name.
+ base::win::ScopedComPtr<IAccessible> accessible;
+ HRESULT hr =
+ V_DISPATCH(selection.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
+ EXPECT_EQ(S_OK, hr);
+ ScopedBstr name;
+ EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
+ EXPECT_STREQ(L"Name2", name);
+}
+
+TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionMultipleSelected) {
+ // We're going to set up a AX_ROLE_LIST_BOX_OPTION with 3 options with
+ // two selected.
+ AXNodeData list;
+ list.id = 0;
+ list.role = AX_ROLE_LIST_BOX;
+
+ list.child_ids.push_back(2);
+ list.child_ids.push_back(3);
+ list.child_ids.push_back(4);
+
+ AXNodeData list_item_2;
+ list_item_2.id = 2;
+ list_item_2.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_2.state = 1 << ui::AX_STATE_SELECTED;
+ list_item_2.AddStringAttribute(AX_ATTR_NAME, "Name2");
+
+ AXNodeData list_item_3;
+ list_item_3.id = 3;
+ list_item_3.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_3.state = 1 << ui::AX_STATE_SELECTED;
+ list_item_3.AddStringAttribute(AX_ATTR_NAME, "Name3");
+
+ AXNodeData list_item_4;
+ list_item_4.id = 4;
+ list_item_4.role = AX_ROLE_LIST_BOX_OPTION;
+ list_item_4.AddStringAttribute(AX_ATTR_NAME, "Name4");
+ Init(list, list_item_2, list_item_3, list_item_4);
+
+ ScopedComPtr<IAccessible> root_obj(GetRootIAccessible());
+
+ ScopedVariant selection;
+ EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
+ ASSERT_NE(nullptr, selection.ptr());
+
+ // We got something back, make sure that it has the corrent name.
+ base::win::ScopedComPtr<IEnumVARIANT> accessibles;
+ HRESULT hr =
+ V_DISPATCH(selection.ptr())->QueryInterface(IID_PPV_ARGS(&accessibles));
+ EXPECT_EQ(S_OK, hr);
+ ULONG ignore;
+
+ // Check out the first selected item.
+ {
+ ScopedVariant item;
+ hr = accessibles->Next(1, item.Receive(), &ignore);
+ EXPECT_EQ(S_OK, hr);
+
+ 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
+ HRESULT hr =
+ V_DISPATCH(item.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
+ EXPECT_EQ(S_OK, hr);
+ ScopedBstr name;
+ EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
+ EXPECT_STREQ(L"Name2", name);
+ }
+
+ // and the second selected element.
+ {
+ ScopedVariant item;
+ hr = accessibles->Next(1, item.Receive(), &ignore);
+ EXPECT_EQ(S_OK, hr);
+
+ base::win::ScopedComPtr<IAccessible> accessible;
+ HRESULT hr =
+ V_DISPATCH(item.ptr())->QueryInterface(IID_PPV_ARGS(&accessible));
+ EXPECT_EQ(S_OK, hr);
+ ScopedBstr name;
+ EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
+ EXPECT_STREQ(L"Name3", name);
+ }
+
+ // There shouldn't be any more selected.
+ {
+ ScopedVariant item;
+ hr = accessibles->Next(1, item.Receive(), &ignore);
+ EXPECT_EQ(S_FALSE, hr);
+ }
+}
+
TEST_F(AXPlatformNodeWinTest, TestIAccessibleRole) {
AXNodeData root;
root.id = 1;
« 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