10#include <UIAutomationClient.h>
11#include <UIAutomationCoreApi.h>
16#include "gtest/gtest.h"
20using Microsoft::WRL::ComPtr;
24#define EXPECT_UIA_BSTR_EQ(node, property_id, expected) \
26 ScopedVariant expectedVariant(expected); \
27 ASSERT_EQ(VT_BSTR, expectedVariant.type()); \
28 ASSERT_NE(nullptr, expectedVariant.ptr()->bstrVal); \
29 ScopedVariant actual; \
30 ASSERT_HRESULT_SUCCEEDED( \
31 node->GetPropertyValue(property_id, actual.Receive())); \
32 ASSERT_EQ(VT_BSTR, actual.type()); \
33 ASSERT_NE(nullptr, actual.ptr()->bstrVal); \
34 EXPECT_STREQ(expectedVariant.ptr()->bstrVal, actual.ptr()->bstrVal); \
50 root.child_ids = {2, 3};
71 ComPtr<IRawElementProviderSimple> root_raw_element_provider_simple;
72 ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(
73 IID_PPV_ARGS(&root_raw_element_provider_simple));
74 ComPtr<IRawElementProviderSimple> text1_raw_element_provider_simple =
75 GetIRawElementProviderSimpleFromChildIndex(0);
76 ComPtr<IRawElementProviderSimple> button_raw_element_provider_simple =
77 GetIRawElementProviderSimpleFromChildIndex(1);
82 ComPtr<IItemContainerProvider> item_container_provider;
83 EXPECT_HRESULT_SUCCEEDED(root_raw_element_provider_simple->GetPatternProvider(
84 UIA_ItemContainerPatternId, &item_container_provider));
85 ASSERT_NE(
nullptr, item_container_provider.Get());
89 ComPtr<IRawElementProviderSimple>
result;
94 unique_id = AXPlatformNodeFromNode(GetRootAsAXNode())->GetUniqueId();
95 unique_id_variant.
Set(SysAllocString(
reinterpret_cast<const wchar_t*
>(
98 ComPtr<IRawElementProviderSimple> invalid_element_provider_simple;
99 EXPECT_HRESULT_SUCCEEDED(
101 &invalid_element_provider_simple));
103 EXPECT_HRESULT_FAILED(item_container_provider->FindItemByProperty(
104 invalid_element_provider_simple.Get(),
106 unique_id_variant, &
result));
114 unique_id = AXPlatformNodeFromNode(GetRootAsAXNode())->GetUniqueId();
115 unique_id_variant.
Set(SysAllocString(
reinterpret_cast<const wchar_t*
>(
120 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
122 unique_id_variant, &
result));
129 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
130 text1_raw_element_provider_simple.Get(),
132 unique_id_variant, &
result));
133 EXPECT_EQ(
nullptr,
result.Get());
139 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
140 button_raw_element_provider_simple.Get(),
142 unique_id_variant, &
result));
143 EXPECT_EQ(
nullptr,
result.Get());
152 unique_id = AXPlatformNodeFromNode(text1_node)->GetUniqueId();
153 unique_id_variant.
Set(SysAllocString(
reinterpret_cast<const wchar_t*
>(
158 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
160 unique_id_variant, &
result));
167 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
168 text1_raw_element_provider_simple.Get(),
170 unique_id_variant, &
result));
171 EXPECT_EQ(
nullptr,
result.Get());
177 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
178 button_raw_element_provider_simple.Get(),
180 unique_id_variant, &
result));
181 EXPECT_EQ(
nullptr,
result.Get());
189 unique_id = AXPlatformNodeFromNode(button_node)->GetUniqueId();
190 unique_id_variant.
Set(SysAllocString(
reinterpret_cast<const wchar_t*
>(
195 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
197 unique_id_variant, &
result));
203 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
204 text1_raw_element_provider_simple.Get(),
206 unique_id_variant, &
result));
213 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
214 button_raw_element_provider_simple.Get(),
216 unique_id_variant, &
result));
217 EXPECT_EQ(
nullptr,
result.Get());
226 AXPlatformNodeFromNode(button_node->
children()[0])->GetUniqueId();
227 unique_id_variant.
Set(SysAllocString(
reinterpret_cast<const wchar_t*
>(
232 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
234 unique_id_variant, &
result));
239 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
240 root_raw_element_provider_simple.Get(),
242 unique_id_variant, &
result));
247 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
248 text1_raw_element_provider_simple.Get(),
250 unique_id_variant, &
result));
255 EXPECT_HRESULT_SUCCEEDED(item_container_provider->FindItemByProperty(
256 button_raw_element_provider_simple.Get(),
258 unique_id_variant, &
result));
269 ComPtr<IRawElementProviderFragmentRoot> expected_fragment_root =
271 ComPtr<IRawElementProviderFragment> fragment_provider;
272 expected_fragment_root.As(&fragment_provider);
274 ComPtr<IRawElementProviderFragmentRoot> actual_fragment_root;
275 EXPECT_HRESULT_SUCCEEDED(
276 fragment_provider->get_FragmentRoot(&actual_fragment_root));
277 EXPECT_EQ(expected_fragment_root.Get(), actual_fragment_root.Get());
286 element1_data.
id = 2;
291 element2_data.
id = 3;
295 Init(root_data, element1_data, element2_data);
298 AXNode* root_node = GetRootAsAXNode();
302 ComPtr<IRawElementProviderFragmentRoot> fragment_root_prov(GetFragmentRoot());
303 ComPtr<IRawElementProviderFragment> root_provider(
304 GetRootIRawElementProviderFragment());
305 ComPtr<IRawElementProviderFragment> element1_provider =
306 QueryInterfaceFromNode<IRawElementProviderFragment>(element1_node);
307 ComPtr<IRawElementProviderFragment> element2_provider =
308 QueryInterfaceFromNode<IRawElementProviderFragment>(element2_node);
310 ComPtr<IRawElementProviderFragment> provider_from_point;
311 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->ElementProviderFromPoint(
312 23, 31, &provider_from_point));
313 EXPECT_EQ(element1_provider.Get(), provider_from_point.Get());
315 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->ElementProviderFromPoint(
316 23, 67, &provider_from_point));
317 EXPECT_EQ(element2_provider.Get(), provider_from_point.Get());
319 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->ElementProviderFromPoint(
320 47, 67, &provider_from_point));
321 EXPECT_EQ(root_provider.Get(), provider_from_point.Get());
324 std::unique_ptr<base::AutoReset<float>> scale_factor_reset =
326 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->ElementProviderFromPoint(
327 60, 60, &provider_from_point));
328 EXPECT_EQ(element1_provider.Get(), provider_from_point.Get());
336 element1_data.
id = 2;
340 element2_data.
id = 3;
343 Init(root_data, element1_data, element2_data);
346 AXNode* root_node = GetRootAsAXNode();
350 ComPtr<IRawElementProviderFragmentRoot> fragment_root_prov(GetFragmentRoot());
351 ComPtr<IRawElementProviderFragment> root_provider(
352 GetRootIRawElementProviderFragment());
353 ComPtr<IRawElementProviderFragment> element1_provider =
354 QueryInterfaceFromNode<IRawElementProviderFragment>(element1_node);
355 ComPtr<IRawElementProviderFragment> element2_provider =
356 QueryInterfaceFromNode<IRawElementProviderFragment>(element2_node);
358 ComPtr<IRawElementProviderFragment> focused_fragment;
359 EXPECT_HRESULT_SUCCEEDED(root_provider->SetFocus());
360 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->GetFocus(&focused_fragment));
361 EXPECT_EQ(root_provider.Get(), focused_fragment.Get());
363 EXPECT_HRESULT_SUCCEEDED(element1_provider->SetFocus());
364 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->GetFocus(&focused_fragment));
365 EXPECT_EQ(element1_provider.Get(), focused_fragment.Get());
367 EXPECT_HRESULT_SUCCEEDED(element2_provider->SetFocus());
368 EXPECT_HRESULT_SUCCEEDED(fragment_root_prov->GetFocus(&focused_fragment));
369 EXPECT_EQ(element2_provider.Get(), focused_fragment.Get());
378 ComPtr<IRawElementProviderSimple> simple_provider =
379 GetRootIRawElementProviderSimple();
380 ComPtr<IRawElementProviderFragment> fragment_provider =
381 GetRootIRawElementProviderFragment();
382 ComPtr<IRawElementProviderFragmentRoot> fragment_root_provider =
385 SetTree(std::make_unique<AXTree>());
386 ax_fragment_root_.reset(
nullptr);
388 ComPtr<IRawElementProviderSimple> returned_simple_provider;
389 ComPtr<IRawElementProviderFragment> returned_fragment_provider;
390 ComPtr<IRawElementProviderFragmentRoot> returned_fragment_root_provider;
394 static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
395 simple_provider->get_HostRawElementProvider(&returned_simple_provider));
398 static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
399 fragment_provider->get_FragmentRoot(&returned_fragment_root_provider));
401 EXPECT_EQ(
static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
402 fragment_provider->GetRuntimeId(returned_runtime_id.
Receive()));
404 EXPECT_EQ(
static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
405 fragment_root_provider->ElementProviderFromPoint(
406 67, 23, &returned_fragment_provider));
408 EXPECT_EQ(
static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
409 fragment_root_provider->GetFocus(&returned_fragment_provider));
421 test_fragment_root_delegate_->child_ =
nullptr;
432 AXPlatformNodeFromNode(GetRootAsAXNode())->GetNativeViewAccessible();
434 EXPECT_EQ(native_view_accessible, fragment_root->
ChildAtIndex(0));
437 test_fragment_root_delegate_->child_ =
nullptr;
448 EXPECT_EQ(
nullptr, fragment_root->
GetParent());
451 AXPlatformNodeFromNode(GetRootAsAXNode())->GetNativeViewAccessible();
452 test_fragment_root_delegate_->parent_ = native_view_accessible;
453 EXPECT_EQ(native_view_accessible, fragment_root->
GetParent());
462 ComPtr<IRawElementProviderSimple> root_provider;
463 ax_fragment_root_->GetNativeViewAccessible()->QueryInterface(
464 IID_PPV_ARGS(&root_provider));
468 test_fragment_root_delegate_->is_control_element_ =
true;
470 EXPECT_HRESULT_SUCCEEDED(root_provider->GetPropertyValue(
471 UIA_IsControlElementPropertyId,
result.Receive()));
472 EXPECT_EQ(
result.type(), VT_BOOL);
473 EXPECT_EQ(
result.ptr()->boolVal, VARIANT_TRUE);
474 EXPECT_HRESULT_SUCCEEDED(root_provider->GetPropertyValue(
475 UIA_IsContentElementPropertyId,
result.Receive()));
476 EXPECT_EQ(
result.type(), VT_BOOL);
477 EXPECT_EQ(
result.ptr()->boolVal, VARIANT_TRUE);
479 test_fragment_root_delegate_->is_control_element_ =
false;
480 EXPECT_HRESULT_SUCCEEDED(root_provider->GetPropertyValue(
481 UIA_IsControlElementPropertyId,
result.Receive()));
482 EXPECT_EQ(
result.type(), VT_BOOL);
483 EXPECT_EQ(
result.ptr()->boolVal, VARIANT_FALSE);
484 EXPECT_HRESULT_SUCCEEDED(root_provider->GetPropertyValue(
485 UIA_IsContentElementPropertyId,
result.Receive()));
486 EXPECT_EQ(
result.type(), VT_BOOL);
487 EXPECT_EQ(
result.ptr()->boolVal, VARIANT_FALSE);
490 EXPECT_HRESULT_SUCCEEDED(root_provider->GetPropertyValue(
491 UIA_ControlTypePropertyId,
result.Receive()));
492 EXPECT_EQ(
result.type(), VT_EMPTY);
518 top_fragment_root_n1.
id = 1;
524 child_fragment_root_n3.
id = 3;
531 child_fragment_root_n3.
child_ids = {6, 7};
537 child_fragment_root_n5.
id = 5;
544 child_fragment_root_n5.
child_ids = {8, 9};
545 top_fragment_root_n1.
child_ids = {2, 3, 4, 5};
548 update.has_tree_data =
true;
549 update.root_id = top_fragment_root_n1.
id;
550 update.nodes = {top_fragment_root_n1,
552 child_fragment_root_n3,
556 child_fragment_root_n5,
564 AXNode* root_node = GetRootAsAXNode();
568 std::unique_ptr<TestFragmentRootDelegate> n3_fragment_root_delegate =
569 std::make_unique<TestFragmentRootDelegate>();
570 std::unique_ptr<AXFragmentRootWin> n3_fragment_root(InitNodeAsFragmentRoot(
571 child_fragment_root_n3_node, n3_fragment_root_delegate.get()));
574 std::unique_ptr<TestFragmentRootDelegate> n5_fragment_root_delegate =
575 std::make_unique<TestFragmentRootDelegate>();
576 std::unique_ptr<AXFragmentRootWin> n5_fragment_root(InitNodeAsFragmentRoot(
577 child_fragment_root_n5_node, n5_fragment_root_delegate.get()));
580 ComPtr<IRawElementProviderFragmentRoot> root_fragment_root =
582 ComPtr<IRawElementProviderFragment> root_fragment;
583 root_fragment_root.As(&root_fragment);
585 ComPtr<IRawElementProviderFragment> test_fragment;
586 EXPECT_HRESULT_SUCCEEDED(
587 root_fragment->Navigate(NavigateDirection_Parent, &test_fragment));
588 EXPECT_EQ(
nullptr, test_fragment.Get());
590 EXPECT_HRESULT_SUCCEEDED(
591 root_fragment->Navigate(NavigateDirection_NextSibling, &test_fragment));
592 EXPECT_EQ(
nullptr, test_fragment.Get());
594 EXPECT_HRESULT_SUCCEEDED(root_fragment->Navigate(
595 NavigateDirection_PreviousSibling, &test_fragment));
596 EXPECT_EQ(
nullptr, test_fragment.Get());
598 EXPECT_HRESULT_SUCCEEDED(
599 root_fragment->Navigate(NavigateDirection_FirstChild, &test_fragment));
600 ComPtr<IUnknown> root_child_unknown = test_fragment_root_delegate_->child_;
601 ComPtr<IRawElementProviderFragment> root_child_fragment;
602 root_child_unknown.As(&root_child_fragment);
603 EXPECT_EQ(root_child_fragment.Get(), test_fragment.Get());
605 EXPECT_HRESULT_SUCCEEDED(
606 root_fragment->Navigate(NavigateDirection_LastChild, &test_fragment));
607 EXPECT_EQ(root_child_fragment.Get(), test_fragment.Get());
610 ComPtr<IRawElementProviderFragmentRoot> n3_fragment_root_provider;
611 n3_fragment_root->GetNativeViewAccessible()->QueryInterface(
612 IID_PPV_ARGS(&n3_fragment_root_provider));
614 ComPtr<IRawElementProviderFragment> n3_fragment;
615 n3_fragment_root_provider.As(&n3_fragment);
616 EXPECT_HRESULT_SUCCEEDED(
617 n3_fragment->Navigate(NavigateDirection_Parent, &test_fragment));
618 EXPECT_EQ(root_child_fragment.Get(), test_fragment.Get());
621 EXPECT_HRESULT_SUCCEEDED(
622 n3_fragment->Navigate(NavigateDirection_PreviousSibling, &test_fragment));
623 EXPECT_EQ(IRawElementProviderFragmentFromNode(sibling_n2_node).
Get(),
624 test_fragment.Get());
627 EXPECT_HRESULT_SUCCEEDED(
628 n3_fragment->Navigate(NavigateDirection_NextSibling, &test_fragment));
629 EXPECT_EQ(IRawElementProviderFragmentFromNode(sibling_n4_node).
Get(),
630 test_fragment.Get());
632 EXPECT_HRESULT_SUCCEEDED(
633 n3_fragment->Navigate(NavigateDirection_FirstChild, &test_fragment));
635 IRawElementProviderFragmentFromNode(child_fragment_root_n3_node).
Get(),
636 test_fragment.Get());
637 EXPECT_HRESULT_SUCCEEDED(
638 n3_fragment->Navigate(NavigateDirection_LastChild, &test_fragment));
640 IRawElementProviderFragmentFromNode(child_fragment_root_n3_node).
Get(),
641 test_fragment.Get());
644 ComPtr<IRawElementProviderFragmentRoot> n5_fragment_root_provider;
645 n5_fragment_root->GetNativeViewAccessible()->QueryInterface(
646 IID_PPV_ARGS(&n5_fragment_root_provider));
648 ComPtr<IRawElementProviderFragment> n5_fragment;
649 n5_fragment_root_provider.As(&n5_fragment);
650 EXPECT_HRESULT_SUCCEEDED(
651 n5_fragment->Navigate(NavigateDirection_Parent, &test_fragment));
652 EXPECT_EQ(root_child_fragment.Get(), test_fragment.Get());
653 EXPECT_HRESULT_SUCCEEDED(
654 n5_fragment->Navigate(NavigateDirection_NextSibling, &test_fragment));
655 EXPECT_EQ(
nullptr, test_fragment.Get());
656 EXPECT_HRESULT_SUCCEEDED(
657 n5_fragment->Navigate(NavigateDirection_PreviousSibling, &test_fragment));
658 EXPECT_EQ(IRawElementProviderFragmentFromNode(sibling_n4_node).
Get(),
659 test_fragment.Get());
660 EXPECT_HRESULT_SUCCEEDED(
661 n5_fragment->Navigate(NavigateDirection_FirstChild, &test_fragment));
663 IRawElementProviderFragmentFromNode(child_fragment_root_n5_node).
Get(),
664 test_fragment.Get());
665 EXPECT_HRESULT_SUCCEEDED(
666 n5_fragment->Navigate(NavigateDirection_LastChild, &test_fragment));
668 IRawElementProviderFragmentFromNode(child_fragment_root_n5_node).
Get(),
669 test_fragment.Get());
682 gfx::kMockAcceleratedWidget));
684 GetRootIAccessible().
Get()));
690 gfx::kMockAcceleratedWidget));
692 GetRootIAccessible().
Get()));
696 ax_fragment_root_.reset();
698 gfx::kMockAcceleratedWidget));
700 GetRootIAccessible().
Get()));
#define EXPECT_UIA_BSTR_EQ(node, property_id, expected)
void Set(const wchar_t *str)
AXFragmentRootTest()=default
AXFragmentRootTest & operator=(const AXFragmentRootTest &)=delete
AXFragmentRootTest(const AXFragmentRootTest &)=delete
~AXFragmentRootTest() override=default
static AXFragmentRootWin * GetForAcceleratedWidget(gfx::AcceleratedWidget widget)
static AXFragmentRootWin * GetFragmentRootParentOf(gfx::NativeViewAccessible accessible)
const std::vector< AXNode * > & children() const
static AXTreeID CreateNewAXTreeID()
static HRESULT CreateMockIRawElementProviderSimple(IRawElementProviderSimple **provider)
static std::unique_ptr< base::AutoReset< float > > SetScaleFactor(float value)
PROPERTYID GetUiaUniqueIdPropertyId() const
static const UiaRegistrarWin & GetInstance()
const GrXPFactory * Get(SkBlendMode mode)
std::u16string NumberToString16(float number)
UnimplementedNativeViewAccessible * NativeViewAccessible
TEST_F(AXPositionTest, Clone)
AXRelativeBounds relative_bounds
std::vector< int32_t > child_ids
void SetName(const std::string &name)