blob: afd1ba7eddee8d898276a8a87edabd59889a61bf [file] [log] [blame]
//
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/accessibility/platform/ax_platform_node_win_unittest.h"
#include <oleacc.h>
#include <wrl/client.h>
#include <memory>
#include "base/auto_reset.h"
#include "base/stl_util.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/win/atl.h"
#include "base/win/scoped_bstr.h"
#include "base/win/scoped_safearray.h"
#include "base/win/scoped_variant.h"
#include "testing/gmock/include/gmock/gmock-matchers.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/iaccessible2/ia2_api_all.h"
#include "ui/accessibility/ax_enums.mojom.h"
#include "ui/accessibility/ax_node_data.h"
#include "ui/accessibility/platform/ax_fragment_root_win.h"
#include "ui/accessibility/platform/ax_platform_node_win.h"
#include "ui/accessibility/platform/test_ax_node_wrapper.h"
#include "ui/base/win/atl_module.h"
using Microsoft::WRL::ComPtr;
using base::win::ScopedBstr;
using base::win::ScopedVariant;
namespace ui {
namespace {
// Most IAccessible functions require a VARIANT set to CHILDID_SELF as
// the first argument.
ScopedVariant SELF(CHILDID_SELF);
} // namespace
// Helper macros for UIAutomation HRESULT expectations
#define EXPECT_UIA_ELEMENTNOTAVAILABLE(expr) \
EXPECT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE), (expr))
#define EXPECT_UIA_INVALIDOPERATION(expr) \
EXPECT_EQ(static_cast<HRESULT>(UIA_E_INVALIDOPERATION), (expr))
#define EXPECT_UIA_ELEMENTNOTENABLED(expr) \
EXPECT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTENABLED), (expr))
#define EXPECT_UIA_NOTSUPPORTED(expr) \
EXPECT_EQ(static_cast<HRESULT>(UIA_E_NOTSUPPORTED), (expr))
#define ASSERT_UIA_ELEMENTNOTAVAILABLE(expr) \
ASSERT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE), (expr))
#define ASSERT_UIA_INVALIDOPERATION(expr) \
ASSERT_EQ(static_cast<HRESULT>(UIA_E_INVALIDOPERATION), (expr))
#define ASSERT_UIA_ELEMENTNOTENABLED(expr) \
ASSERT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTENABLED), (expr))
#define ASSERT_UIA_NOTSUPPORTED(expr) \
ASSERT_EQ(static_cast<HRESULT>(UIA_E_NOTSUPPORTED), (expr))
// Helper macros for testing UIAutomation property values and maintain
// correct stack tracing and failure causality.
//
// WARNING: These aren't intended to be generic EXPECT_BSTR_EQ macros
// as the logic is specific to extracting and comparing UIA property
// values.
#define EXPECT_UIA_EMPTY(node, property_id) \
{ \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(property_id, actual.Receive())); \
EXPECT_EQ(VT_EMPTY, actual.type()); \
}
#define EXPECT_UIA_VALUE_EQ(node, property_id, expectedVariant) \
{ \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(property_id, actual.Receive())); \
EXPECT_EQ(0, actual.Compare(expectedVariant)); \
}
#define EXPECT_UIA_BSTR_EQ(node, property_id, expected) \
{ \
ScopedVariant expectedVariant(expected); \
ASSERT_EQ(VT_BSTR, expectedVariant.type()); \
ASSERT_NE(nullptr, expectedVariant.ptr()->bstrVal); \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(property_id, actual.Receive())); \
ASSERT_EQ(VT_BSTR, actual.type()); \
ASSERT_NE(nullptr, actual.ptr()->bstrVal); \
EXPECT_STREQ(expectedVariant.ptr()->bstrVal, actual.ptr()->bstrVal); \
}
#define EXPECT_UIA_BOOL_EQ(node, property_id, expected) \
{ \
ScopedVariant expectedVariant(expected, VT_BOOL); \
ASSERT_EQ(VT_BOOL, expectedVariant.type()); \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(property_id, actual.Receive())); \
EXPECT_EQ(expectedVariant.ptr()->boolVal, actual.ptr()->boolVal); \
}
#define EXPECT_UIA_DOUBLE_ARRAY_EQ(node, array_property_id, \
expected_property_values) \
{ \
ScopedVariant array; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(array_property_id, array.Receive())); \
ASSERT_EQ(VT_ARRAY | VT_R8, array.type()); \
ASSERT_EQ(1u, SafeArrayGetDim(array.ptr()->parray)); \
LONG array_lower_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetLBound(array.ptr()->parray, 1, &array_lower_bound)); \
LONG array_upper_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetUBound(array.ptr()->parray, 1, &array_upper_bound)); \
double* array_data; \
ASSERT_HRESULT_SUCCEEDED(::SafeArrayAccessData( \
array.ptr()->parray, reinterpret_cast<void**>(&array_data))); \
size_t count = array_upper_bound - array_lower_bound + 1; \
ASSERT_EQ(expected_property_values.size(), count); \
for (size_t i = 0; i < count; ++i) { \
EXPECT_EQ(array_data[i], expected_property_values[i]); \
} \
ASSERT_HRESULT_SUCCEEDED(::SafeArrayUnaccessData(array.ptr()->parray)); \
}
#define EXPECT_UIA_INT_EQ(node, property_id, expected) \
{ \
ScopedVariant expectedVariant(expected, VT_I4); \
ASSERT_EQ(VT_I4, expectedVariant.type()); \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(property_id, actual.Receive())); \
EXPECT_EQ(expectedVariant.ptr()->intVal, actual.ptr()->intVal); \
}
#define EXPECT_UIA_ELEMENT_ARRAY_BSTR_EQ(array, element_test_property_id, \
expected_property_values) \
{ \
ASSERT_EQ(1u, SafeArrayGetDim(array)); \
LONG array_lower_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetLBound(array, 1, &array_lower_bound)); \
LONG array_upper_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetUBound(array, 1, &array_upper_bound)); \
IUnknown** array_data; \
ASSERT_HRESULT_SUCCEEDED( \
::SafeArrayAccessData(array, reinterpret_cast<void**>(&array_data))); \
size_t count = array_upper_bound - array_lower_bound + 1; \
ASSERT_EQ(expected_property_values.size(), count); \
for (size_t i = 0; i < count; ++i) { \
CComPtr<IRawElementProviderSimple> element; \
ASSERT_HRESULT_SUCCEEDED(array_data[i]->QueryInterface(&element)); \
EXPECT_UIA_BSTR_EQ(element, element_test_property_id, \
expected_property_values[i].c_str()); \
} \
ASSERT_HRESULT_SUCCEEDED(::SafeArrayUnaccessData(array)); \
}
#define EXPECT_UIA_PROPERTY_ELEMENT_ARRAY_BSTR_EQ(node, array_property_id, \
element_test_property_id, \
expected_property_values) \
{ \
ScopedVariant array; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(array_property_id, array.Receive())); \
ASSERT_EQ(VT_ARRAY | VT_UNKNOWN, array.type()); \
EXPECT_UIA_ELEMENT_ARRAY_BSTR_EQ(array.ptr()->parray, \
element_test_property_id, \
expected_property_values); \
}
#define EXPECT_UIA_PROPERTY_UNORDERED_ELEMENT_ARRAY_BSTR_EQ( \
node, array_property_id, element_test_property_id, \
expected_property_values) \
{ \
ScopedVariant array; \
ASSERT_HRESULT_SUCCEEDED( \
node->GetPropertyValue(array_property_id, array.Receive())); \
ASSERT_EQ(VT_ARRAY | VT_UNKNOWN, array.type()); \
ASSERT_EQ(1u, SafeArrayGetDim(array.ptr()->parray)); \
LONG array_lower_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetLBound(array.ptr()->parray, 1, &array_lower_bound)); \
LONG array_upper_bound; \
ASSERT_HRESULT_SUCCEEDED( \
SafeArrayGetUBound(array.ptr()->parray, 1, &array_upper_bound)); \
IUnknown** array_data; \
ASSERT_HRESULT_SUCCEEDED(::SafeArrayAccessData( \
array.ptr()->parray, reinterpret_cast<void**>(&array_data))); \
size_t count = array_upper_bound - array_lower_bound + 1; \
ASSERT_EQ(expected_property_values.size(), count); \
std::vector<std::wstring> property_values; \
for (size_t i = 0; i < count; ++i) { \
CComPtr<IRawElementProviderSimple> element; \
ASSERT_HRESULT_SUCCEEDED(array_data[i]->QueryInterface(&element)); \
ScopedVariant actual; \
ASSERT_HRESULT_SUCCEEDED(element->GetPropertyValue( \
element_test_property_id, actual.Receive())); \
ASSERT_EQ(VT_BSTR, actual.type()); \
ASSERT_NE(nullptr, actual.ptr()->bstrVal); \
property_values.push_back(std::wstring( \
V_BSTR(actual.ptr()), SysStringLen(V_BSTR(actual.ptr())))); \
} \
ASSERT_HRESULT_SUCCEEDED(::SafeArrayUnaccessData(array.ptr()->parray)); \
EXPECT_THAT(property_values, \
testing::UnorderedElementsAreArray(expected_property_values)); \
}
AXPlatformNodeWinTest::AXPlatformNodeWinTest() {}
AXPlatformNodeWinTest::~AXPlatformNodeWinTest() {}
void AXPlatformNodeWinTest::SetUp() {
win::CreateATLModuleIfNeeded();
}
void AXPlatformNodeWinTest::TearDown() {
// Destroy the tree and make sure we're not leaking any objects.
ax_fragment_root_.reset(nullptr);
tree_.reset(nullptr);
AXNodePosition::SetTree(nullptr);
ASSERT_EQ(0U, AXPlatformNodeBase::GetInstanceCountForTesting());
}
AXPlatformNode* AXPlatformNodeWinTest::AXPlatformNodeFromNode(AXNode* node) {
const TestAXNodeWrapper* wrapper =
TestAXNodeWrapper::GetOrCreate(tree_.get(), node);
if (!wrapper)
return nullptr;
return wrapper->ax_platform_node();
}
template <typename T>
ComPtr<T> AXPlatformNodeWinTest::QueryInterfaceFromNodeId(int32_t id) {
const TestAXNodeWrapper* wrapper =
TestAXNodeWrapper::GetOrCreate(tree_.get(), tree_->GetFromId(id));
if (!wrapper)
return ComPtr<T>();
AXPlatformNode* ax_platform_node = wrapper->ax_platform_node();
ComPtr<T> result;
EXPECT_HRESULT_SUCCEEDED(
ax_platform_node->GetNativeViewAccessible()->QueryInterface(__uuidof(T),
&result));
return result;
}
template <typename T>
ComPtr<T> AXPlatformNodeWinTest::QueryInterfaceFromNode(AXNode* node) {
AXPlatformNode* ax_platform_node = AXPlatformNodeFromNode(node);
if (!ax_platform_node)
return ComPtr<T>();
ComPtr<T> result;
EXPECT_HRESULT_SUCCEEDED(
ax_platform_node->GetNativeViewAccessible()->QueryInterface(__uuidof(T),
&result));
return result;
}
ComPtr<IRawElementProviderSimple>
AXPlatformNodeWinTest::GetRootIRawElementProviderSimple() {
return QueryInterfaceFromNode<IRawElementProviderSimple>(GetRootNode());
}
ComPtr<IRawElementProviderSimple>
AXPlatformNodeWinTest::GetIRawElementProviderSimpleFromChildIndex(
int child_index) {
if (!GetRootNode() || child_index < 0 ||
size_t{child_index} >= GetRootNode()->children().size()) {
return ComPtr<IRawElementProviderSimple>();
}
return QueryInterfaceFromNode<IRawElementProviderSimple>(
GetRootNode()->children()[size_t{child_index}]);
}
ComPtr<IRawElementProviderFragment>
AXPlatformNodeWinTest::GetRootIRawElementProviderFragment() {
return QueryInterfaceFromNode<IRawElementProviderFragment>(GetRootNode());
}
Microsoft::WRL::ComPtr<IRawElementProviderFragment>
AXPlatformNodeWinTest::IRawElementProviderFragmentFromNode(AXNode* node) {
AXPlatformNode* platform_node = AXPlatformNodeFromNode(node);
gfx::NativeViewAccessible native_view =
platform_node->GetNativeViewAccessible();
ComPtr<IUnknown> unknown_node = native_view;
ComPtr<IRawElementProviderFragment> fragment_node;
unknown_node.As(&fragment_node);
return fragment_node;
}
ComPtr<IAccessible> AXPlatformNodeWinTest::IAccessibleFromNode(AXNode* node) {
return QueryInterfaceFromNode<IAccessible>(node);
}
ComPtr<IAccessible> AXPlatformNodeWinTest::GetRootIAccessible() {
return IAccessibleFromNode(GetRootNode());
}
ComPtr<IAccessible2> AXPlatformNodeWinTest::ToIAccessible2(
ComPtr<IUnknown> unknown) {
CHECK(unknown);
ComPtr<IServiceProvider> service_provider;
unknown.As(&service_provider);
ComPtr<IAccessible2> result;
CHECK(SUCCEEDED(
service_provider->QueryService(IID_IAccessible2, IID_PPV_ARGS(&result))));
return result;
}
ComPtr<IAccessible2> AXPlatformNodeWinTest::ToIAccessible2(
ComPtr<IAccessible> accessible) {
CHECK(accessible);
ComPtr<IServiceProvider> service_provider;
accessible.As(&service_provider);
ComPtr<IAccessible2> result;
CHECK(SUCCEEDED(
service_provider->QueryService(IID_IAccessible2, IID_PPV_ARGS(&result))));
return result;
}
ComPtr<IAccessible2_2> AXPlatformNodeWinTest::ToIAccessible2_2(
ComPtr<IAccessible> accessible) {
CHECK(accessible);
ComPtr<IServiceProvider> service_provider;
accessible.As(&service_provider);
ComPtr<IAccessible2_2> result;
CHECK(SUCCEEDED(service_provider->QueryService(IID_IAccessible2_2,
IID_PPV_ARGS(&result))));
return result;
}
void AXPlatformNodeWinTest::CheckVariantHasName(const ScopedVariant& variant,
const wchar_t* expected_name) {
ASSERT_NE(nullptr, variant.ptr());
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(variant.ptr())->QueryInterface(IID_PPV_ARGS(&accessible)));
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(expected_name, name);
}
void AXPlatformNodeWinTest::CheckIUnknownHasName(ComPtr<IUnknown> unknown,
const wchar_t* expected_name) {
ComPtr<IAccessible2> accessible = ToIAccessible2(unknown);
ASSERT_NE(nullptr, accessible.Get());
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(expected_name, name);
}
ComPtr<IAccessibleTableCell> AXPlatformNodeWinTest::GetCellInTable() {
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable2> table;
root_obj.As(&table);
if (!table)
return ComPtr<IAccessibleTableCell>();
ComPtr<IUnknown> cell;
table->get_cellAt(1, 1, &cell);
if (!cell)
return ComPtr<IAccessibleTableCell>();
ComPtr<IAccessibleTableCell> table_cell;
cell.As(&table_cell);
return table_cell;
}
void AXPlatformNodeWinTest::InitFragmentRoot() {
test_fragment_root_delegate_ = std::make_unique<TestFragmentRootDelegate>();
ax_fragment_root_.reset(InitNodeAsFragmentRoot(
GetRootNode(), test_fragment_root_delegate_.get()));
}
AXFragmentRootWin* AXPlatformNodeWinTest::InitNodeAsFragmentRoot(
AXNode* node,
TestFragmentRootDelegate* delegate) {
delegate->child_ = AXPlatformNodeFromNode(node)->GetNativeViewAccessible();
if (node->parent())
delegate->parent_ =
AXPlatformNodeFromNode(node->parent())->GetNativeViewAccessible();
return new AXFragmentRootWin(gfx::kMockAcceleratedWidget, delegate);
}
ComPtr<IRawElementProviderFragmentRoot>
AXPlatformNodeWinTest::GetFragmentRoot() {
ComPtr<IRawElementProviderFragmentRoot> fragment_root_provider;
ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(
IID_PPV_ARGS(&fragment_root_provider));
return fragment_root_provider;
}
AXPlatformNodeWinTest::PatternSet
AXPlatformNodeWinTest::GetSupportedPatternsFromNodeId(int32_t id) {
ComPtr<IRawElementProviderSimple> raw_element_provider_simple =
QueryInterfaceFromNodeId<IRawElementProviderSimple>(id);
PatternSet supported_patterns;
static const std::vector<LONG> all_supported_patterns_ = {
UIA_TextChildPatternId, UIA_TextEditPatternId,
UIA_TextPatternId, UIA_WindowPatternId,
UIA_InvokePatternId, UIA_ExpandCollapsePatternId,
UIA_GridPatternId, UIA_GridItemPatternId,
UIA_RangeValuePatternId, UIA_ScrollPatternId,
UIA_ScrollItemPatternId, UIA_TablePatternId,
UIA_TableItemPatternId, UIA_SelectionItemPatternId,
UIA_SelectionPatternId, UIA_TogglePatternId,
UIA_ValuePatternId,
};
for (LONG property_id : all_supported_patterns_) {
CComPtr<IUnknown> provider = nullptr;
if (SUCCEEDED(raw_element_provider_simple->GetPatternProvider(property_id,
&provider)) &&
provider) {
supported_patterns.insert(property_id);
}
}
return supported_patterns;
}
TestFragmentRootDelegate::TestFragmentRootDelegate() = default;
TestFragmentRootDelegate::~TestFragmentRootDelegate() = default;
gfx::NativeViewAccessible TestFragmentRootDelegate::GetChildOfAXFragmentRoot() {
return child_;
}
gfx::NativeViewAccessible
TestFragmentRootDelegate::GetParentOfAXFragmentRoot() {
return parent_;
}
bool TestFragmentRootDelegate::IsAXFragmentRootAControlElement() {
return is_control_element_;
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleDetachedObject) {
AXNodeData root;
root.id = 1;
root.SetName("Name");
Init(root);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ScopedBstr name;
EXPECT_EQ(S_OK, root_obj->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"Name", name);
tree_ = std::make_unique<AXTree>();
ScopedBstr name2;
EXPECT_EQ(E_FAIL, root_obj->get_accName(SELF, name2.Receive()));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleHitTest) {
AXNodeData root;
root.id = 1;
root.relative_bounds.bounds = gfx::RectF(0, 0, 40, 40);
AXNodeData node1;
node1.id = 2;
node1.relative_bounds.bounds = gfx::RectF(0, 0, 10, 10);
node1.SetName("Name1");
root.child_ids.push_back(node1.id);
AXNodeData node2;
node2.id = 3;
node2.relative_bounds.bounds = gfx::RectF(20, 20, 20, 20);
node2.SetName("Name2");
root.child_ids.push_back(node2.id);
AXNodeData node3;
node3.id = 4;
node3.relative_bounds.bounds = gfx::RectF(10, 10, 10, 10);
node3.SetName("Name3");
root.child_ids.push_back(node3.id);
// Overlapping child view.
AXNodeData node4;
node4.id = 5;
node4.relative_bounds.bounds = gfx::RectF(10, 10, 5, 5);
node4.SetName("Name4");
node3.child_ids.push_back(node4.id);
Init(root, node1, node2, node3, node4);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
// This is way outside of the root node.
ScopedVariant obj_1;
EXPECT_EQ(S_FALSE, root_obj->accHitTest(50, 50, obj_1.Receive()));
EXPECT_EQ(VT_EMPTY, obj_1.type());
// This is directly on node 1.
EXPECT_EQ(S_OK, root_obj->accHitTest(5, 5, obj_1.Receive()));
ASSERT_NE(nullptr, obj_1.ptr());
CheckVariantHasName(obj_1, L"Name1");
// This is directly on node 3 and 4.
ScopedVariant obj_2;
EXPECT_EQ(S_OK, root_obj->accHitTest(12, 12, obj_2.Receive()));
ASSERT_NE(nullptr, obj_2.ptr());
CheckVariantHasName(obj_2, L"Name4");
// This is directly on node 2 with a scale factor of 1.5.
ScopedVariant obj_3;
std::unique_ptr<base::AutoReset<float>> scale_factor_reset =
TestAXNodeWrapper::SetScaleFactor(1.5);
EXPECT_EQ(S_OK, root_obj->accHitTest(38, 38, obj_3.Receive()));
ASSERT_NE(nullptr, obj_3.ptr());
CheckVariantHasName(obj_3, L"Name2");
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleName) {
AXNodeData root;
root.id = 1;
root.SetName("Name");
Init(root);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ScopedBstr name;
EXPECT_EQ(S_OK, root_obj->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"Name", name);
EXPECT_EQ(E_INVALIDARG, root_obj->get_accName(SELF, nullptr));
ScopedVariant bad_id(999);
ScopedBstr name2;
EXPECT_EQ(E_INVALIDARG, root_obj->get_accName(bad_id, name2.Receive()));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleDescription) {
AXNodeData root;
root.id = 1;
root.AddStringAttribute(ax::mojom::StringAttribute::kDescription,
"Description");
Init(root);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ScopedBstr description;
EXPECT_EQ(S_OK, root_obj->get_accDescription(SELF, description.Receive()));
EXPECT_STREQ(L"Description", description);
EXPECT_EQ(E_INVALIDARG, root_obj->get_accDescription(SELF, nullptr));
ScopedVariant bad_id(999);
ScopedBstr d2;
EXPECT_EQ(E_INVALIDARG, root_obj->get_accDescription(bad_id, d2.Receive()));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleValue) {
AXNodeData root;
root.id = 1;
root.AddStringAttribute(ax::mojom::StringAttribute::kValue, "Value");
Init(root);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ScopedBstr value;
EXPECT_EQ(S_OK, root_obj->get_accValue(SELF, value.Receive()));
EXPECT_STREQ(L"Value", value);
EXPECT_EQ(E_INVALIDARG, root_obj->get_accValue(SELF, nullptr));
ScopedVariant bad_id(999);
ScopedBstr v2;
EXPECT_EQ(E_INVALIDARG, root_obj->get_accValue(bad_id, v2.Receive()));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleShortcut) {
AXNodeData root;
root.id = 1;
root.AddStringAttribute(ax::mojom::StringAttribute::kKeyShortcuts,
"Shortcut");
Init(root);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ScopedBstr shortcut;
EXPECT_EQ(S_OK, root_obj->get_accKeyboardShortcut(SELF, shortcut.Receive()));
EXPECT_STREQ(L"Shortcut", shortcut);
EXPECT_EQ(E_INVALIDARG, root_obj->get_accKeyboardShortcut(SELF, nullptr));
ScopedVariant bad_id(999);
ScopedBstr k2;
EXPECT_EQ(E_INVALIDARG,
root_obj->get_accKeyboardShortcut(bad_id, k2.Receive()));
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleSelectionListBoxOptionNothingSelected) {
AXNodeData list;
list.id = 1;
list.role = ax::mojom::Role::kListBox;
AXNodeData list_item_1;
list_item_1.id = 2;
list_item_1.role = ax::mojom::Role::kListBoxOption;
list_item_1.SetName("Name1");
AXNodeData list_item_2;
list_item_2.id = 3;
list_item_2.role = ax::mojom::Role::kListBoxOption;
list_item_2.SetName("Name2");
list.child_ids.push_back(list_item_1.id);
list.child_ids.push_back(list_item_2.id);
Init(list, list_item_1, list_item_2);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_EMPTY, selection.type());
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleSelectionListBoxOptionOneSelected) {
AXNodeData list;
list.id = 1;
list.role = ax::mojom::Role::kListBox;
AXNodeData list_item_1;
list_item_1.id = 2;
list_item_1.role = ax::mojom::Role::kListBoxOption;
list_item_1.AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
list_item_1.SetName("Name1");
AXNodeData list_item_2;
list_item_2.id = 3;
list_item_2.role = ax::mojom::Role::kListBoxOption;
list_item_2.SetName("Name2");
list.child_ids.push_back(list_item_1.id);
list.child_ids.push_back(list_item_2.id);
Init(list, list_item_1, list_item_2);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_DISPATCH, selection.type());
CheckVariantHasName(selection, L"Name1");
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleSelectionListBoxOptionMultipleSelected) {
AXNodeData list;
list.id = 1;
list.role = ax::mojom::Role::kListBox;
AXNodeData list_item_1;
list_item_1.id = 2;
list_item_1.role = ax::mojom::Role::kListBoxOption;
list_item_1.AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
list_item_1.SetName("Name1");
AXNodeData list_item_2;
list_item_2.id = 3;
list_item_2.role = ax::mojom::Role::kListBoxOption;
list_item_2.AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
list_item_2.SetName("Name2");
AXNodeData list_item_3;
list_item_3.id = 4;
list_item_3.role = ax::mojom::Role::kListBoxOption;
list_item_3.SetName("Name3");
list.child_ids.push_back(list_item_1.id);
list.child_ids.push_back(list_item_2.id);
list.child_ids.push_back(list_item_3.id);
Init(list, list_item_1, list_item_2, list_item_3);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_UNKNOWN, selection.type());
ASSERT_NE(nullptr, selection.ptr());
// Loop through the selections and make sure we have the right ones.
ComPtr<IEnumVARIANT> accessibles;
ASSERT_HRESULT_SUCCEEDED(
V_UNKNOWN(selection.ptr())
->QueryInterface(IID_PPV_ARGS(accessibles.GetAddressOf())));
ULONG retrieved_count;
// Check out the first selected item.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"Name1", name);
}
// And the second selected element.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"Name2", name);
}
// There shouldn't be any more selected.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_FALSE, hr);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionTableNothingSelected) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_EMPTY, selection.type());
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionTableRowOneSelected) {
AXTreeUpdate update = Build3X3Table();
// 5 == table_row_1
update.nodes[5].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_DISPATCH, selection.type());
ASSERT_NE(nullptr, selection.ptr());
ComPtr<IAccessible> row;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(selection.ptr())
->QueryInterface(IID_PPV_ARGS(row.GetAddressOf())));
ScopedVariant role;
EXPECT_HRESULT_SUCCEEDED(row->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_ROW, V_I4(role.ptr()));
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleSelectionTableRowMultipleSelected) {
AXTreeUpdate update = Build3X3Table();
// 5 == table_row_1
// 9 == table_row_2
update.nodes[5].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[9].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ScopedVariant selection;
EXPECT_EQ(S_OK, root_obj->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_UNKNOWN, selection.type());
ASSERT_NE(nullptr, selection.ptr());
// Loop through the selections and make sure we have the right ones.
ComPtr<IEnumVARIANT> accessibles;
ASSERT_HRESULT_SUCCEEDED(
V_UNKNOWN(selection.ptr())
->QueryInterface(IID_PPV_ARGS(accessibles.GetAddressOf())));
ULONG retrieved_count;
// Check out the first selected row.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedVariant role;
EXPECT_HRESULT_SUCCEEDED(accessible->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_ROW, V_I4(role.ptr()));
}
// And the second selected element.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedVariant role;
EXPECT_HRESULT_SUCCEEDED(accessible->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_ROW, V_I4(role.ptr()));
}
// There shouldn't be any more selected.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_FALSE, hr);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleSelectionTableCellOneSelected) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ComPtr<IDispatch> row2;
ASSERT_HRESULT_SUCCEEDED(
root_obj->get_accChild(ScopedVariant(2), row2.GetAddressOf()));
ComPtr<IAccessible> row2_accessible;
ASSERT_HRESULT_SUCCEEDED(row2.As(&row2_accessible));
ScopedVariant selection;
EXPECT_EQ(S_OK, row2_accessible->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_DISPATCH, selection.type());
ASSERT_NE(nullptr, selection.ptr());
ComPtr<IAccessible> cell;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(selection.ptr())
->QueryInterface(IID_PPV_ARGS(cell.GetAddressOf())));
ScopedVariant role;
EXPECT_HRESULT_SUCCEEDED(cell->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_CELL, V_I4(role.ptr()));
ScopedBstr name;
EXPECT_EQ(S_OK, cell->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"1", name);
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleSelectionTableCellMultipleSelected) {
AXTreeUpdate update = Build3X3Table();
// 11 == table_cell_3
// 12 == table_cell_4
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ASSERT_NE(nullptr, root_obj.Get());
ComPtr<IDispatch> row3;
ASSERT_HRESULT_SUCCEEDED(
root_obj->get_accChild(ScopedVariant(3), row3.GetAddressOf()));
ComPtr<IAccessible> row3_accessible;
ASSERT_HRESULT_SUCCEEDED(row3.As(&row3_accessible));
ScopedVariant selection;
EXPECT_EQ(S_OK, row3_accessible->get_accSelection(selection.Receive()));
EXPECT_EQ(VT_UNKNOWN, selection.type());
ASSERT_NE(nullptr, selection.ptr());
// Loop through the selections and make sure we have the right ones.
ComPtr<IEnumVARIANT> accessibles;
ASSERT_HRESULT_SUCCEEDED(
V_UNKNOWN(selection.ptr())
->QueryInterface(IID_PPV_ARGS(accessibles.GetAddressOf())));
ULONG retrieved_count;
// Check out the first selected cell.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"3", name);
}
// And the second selected cell.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_OK, hr);
ComPtr<IAccessible> accessible;
ASSERT_HRESULT_SUCCEEDED(
V_DISPATCH(item.ptr())
->QueryInterface(IID_PPV_ARGS(accessible.GetAddressOf())));
ScopedBstr name;
EXPECT_EQ(S_OK, accessible->get_accName(SELF, name.Receive()));
EXPECT_STREQ(L"4", name);
}
// There shouldn't be any more selected.
{
ScopedVariant item;
HRESULT hr = accessibles->Next(1, item.Receive(), &retrieved_count);
EXPECT_EQ(S_FALSE, hr);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleRole) {
AXNodeData root;
root.id = 1;
root.child_ids.push_back(2);
AXNodeData child;
child.id = 2;
Init(root, child);
AXNode* child_node = GetRootNode()->children()[0];
ComPtr<IAccessible> child_iaccessible(IAccessibleFromNode(child_node));
ScopedVariant role;
child.role = ax::mojom::Role::kAlert;
child_node->SetData(child);
EXPECT_EQ(S_OK, child_iaccessible->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_ALERT, V_I4(role.ptr()));
child.role = ax::mojom::Role::kButton;
child_node->SetData(child);
EXPECT_EQ(S_OK, child_iaccessible->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_PUSHBUTTON, V_I4(role.ptr()));
child.role = ax::mojom::Role::kPopUpButton;
child_node->SetData(child);
EXPECT_EQ(S_OK, child_iaccessible->get_accRole(SELF, role.Receive()));
EXPECT_EQ(ROLE_SYSTEM_BUTTONMENU, V_I4(role.ptr()));
EXPECT_EQ(E_INVALIDARG, child_iaccessible->get_accRole(SELF, nullptr));
ScopedVariant bad_id(999);
EXPECT_EQ(E_INVALIDARG,
child_iaccessible->get_accRole(bad_id, role.Receive()));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleLocation) {
AXNodeData root;
root.id = 1;
root.relative_bounds.bounds = gfx::RectF(10, 40, 800, 600);
Init(root);
TestAXNodeWrapper::SetGlobalCoordinateOffset(gfx::Vector2d(100, 200));
LONG x_left, y_top, width, height;
EXPECT_EQ(S_OK, GetRootIAccessible()->accLocation(&x_left, &y_top, &width,
&height, SELF));
EXPECT_EQ(110, x_left);
EXPECT_EQ(240, y_top);
EXPECT_EQ(800, width);
EXPECT_EQ(600, height);
EXPECT_EQ(E_INVALIDARG, GetRootIAccessible()->accLocation(
nullptr, &y_top, &width, &height, SELF));
EXPECT_EQ(E_INVALIDARG, GetRootIAccessible()->accLocation(
&x_left, nullptr, &width, &height, SELF));
EXPECT_EQ(E_INVALIDARG, GetRootIAccessible()->accLocation(
&x_left, &y_top, nullptr, &height, SELF));
EXPECT_EQ(E_INVALIDARG, GetRootIAccessible()->accLocation(
&x_left, &y_top, &width, nullptr, SELF));
ScopedVariant bad_id(999);
EXPECT_EQ(E_INVALIDARG, GetRootIAccessible()->accLocation(
&x_left, &y_top, &width, &height, bad_id));
// Un-set the global offset so that it doesn't affect subsequent tests.
TestAXNodeWrapper::SetGlobalCoordinateOffset(gfx::Vector2d(0, 0));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleChildAndParent) {
AXNodeData root;
root.id = 1;
root.child_ids.push_back(2);
root.child_ids.push_back(3);
AXNodeData button;
button.role = ax::mojom::Role::kButton;
button.id = 2;
AXNodeData checkbox;
checkbox.role = ax::mojom::Role::kCheckBox;
checkbox.id = 3;
Init(root, button, checkbox);
AXNode* button_node = GetRootNode()->children()[0];
AXNode* checkbox_node = GetRootNode()->children()[1];
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IAccessible> button_iaccessible(IAccessibleFromNode(button_node));
ComPtr<IAccessible> checkbox_iaccessible(IAccessibleFromNode(checkbox_node));
LONG child_count;
EXPECT_EQ(S_OK, root_iaccessible->get_accChildCount(&child_count));
EXPECT_EQ(2L, child_count);
EXPECT_EQ(S_OK, button_iaccessible->get_accChildCount(&child_count));
EXPECT_EQ(0L, child_count);
EXPECT_EQ(S_OK, checkbox_iaccessible->get_accChildCount(&child_count));
EXPECT_EQ(0L, child_count);
{
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK,
root_iaccessible->get_accChild(SELF, result.GetAddressOf()));
EXPECT_EQ(result.Get(), root_iaccessible.Get());
}
{
ComPtr<IDispatch> result;
ScopedVariant child1(1);
EXPECT_EQ(S_OK,
root_iaccessible->get_accChild(child1, result.GetAddressOf()));
EXPECT_EQ(result.Get(), button_iaccessible.Get());
}
{
ComPtr<IDispatch> result;
ScopedVariant child2(2);
EXPECT_EQ(S_OK,
root_iaccessible->get_accChild(child2, result.GetAddressOf()));
EXPECT_EQ(result.Get(), checkbox_iaccessible.Get());
}
{
// Asking for child id 3 should fail.
ComPtr<IDispatch> result;
ScopedVariant child3(3);
EXPECT_EQ(E_INVALIDARG,
root_iaccessible->get_accChild(child3, result.GetAddressOf()));
}
// We should be able to ask for the button by its unique id too.
LONG button_unique_id;
ComPtr<IAccessible2> button_iaccessible2 = ToIAccessible2(button_iaccessible);
button_iaccessible2->get_uniqueID(&button_unique_id);
ASSERT_LT(button_unique_id, 0);
{
ComPtr<IDispatch> result;
ScopedVariant button_id_variant(button_unique_id);
EXPECT_EQ(S_OK, root_iaccessible->get_accChild(button_id_variant,
result.GetAddressOf()));
EXPECT_EQ(result.Get(), button_iaccessible.Get());
}
// We shouldn't be able to ask for the root node by its unique ID
// from one of its children, though.
LONG root_unique_id;
ComPtr<IAccessible2> root_iaccessible2 = ToIAccessible2(root_iaccessible);
root_iaccessible2->get_uniqueID(&root_unique_id);
ASSERT_LT(root_unique_id, 0);
{
ComPtr<IDispatch> result;
ScopedVariant root_id_variant(root_unique_id);
EXPECT_EQ(E_INVALIDARG, button_iaccessible->get_accChild(
root_id_variant, result.GetAddressOf()));
}
// Now check parents.
{
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, button_iaccessible->get_accParent(result.GetAddressOf()));
EXPECT_EQ(result.Get(), root_iaccessible.Get());
}
{
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, checkbox_iaccessible->get_accParent(result.GetAddressOf()));
EXPECT_EQ(result.Get(), root_iaccessible.Get());
}
{
ComPtr<IDispatch> result;
EXPECT_EQ(S_FALSE, root_iaccessible->get_accParent(result.GetAddressOf()));
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessible2IndexInParent) {
AXNodeData root;
root.id = 1;
root.child_ids.push_back(2);
root.child_ids.push_back(3);
AXNodeData left;
left.id = 2;
AXNodeData right;
right.id = 3;
Init(root, left, right);
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IAccessible2> root_iaccessible2 = ToIAccessible2(root_iaccessible);
ComPtr<IAccessible> left_iaccessible(
IAccessibleFromNode(GetRootNode()->children()[0]));
ComPtr<IAccessible2> left_iaccessible2 = ToIAccessible2(left_iaccessible);
ComPtr<IAccessible> right_iaccessible(
IAccessibleFromNode(GetRootNode()->children()[1]));
ComPtr<IAccessible2> right_iaccessible2 = ToIAccessible2(right_iaccessible);
LONG index;
EXPECT_EQ(E_FAIL, root_iaccessible2->get_indexInParent(&index));
EXPECT_EQ(S_OK, left_iaccessible2->get_indexInParent(&index));
EXPECT_EQ(0, index);
EXPECT_EQ(S_OK, right_iaccessible2->get_indexInParent(&index));
EXPECT_EQ(1, index);
}
TEST_F(AXPlatformNodeWinTest, TestAccNavigate) {
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
AXNodeData child1;
child1.id = 2;
child1.role = ax::mojom::Role::kStaticText;
root.child_ids.push_back(2);
AXNodeData child2;
child2.id = 3;
child2.role = ax::mojom::Role::kStaticText;
root.child_ids.push_back(3);
Init(root, child1, child2);
ComPtr<IAccessible> ia_root(GetRootIAccessible());
ComPtr<IDispatch> disp_root;
ASSERT_HRESULT_SUCCEEDED(ia_root.CopyTo(disp_root.GetAddressOf()));
ScopedVariant var_root(disp_root.Get());
ComPtr<IAccessible> ia_child1(
IAccessibleFromNode(GetRootNode()->children()[0]));
ComPtr<IDispatch> disp_child1;
ASSERT_HRESULT_SUCCEEDED(ia_child1.CopyTo(disp_child1.GetAddressOf()));
ScopedVariant var_child1(disp_child1.Get());
ComPtr<IAccessible> ia_child2(
IAccessibleFromNode(GetRootNode()->children()[1]));
ComPtr<IDispatch> disp_child2;
ASSERT_HRESULT_SUCCEEDED(ia_child2.CopyTo(disp_child2.GetAddressOf()));
ScopedVariant var_child2(disp_child2.Get());
ScopedVariant end;
// Invalid arguments.
EXPECT_EQ(
E_INVALIDARG,
ia_root->accNavigate(NAVDIR_NEXT, ScopedVariant::kEmptyVariant, nullptr));
EXPECT_EQ(E_INVALIDARG,
ia_child1->accNavigate(NAVDIR_NEXT, ScopedVariant::kEmptyVariant,
end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
// Navigating to first/last child should only be from self.
EXPECT_EQ(E_INVALIDARG,
ia_root->accNavigate(NAVDIR_FIRSTCHILD, var_root, end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
EXPECT_EQ(E_INVALIDARG,
ia_root->accNavigate(NAVDIR_LASTCHILD, var_root, end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
// Spatial directions are not supported.
EXPECT_EQ(E_NOTIMPL, ia_child1->accNavigate(NAVDIR_UP, SELF, end.AsInput()));
EXPECT_EQ(E_NOTIMPL, ia_root->accNavigate(NAVDIR_DOWN, SELF, end.AsInput()));
EXPECT_EQ(E_NOTIMPL,
ia_child1->accNavigate(NAVDIR_RIGHT, SELF, end.AsInput()));
EXPECT_EQ(E_NOTIMPL,
ia_child2->accNavigate(NAVDIR_LEFT, SELF, end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
// Logical directions should be supported.
EXPECT_EQ(S_OK, ia_root->accNavigate(NAVDIR_FIRSTCHILD, SELF, end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child1.ptr()), V_DISPATCH(end.ptr()));
EXPECT_EQ(S_OK, ia_root->accNavigate(NAVDIR_LASTCHILD, SELF, end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child2.ptr()), V_DISPATCH(end.ptr()));
EXPECT_EQ(S_OK, ia_child1->accNavigate(NAVDIR_NEXT, SELF, end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child2.ptr()), V_DISPATCH(end.ptr()));
EXPECT_EQ(S_OK, ia_child2->accNavigate(NAVDIR_PREVIOUS, SELF, end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child1.ptr()), V_DISPATCH(end.ptr()));
// Child indices can also be passed by variant.
// Indices are one-based.
EXPECT_EQ(S_OK,
ia_root->accNavigate(NAVDIR_NEXT, ScopedVariant(1), end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child2.ptr()), V_DISPATCH(end.ptr()));
EXPECT_EQ(S_OK, ia_root->accNavigate(NAVDIR_PREVIOUS, ScopedVariant(2),
end.AsInput()));
EXPECT_EQ(VT_DISPATCH, end.type());
EXPECT_EQ(V_DISPATCH(var_child1.ptr()), V_DISPATCH(end.ptr()));
// Test out-of-bounds.
EXPECT_EQ(S_FALSE,
ia_child1->accNavigate(NAVDIR_PREVIOUS, SELF, end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
EXPECT_EQ(S_FALSE, ia_child2->accNavigate(NAVDIR_NEXT, SELF, end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
EXPECT_EQ(S_FALSE, ia_root->accNavigate(NAVDIR_PREVIOUS, ScopedVariant(1),
end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
EXPECT_EQ(S_FALSE,
ia_root->accNavigate(NAVDIR_NEXT, ScopedVariant(2), end.AsInput()));
EXPECT_EQ(VT_EMPTY, end.type());
}
TEST_F(AXPlatformNodeWinTest, TestIAccessible2TextFieldSetSelection) {
Init(BuildTextField());
ComPtr<IAccessible2> ia2_text_field = ToIAccessible2(GetRootIAccessible());
ComPtr<IAccessibleText> text_field;
ia2_text_field.CopyTo(text_field.GetAddressOf());
ASSERT_NE(nullptr, text_field.Get());
EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 0, 1));
EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 1, 0));
EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, 2, 2));
EXPECT_HRESULT_SUCCEEDED(text_field->setSelection(0, IA2_TEXT_OFFSET_CARET,
IA2_TEXT_OFFSET_LENGTH));
EXPECT_HRESULT_FAILED(text_field->setSelection(1, 0, 0));
EXPECT_HRESULT_FAILED(text_field->setSelection(0, 0, 50));
}
// This test is disabled until UpdateStep2ComputeHypertext is migrated over
// to AXPlatformNodeWin because |hypertext_| is only initialized
// on the BrowserAccessibility side.
TEST_F(AXPlatformNodeWinTest,
DISABLED_TestIAccessible2ContentEditableSetSelection) {
Init(BuildContentEditable());
ComPtr<IAccessible2> ia2_text_field = ToIAccessible2(GetRootIAccessible());
ComPtr<IAccessibleText> content_editable;
ia2_text_field.CopyTo(content_editable.GetAddressOf());
ASSERT_NE(nullptr, content_editable.Get());
EXPECT_HRESULT_SUCCEEDED(content_editable->setSelection(0, 0, 1));
EXPECT_HRESULT_SUCCEEDED(content_editable->setSelection(0, 1, 0));
EXPECT_HRESULT_SUCCEEDED(content_editable->setSelection(0, 2, 2));
EXPECT_HRESULT_SUCCEEDED(content_editable->setSelection(
0, IA2_TEXT_OFFSET_CARET, IA2_TEXT_OFFSET_LENGTH));
EXPECT_HRESULT_FAILED(content_editable->setSelection(1, 0, 0));
EXPECT_HRESULT_FAILED(content_editable->setSelection(0, 0, 50));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetAccessibilityAt) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
ComPtr<IUnknown> cell_1;
EXPECT_EQ(S_OK, result->get_accessibleAt(1, 1, cell_1.GetAddressOf()));
CheckIUnknownHasName(cell_1, L"1");
ComPtr<IUnknown> cell_2;
EXPECT_EQ(S_OK, result->get_accessibleAt(1, 2, cell_2.GetAddressOf()));
CheckIUnknownHasName(cell_2, L"2");
ComPtr<IUnknown> cell_3;
EXPECT_EQ(S_OK, result->get_accessibleAt(2, 1, cell_3.GetAddressOf()));
CheckIUnknownHasName(cell_3, L"3");
ComPtr<IUnknown> cell_4;
EXPECT_EQ(S_OK, result->get_accessibleAt(2, 2, cell_4.GetAddressOf()));
CheckIUnknownHasName(cell_4, L"4");
}
TEST_F(AXPlatformNodeWinTest,
TestIAccessibleTableGetAccessibilityAtOutOfBounds) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
{
ComPtr<IUnknown> cell;
EXPECT_EQ(E_INVALIDARG,
result->get_accessibleAt(-1, -1, cell.GetAddressOf()));
}
{
ComPtr<IUnknown> cell;
EXPECT_EQ(E_INVALIDARG,
result->get_accessibleAt(0, 5, cell.GetAddressOf()));
}
{
ComPtr<IUnknown> cell;
EXPECT_EQ(E_INVALIDARG,
result->get_accessibleAt(5, 0, cell.GetAddressOf()));
}
{
ComPtr<IUnknown> cell;
EXPECT_EQ(E_INVALIDARG,
result->get_accessibleAt(10, 10, cell.GetAddressOf()));
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableQueryInterfaceOnNonTable) {
ComPtr<IAccessibleTable> table;
ComPtr<IAccessibleTable2> table2;
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kWebArea;
Init(root);
ComPtr<IAccessible> root_obj = GetRootIAccessible();
EXPECT_EQ(E_NOINTERFACE, root_obj->QueryInterface(IID_PPV_ARGS(&table)));
EXPECT_EQ(E_NOINTERFACE, root_obj->QueryInterface(IID_PPV_ARGS(&table2)));
AXTreeUpdate update = Build3X3Table();
update.node_id_to_clear = 1;
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
EXPECT_EQ(E_NOINTERFACE, cell->QueryInterface(IID_PPV_ARGS(&table)));
EXPECT_EQ(E_NOINTERFACE, cell->QueryInterface(IID_PPV_ARGS(&table2)));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellQueryInterfaceOnNonCell) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj = GetRootIAccessible();
ComPtr<IAccessibleTableCell> cell;
EXPECT_EQ(E_NOINTERFACE, root_obj->QueryInterface(IID_PPV_ARGS(&cell)));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessible2ScrollToPoint) {
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
root.relative_bounds.bounds = gfx::RectF(0, 0, 2000, 2000);
AXNodeData child1;
child1.id = 2;
child1.role = ax::mojom::Role::kStaticText;
child1.relative_bounds.bounds = gfx::RectF(10, 10, 10, 10);
root.child_ids.push_back(2);
Init(root, child1);
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, root_iaccessible->get_accChild(ScopedVariant(1),
result.GetAddressOf()));
ComPtr<IAccessible2> ax_child1;
EXPECT_EQ(S_OK, result.CopyTo(ax_child1.GetAddressOf()));
result.Reset();
LONG x_left, y_top, width, height;
EXPECT_EQ(S_OK,
ax_child1->accLocation(&x_left, &y_top, &width, &height, SELF));
EXPECT_EQ(10, x_left);
EXPECT_EQ(10, y_top);
EXPECT_EQ(10, width);
EXPECT_EQ(10, height);
ComPtr<IAccessible2> root_iaccessible2 = ToIAccessible2(root_iaccessible);
EXPECT_EQ(S_OK, root_iaccessible2->scrollToPoint(
IA2_COORDTYPE_SCREEN_RELATIVE, 600, 650));
EXPECT_EQ(S_OK,
ax_child1->accLocation(&x_left, &y_top, &width, &height, SELF));
EXPECT_EQ(610, x_left);
EXPECT_EQ(660, y_top);
EXPECT_EQ(10, width);
EXPECT_EQ(10, height);
EXPECT_EQ(S_OK, root_iaccessible2->scrollToPoint(
IA2_COORDTYPE_PARENT_RELATIVE, 0, 0));
EXPECT_EQ(S_OK,
ax_child1->accLocation(&x_left, &y_top, &width, &height, SELF));
EXPECT_EQ(10, x_left);
EXPECT_EQ(10, y_top);
EXPECT_EQ(10, width);
EXPECT_EQ(10, height);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessible2ScrollTo) {
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
root.relative_bounds.bounds = gfx::RectF(0, 0, 2000, 2000);
AXNodeData child1;
child1.id = 2;
child1.role = ax::mojom::Role::kStaticText;
child1.relative_bounds.bounds = gfx::RectF(10, 10, 10, 10);
root.child_ids.push_back(2);
Init(root, child1);
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, root_iaccessible->get_accChild(ScopedVariant(1),
result.GetAddressOf()));
ComPtr<IAccessible2> ax_child1;
EXPECT_EQ(S_OK, result.CopyTo(ax_child1.GetAddressOf()));
result.Reset();
LONG x_left, y_top, width, height;
EXPECT_EQ(S_OK,
ax_child1->accLocation(&x_left, &y_top, &width, &height, SELF));
EXPECT_EQ(10, x_left);
EXPECT_EQ(10, y_top);
EXPECT_EQ(10, width);
EXPECT_EQ(10, height);
ComPtr<IAccessible2> root_iaccessible2 = ToIAccessible2(root_iaccessible);
EXPECT_EQ(S_OK, ax_child1->scrollTo(IA2_SCROLL_TYPE_ANYWHERE));
EXPECT_EQ(S_OK,
ax_child1->accLocation(&x_left, &y_top, &width, &height, SELF));
EXPECT_EQ(0, x_left);
EXPECT_EQ(0, y_top);
EXPECT_EQ(10, width);
EXPECT_EQ(10, height);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetChildIndex) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG id;
EXPECT_EQ(S_OK, result->get_childIndex(0, 0, &id));
EXPECT_EQ(id, 0);
EXPECT_EQ(S_OK, result->get_childIndex(0, 1, &id));
EXPECT_EQ(id, 1);
EXPECT_EQ(S_OK, result->get_childIndex(1, 0, &id));
EXPECT_EQ(id, 3);
EXPECT_EQ(S_OK, result->get_childIndex(1, 1, &id));
EXPECT_EQ(id, 4);
EXPECT_EQ(E_INVALIDARG, result->get_childIndex(-1, -1, &id));
EXPECT_EQ(E_INVALIDARG, result->get_childIndex(0, 5, &id));
EXPECT_EQ(E_INVALIDARG, result->get_childIndex(5, 0, &id));
EXPECT_EQ(E_INVALIDARG, result->get_childIndex(5, 5, &id));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetColumnDescription) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
{
ScopedBstr name;
EXPECT_EQ(S_FALSE, result->get_columnDescription(0, name.Receive()));
}
{
ScopedBstr name;
EXPECT_EQ(S_OK, result->get_columnDescription(1, name.Receive()));
EXPECT_STREQ(L"column header 1", name);
}
{
ScopedBstr name;
EXPECT_EQ(S_OK, result->get_columnDescription(2, name.Receive()));
EXPECT_STREQ(L"column header 2", name);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetColumnExtentAt) {
// TODO(dougt) This table doesn't have any spanning cells. This test
// tests get_columnExtentAt for (1) and an invalid input.
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG columns_spanned;
EXPECT_EQ(S_OK, result->get_columnExtentAt(1, 1, &columns_spanned));
EXPECT_EQ(columns_spanned, 1);
EXPECT_EQ(E_INVALIDARG, result->get_columnExtentAt(-1, -1, &columns_spanned));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetColumnIndex) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG index;
EXPECT_EQ(S_OK, result->get_columnIndex(2, &index));
EXPECT_EQ(index, 2);
EXPECT_EQ(S_OK, result->get_columnIndex(3, &index));
EXPECT_EQ(index, 0);
EXPECT_EQ(E_INVALIDARG, result->get_columnIndex(-1, &index));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNColumns) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG count;
EXPECT_EQ(S_OK, result->get_nColumns(&count));
EXPECT_EQ(count, 3);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNRows) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG count;
EXPECT_EQ(S_OK, result->get_nRows(&count));
EXPECT_EQ(count, 3);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetRowDescription) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
{
ScopedBstr name;
EXPECT_EQ(S_FALSE, result->get_rowDescription(0, name.Receive()));
}
{
ScopedBstr name;
EXPECT_EQ(S_OK, result->get_rowDescription(1, name.Receive()));
EXPECT_STREQ(L"row header 1", name);
}
{
ScopedBstr name;
EXPECT_EQ(S_OK, result->get_rowDescription(2, name.Receive()));
EXPECT_STREQ(L"row header 2", name);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetRowExtentAt) {
// TODO(dougt) This table doesn't have any spanning cells. This test
// tests get_rowExtentAt for (1) and an invalid input.
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG rows_spanned;
EXPECT_EQ(S_OK, result->get_rowExtentAt(0, 1, &rows_spanned));
EXPECT_EQ(1, rows_spanned);
EXPECT_EQ(E_INVALIDARG, result->get_columnExtentAt(-1, -1, &rows_spanned));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetRowIndex) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG index;
EXPECT_EQ(S_OK, result->get_rowIndex(2, &index));
EXPECT_EQ(0, index);
EXPECT_EQ(S_OK, result->get_rowIndex(3, &index));
EXPECT_EQ(1, index);
EXPECT_EQ(E_INVALIDARG, result->get_rowIndex(-1, &index));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetRowColumnExtentsAtIndex) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG row, column, row_extents, column_extents;
BOOLEAN is_selected = false;
EXPECT_EQ(S_OK,
result->get_rowColumnExtentsAtIndex(0, &row, &column, &row_extents,
&column_extents, &is_selected));
EXPECT_EQ(0, row);
EXPECT_EQ(0, column);
EXPECT_EQ(1, row_extents);
EXPECT_EQ(1, column_extents);
EXPECT_FALSE(is_selected);
EXPECT_EQ(E_INVALIDARG,
result->get_rowColumnExtentsAtIndex(-1, &row, &column, &row_extents,
&column_extents, &is_selected));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetCellAt) {
Init(Build3X3Table());
ComPtr<IAccessible> root_obj(GetRootIAccessible());
ComPtr<IAccessibleTable2> result;
root_obj.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
{
ComPtr<IUnknown> cell;
EXPECT_EQ(S_OK, result->get_cellAt(1, 1, cell.GetAddressOf()));
CheckIUnknownHasName(cell, L"1");
}
{
ComPtr<IUnknown> cell;
EXPECT_EQ(E_INVALIDARG, result->get_cellAt(-1, -1, cell.GetAddressOf()));
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetColumnExtent) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
LONG column_spanned;
EXPECT_EQ(S_OK, cell->get_columnExtent(&column_spanned));
EXPECT_EQ(1, column_spanned);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetColumnHeaderCells) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
IUnknown** cell_accessibles;
LONG number_cells;
EXPECT_EQ(S_OK,
cell->get_columnHeaderCells(&cell_accessibles, &number_cells));
EXPECT_EQ(1, number_cells);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetColumnIndex) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
LONG index;
EXPECT_EQ(S_OK, cell->get_columnIndex(&index));
EXPECT_EQ(index, 1);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetRowExtent) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
LONG rows_spanned;
EXPECT_EQ(S_OK, cell->get_rowExtent(&rows_spanned));
EXPECT_EQ(rows_spanned, 1);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetRowHeaderCells) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
IUnknown** cell_accessibles;
LONG number_cells;
EXPECT_EQ(S_OK, cell->get_rowHeaderCells(&cell_accessibles, &number_cells));
EXPECT_EQ(number_cells, 1);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetRowIndex) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
LONG index;
EXPECT_EQ(S_OK, cell->get_rowIndex(&index));
EXPECT_EQ(index, 1);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetRowColumnExtent) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
LONG row, column, row_extents, column_extents;
BOOLEAN is_selected = false;
EXPECT_EQ(S_OK, cell->get_rowColumnExtents(&row, &column, &row_extents,
&column_extents, &is_selected));
EXPECT_EQ(1, row);
EXPECT_EQ(1, column);
EXPECT_EQ(1, row_extents);
EXPECT_EQ(1, column_extents);
EXPECT_FALSE(is_selected);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableCellGetTable) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
// Check to make sure that this is the right table by checking one cell.
ComPtr<IUnknown> cell_1;
EXPECT_EQ(S_OK, result->get_accessibleAt(1, 1, cell_1.GetAddressOf()));
CheckIUnknownHasName(cell_1, L"1");
}
TEST_F(AXPlatformNodeWinTest, TestIAccessible2GetNRelations) {
// This is is a duplicated of
// BrowserAccessibilityTest::TestIAccessible2Relations but without the
// specific COM/BrowserAccessibility knowledge.
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
std::vector<int32_t> describedby_ids = {1, 2, 3};
root.AddIntListAttribute(ax::mojom::IntListAttribute::kDescribedbyIds,
describedby_ids);
AXNodeData child1;
child1.id = 2;
child1.role = ax::mojom::Role::kStaticText;
root.child_ids.push_back(2);
AXNodeData child2;
child2.id = 3;
child2.role = ax::mojom::Role::kStaticText;
root.child_ids.push_back(3);
Init(root, child1, child2);
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IAccessible2> root_iaccessible2 = ToIAccessible2(root_iaccessible);
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(1),
result.GetAddressOf()));
ComPtr<IAccessible2> ax_child1;
EXPECT_EQ(S_OK, result.CopyTo(ax_child1.GetAddressOf()));
result.Reset();
EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(2),
result.GetAddressOf()));
ComPtr<IAccessible2> ax_child2;
EXPECT_EQ(S_OK, result.CopyTo(ax_child2.GetAddressOf()));
result.Reset();
LONG n_relations = 0;
LONG n_targets = 0;
ScopedBstr relation_type;
ComPtr<IAccessibleRelation> describedby_relation;
ComPtr<IAccessibleRelation> description_for_relation;
ComPtr<IUnknown> target;
EXPECT_HRESULT_SUCCEEDED(root_iaccessible2->get_nRelations(&n_relations));
EXPECT_EQ(1, n_relations);
EXPECT_HRESULT_SUCCEEDED(
root_iaccessible2->get_relation(0, describedby_relation.GetAddressOf()));
EXPECT_HRESULT_SUCCEEDED(
describedby_relation->get_relationType(relation_type.Receive()));
EXPECT_EQ(L"describedBy", base::string16(relation_type));
relation_type.Reset();
EXPECT_HRESULT_SUCCEEDED(describedby_relation->get_nTargets(&n_targets));
EXPECT_EQ(2, n_targets);
EXPECT_HRESULT_SUCCEEDED(
describedby_relation->get_target(0, target.GetAddressOf()));
target.Reset();
EXPECT_HRESULT_SUCCEEDED(
describedby_relation->get_target(1, target.GetAddressOf()));
target.Reset();
describedby_relation.Reset();
// Test the reverse relations.
EXPECT_HRESULT_SUCCEEDED(ax_child1->get_nRelations(&n_relations));
EXPECT_EQ(1, n_relations);
EXPECT_HRESULT_SUCCEEDED(
ax_child1->get_relation(0, description_for_relation.GetAddressOf()));
EXPECT_HRESULT_SUCCEEDED(
description_for_relation->get_relationType(relation_type.Receive()));
EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
relation_type.Reset();
EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
EXPECT_EQ(1, n_targets);
EXPECT_HRESULT_SUCCEEDED(
description_for_relation->get_target(0, target.GetAddressOf()));
target.Reset();
description_for_relation.Reset();
EXPECT_HRESULT_SUCCEEDED(ax_child2->get_nRelations(&n_relations));
EXPECT_EQ(1, n_relations);
EXPECT_HRESULT_SUCCEEDED(
ax_child2->get_relation(0, description_for_relation.GetAddressOf()));
EXPECT_HRESULT_SUCCEEDED(
description_for_relation->get_relationType(relation_type.Receive()));
EXPECT_EQ(L"descriptionFor", base::string16(relation_type));
relation_type.Reset();
EXPECT_HRESULT_SUCCEEDED(description_for_relation->get_nTargets(&n_targets));
EXPECT_EQ(1, n_targets);
EXPECT_HRESULT_SUCCEEDED(
description_for_relation->get_target(0, target.GetAddressOf()));
target.Reset();
// TODO(dougt): Try adding one more relation.
}
TEST_F(AXPlatformNodeWinTest, DISABLED_TestRelationTargetsOfType) {
AXNodeData root;
root.id = 1;
root.role = ax::mojom::Role::kRootWebArea;
root.AddIntAttribute(ax::mojom::IntAttribute::kDetailsId, 2);
AXNodeData child1;
child1.id = 2;
child1.role = ax::mojom::Role::kStaticText;
root.child_ids.push_back(2);
AXNodeData child2;
child2.id = 3;
child2.role = ax::mojom::Role::kStaticText;
std::vector<int32_t> labelledby_ids = {1, 4};
child2.AddIntListAttribute(ax::mojom::IntListAttribute::kLabelledbyIds,
labelledby_ids);
root.child_ids.push_back(3);
AXNodeData child3;
child3.id = 4;
child3.role = ax::mojom::Role::kStaticText;
child3.AddIntAttribute(ax::mojom::IntAttribute::kDetailsId, 2);
root.child_ids.push_back(4);
Init(root, child1, child2, child3);
ComPtr<IAccessible> root_iaccessible(GetRootIAccessible());
ComPtr<IAccessible2_2> root_iaccessible2 = ToIAccessible2_2(root_iaccessible);
ComPtr<IDispatch> result;
EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(1),
result.GetAddressOf()));
ComPtr<IAccessible2_2> ax_child1;
EXPECT_EQ(S_OK, result.CopyTo(ax_child1.GetAddressOf()));
result.Reset();
EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(2),
result.GetAddressOf()));
ComPtr<IAccessible2_2> ax_child2;
EXPECT_EQ(S_OK, result.CopyTo(ax_child2.GetAddressOf()));
result.Reset();
EXPECT_EQ(S_OK, root_iaccessible2->get_accChild(ScopedVariant(3),
result.GetAddressOf()));
ComPtr<IAccessible2_2> ax_child3;
EXPECT_EQ(S_OK, result.CopyTo(ax_child3.GetAddressOf()));
result.Reset();
{
ScopedBstr type(L"details");
IUnknown** targets;
LONG n_targets;
EXPECT_EQ(S_OK, root_iaccessible2->get_relationTargetsOfType(
type, 0, &targets, &n_targets));
ASSERT_EQ(1, n_targets);
EXPECT_EQ(ax_child1.Get(), targets[0]);
CoTaskMemFree(targets);
}
{
ScopedBstr type(IA2_RELATION_LABELLED_BY);
IUnknown** targets;
LONG n_targets;
EXPECT_EQ(S_OK, ax_child2->get_relationTargetsOfType(type, 0, &targets,
&n_targets));
ASSERT_EQ(2, n_targets);
EXPECT_EQ(root_iaccessible2.Get(), targets[0]);
EXPECT_EQ(ax_child3.Get(), targets[1]);
CoTaskMemFree(targets);
}
{
ScopedBstr type(L"detailsFor");
IUnknown** targets;
LONG n_targets;
EXPECT_EQ(S_OK, ax_child1->get_relationTargetsOfType(type, 0, &targets,
&n_targets));
ASSERT_EQ(2, n_targets);
EXPECT_EQ(root_iaccessible2.Get(), targets[0]);
EXPECT_EQ(ax_child3.Get(), targets[1]);
CoTaskMemFree(targets);
}
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedChildrenZero) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedChildren;
EXPECT_EQ(S_OK, result->get_nSelectedChildren(&selectedChildren));
EXPECT_EQ(0, selectedChildren);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedChildrenOne) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedChildren;
EXPECT_EQ(S_OK, result->get_nSelectedChildren(&selectedChildren));
EXPECT_EQ(1, selectedChildren);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedChildrenMany) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
// 8 == table_cell_2
// 11 == table_cell_3
// 12 == table_cell_4
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedChildren;
EXPECT_EQ(S_OK, result->get_nSelectedChildren(&selectedChildren));
EXPECT_EQ(4, selectedChildren);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedColumnsZero) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedColumns;
EXPECT_EQ(S_OK, result->get_nSelectedColumns(&selectedColumns));
EXPECT_EQ(0, selectedColumns);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedColumnsOne) {
AXTreeUpdate update = Build3X3Table();
// 3 == table_column_header_2
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[3].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedColumns;
EXPECT_EQ(S_OK, result->get_nSelectedColumns(&selectedColumns));
EXPECT_EQ(1, selectedColumns);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedColumnsMany) {
AXTreeUpdate update = Build3X3Table();
// 3 == table_column_header_2
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[3].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
// 4 == table_column_header_3
// 8 == table_cell_2
// 12 == table_cell_4
update.nodes[4].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedColumns;
EXPECT_EQ(S_OK, result->get_nSelectedColumns(&selectedColumns));
EXPECT_EQ(2, selectedColumns);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedRowsZero) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedRows;
EXPECT_EQ(S_OK, result->get_nSelectedRows(&selectedRows));
EXPECT_EQ(0, selectedRows);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedRowsOne) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_1
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedRows;
EXPECT_EQ(S_OK, result->get_nSelectedRows(&selectedRows));
EXPECT_EQ(1, selectedRows);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetNSelectedRowsMany) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_3
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
// 10 == table_row_header_3
// 11 == table_cell_1
// 12 == table_cell_2
update.nodes[10].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG selectedRows;
EXPECT_EQ(S_OK, result->get_nSelectedRows(&selectedRows));
EXPECT_EQ(2, selectedRows);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedChildren) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
// 12 == table_cell_4
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max = 10;
LONG* indices;
LONG count;
EXPECT_EQ(S_OK, result->get_selectedChildren(max, &indices, &count));
EXPECT_EQ(2, count);
EXPECT_EQ(4, indices[0]);
EXPECT_EQ(8, indices[1]);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedChildrenZeroMax) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
// 12 == table_cell_4
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG* indices;
LONG count;
EXPECT_EQ(E_INVALIDARG, result->get_selectedChildren(0, &indices, &count));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedColumnsZero) {
AXTreeUpdate update = Build3X3Table();
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_columns = 10;
LONG* columns;
LONG n_columns;
EXPECT_EQ(S_OK,
result->get_selectedColumns(max_columns, &columns, &n_columns));
EXPECT_EQ(0, n_columns);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedColumnsOne) {
AXTreeUpdate update = Build3X3Table();
// 3 == table_column_header_2
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[3].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_columns = 10;
LONG* columns;
LONG n_columns;
EXPECT_EQ(S_OK,
result->get_selectedColumns(max_columns, &columns, &n_columns));
EXPECT_EQ(1, n_columns);
EXPECT_EQ(1, columns[0]);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedColumnsMany) {
AXTreeUpdate update = Build3X3Table();
// 3 == table_column_header_2
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[3].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
// 4 == table_column_header_3
// 8 == table_cell_2
// 12 == table_cell_4
update.nodes[4].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_columns = 10;
LONG* columns;
LONG n_columns;
EXPECT_EQ(S_OK,
result->get_selectedColumns(max_columns, &columns, &n_columns));
EXPECT_EQ(2, n_columns);
EXPECT_EQ(1, columns[0]);
EXPECT_EQ(2, columns[1]);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedRowsZero) {
Init(Build3X3Table());
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_rows = 10;
LONG* rows;
LONG n_rows;
EXPECT_EQ(S_OK, result->get_selectedRows(max_rows, &rows, &n_rows));
EXPECT_EQ(0, n_rows);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedRowsOne) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_1
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_rows = 10;
LONG* rows;
LONG n_rows;
EXPECT_EQ(S_OK, result->get_selectedRows(max_rows, &rows, &n_rows));
EXPECT_EQ(1, n_rows);
EXPECT_EQ(1, rows[0]);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableGetSelectedRowsMany) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_3
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
// 10 == table_row_header_3
// 11 == table_cell_1
// 12 == table_cell_2
update.nodes[10].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[12].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
LONG max_rows = 10;
LONG* rows;
LONG n_rows;
EXPECT_EQ(S_OK, result->get_selectedRows(max_rows, &rows, &n_rows));
EXPECT_EQ(2, n_rows);
EXPECT_EQ(1, rows[0]);
EXPECT_EQ(2, rows[1]);
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableIsColumnSelected) {
AXTreeUpdate update = Build3X3Table();
// 3 == table_column_header_2
// 7 == table_cell_1
// 11 == table_cell_3
update.nodes[3].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[11].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
BOOLEAN selected = false;
EXPECT_EQ(S_OK, result->get_isColumnSelected(0, &selected));
EXPECT_FALSE(selected);
EXPECT_EQ(S_OK, result->get_isColumnSelected(1, &selected));
EXPECT_TRUE(selected);
EXPECT_EQ(S_OK, result->get_isColumnSelected(2, &selected));
EXPECT_FALSE(selected);
EXPECT_EQ(E_INVALIDARG, result->get_isColumnSelected(3, &selected));
EXPECT_EQ(E_INVALIDARG, result->get_isColumnSelected(-3, &selected));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableIsRowSelected) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_3
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[7].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
update.nodes[8].AddBoolAttribute(ax::mojom::BoolAttribute::kSelected, true);
Init(update);
ComPtr<IAccessibleTableCell> cell = GetCellInTable();
ASSERT_NE(nullptr, cell.Get());
ComPtr<IUnknown> table;
EXPECT_EQ(S_OK, cell->get_table(table.GetAddressOf()));
ComPtr<IAccessibleTable> result;
table.CopyTo(result.GetAddressOf());
ASSERT_NE(nullptr, result.Get());
BOOLEAN selected;
EXPECT_EQ(S_OK, result->get_isRowSelected(0, &selected));
EXPECT_FALSE(selected);
EXPECT_EQ(S_OK, result->get_isRowSelected(1, &selected));
EXPECT_TRUE(selected);
EXPECT_EQ(S_OK, result->get_isRowSelected(2, &selected));
EXPECT_FALSE(selected);
EXPECT_EQ(E_INVALIDARG, result->get_isRowSelected(3, &selected));
EXPECT_EQ(E_INVALIDARG, result->get_isRowSelected(-3, &selected));
}
TEST_F(AXPlatformNodeWinTest, TestIAccessibleTableIsSelected) {
AXTreeUpdate update = Build3X3Table();
// 6 == table_row_header_3
// 7 == table_cell_1
// 8 == table_cell_2
update.nodes[6].