7#include <UIAutomationClient.h>
8#include <UIAutomationCoreApi.h>
21#include "flutter/fml/icu_util.h"
22#include "third_party/icu/source/common/unicode/putil.h"
24using Microsoft::WRL::ComPtr;
29#define EXPECT_UIA_ELEMENTNOTAVAILABLE(expr) \
30 EXPECT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE), (expr))
31#define EXPECT_UIA_INVALIDOPERATION(expr) \
32 EXPECT_EQ(static_cast<HRESULT>(UIA_E_INVALIDOPERATION), (expr))
33#define EXPECT_UIA_ELEMENTNOTENABLED(expr) \
34 EXPECT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTENABLED), (expr))
35#define EXPECT_UIA_NOTSUPPORTED(expr) \
36 EXPECT_EQ(static_cast<HRESULT>(UIA_E_NOTSUPPORTED), (expr))
38#define ASSERT_UIA_ELEMENTNOTAVAILABLE(expr) \
39 ASSERT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTAVAILABLE), (expr))
40#define ASSERT_UIA_INVALIDOPERATION(expr) \
41 ASSERT_EQ(static_cast<HRESULT>(UIA_E_INVALIDOPERATION), (expr))
42#define ASSERT_UIA_ELEMENTNOTENABLED(expr) \
43 ASSERT_EQ(static_cast<HRESULT>(UIA_E_ELEMENTNOTENABLED), (expr))
44#define ASSERT_UIA_NOTSUPPORTED(expr) \
45 ASSERT_EQ(static_cast<HRESULT>(UIA_E_NOTSUPPORTED), (expr))
47#define EXPECT_UIA_GETPROPERTYVALUE_EQ(node, property_id, expected) \
49 base::win::ScopedVariant expectedVariant(expected); \
50 ASSERT_EQ(VT_BSTR, expectedVariant.type()); \
51 ASSERT_NE(nullptr, expectedVariant.ptr()->bstrVal); \
52 base::win::ScopedVariant actual; \
53 ASSERT_HRESULT_SUCCEEDED( \
54 node->GetPropertyValue(property_id, actual.Receive())); \
55 ASSERT_EQ(VT_BSTR, actual.type()); \
56 ASSERT_NE(nullptr, actual.ptr()->bstrVal); \
57 EXPECT_STREQ(expectedVariant.ptr()->bstrVal, actual.ptr()->bstrVal); \
60#define EXPECT_UIA_ELEMENT_ARRAY_BSTR_EQ(array, element_test_property_id, \
61 expected_property_values) \
63 ASSERT_EQ(1u, SafeArrayGetDim(array)); \
64 LONG array_lower_bound; \
65 ASSERT_HRESULT_SUCCEEDED( \
66 SafeArrayGetLBound(array, 1, &array_lower_bound)); \
67 LONG array_upper_bound; \
68 ASSERT_HRESULT_SUCCEEDED( \
69 SafeArrayGetUBound(array, 1, &array_upper_bound)); \
70 IUnknown** array_data; \
71 ASSERT_HRESULT_SUCCEEDED( \
72 ::SafeArrayAccessData(array, reinterpret_cast<void**>(&array_data))); \
73 size_t count = array_upper_bound - array_lower_bound + 1; \
74 ASSERT_EQ(expected_property_values.size(), count); \
75 for (size_t i = 0; i < count; ++i) { \
76 ComPtr<IRawElementProviderSimple> element; \
77 ASSERT_HRESULT_SUCCEEDED( \
78 array_data[i]->QueryInterface(IID_PPV_ARGS(&element))); \
79 EXPECT_UIA_GETPROPERTYVALUE_EQ(element, element_test_property_id, \
80 expected_property_values[i].c_str()); \
82 ASSERT_HRESULT_SUCCEEDED(::SafeArrayUnaccessData(array)); \
85#define EXPECT_UIA_SAFEARRAY_EQ(safearray, expected_property_values) \
87 using T = typename decltype(expected_property_values)::value_type; \
88 EXPECT_EQ(sizeof(T), ::SafeArrayGetElemsize(safearray)); \
89 EXPECT_EQ(1u, SafeArrayGetDim(safearray)); \
90 LONG array_lower_bound; \
91 EXPECT_HRESULT_SUCCEEDED( \
92 SafeArrayGetLBound(safearray, 1, &array_lower_bound)); \
93 LONG array_upper_bound; \
94 EXPECT_HRESULT_SUCCEEDED( \
95 SafeArrayGetUBound(safearray, 1, &array_upper_bound)); \
96 const size_t count = array_upper_bound - array_lower_bound + 1; \
97 EXPECT_EQ(expected_property_values.size(), count); \
98 if (sizeof(T) == ::SafeArrayGetElemsize(safearray) && \
99 count == expected_property_values.size()) { \
101 EXPECT_HRESULT_SUCCEEDED(::SafeArrayAccessData( \
102 safearray, reinterpret_cast<void**>(&array_data))); \
103 for (size_t i = 0; i < count; ++i) { \
104 EXPECT_EQ(array_data[i], expected_property_values[i]); \
106 EXPECT_HRESULT_SUCCEEDED(::SafeArrayUnaccessData(safearray)); \
110#define EXPECT_UIA_TEXTATTRIBUTE_EQ(provider, attribute, variant) \
112 base::win::ScopedVariant scoped_variant; \
113 EXPECT_HRESULT_SUCCEEDED( \
114 provider->GetAttributeValue(attribute, scoped_variant.Receive())); \
115 EXPECT_EQ(0, scoped_variant.Compare(variant)); \
118#define EXPECT_UIA_TEXTATTRIBUTE_MIXED(provider, attribute) \
120 ComPtr<IUnknown> expected_mixed; \
121 EXPECT_HRESULT_SUCCEEDED( \
122 ::UiaGetReservedMixedAttributeValue(&expected_mixed)); \
123 base::win::ScopedVariant scoped_variant; \
124 EXPECT_HRESULT_SUCCEEDED( \
125 provider->GetAttributeValue(attribute, scoped_variant.Receive())); \
126 EXPECT_EQ(VT_UNKNOWN, scoped_variant.type()); \
127 EXPECT_EQ(expected_mixed.Get(), V_UNKNOWN(scoped_variant.ptr())); \
130#define EXPECT_UIA_TEXTATTRIBUTE_NOTSUPPORTED(provider, attribute) \
132 ComPtr<IUnknown> expected_notsupported; \
133 EXPECT_HRESULT_SUCCEEDED( \
134 ::UiaGetReservedNotSupportedValue(&expected_notsupported)); \
135 base::win::ScopedVariant scoped_variant; \
136 EXPECT_HRESULT_SUCCEEDED( \
137 provider->GetAttributeValue(attribute, scoped_variant.Receive())); \
138 EXPECT_EQ(VT_UNKNOWN, scoped_variant.type()); \
139 EXPECT_EQ(expected_notsupported.Get(), V_UNKNOWN(scoped_variant.ptr())); \
142#define EXPECT_UIA_TEXTRANGE_EQ(provider, expected_content) \
144 base::win::ScopedBstr provider_content; \
145 EXPECT_HRESULT_SUCCEEDED( \
146 provider->GetText(-1, provider_content.Receive())); \
147 EXPECT_STREQ(expected_content, provider_content.Get()); \
150#define EXPECT_UIA_FIND_TEXT(text_range_provider, search_term, ignore_case, \
153 base::win::ScopedBstr find_string(search_term); \
154 ComPtr<ITextRangeProvider> text_range_provider_found; \
155 EXPECT_HRESULT_SUCCEEDED(text_range_provider->FindText( \
156 find_string.Get(), false, ignore_case, &text_range_provider_found)); \
157 if (text_range_provider_found == nullptr) { \
158 EXPECT_TRUE(false); \
160 SetOwner(owner, text_range_provider_found.Get()); \
161 base::win::ScopedBstr found_content; \
162 EXPECT_HRESULT_SUCCEEDED( \
163 text_range_provider_found->GetText(-1, found_content.Receive())); \
165 EXPECT_TRUE(StringCompareICU(found_content.Get(), find_string.Get())); \
167 EXPECT_EQ(0, wcscmp(found_content.Get(), find_string.Get())); \
171#define EXPECT_UIA_FIND_TEXT_NO_MATCH(text_range_provider, search_term, \
172 ignore_case, owner) \
174 base::win::ScopedBstr find_string(search_term); \
175 ComPtr<ITextRangeProvider> text_range_provider_found; \
176 EXPECT_HRESULT_SUCCEEDED(text_range_provider->FindText( \
177 find_string.Get(), false, ignore_case, &text_range_provider_found)); \
178 EXPECT_EQ(nullptr, text_range_provider_found); \
181#define EXPECT_UIA_MOVE_ENDPOINT_BY_UNIT(text_range_provider, endpoint, unit, \
182 count, expected_text, expected_count) \
185 EXPECT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit( \
186 endpoint, unit, count, &result_count)); \
187 EXPECT_EQ(expected_count, result_count); \
188 EXPECT_UIA_TEXTRANGE_EQ(text_range_provider, expected_text); \
191#define EXPECT_UIA_MOVE(text_range_provider, unit, count, expected_text, \
195 EXPECT_HRESULT_SUCCEEDED( \
196 text_range_provider->Move(unit, count, &result_count)); \
197 EXPECT_EQ(expected_count, result_count); \
198 EXPECT_UIA_TEXTRANGE_EQ(text_range_provider, expected_text); \
201#define EXPECT_ENCLOSING_ELEMENT(ax_node_given, ax_node_expected) \
203 ComPtr<ITextRangeProvider> text_range_provider; \
204 GetTextRangeProviderFromTextNode(text_range_provider, ax_node_given); \
205 ComPtr<IRawElementProviderSimple> enclosing_element; \
206 ASSERT_HRESULT_SUCCEEDED( \
207 text_range_provider->GetEnclosingElement(&enclosing_element)); \
208 ComPtr<IRawElementProviderSimple> expected_text_provider = \
209 QueryInterfaceFromNode<IRawElementProviderSimple>(ax_node_expected); \
210 EXPECT_EQ(expected_text_provider.Get(), enclosing_element.Get()); \
213#define DCHECK_EQ(a, b) BASE_DCHECK((a) == (b))
218 reinterpret_cast<char16_t*
>(right), &
start, &
length,
true,
230 anchor.
id(), text_offset, affinity);
236 const AXPlatformNodeTextRangeProviderWin* text_range) {
237 return text_range->start();
241 const AXPlatformNodeTextRangeProviderWin* text_range) {
242 return text_range->end();
246 const AXPlatformNodeTextRangeProviderWin* text_range) {
247 return text_range->GetOwner();
251 ITextRangeProvider* destination_range) {
252 ComPtr<ITextRangeProvider> source_provider = source_range;
253 ComPtr<ITextRangeProvider> destination_provider = destination_range;
255 ComPtr<AXPlatformNodeTextRangeProviderWin> source_provider_internal;
256 ComPtr<AXPlatformNodeTextRangeProviderWin> destination_provider_internal;
258 source_provider->QueryInterface(IID_PPV_ARGS(&source_provider_internal));
259 destination_provider->QueryInterface(
260 IID_PPV_ARGS(&destination_provider_internal));
261 destination_provider_internal->SetOwnerForTesting(
262 source_provider_internal->GetOwner());
266 ITextRangeProvider* destination_range) {
267 ComPtr<AXPlatformNodeTextRangeProviderWin> destination_provider_internal;
269 static_cast<AXPlatformNodeTextRangeProviderWin*
>(destination_range);
270 destination_range->QueryInterface(
271 IID_PPV_ARGS(&destination_provider_internal));
272 destination_provider_internal->SetOwnerForTesting(owner);
280 text_range->NormalizeTextRange(
start,
end);
284 ComPtr<ITextRangeProvider>& text_range_provider,
286 ComPtr<IRawElementProviderSimple> provider_simple =
287 QueryInterfaceFromNode<IRawElementProviderSimple>(text_node);
288 ASSERT_NE(
nullptr, provider_simple.Get());
290 ComPtr<ITextProvider> text_provider;
291 EXPECT_HRESULT_SUCCEEDED(
292 provider_simple->GetPatternProvider(UIA_TextPatternId, &text_provider));
293 ASSERT_NE(
nullptr, text_provider.Get());
295 EXPECT_HRESULT_SUCCEEDED(
296 text_provider->get_DocumentRange(&text_range_provider));
297 ASSERT_NE(
nullptr, text_range_provider.Get());
299 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider_interal;
300 EXPECT_HRESULT_SUCCEEDED(text_range_provider->QueryInterface(
301 IID_PPV_ARGS(&text_range_provider_interal)));
303 ASSERT_NE(ax_platform_node,
nullptr);
304 text_range_provider_interal->SetOwnerForTesting(
305 static_cast<AXPlatformNodeWin*
>(ax_platform_node));
309 ComPtr<AXPlatformNodeTextRangeProviderWin>& text_range_provider_win,
310 AXPlatformNodeWin* owner,
311 const AXNode* start_anchor,
322 ComPtr<ITextRangeProvider> text_range_provider =
323 AXPlatformNodeTextRangeProviderWin::CreateTextRangeProviderForTesting(
324 owner, std::move(range_start), std::move(range_end));
326 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range_provider_win));
330 std::vector<int>& word_start_offsets,
331 std::vector<int>& word_end_offsets) {
332 char previous_char =
' ';
333 word_start_offsets = std::vector<int>();
334 for (
size_t i = 0;
i <
text.size(); ++
i) {
335 if (previous_char ==
' ' &&
text[
i] !=
' ')
336 word_start_offsets.push_back(
i);
337 previous_char =
text[
i];
341 word_end_offsets = std::vector<int>();
342 for (
size_t i =
text.size();
i > 0; --
i) {
343 if (previous_char ==
' ' &&
text[
i - 1] !=
' ')
344 word_end_offsets.push_back(
i);
345 previous_char =
text[
i - 1];
347 std::reverse(word_end_offsets.begin(), word_end_offsets.end());
351 const std::vector<std::string>& text_nodes_content,
352 bool build_word_boundaries_offsets =
false,
353 bool place_text_on_one_line =
false) {
356 root_data.
id = ++current_id;
361 update.has_tree_data =
true;
363 for (
const std::string& text_content : text_nodes_content) {
365 static_text_data.
id = ++current_id;
367 static_text_data.
SetName(text_content);
368 root_data.
child_ids.push_back(static_text_data.
id);
371 inline_box_data.
id = ++current_id;
373 inline_box_data.
SetName(text_content);
376 if (build_word_boundaries_offsets) {
377 std::vector<int> word_end_offsets;
378 std::vector<int> word_start_offsets;
387 if (place_text_on_one_line && !
update.nodes.empty()) {
391 previous_inline_box_data->
id);
394 previous_inline_box_data->
id);
399 update.nodes.push_back(static_text_data);
400 update.nodes.push_back(inline_box_data);
422 const int ROOT_ID = 1;
423 const int BUTTON_ID = 2;
424 const int CHECK_BOX_ID = 3;
425 const int TEXT_FIELD_ID = 4;
426 const int STATIC_TEXT1_ID = 5;
427 const int INLINE_BOX1_ID = 6;
428 const int LINE_BREAK_ID = 7;
429 const int INLINE_BOX_LINE_BREAK_ID = 8;
430 const int STATIC_TEXT2_ID = 9;
431 const int INLINE_BOX2_ID = 10;
434 button.
id = BUTTON_ID;
435 check_box.
id = CHECK_BOX_ID;
436 text_field.
id = TEXT_FIELD_ID;
437 static_text1.
id = STATIC_TEXT1_ID;
438 inline_box1.
id = INLINE_BOX1_ID;
439 line_break.
id = LINE_BREAK_ID;
440 inline_box_line_break.
id = INLINE_BOX_LINE_BREAK_ID;
441 static_text2.
id = STATIC_TEXT2_ID;
442 inline_box2.
id = INLINE_BOX2_ID;
444 std::string LINE_1_TEXT =
"Line 1";
445 std::string LINE_2_TEXT =
"Line 2";
446 std::string LINE_BREAK_TEXT =
"\n";
447 std::string ALL_TEXT = LINE_1_TEXT + LINE_BREAK_TEXT + LINE_2_TEXT;
448 std::string BUTTON_TEXT =
"Button";
449 std::string CHECKBOX_TEXT =
"Check box";
460 root.child_ids.push_back(button.
id);
464 check_box.
SetName(CHECKBOX_TEXT);
468 root.child_ids.push_back(check_box.
id);
479 std::vector<int32_t>{0, 7});
483 root.child_ids.push_back(text_field.
id);
487 static_text1.
SetName(LINE_1_TEXT);
492 inline_box1.
SetName(LINE_1_TEXT);
494 std::vector<int32_t> character_offsets1;
496 character_offsets1.push_back(225);
497 character_offsets1.push_back(230);
498 character_offsets1.push_back(235);
499 character_offsets1.push_back(240);
500 character_offsets1.push_back(245);
501 character_offsets1.push_back(250);
505 std::vector<int32_t>{0, 5});
507 std::vector<int32_t>{4, 6});
513 line_break.
SetName(LINE_BREAK_TEXT);
517 line_break.
child_ids.push_back(inline_box_line_break.
id);
522 inline_box_line_break.
SetName(LINE_BREAK_TEXT);
533 static_text2.
SetName(LINE_2_TEXT);
538 inline_box2.
SetName(LINE_2_TEXT);
540 std::vector<int32_t> character_offsets2;
542 character_offsets2.push_back(227);
543 character_offsets2.push_back(234);
544 character_offsets2.push_back(241);
545 character_offsets2.push_back(248);
546 character_offsets2.push_back(255);
547 character_offsets2.push_back(262);
551 std::vector<int32_t>{0, 5});
553 std::vector<int32_t>{4, 6});
556 update.has_tree_data =
true;
559 root, button, check_box, text_field,
560 static_text1, inline_box1, line_break, inline_box_line_break,
561 static_text2, inline_box2};
567 L"First line of text\nStandalone line\n"
568 L"bold text\nParagraph 1\nParagraph 2";
580 std::string text_content =
"First line of text";
581 text_data.
SetName(text_content);
582 std::vector<int> word_end_offsets;
583 std::vector<int> word_start_offsets;
597 line_break1_data.
id = 5;
601 line_break1_data.
SetName(
"\n");
604 standalone_text_data.
id = 6;
606 text_content =
"Standalone line";
607 standalone_text_data.
SetName(text_content);
616 line_break2_data.
id = 7;
620 line_break2_data.
SetName(
"\n");
622 group2_data.
child_ids = {line_break1_data.
id, standalone_text_data.
id,
623 line_break2_data.
id};
625 line_break2_data.
id);
627 standalone_text_data.
id);
630 bold_text_data.
id = 8;
635 text_content =
"bold text";
636 bold_text_data.
SetName(text_content);
645 paragraph1_data.
id = 9;
651 paragraph1_text_data.
id = 10;
653 text_content =
"Paragraph 1";
654 paragraph1_text_data.
SetName(text_content);
665 ignored_text_data.
id = 11;
668 text_content =
"ignored text";
669 ignored_text_data.
SetName(text_content);
671 paragraph1_data.
child_ids = {paragraph1_text_data.
id, ignored_text_data.
id};
674 paragraph2_data.
id = 12;
680 paragraph2_text_data.
id = 13;
682 text_content =
"Paragraph 2";
683 paragraph2_text_data.
SetName(text_content);
692 paragraph2_data.
child_ids = {paragraph2_text_data.
id};
697 root_data.
child_ids = {group1_data.
id, group2_data.
id, bold_text_data.
id,
698 paragraph1_data.
id, paragraph2_data.
id};
701 update.has_tree_data =
true;
703 update.nodes = {root_data, group1_data,
704 text_data, group2_data,
705 line_break1_data, standalone_text_data,
706 line_break2_data, bold_text_data,
707 paragraph1_data, paragraph1_text_data,
708 ignored_text_data, paragraph2_data,
709 paragraph2_text_data};
736 text_data.
SetName(
"Text with formatting");
746 line_break1_data.
id = 5;
748 line_break1_data.
SetName(
"\n");
751 standalone_text_data.
id = 6;
753 standalone_text_data.
SetName(
"Standalone line with no formatting");
756 line_break2_data.
id = 7;
758 line_break2_data.
SetName(
"\n");
760 group2_data.
child_ids = {line_break1_data.
id, standalone_text_data.
id,
761 line_break2_data.
id};
773 bold_text_data.
id = 9;
775 bold_text_data.
SetName(
"bold text");
779 paragraph1_data.
id = 10;
786 paragraph1_text_data.
id = 11;
788 paragraph1_text_data.
SetName(
"Paragraph 1");
789 paragraph1_data.
child_ids = {paragraph1_text_data.
id};
792 paragraph2_data.
id = 12;
800 paragraph2_text_data.
id = 13;
802 paragraph2_text_data.
SetName(
"Paragraph 2");
803 paragraph2_data.
child_ids = {paragraph2_text_data.
id};
806 paragraph3_data.
id = 14;
814 paragraph3_text_data.
id = 15;
816 paragraph3_text_data.
SetName(
"Paragraph 3");
817 paragraph3_data.
child_ids = {paragraph3_text_data.
id};
820 paragraph4_data.
id = 16;
828 paragraph4_text_data.
id = 17;
830 paragraph4_text_data.
SetName(
"Paragraph 4");
831 paragraph4_data.
child_ids = {paragraph4_text_data.
id};
837 group3_data.
id, paragraph1_data.
id,
838 paragraph2_data.
id, paragraph3_data.
id,
842 update.has_tree_data =
true;
844 update.nodes = {root_data,
849 standalone_text_data,
854 paragraph1_text_data,
856 paragraph2_text_data,
858 paragraph3_text_data,
860 paragraph4_text_data};
868 EXPECT_EQ(
a->anchor_id(),
b->anchor_id());
869 EXPECT_EQ(
a->text_offset(),
b->text_offset());
874 :
public CComObjectRootEx<CComMultiThreadModel>,
875 public ITextRangeProvider {
878 COM_INTERFACE_ENTRY(ITextRangeProvider)
885 CComObject<MockAXPlatformNodeTextRangeProviderWin>* text_range_provider =
888 CComObject<MockAXPlatformNodeTextRangeProviderWin>::CreateInstance(
889 &text_range_provider);
891 *provider = text_range_provider;
900 IFACEMETHODIMP
Clone(ITextRangeProvider** clone)
override {
909 ITextRangeProvider* other,
910 TextPatternRangeEndpoint other_endpoint,
922 ITextRangeProvider**
result)
override {
929 ITextRangeProvider**
result)
override {
943 IRawElementProviderSimple** element)
override {
951 IFACEMETHODIMP
Move(TextUnit unit,
int count,
int* units_moved)
override {
958 int* units_moved)
override {
963 TextPatternRangeEndpoint this_endpoint,
964 ITextRangeProvider* other,
965 TextPatternRangeEndpoint other_endpoint)
override {
969 IFACEMETHODIMP
Select()
override {
return E_NOTIMPL; }
985 Init(BuildTextDocument({
"some text"}));
987 ComPtr<ITextRangeProvider> text_range_provider;
988 GetTextRangeProviderFromTextNode(text_range_provider,
989 GetRootAsAXNode()->children()[0]);
992 ComPtr<ITextRangeProvider> text_range_provider_clone;
993 text_range_provider->Clone(&text_range_provider_clone);
994 CopyOwnerToClone(text_range_provider.Get(), text_range_provider_clone.Get());
995 ComPtr<AXPlatformNodeTextRangeProviderWin> original_range;
996 ComPtr<AXPlatformNodeTextRangeProviderWin> clone_range;
998 text_range_provider->QueryInterface(IID_PPV_ARGS(&original_range));
999 text_range_provider_clone->QueryInterface(IID_PPV_ARGS(&clone_range));
1001 EXPECT_EQ(*GetStart(original_range.Get()), *GetStart(clone_range.Get()));
1002 EXPECT_EQ(*GetEnd(original_range.Get()), *GetEnd(clone_range.Get()));
1003 EXPECT_EQ(GetOwner(original_range.Get()), GetOwner(clone_range.Get()));
1006 text_range_provider.Reset();
1007 EXPECT_EQ(
nullptr, text_range_provider.Get());
1014 TestITextRangeProviderCompareEndpoints) {
1015 Init(BuildTextDocument({
"some text",
"more text"},
1019 AXNode* root_node = GetRootAsAXNode();
1023 ComPtr<ITextRangeProvider> document_text_range_provider;
1024 GetTextRangeProviderFromTextNode(document_text_range_provider, root_node);
1027 ComPtr<ITextRangeProvider> text_range_provider;
1028 GetTextRangeProviderFromTextNode(text_range_provider,
1032 ComPtr<ITextRangeProvider> more_text_range_provider;
1033 GetTextRangeProviderFromTextNode(more_text_range_provider,
1038 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->CompareEndpoints(
1039 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
1040 TextPatternRangeEndpoint_Start, &
result));
1043 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->CompareEndpoints(
1044 TextPatternRangeEndpoint_End, document_text_range_provider.Get(),
1045 TextPatternRangeEndpoint_End, &
result));
1048 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->CompareEndpoints(
1049 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
1050 TextPatternRangeEndpoint_End, &
result));
1053 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->CompareEndpoints(
1054 TextPatternRangeEndpoint_End, document_text_range_provider.Get(),
1055 TextPatternRangeEndpoint_Start, &
result));
1061 EXPECT_HRESULT_SUCCEEDED(text_range_provider->CompareEndpoints(
1062 TextPatternRangeEndpoint_Start, more_text_range_provider.Get(),
1063 TextPatternRangeEndpoint_Start, &
result));
1066 EXPECT_HRESULT_SUCCEEDED(text_range_provider->CompareEndpoints(
1067 TextPatternRangeEndpoint_End, more_text_range_provider.Get(),
1068 TextPatternRangeEndpoint_Start, &
result));
1074 EXPECT_HRESULT_SUCCEEDED(text_range_provider->CompareEndpoints(
1075 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
1076 TextPatternRangeEndpoint_Start, &
result));
1079 EXPECT_HRESULT_SUCCEEDED(text_range_provider->CompareEndpoints(
1080 TextPatternRangeEndpoint_End, document_text_range_provider.Get(),
1081 TextPatternRangeEndpoint_End, &
result));
1085 EXPECT_HRESULT_SUCCEEDED(more_text_range_provider->CompareEndpoints(
1086 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
1087 TextPatternRangeEndpoint_Start, &
result));
1090 EXPECT_HRESULT_SUCCEEDED(more_text_range_provider->CompareEndpoints(
1091 TextPatternRangeEndpoint_End, document_text_range_provider.Get(),
1092 TextPatternRangeEndpoint_End, &
result));
1097 TestITextRangeProviderExpandToEnclosingCharacter) {
1100 AXNode* root_node = GetRootAsAXNode();
1102 ComPtr<ITextRangeProvider> text_range_provider;
1103 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1104 ASSERT_HRESULT_SUCCEEDED(
1105 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
1109 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1110 TextPatternRangeEndpoint_End, TextUnit_Character, 2, &
count));
1111 ASSERT_EQ(2,
count);
1112 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1113 TextPatternRangeEndpoint_Start, TextUnit_Character, 1, &
count));
1114 ASSERT_EQ(1,
count);
1117 ASSERT_HRESULT_SUCCEEDED(
1118 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
1121 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1122 TextPatternRangeEndpoint_End, TextUnit_Character, 9, &
count));
1123 ASSERT_EQ(9,
count);
1124 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1125 TextPatternRangeEndpoint_Start, TextUnit_Character, 8, &
count));
1126 ASSERT_EQ(8,
count);
1129 ASSERT_HRESULT_SUCCEEDED(
1130 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
1135 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1136 TextPatternRangeEndpoint_End, TextUnit_Character, 9, &
count));
1137 ASSERT_EQ(8,
count);
1138 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1139 TextPatternRangeEndpoint_Start, TextUnit_Character, 9, &
count));
1140 ASSERT_EQ(9,
count);
1142 ASSERT_HRESULT_SUCCEEDED(
1143 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
1149 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1150 TextPatternRangeEndpoint_End, TextUnit_Character, -9, &
count));
1151 ASSERT_EQ(-9,
count);
1152 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1153 TextPatternRangeEndpoint_Start, TextUnit_Character, -1,
1155 ASSERT_EQ(-1,
count);
1156 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1157 TextPatternRangeEndpoint_Start, TextUnit_Character, 1, &
count));
1158 ASSERT_EQ(1,
count);
1159 ASSERT_HRESULT_SUCCEEDED(
1160 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
1164 ComPtr<IRawElementProviderSimple> more_text_provider =
1165 QueryInterfaceFromNode<IRawElementProviderSimple>(
1166 root_node->
children()[1]->children()[0]);
1167 ComPtr<IRawElementProviderSimple> enclosing_element;
1168 ASSERT_HRESULT_SUCCEEDED(
1169 text_range_provider->GetEnclosingElement(&enclosing_element));
1170 EXPECT_EQ(more_text_provider.Get(), enclosing_element.Get());
1174 TestITextRangeProviderExpandToEnclosingWord) {
1175 Init(BuildTextDocument({
"some text",
"definitely not text"},
1178 ComPtr<ITextRangeProvider> text_range_provider;
1179 GetTextRangeProviderFromTextNode(text_range_provider,
1180 GetRootAsAXNode()->children()[1]);
1184 ASSERT_HRESULT_SUCCEEDED(
1185 text_range_provider->ExpandToEnclosingUnit(TextUnit_Word));
1190 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1191 TextPatternRangeEndpoint_Start, TextUnit_Character, -2,
1193 ASSERT_EQ(-2,
count);
1196 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1197 TextPatternRangeEndpoint_End, TextUnit_Character, 4, &
count));
1198 ASSERT_EQ(4,
count);
1201 ASSERT_HRESULT_SUCCEEDED(
1202 text_range_provider->ExpandToEnclosingUnit(TextUnit_Word));
1206 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1207 TextPatternRangeEndpoint_Start, TextUnit_Character, 18,
1209 ASSERT_EQ(18,
count);
1212 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1213 TextPatternRangeEndpoint_End, TextUnit_Character, 1, &
count));
1214 ASSERT_EQ(1,
count);
1217 ASSERT_HRESULT_SUCCEEDED(
1218 text_range_provider->ExpandToEnclosingUnit(TextUnit_Word));
1223 TestITextRangeProviderExpandToEnclosingLine) {
1224 Init(BuildTextDocument({
"line #1",
"maybe line #1?",
"not line #1"}));
1226 ComPtr<ITextRangeProvider> text_range_provider;
1227 GetTextRangeProviderFromTextNode(text_range_provider,
1228 GetRootAsAXNode()->children()[0]);
1233 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1234 TextPatternRangeEndpoint_End, TextUnit_Character, -11, &
count));
1235 ASSERT_EQ(-7,
count);
1238 ASSERT_HRESULT_SUCCEEDED(
1239 text_range_provider->ExpandToEnclosingUnit(TextUnit_Line));
1243 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1244 TextPatternRangeEndpoint_Start, TextUnit_Character, 13,
1246 ASSERT_EQ(13,
count);
1249 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1250 TextPatternRangeEndpoint_End, TextUnit_Character, 4, &
count));
1251 ASSERT_EQ(4,
count);
1254 ASSERT_HRESULT_SUCCEEDED(
1255 text_range_provider->ExpandToEnclosingUnit(TextUnit_Line));
1259 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1260 TextPatternRangeEndpoint_Start, TextUnit_Character, 29,
1262 ASSERT_EQ(25,
count);
1265 ASSERT_HRESULT_SUCCEEDED(
1266 text_range_provider->ExpandToEnclosingUnit(TextUnit_Line));
1272 DISABLED_TestITextRangeProviderExpandToEnclosingParagraph) {
1273 Init(BuildAXTreeForMove());
1274 AXNode* root_node = GetRootAsAXNode();
1276 ComPtr<ITextRangeProvider> text_range_provider;
1277 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1280 tree_for_move_full_text.data());
1289 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1290 TextPatternRangeEndpoint_End, TextUnit_Paragraph, -5, &
count));
1291 EXPECT_EQ(-5,
count);
1294 ASSERT_HRESULT_SUCCEEDED(
1295 text_range_provider->ExpandToEnclosingUnit(TextUnit_Paragraph));
1300 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1301 TextPatternRangeEndpoint_Start, TextUnit_Line, 2, &
count));
1302 EXPECT_EQ(2,
count);
1305 ASSERT_HRESULT_SUCCEEDED(
1306 text_range_provider->ExpandToEnclosingUnit(TextUnit_Paragraph));
1311 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1312 TextPatternRangeEndpoint_Start, TextUnit_Line, 1, &
count));
1313 EXPECT_EQ(1,
count);
1320 ASSERT_HRESULT_SUCCEEDED(
1321 text_range_provider->ExpandToEnclosingUnit(TextUnit_Paragraph));
1326 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1327 TextPatternRangeEndpoint_Start, TextUnit_Document, 1, &
count));
1328 EXPECT_EQ(1,
count);
1330 ASSERT_HRESULT_SUCCEEDED(
1331 text_range_provider->ExpandToEnclosingUnit(TextUnit_Paragraph));
1337 DISABLED_TestITextRangeProviderExpandToEnclosingFormat) {
1338 Init(BuildAXTreeForMoveByFormat());
1339 AXNode* root_node = GetRootAsAXNode();
1340 ComPtr<ITextRangeProvider> text_range_provider;
1341 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1342 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider_internal;
1343 ASSERT_HRESULT_SUCCEEDED(text_range_provider->QueryInterface(
1344 IID_PPV_ARGS(&text_range_provider_internal)));
1347 text_range_provider,
1348 L"Text with formatting\nStandalone line with no formatting\nbold "
1349 L"text\nParagraph 1\nParagraph 2\nParagraph 3\nParagraph 4");
1358 ComPtr<ITextRangeProvider> units_a_b_provider;
1359 ASSERT_HRESULT_SUCCEEDED(text_range_provider->Clone(&units_a_b_provider));
1360 CopyOwnerToClone(text_range_provider.Get(), units_a_b_provider.Get());
1363 ASSERT_HRESULT_SUCCEEDED(units_a_b_provider->MoveEndpointByUnit(
1364 TextPatternRangeEndpoint_Start, TextUnit_Line, 5, &
count));
1365 ASSERT_EQ(5,
count);
1366 ASSERT_HRESULT_SUCCEEDED(units_a_b_provider->MoveEndpointByUnit(
1367 TextPatternRangeEndpoint_End, TextUnit_Line, -1, &
count));
1368 ASSERT_EQ(-1,
count);
1370 L"Paragraph 1\nParagraph 2\nParagraph 3");
1374 ComPtr<ITextRangeProvider> unit_a_provider;
1375 ASSERT_HRESULT_SUCCEEDED(units_a_b_provider->Clone(&unit_a_provider));
1376 CopyOwnerToClone(units_a_b_provider.Get(), unit_a_provider.Get());
1377 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->MoveEndpointByUnit(
1378 TextPatternRangeEndpoint_End, TextUnit_Line, -2, &
count));
1379 ASSERT_EQ(-2,
count);
1384 SCOPED_TRACE(
"Case 1: Degenerate range at start of A.");
1385 ComPtr<ITextRangeProvider> test_case_provider;
1386 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1387 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1388 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByRange(
1389 TextPatternRangeEndpoint_End, test_case_provider.Get(),
1390 TextPatternRangeEndpoint_Start));
1393 ASSERT_HRESULT_SUCCEEDED(
1394 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1396 ASSERT_HRESULT_SUCCEEDED(
1397 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1403 SCOPED_TRACE(
"Case 2: Range from start of A to middle of A.");
1404 ComPtr<ITextRangeProvider> test_case_provider;
1405 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1406 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1407 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1408 TextPatternRangeEndpoint_End, TextUnit_Character, -7,
1410 ASSERT_EQ(-7,
count);
1413 ASSERT_HRESULT_SUCCEEDED(
1414 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1416 ASSERT_HRESULT_SUCCEEDED(
1417 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1423 SCOPED_TRACE(
"Case 3: Range from start of A to end of A.");
1424 ComPtr<ITextRangeProvider> test_case_provider;
1425 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1426 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1429 ASSERT_HRESULT_SUCCEEDED(
1430 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1432 ASSERT_HRESULT_SUCCEEDED(
1433 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1439 SCOPED_TRACE(
"Case 4: Range from start of A to middle of B.");
1440 ComPtr<ITextRangeProvider> test_case_provider;
1441 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1442 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1443 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1444 TextPatternRangeEndpoint_End, TextUnit_Character, 5, &
count));
1445 ASSERT_EQ(5,
count);
1448 ASSERT_HRESULT_SUCCEEDED(
1449 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1451 ASSERT_HRESULT_SUCCEEDED(
1452 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1458 SCOPED_TRACE(
"Case 5: Degenerate range in middle of A.");
1459 ComPtr<ITextRangeProvider> test_case_provider;
1460 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1461 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1462 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1463 TextPatternRangeEndpoint_Start, TextUnit_Character, 4,
1465 ASSERT_EQ(4,
count);
1466 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByRange(
1467 TextPatternRangeEndpoint_End, test_case_provider.Get(),
1468 TextPatternRangeEndpoint_Start));
1471 ASSERT_HRESULT_SUCCEEDED(
1472 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1474 ASSERT_HRESULT_SUCCEEDED(
1475 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1481 SCOPED_TRACE(
"Case 6: Range from middle of A to middle of A.");
1482 ComPtr<ITextRangeProvider> test_case_provider;
1483 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1484 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1485 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1486 TextPatternRangeEndpoint_Start, TextUnit_Character, 4,
1488 ASSERT_EQ(4,
count);
1489 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1490 TextPatternRangeEndpoint_End, TextUnit_Character, -2,
1492 ASSERT_EQ(-2,
count);
1495 ASSERT_HRESULT_SUCCEEDED(
1496 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1498 ASSERT_HRESULT_SUCCEEDED(
1499 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1505 SCOPED_TRACE(
"Case 7: Range from middle of A to end of A.");
1506 ComPtr<ITextRangeProvider> test_case_provider;
1507 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1508 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1509 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1510 TextPatternRangeEndpoint_Start, TextUnit_Character, 4,
1512 ASSERT_EQ(4,
count);
1515 ASSERT_HRESULT_SUCCEEDED(
1516 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1518 ASSERT_HRESULT_SUCCEEDED(
1519 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1525 SCOPED_TRACE(
"Case 8: Range from middle of A to middle of B.");
1526 ComPtr<ITextRangeProvider> test_case_provider;
1527 ASSERT_HRESULT_SUCCEEDED(unit_a_provider->Clone(&test_case_provider));
1528 CopyOwnerToClone(unit_a_provider.Get(), test_case_provider.Get());
1529 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1530 TextPatternRangeEndpoint_Start, TextUnit_Character, 5,
1532 ASSERT_EQ(5,
count);
1533 ASSERT_HRESULT_SUCCEEDED(test_case_provider->MoveEndpointByUnit(
1534 TextPatternRangeEndpoint_End, TextUnit_Character, 5, &
count));
1535 ASSERT_EQ(5,
count);
1538 ASSERT_HRESULT_SUCCEEDED(
1539 test_case_provider->ExpandToEnclosingUnit(TextUnit_Format));
1541 ASSERT_HRESULT_SUCCEEDED(
1542 test_case_provider->Compare(unit_a_provider.Get(), &are_same));
1549 DISABLED_TestITextRangeProviderExpandToEnclosingFormatWithEmptyObjects) {
1579 static_text_3.
id = 3;
1580 inline_box_4.
id = 4;
1581 generic_container_5.
id = 5;
1585 root_1.
child_ids = {heading_2.
id, generic_container_5.
id, button_6.
id};
1592 static_text_3.
SetName(
"3.14");
1607 update.tree_data = tree_data;
1608 update.has_tree_data =
true;
1610 update.nodes.push_back(root_1);
1611 update.nodes.push_back(heading_2);
1612 update.nodes.push_back(static_text_3);
1613 update.nodes.push_back(inline_box_4);
1614 update.nodes.push_back(generic_container_5);
1615 update.nodes.push_back(button_6);
1619 AXNode* root_node = GetRootAsAXNode();
1620 ComPtr<ITextRangeProvider> text_range_provider;
1621 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1628 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1629 TextPatternRangeEndpoint_Start, TextUnit_Character, 5, &
count));
1630 ASSERT_EQ(5,
count);
1631 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1632 TextPatternRangeEndpoint_End, TextUnit_Character, -1, &
count));
1633 ASSERT_EQ(-1,
count);
1638 ASSERT_HRESULT_SUCCEEDED(
1639 text_range_provider->ExpandToEnclosingUnit(TextUnit_Format));
1644 TestITextRangeProviderExpandToEnclosingDocument) {
1645 Init(BuildTextDocument({
"some text",
"more text",
"even more text"}));
1647 AXNode* root_node = GetRootAsAXNode();
1654 const TextUnit textunit_types[] = {TextUnit_Document, TextUnit_Page};
1655 ComPtr<ITextRangeProvider> text_range_provider;
1657 for (
auto& textunit : textunit_types) {
1658 GetTextRangeProviderFromTextNode(text_range_provider, text_node);
1659 ASSERT_HRESULT_SUCCEEDED(
1660 text_range_provider->ExpandToEnclosingUnit(textunit));
1662 L"some textmore texteven more text");
1664 GetTextRangeProviderFromTextNode(text_range_provider, more_text_node);
1665 ASSERT_HRESULT_SUCCEEDED(
1666 text_range_provider->ExpandToEnclosingUnit(textunit));
1668 L"some textmore texteven more text");
1670 GetTextRangeProviderFromTextNode(text_range_provider, even_more_text_node);
1671 ASSERT_HRESULT_SUCCEEDED(
1672 text_range_provider->ExpandToEnclosingUnit(textunit));
1674 L"some textmore texteven more text");
1681 DISABLED_TestITextRangeProviderIgnoredForTextNavigation) {
1702 static_text_2.
id = 2;
1703 inline_box_3.
id = 3;
1705 static_text_5.
id = 5;
1706 inline_box_6.
id = 6;
1707 generic_container_7.
id = 7;
1708 static_text_8.
id = 8;
1709 inline_box_9.
id = 9;
1712 root_1.
child_ids = {static_text_2.
id, splitter_4.
id, static_text_5.
id,
1713 generic_container_7.
id, static_text_8.
id};
1747 update.tree_data = tree_data;
1748 update.has_tree_data =
true;
1751 root_1, static_text_2, inline_box_3, splitter_4,
1752 static_text_5, inline_box_6, generic_container_7, static_text_8,
1757 AXNode* root_node = GetRootAsAXNode();
1758 ComPtr<ITextRangeProvider> text_range_provider;
1759 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1762 L"foo\n\xFFFC\nbar\n\xFFFC\nbaz");
1765 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1766 TextPatternRangeEndpoint_Start, TextUnit_Paragraph, 1, &
count));
1767 ASSERT_EQ(1,
count);
1770 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
1771 TextPatternRangeEndpoint_Start, TextUnit_Paragraph, 1, &
count));
1772 ASSERT_EQ(1,
count);
1779 DISABLED_TestITextRangeProviderInvalidCalls) {
1784 Init(BuildTextDocument({}));
1786 ComPtr<ITextRangeProvider> text_range_provider;
1787 GetTextRangeProviderFromTextNode(text_range_provider, GetRootAsAXNode());
1790 ComPtr<ITextRangeProvider> text_range_provider_clone;
1792 text_range_provider->Clone(&text_range_provider_clone));
1794 BOOL compare_result;
1796 text_range_provider.Get(), &compare_result));
1798 int compare_endpoints_result;
1800 TextPatternRangeEndpoint_Start, text_range_provider.Get(),
1801 TextPatternRangeEndpoint_Start, &compare_endpoints_result));
1804 V_VT(&attr_val) = VT_BOOL;
1805 V_BOOL(&attr_val) = VARIANT_TRUE;
1806 ComPtr<ITextRangeProvider> matched_range_provider;
1808 UIA_IsHiddenAttributeId, attr_val,
true, &matched_range_provider));
1811 TextPatternRangeEndpoint_Start, text_range_provider.Get(),
1812 TextPatternRangeEndpoint_Start));
1821 Init(BuildTextDocument({}));
1823 ComPtr<ITextRangeProvider> this_provider;
1824 GetTextRangeProviderFromTextNode(this_provider, GetRootAsAXNode());
1826 ComPtr<ITextRangeProvider> other_provider_different_type;
1828 &other_provider_different_type);
1830 BOOL compare_result;
1832 other_provider_different_type.Get(), &compare_result));
1834 int compare_endpoints_result;
1836 TextPatternRangeEndpoint_Start, other_provider_different_type.Get(),
1837 TextPatternRangeEndpoint_Start, &compare_endpoints_result));
1840 TextPatternRangeEndpoint_Start, other_provider_different_type.Get(),
1841 TextPatternRangeEndpoint_Start));
1846 Init(BuildTextDocument({
"some text",
"more text"}));
1848 AXNode* root_node = GetRootAsAXNode();
1851 ComPtr<ITextRangeProvider> text_range_provider;
1852 GetTextRangeProviderFromTextNode(text_range_provider, text_node);
1855 EXPECT_HRESULT_SUCCEEDED(
1856 text_range_provider->GetText(-1, text_content.
Receive()));
1857 EXPECT_STREQ(text_content.
Get(),
L"some text");
1858 text_content.
Reset();
1860 EXPECT_HRESULT_SUCCEEDED(
1861 text_range_provider->GetText(4, text_content.
Receive()));
1862 EXPECT_STREQ(text_content.
Get(),
L"some");
1863 text_content.
Reset();
1865 EXPECT_HRESULT_SUCCEEDED(
1866 text_range_provider->GetText(0, text_content.
Receive()));
1867 EXPECT_STREQ(text_content.
Get(),
L"");
1868 text_content.
Reset();
1870 EXPECT_HRESULT_SUCCEEDED(
1871 text_range_provider->GetText(9, text_content.
Receive()));
1872 EXPECT_STREQ(text_content.
Get(),
L"some text");
1873 text_content.
Reset();
1875 EXPECT_HRESULT_SUCCEEDED(
1876 text_range_provider->GetText(10, text_content.
Receive()));
1877 EXPECT_STREQ(text_content.
Get(),
L"some text");
1878 text_content.
Reset();
1880 EXPECT_HRESULT_FAILED(text_range_provider->GetText(-1,
nullptr));
1882 EXPECT_HRESULT_FAILED(
1883 text_range_provider->GetText(-2, text_content.
Receive()));
1884 text_content.
Reset();
1886 ComPtr<ITextRangeProvider> document_textrange;
1887 GetTextRangeProviderFromTextNode(document_textrange, root_node);
1889 EXPECT_HRESULT_SUCCEEDED(
1890 document_textrange->GetText(-1, text_content.
Receive()));
1891 EXPECT_STREQ(text_content.
Get(),
L"some textmore text");
1892 text_content.
Reset();
1896 TestITextRangeProviderMoveCharacter) {
1897 Init(BuildAXTreeForMove());
1898 AXNode* root_node = GetRootAsAXNode();
1900 ComPtr<ITextRangeProvider> text_range_provider;
1901 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1906 L"First line of text\nStandalone line\n"
1907 L"bold textParagraph 1Paragraph 2",
1958 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
1984 DISABLED_TestITextRangeProviderMoveFormat) {
1985 Init(BuildAXTreeForMoveByFormat());
1986 AXNode* root_node = GetRootAsAXNode();
1988 ComPtr<ITextRangeProvider> text_range_provider;
1989 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
1993 text_range_provider, TextUnit_Format,
1996 L"Text with formatting\nStandalone line with no formatting\nbold "
1997 L"text\nParagraph 1\nParagraph 2\nParagraph 3\nParagraph 4",
2003 L"\nStandalone line with no formatting\n",
2011 L"Paragraph 2\nParagraph 3",
2031 L"\nStandalone line with no formatting\n",
2035 L"Text with formatting",
2043 L"Text with formatting",
2048 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
2053 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
2055 L"Text with formatting",
2064 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Format,
2069 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Format,
2074 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Format,
2079 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Format,
2087 L"Text with formatting",
2090 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
2116 DISABLED_TestITextRangeProviderMoveWord) {
2117 Init(BuildAXTreeForMove());
2118 AXNode* root_node = GetRootAsAXNode();
2120 ComPtr<ITextRangeProvider> text_range_provider;
2121 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
2125 tree_for_move_full_text.data(),
2183 TextPatternRangeEndpoint_End, TextUnit_Word,
2209 DISABLED_TestITextRangeProviderMoveLine) {
2210 Init(BuildAXTreeForMove());
2211 AXNode* root_node = GetRootAsAXNode();
2213 ComPtr<ITextRangeProvider> text_range_provider;
2214 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
2218 tree_for_move_full_text.data(),
2248 L"First line of text",
2255 L"First line of text",
2260 TextPatternRangeEndpoint_End, TextUnit_Line,
2286 DISABLED_TestITextRangeProviderMoveParagraph) {
2287 Init(BuildAXTreeForMove());
2288 AXNode* root_node = GetRootAsAXNode();
2290 ComPtr<ITextRangeProvider> text_range_provider;
2291 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
2295 tree_for_move_full_text.data(),
2299 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2301 L"First line of text\n",
2310 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2315 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2317 L"First line of text\n",
2326 L"Standalone line\n",
2365 L"Standalone line\n",
2372 L"First line of text\n",
2376 L"First line of text\n",
2383 L"First line of text\n",
2388 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2393 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2395 L"First line of text\n",
2404 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Paragraph,
2409 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Paragraph,
2414 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Paragraph,
2419 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Paragraph,
2430 L"First line of text\n",
2433 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Paragraph,
2459 DISABLED_TestITextRangeProviderMoveDocument) {
2460 Init(BuildAXTreeForMove());
2461 AXNode* root_node = GetRootAsAXNode();
2463 ComPtr<ITextRangeProvider> text_range_provider;
2464 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
2468 tree_for_move_full_text.data(),
2472 tree_for_move_full_text.data(),
2475 tree_for_move_full_text.data(),
2478 tree_for_move_full_text.data(),
2481 tree_for_move_full_text.data(),
2486 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Document,
2511 Init(BuildAXTreeForMove());
2512 AXNode* root_node = GetRootAsAXNode();
2514 ComPtr<ITextRangeProvider> text_range_provider;
2515 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
2521 TestITextRangeProviderMoveEndpointByDocument) {
2522 Init(BuildTextDocument({
"some text",
"more text",
"even more text"}));
2527 const TextUnit textunit_types[] = {TextUnit_Document, TextUnit_Page};
2528 ComPtr<ITextRangeProvider> text_range_provider;
2530 for (
auto& textunit : textunit_types) {
2531 GetTextRangeProviderFromTextNode(text_range_provider, text_node);
2535 TextPatternRangeEndpoint_End, textunit,
2542 text_range_provider, TextPatternRangeEndpoint_End, textunit,
2544 L"more texteven more text",
2549 text_range_provider, TextPatternRangeEndpoint_End, textunit,
2551 L"more texteven more text",
2556 TextPatternRangeEndpoint_End, textunit,
2565 text_range_provider, TextPatternRangeEndpoint_End, textunit,
2567 L"some textmore texteven more text",
2572 TextPatternRangeEndpoint_Start, textunit,
2579 text_range_provider, TextPatternRangeEndpoint_Start, textunit,
2581 L"some textmore texteven more text",
2589 DISABLED_TestITextRangeProviderMoveEndpointByCharacterMultilingual) {
2591 const std::string english =
"hey";
2595 const std::string hindi =
2600 const std::string thai =
2603 Init(BuildTextDocument({english, hindi, thai}));
2605 ComPtr<ITextRangeProvider> text_range_provider;
2606 GetTextRangeProviderFromTextNode(text_range_provider,
2607 GetRootAsAXNode()->children()[0]);
2612 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
2618 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
2624 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2633 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2640 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2642 L"ey\x939\x93F\x928\x94D\x926\x940",
2647 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
2649 L"\x939\x93F\x928\x94D\x926\x940",
2656 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2658 L"\x939\x93F\x928\x94D\x926\x940\xE23\xE39\xE49",
2663 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2669 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2672 L"\x939\x93F\x928\x94D\x926\x940\xE23\xE39\xE49\xE2A\xE36",
2677 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
2680 L"\x939\x93F\x928\x94D\x926\x940\xE23\xE39\xE49\xE2A\xE36\xE01",
2685 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
2687 L"\x0E2A\x0E36\x0E01",
2691 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
2693 L"\x0E23\x0E39\x0E49\x0E2A\x0E36\x0E01",
2699 DISABLED_TestITextRangeProviderMoveEndpointByWord) {
2700 Init(BuildTextDocument({
"some text",
"more text",
"even more text"},
2703 ComPtr<ITextRangeProvider> text_range_provider;
2704 GetTextRangeProviderFromTextNode(text_range_provider,
2705 GetRootAsAXNode()->children()[1]);
2710 TextPatternRangeEndpoint_End, TextUnit_Word,
2717 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2722 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2729 TextPatternRangeEndpoint_End, TextUnit_Word,
2734 TextPatternRangeEndpoint_End, TextUnit_Word,
2741 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2746 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2751 TextPatternRangeEndpoint_End, TextUnit_Word,
2758 TextPatternRangeEndpoint_End, TextUnit_Word,
2763 TextPatternRangeEndpoint_End, TextUnit_Word,
2768 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2775 TextPatternRangeEndpoint_End, TextUnit_Word,
2777 L"more texteven more text",
2780 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2785 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Word,
2787 L"some textmore texteven more text",
2790 TextPatternRangeEndpoint_End, TextUnit_Word,
2798 DISABLED_TestITextRangeProviderMoveEndpointByLine) {
2799 Init(BuildTextDocument({
"0",
"1",
"2",
"3",
"4",
"5",
"6"}));
2801 ComPtr<ITextRangeProvider> text_range_provider;
2802 GetTextRangeProviderFromTextNode(text_range_provider,
2803 GetRootAsAXNode()->children()[3]);
2808 TextPatternRangeEndpoint_End, TextUnit_Line,
2815 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2820 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2827 TextPatternRangeEndpoint_End, TextUnit_Line,
2832 TextPatternRangeEndpoint_End, TextUnit_Line,
2839 TextPatternRangeEndpoint_End, TextUnit_Line,
2844 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2849 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2854 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2861 TextPatternRangeEndpoint_End, TextUnit_Line,
2866 TextPatternRangeEndpoint_End, TextUnit_Line,
2871 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2876 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Line,
2885 DISABLED_TestITextRangeProviderMoveEndpointByUnitTextField) {
2898 std::string text_content =
"some text";
2899 text_data.
SetName(text_content);
2900 std::vector<int> word_start_offsets, word_end_offsets;
2901 ComputeWordBoundariesOffsets(text_content, word_start_offsets,
2904 word_start_offsets);
2909 text_input_data.
id = 4;
2922 more_text_data.
id = 6;
2924 text_content =
"more text";
2925 more_text_data.
SetName(text_content);
2926 ComputeWordBoundariesOffsets(text_content, word_start_offsets,
2929 word_start_offsets);
2934 empty_text_data.
id = 7;
2939 ComputeWordBoundariesOffsets(text_content, word_start_offsets,
2942 word_start_offsets);
2946 root_data.
child_ids = {group1_data.
id, text_input_data.
id, group2_data.
id};
2954 update.tree_data = tree_data;
2955 update.has_tree_data =
true;
2957 update.nodes = {root_data, group1_data, text_data, text_input_data,
2958 group2_data, more_text_data, empty_text_data};
2963 AXNode* root_node = GetRootAsAXNode();
2966 ComPtr<ITextRangeProvider> text_range_provider;
2967 GetTextRangeProviderFromTextNode(text_range_provider, text_node);
2973 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
2974 TextPatternRangeEndpoint_End, TextUnit_Character, 2, &
count));
2975 ASSERT_EQ(2,
count);
2980 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
2981 TextPatternRangeEndpoint_End, TextUnit_Character, 2, &
count));
2982 ASSERT_EQ(2,
count);
2985 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
2986 TextPatternRangeEndpoint_End, TextUnit_Character, -1, &
count));
2987 ASSERT_EQ(-1,
count);
2990 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
2991 TextPatternRangeEndpoint_End, TextUnit_Character, -2, &
count));
2992 ASSERT_EQ(-2,
count);
2996 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
2997 TextPatternRangeEndpoint_End, TextUnit_Word, 1, &
count));
2998 ASSERT_EQ(1,
count);
3001 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3002 TextPatternRangeEndpoint_End, TextUnit_Word, 1, &
count));
3003 ASSERT_EQ(1,
count);
3006 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3007 TextPatternRangeEndpoint_End, TextUnit_Word, -1, &
count));
3008 ASSERT_EQ(-1,
count);
3011 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3012 TextPatternRangeEndpoint_End, TextUnit_Word, -1, &
count));
3013 ASSERT_EQ(-1,
count);
3017 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3018 TextPatternRangeEndpoint_End, TextUnit_Line, 1, &
count));
3019 ASSERT_EQ(1,
count);
3022 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3023 TextPatternRangeEndpoint_End, TextUnit_Line, 1, &
count));
3024 ASSERT_EQ(1,
count);
3027 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3028 TextPatternRangeEndpoint_End, TextUnit_Line, -1, &
count));
3029 ASSERT_EQ(-1,
count);
3032 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3033 TextPatternRangeEndpoint_End, TextUnit_Line, -1, &
count));
3034 ASSERT_EQ(-1,
count);
3040 DISABLED_TestITextRangeProviderMoveEndpointByFormat) {
3041 Init(BuildAXTreeForMoveByFormat());
3042 AXNode* root_node = GetRootAsAXNode();
3044 ComPtr<ITextRangeProvider> text_range_provider;
3045 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
3048 text_range_provider,
3049 L"Text with formatting\nStandalone line with no formatting\nbold "
3050 L"text\nParagraph 1\nParagraph 2\nParagraph 3\nParagraph 4");
3052 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3055 L"Text with formatting\nStandalone line with no formatting\nbold "
3056 L"text\nParagraph 1",
3060 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3063 L"Text with formatting\nStandalone line with no formatting\nbold text",
3067 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3070 L"Text with formatting\nStandalone line with no formatting\n",
3074 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3076 L"Text with formatting",
3080 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3086 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3089 L"Text with formatting\nStandalone line with no formatting\nbold "
3090 L"text\nParagraph 1\nParagraph 2\nParagraph 3\nParagraph 4",
3094 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Format,
3101 Init(BuildTextDocument({
"some text",
"some text"}));
3102 AXNode* root_node = GetRootAsAXNode();
3106 ComPtr<ITextRangeProvider> document_text_range_provider;
3107 GetTextRangeProviderFromTextNode(document_text_range_provider, root_node);
3110 ComPtr<ITextRangeProvider> text_range_provider;
3111 GetTextRangeProviderFromTextNode(text_range_provider,
3115 ComPtr<ITextRangeProvider> more_text_range_provider;
3116 GetTextRangeProviderFromTextNode(more_text_range_provider,
3122 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->Compare(
3123 document_text_range_provider.Get(), &
result));
3128 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->Compare(
3129 text_range_provider.Get(), &
result));
3136 EXPECT_HRESULT_SUCCEEDED(
3137 text_range_provider->Compare(more_text_range_provider.Get(), &
result));
3142 Init(BuildTextDocument({
"some text"}));
3144 ComPtr<ITextRangeProvider> text_range_provider;
3145 GetTextRangeProviderFromTextNode(text_range_provider, GetRootAsAXNode());
3154 DISABLED_TestITextRangeProviderGetBoundingRectangles) {
3157 ComPtr<ITextRangeProvider> text_range_provider;
3164 GetTextRangeProviderFromTextNode(text_range_provider, GetRootAsAXNode());
3165 EXPECT_HRESULT_SUCCEEDED(
3166 text_range_provider->GetBoundingRectangles(rectangles.
Receive()));
3167 std::vector<double> expected_values = {20, 20, 200, 30,
3178 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3179 TextPatternRangeEndpoint_End, TextUnit_Character, -1,
3181 ASSERT_EQ(-1, units_moved);
3182 EXPECT_HRESULT_SUCCEEDED(
3183 text_range_provider->GetBoundingRectangles(rectangles.
Receive()));
3184 expected_values = {20, 20, 200, 30,
3195 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3196 TextPatternRangeEndpoint_End, TextUnit_Line, -1, &units_moved));
3197 ASSERT_EQ(-1, units_moved);
3198 EXPECT_HRESULT_SUCCEEDED(
3199 text_range_provider->GetBoundingRectangles(rectangles.
Receive()));
3200 expected_values = {20, 20, 200, 30,
3210 ASSERT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByUnit(
3211 TextPatternRangeEndpoint_End, TextUnit_Word, -3, &units_moved));
3212 ASSERT_EQ(-3, units_moved);
3213 EXPECT_HRESULT_SUCCEEDED(
3214 text_range_provider->GetBoundingRectangles(rectangles.
Receive()));
3215 expected_values = {20, 20, 200, 30,
3221 TestITextRangeProviderGetEnclosingElement) {
3243 paragraph_data.
id = 2;
3248 static_text_data1.
id = 3;
3250 paragraph_data.
child_ids.push_back(static_text_data1.
id);
3253 inline_text_data1.
id = 4;
3255 static_text_data1.
child_ids.push_back(inline_text_data1.
id);
3263 static_text_data2.
id = 6;
3265 link_data.
child_ids.push_back(static_text_data2.
id);
3268 inline_text_data2.
id = 7;
3270 static_text_data2.
child_ids.push_back(inline_text_data2.
id);
3275 paragraph_data.
child_ids.push_back(link_data2.
id);
3283 list_item_data.
id = 10;
3288 static_text_data3.
id = 11;
3290 list_item_data.
child_ids.push_back(static_text_data3.
id);
3293 inline_text_data3.
id = 12;
3295 static_text_data3.
child_ids.push_back(inline_text_data3.
id);
3304 paragraph_data.
child_ids.push_back(search_box.
id);
3307 search_text.
id = 14;
3310 search_text.
SetName(
"placeholder");
3314 pdf_highlight_data.
id = 15;
3316 paragraph_data.
child_ids.push_back(pdf_highlight_data.
id);
3319 static_text_data4.
id = 16;
3321 pdf_highlight_data.
child_ids.push_back(static_text_data4.
id);
3324 inline_text_data4.
id = 17;
3326 static_text_data4.
child_ids.push_back(inline_text_data4.
id);
3331 update.tree_data = tree_data;
3332 update.has_tree_data =
true;
3334 update.nodes = {root_data, paragraph_data, static_text_data1,
3335 inline_text_data1, link_data, static_text_data2,
3336 inline_text_data2, link_data2, list_data,
3337 list_item_data, static_text_data3, inline_text_data3,
3338 search_box, search_text, pdf_highlight_data,
3339 static_text_data4, inline_text_data4};
3359 AXPlatformNodeWin* owner =
3360 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(paragraph_node));
3361 ASSERT_NE(owner,
nullptr);
3363 ComPtr<IRawElementProviderSimple> link_node_raw =
3364 QueryInterfaceFromNode<IRawElementProviderSimple>(link_node);
3365 ComPtr<IRawElementProviderSimple> static_text_node_raw1 =
3366 QueryInterfaceFromNode<IRawElementProviderSimple>(static_text_node1);
3367 ComPtr<IRawElementProviderSimple> static_text_node_raw2 =
3368 QueryInterfaceFromNode<IRawElementProviderSimple>(static_text_node2);
3369 ComPtr<IRawElementProviderSimple> static_text_node_raw3 =
3370 QueryInterfaceFromNode<IRawElementProviderSimple>(static_text_node3);
3371 ComPtr<IRawElementProviderSimple> inline_text_node_raw1 =
3372 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_node1);
3373 ComPtr<IRawElementProviderSimple> inline_text_node_raw2 =
3374 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_node2);
3375 ComPtr<IRawElementProviderSimple> inline_text_node_raw3 =
3376 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_node3);
3377 ComPtr<IRawElementProviderSimple> search_box_node_raw =
3378 QueryInterfaceFromNode<IRawElementProviderSimple>(search_box_node);
3379 ComPtr<IRawElementProviderSimple> search_text_node_raw =
3380 QueryInterfaceFromNode<IRawElementProviderSimple>(search_text_node);
3381 ComPtr<IRawElementProviderSimple> pdf_highlight_node_raw =
3382 QueryInterfaceFromNode<IRawElementProviderSimple>(pdf_highlight_node);
3383 ComPtr<IRawElementProviderSimple> inline_text_node_raw4 =
3384 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_node4);
3392 ComPtr<ITextProvider> text_provider;
3393 EXPECT_HRESULT_SUCCEEDED(inline_text_node_raw1->GetPatternProvider(
3394 UIA_TextPatternId, &text_provider));
3396 ComPtr<ITextRangeProvider> text_range_provider;
3397 EXPECT_HRESULT_SUCCEEDED(
3398 text_provider->get_DocumentRange(&text_range_provider));
3399 SetOwner(owner, text_range_provider.Get());
3401 ComPtr<IRawElementProviderSimple> enclosing_element;
3402 EXPECT_HRESULT_SUCCEEDED(
3403 text_range_provider->GetEnclosingElement(&enclosing_element));
3404 EXPECT_EQ(inline_text_node_raw1.Get(), enclosing_element.Get());
3406 EXPECT_HRESULT_SUCCEEDED(inline_text_node_raw2->GetPatternProvider(
3407 UIA_TextPatternId, &text_provider));
3409 EXPECT_HRESULT_SUCCEEDED(
3410 text_provider->get_DocumentRange(&text_range_provider));
3411 SetOwner(owner, text_range_provider.Get());
3413 EXPECT_HRESULT_SUCCEEDED(
3414 text_range_provider->GetEnclosingElement(&enclosing_element));
3415 EXPECT_EQ(link_node_raw.Get(), enclosing_element.Get());
3417 EXPECT_HRESULT_SUCCEEDED(inline_text_node_raw3->GetPatternProvider(
3418 UIA_TextPatternId, &text_provider));
3420 EXPECT_HRESULT_SUCCEEDED(
3421 text_provider->get_DocumentRange(&text_range_provider));
3422 SetOwner(owner, text_range_provider.Get());
3424 EXPECT_HRESULT_SUCCEEDED(
3425 text_range_provider->GetEnclosingElement(&enclosing_element));
3426 EXPECT_EQ(inline_text_node_raw3.Get(), enclosing_element.Get());
3430 EXPECT_HRESULT_SUCCEEDED(search_text_node_raw->GetPatternProvider(
3431 UIA_TextPatternId, &text_provider));
3433 EXPECT_HRESULT_SUCCEEDED(
3434 text_provider->get_DocumentRange(&text_range_provider));
3435 SetOwner(owner, text_range_provider.Get());
3437 EXPECT_HRESULT_SUCCEEDED(
3438 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
3440 EXPECT_HRESULT_SUCCEEDED(
3441 text_range_provider->GetEnclosingElement(&enclosing_element));
3442 EXPECT_EQ(search_box_node_raw.Get(), enclosing_element.Get());
3446 EXPECT_HRESULT_SUCCEEDED(inline_text_node_raw4->GetPatternProvider(
3447 UIA_TextPatternId, &text_provider));
3449 EXPECT_HRESULT_SUCCEEDED(
3450 text_provider->get_DocumentRange(&text_range_provider));
3451 SetOwner(owner, text_range_provider.Get());
3453 EXPECT_HRESULT_SUCCEEDED(
3454 text_range_provider->GetEnclosingElement(&enclosing_element));
3455 EXPECT_EQ(pdf_highlight_node_raw.Get(), enclosing_element.Get());
3459 TestITextRangeProviderGetEnclosingElementRichButton) {
3482 static_text_1.
id = 3;
3483 inline_text_1.
id = 4;
3486 static_text_2.
id = 7;
3487 inline_text_2.
id = 8;
3490 root.child_ids = {button_1.
id, button_2.
id};
3496 static_text_1.
child_ids.push_back(inline_text_1.
id);
3507 static_text_2.
child_ids.push_back(inline_text_2.
id);
3514 update.tree_data = tree_data;
3515 update.has_tree_data =
true;
3517 update.nodes = {
root, button_1, static_text_1, inline_text_1,
3518 button_2, heading, static_text_2, inline_text_2};
3529 AXPlatformNodeWin* owner =
3530 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(button_1_node));
3531 ASSERT_NE(owner,
nullptr);
3533 ComPtr<IRawElementProviderSimple> button_1_node_raw =
3534 QueryInterfaceFromNode<IRawElementProviderSimple>(button_1_node);
3535 ComPtr<IRawElementProviderSimple> inline_text_1_node_raw =
3536 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_1_node);
3538 ComPtr<IRawElementProviderSimple> button_2_node_raw =
3539 QueryInterfaceFromNode<IRawElementProviderSimple>(button_2_node);
3540 ComPtr<IRawElementProviderSimple> static_text_2_node_raw =
3541 QueryInterfaceFromNode<IRawElementProviderSimple>(static_text_2_node);
3542 ComPtr<IRawElementProviderSimple> inline_text_2_node_raw =
3543 QueryInterfaceFromNode<IRawElementProviderSimple>(inline_text_2_node);
3548 ComPtr<ITextProvider> text_provider;
3549 EXPECT_HRESULT_SUCCEEDED(inline_text_1_node_raw->GetPatternProvider(
3550 UIA_TextPatternId, &text_provider));
3552 ComPtr<ITextRangeProvider> text_range_provider;
3553 EXPECT_HRESULT_SUCCEEDED(
3554 text_provider->get_DocumentRange(&text_range_provider));
3555 SetOwner(owner, text_range_provider.Get());
3557 ComPtr<IRawElementProviderSimple> enclosing_element;
3558 EXPECT_HRESULT_SUCCEEDED(
3559 text_range_provider->GetEnclosingElement(&enclosing_element));
3560 EXPECT_EQ(button_1_node_raw.Get(), enclosing_element.Get());
3566 EXPECT_HRESULT_SUCCEEDED(inline_text_2_node_raw->GetPatternProvider(
3567 UIA_TextPatternId, &text_provider));
3569 EXPECT_HRESULT_SUCCEEDED(
3570 text_provider->get_DocumentRange(&text_range_provider));
3571 SetOwner(owner, text_range_provider.Get());
3573 EXPECT_HRESULT_SUCCEEDED(
3574 text_range_provider->GetEnclosingElement(&enclosing_element));
3575 EXPECT_EQ(button_2_node_raw.Get(), enclosing_element.Get());
3579 TestITextRangeProviderMoveEndpointByRange) {
3580 Init(BuildTextDocument({
"some text",
"more text"}));
3582 AXNode* root_node = GetRootAsAXNode();
3585 AXPlatformNodeWin* owner =
3586 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(root_node));
3587 ASSERT_NE(owner,
nullptr);
3590 ComPtr<IRawElementProviderSimple> root_node_raw =
3591 QueryInterfaceFromNode<IRawElementProviderSimple>(root_node);
3592 ComPtr<ITextProvider> document_provider;
3593 EXPECT_HRESULT_SUCCEEDED(
3594 root_node_raw->GetPatternProvider(UIA_TextPatternId, &document_provider));
3595 ComPtr<ITextRangeProvider> document_text_range_provider;
3596 ComPtr<AXPlatformNodeTextRangeProviderWin> document_text_range;
3599 ComPtr<IRawElementProviderSimple> text_node_raw =
3600 QueryInterfaceFromNode<IRawElementProviderSimple>(text_node);
3601 ComPtr<ITextProvider> text_provider;
3602 EXPECT_HRESULT_SUCCEEDED(
3603 text_node_raw->GetPatternProvider(UIA_TextPatternId, &text_provider));
3604 ComPtr<ITextRangeProvider> text_range_provider;
3605 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range;
3608 ComPtr<IRawElementProviderSimple> more_text_node_raw =
3609 QueryInterfaceFromNode<IRawElementProviderSimple>(more_text_node);
3610 ComPtr<ITextProvider> more_text_provider;
3611 EXPECT_HRESULT_SUCCEEDED(more_text_node_raw->GetPatternProvider(
3612 UIA_TextPatternId, &more_text_provider));
3613 ComPtr<ITextRangeProvider> more_text_range_provider;
3614 ComPtr<AXPlatformNodeTextRangeProviderWin> more_text_range;
3631 EXPECT_HRESULT_SUCCEEDED(
3632 document_provider->get_DocumentRange(&document_text_range_provider));
3633 SetOwner(owner, document_text_range_provider.Get());
3635 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->MoveEndpointByRange(
3636 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
3637 TextPatternRangeEndpoint_End));
3639 document_text_range_provider->QueryInterface(
3640 IID_PPV_ARGS(&document_text_range));
3641 EXPECT_EQ(*GetStart(document_text_range.Get()),
3642 *GetEnd(document_text_range.Get()));
3659 EXPECT_HRESULT_SUCCEEDED(
3660 document_provider->get_DocumentRange(&document_text_range_provider));
3661 SetOwner(owner, document_text_range_provider.Get());
3663 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->MoveEndpointByRange(
3664 TextPatternRangeEndpoint_Start, document_text_range_provider.Get(),
3665 TextPatternRangeEndpoint_End));
3667 document_text_range_provider->QueryInterface(
3668 IID_PPV_ARGS(&document_text_range));
3669 EXPECT_EQ(*GetStart(document_text_range.Get()),
3670 *GetEnd(document_text_range.Get()));
3686 EXPECT_HRESULT_SUCCEEDED(
3687 document_provider->get_DocumentRange(&document_text_range_provider));
3688 SetOwner(owner, document_text_range_provider.Get());
3690 EXPECT_HRESULT_SUCCEEDED(
3691 more_text_provider->get_DocumentRange(&more_text_range_provider));
3692 SetOwner(owner, more_text_range_provider.Get());
3694 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->MoveEndpointByRange(
3695 TextPatternRangeEndpoint_Start, more_text_range_provider.Get(),
3696 TextPatternRangeEndpoint_Start));
3698 document_text_range_provider->QueryInterface(
3699 IID_PPV_ARGS(&document_text_range));
3700 more_text_range_provider->QueryInterface(IID_PPV_ARGS(&more_text_range));
3701 EXPECT_EQ(*GetStart(document_text_range.Get()),
3702 *GetStart(more_text_range.Get()));
3718 EXPECT_HRESULT_SUCCEEDED(
3719 document_provider->get_DocumentRange(&document_text_range_provider));
3720 SetOwner(owner, document_text_range_provider.Get());
3722 EXPECT_HRESULT_SUCCEEDED(
3723 text_provider->get_DocumentRange(&text_range_provider));
3724 SetOwner(owner, text_range_provider.Get());
3726 EXPECT_HRESULT_SUCCEEDED(document_text_range_provider->MoveEndpointByRange(
3727 TextPatternRangeEndpoint_End, text_range_provider.Get(),
3728 TextPatternRangeEndpoint_End));
3730 document_text_range_provider->QueryInterface(
3731 IID_PPV_ARGS(&document_text_range));
3732 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range));
3733 EXPECT_EQ(*GetEnd(document_text_range.Get()), *GetEnd(text_range.Get()));
3749 EXPECT_HRESULT_SUCCEEDED(
3750 text_provider->get_DocumentRange(&text_range_provider));
3751 SetOwner(owner, document_text_range_provider.Get());
3753 EXPECT_HRESULT_SUCCEEDED(
3754 more_text_provider->get_DocumentRange(&more_text_range_provider));
3755 SetOwner(owner, more_text_range_provider.Get());
3757 EXPECT_HRESULT_SUCCEEDED(more_text_range_provider->MoveEndpointByRange(
3758 TextPatternRangeEndpoint_End, text_range_provider.Get(),
3759 TextPatternRangeEndpoint_Start));
3761 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range));
3762 more_text_range_provider->QueryInterface(IID_PPV_ARGS(&more_text_range));
3763 EXPECT_EQ(*GetEnd(more_text_range.Get()), *GetStart(text_range.Get()));
3764 EXPECT_EQ(*GetStart(more_text_range.Get()), *GetStart(text_range.Get()));
3780 EXPECT_HRESULT_SUCCEEDED(
3781 text_provider->get_DocumentRange(&text_range_provider));
3782 SetOwner(owner, text_range_provider.Get());
3784 EXPECT_HRESULT_SUCCEEDED(
3785 more_text_provider->get_DocumentRange(&more_text_range_provider));
3786 SetOwner(owner, more_text_range_provider.Get());
3788 EXPECT_HRESULT_SUCCEEDED(text_range_provider->MoveEndpointByRange(
3789 TextPatternRangeEndpoint_Start, more_text_range_provider.Get(),
3790 TextPatternRangeEndpoint_End));
3792 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range));
3793 more_text_range_provider->QueryInterface(IID_PPV_ARGS(&more_text_range));
3794 EXPECT_EQ(*GetStart(text_range.Get()), *GetEnd(more_text_range.Get()));
3795 EXPECT_EQ(*GetEnd(text_range.Get()), *GetEnd(more_text_range.Get()));
3800 DISABLED_TestITextRangeProviderGetAttributeValue) {
3827 text_data.
SetName(
"some text and some other text");
3830 heading_data.
id = 3;
3842 heading_text_data.
id = 4;
3860 heading_text_data.
SetName(
"more text");
3872 mark_text_data.
id = 6;
3879 mark_text_data.
SetName(
"marked text");
3890 list_item_data.
id = 8;
3901 list_item_text_data.
id = 9;
3907 list_item_text_data.
SetName(
"list item");
3910 list_item2_data.
id = 10;
3921 list_item2_text_data.
id = 11;
3927 list_item2_text_data.
SetName(
"list item 2");
3930 input_text_data.
id = 12;
3945 input_text_data.
SetName(
"placeholder");
3949 placeholder_text_data.
id = 13;
3955 placeholder_text_data.
SetName(
"placeholder");
3958 input_text_data2.
id = 14;
3972 input_text_data2.
SetName(
"foo");
3976 placeholder_text_data2.
id = 15;
3982 placeholder_text_data2.
SetName(
"placeholder2");
3992 link_text_data.
id = 17;
4002 root_data.
child_ids = {2, 3, 5, 7, 12, 14, 16};
4007 update.tree_data = tree_data;
4008 update.has_tree_data =
true;
4010 update.nodes.push_back(root_data);
4011 update.nodes.push_back(text_data);
4012 update.nodes.push_back(heading_data);
4013 update.nodes.push_back(heading_text_data);
4014 update.nodes.push_back(mark_data);
4015 update.nodes.push_back(mark_text_data);
4016 update.nodes.push_back(list_data);
4017 update.nodes.push_back(list_item_data);
4018 update.nodes.push_back(list_item_text_data);
4019 update.nodes.push_back(list_item2_data);
4020 update.nodes.push_back(list_item2_text_data);
4021 update.nodes.push_back(input_text_data);
4022 update.nodes.push_back(placeholder_text_data);
4023 update.nodes.push_back(input_text_data2);
4024 update.nodes.push_back(placeholder_text_data2);
4025 update.nodes.push_back(link_data);
4026 update.nodes.push_back(link_text_data);
4030 AXNode* root_node = GetRootAsAXNode();
4044 AXNode* placeholder_text_node2 = input_text_node2->
children()[0];
4048 ComPtr<ITextRangeProvider> document_range_provider;
4049 GetTextRangeProviderFromTextNode(document_range_provider, root_node);
4050 ComPtr<ITextRangeProvider> text_range_provider;
4051 GetTextRangeProviderFromTextNode(text_range_provider, text_node);
4052 ComPtr<ITextRangeProvider> heading_text_range_provider;
4053 GetTextRangeProviderFromTextNode(heading_text_range_provider,
4055 ComPtr<ITextRangeProvider> mark_text_range_provider;
4056 GetTextRangeProviderFromTextNode(mark_text_range_provider, mark_text_node);
4057 ComPtr<ITextRangeProvider> list_item_text_range_provider;
4058 GetTextRangeProviderFromTextNode(list_item_text_range_provider,
4059 list_item_text_node);
4060 ComPtr<ITextRangeProvider> list_item2_text_range_provider;
4061 GetTextRangeProviderFromTextNode(list_item2_text_range_provider,
4062 list_item2_text_node);
4064 ComPtr<ITextRangeProvider> placeholder_text_range_provider;
4065 GetTextRangeProviderFromTextNode(placeholder_text_range_provider,
4066 placeholder_text_node);
4068 ComPtr<ITextRangeProvider> placeholder_text_range_provider2;
4069 GetTextRangeProviderFromTextNode(placeholder_text_range_provider2,
4070 placeholder_text_node2);
4072 ComPtr<ITextRangeProvider> link_text_range_provider;
4073 GetTextRangeProviderFromTextNode(link_text_range_provider, link_text_node);
4078 expected_variant.
Set(
static_cast<int32_t
>(0x00EFBEADU));
4080 UIA_BackgroundColorAttributeId, expected_variant);
4084 UIA_BackgroundColorAttributeId, expected_variant);
4085 expected_variant.
Reset();
4087 expected_variant.
Set(
static_cast<int32_t
>(BulletStyle::BulletStyle_None));
4089 UIA_BulletStyleAttributeId, expected_variant);
4090 expected_variant.
Reset();
4092 expected_variant.
Set(
4093 static_cast<int32_t
>(BulletStyle::BulletStyle_FilledRoundBullet));
4095 UIA_BulletStyleAttributeId, expected_variant);
4096 expected_variant.
Reset();
4100 EXPECT_HRESULT_SUCCEEDED(text_range_provider->GetAttributeValue(
4101 UIA_CultureAttributeId, lang_variant.
Receive()));
4103 EXPECT_EQ(lang_variant.
type(), VT_I4);
4104 const LCID lcid = V_I4(lang_variant.
ptr());
4105 EXPECT_EQ(LANG_FRENCH, PRIMARYLANGID(lcid));
4106 EXPECT_EQ(SUBLANG_FRENCH_CANADIAN, SUBLANGID(lcid));
4107 EXPECT_EQ(SORT_DEFAULT, SORTIDFROMLCID(lcid));
4110 std::wstring font_name =
L"sans";
4111 expected_variant.
Set(SysAllocString(font_name.c_str()));
4114 expected_variant.
Reset();
4116 expected_variant.
Set(12.0);
4119 expected_variant.
Reset();
4121 expected_variant.
Set(300);
4124 expected_variant.
Reset();
4127 expected_variant.
Set(
static_cast<int32_t
>(0x00DEC0ADU));
4129 UIA_ForegroundColorAttributeId, expected_variant);
4131 UIA_ForegroundColorAttributeId, expected_variant);
4132 expected_variant.
Reset();
4134 expected_variant.
Set(
false);
4137 expected_variant.
Reset();
4140 UIA_IsHiddenAttributeId);
4142 expected_variant.
Set(
true);
4145 expected_variant.
Reset();
4147 expected_variant.
Set(
false);
4149 UIA_IsItalicAttributeId, expected_variant);
4150 expected_variant.
Reset();
4152 expected_variant.
Set(
true);
4155 expected_variant.
Reset();
4157 expected_variant.
Set(
false);
4159 UIA_IsReadOnlyAttributeId, expected_variant);
4160 expected_variant.
Reset();
4162 expected_variant.
Set(
false);
4164 UIA_IsReadOnlyAttributeId, expected_variant);
4165 expected_variant.
Reset();
4167 expected_variant.
Set(
true);
4169 UIA_IsReadOnlyAttributeId, expected_variant);
4170 expected_variant.
Reset();
4172 expected_variant.
Set(
true);
4174 UIA_IsReadOnlyAttributeId, expected_variant);
4175 expected_variant.
Reset();
4177 expected_variant.
Set(HorizontalTextAlignment_Centered);
4179 UIA_HorizontalTextAlignmentAttributeId,
4181 expected_variant.
Reset();
4183 expected_variant.
Set(HorizontalTextAlignment_Justified);
4185 UIA_HorizontalTextAlignmentAttributeId,
4187 expected_variant.
Reset();
4189 expected_variant.
Set(
true);
4192 expected_variant.
Reset();
4194 expected_variant.
Set(
false);
4196 UIA_IsSubscriptAttributeId, expected_variant);
4197 expected_variant.
Reset();
4199 expected_variant.
Set(
false);
4202 expected_variant.
Reset();
4204 expected_variant.
Set(
true);
4206 UIA_IsSuperscriptAttributeId, expected_variant);
4207 expected_variant.
Reset();
4209 expected_variant.
Set(TextDecorationLineStyle::TextDecorationLineStyle_Dot);
4212 expected_variant.
Reset();
4214 expected_variant.
Set(TextDecorationLineStyle::TextDecorationLineStyle_Dash);
4216 text_range_provider, UIA_StrikethroughStyleAttributeId, expected_variant);
4217 expected_variant.
Reset();
4219 expected_variant.
Set(TextDecorationLineStyle::TextDecorationLineStyle_Single);
4221 UIA_UnderlineStyleAttributeId, expected_variant);
4222 expected_variant.
Reset();
4224 std::wstring style_name;
4225 expected_variant.
Set(SysAllocString(style_name.c_str()));
4228 expected_variant.
Reset();
4230 expected_variant.
Set(
static_cast<int32_t
>(StyleId_Heading6));
4232 UIA_StyleIdAttributeId, expected_variant);
4233 expected_variant.
Reset();
4235 style_name =
L"mark";
4236 expected_variant.
Set(SysAllocString(style_name.c_str()));
4238 UIA_StyleNameAttributeId, expected_variant);
4239 expected_variant.
Reset();
4241 expected_variant.
Set(
static_cast<int32_t
>(StyleId_NumberedList));
4243 UIA_StyleIdAttributeId, expected_variant);
4244 expected_variant.
Reset();
4246 expected_variant.
Set(
static_cast<int32_t
>(StyleId_BulletedList));
4248 UIA_StyleIdAttributeId, expected_variant);
4249 expected_variant.
Reset();
4251 expected_variant.
Set(
4252 static_cast<int32_t
>(FlowDirections::FlowDirections_RightToLeft));
4254 text_range_provider, UIA_TextFlowDirectionsAttributeId, expected_variant);
4256 UIA_TextFlowDirectionsAttributeId);
4257 expected_variant.
Reset();
4263 TextPatternRangeEndpoint_Start,
4269 TextPatternRangeEndpoint_Start,
4274 expected_variant.
Set(
false);
4276 UIA_IsSuperscriptAttributeId, expected_variant);
4277 expected_variant.
Reset();
4282 TextPatternRangeEndpoint_End,
4288 TextPatternRangeEndpoint_End,
4293 expected_variant.
Set(
4294 static_cast<int32_t
>(FlowDirections::FlowDirections_RightToLeft));
4296 UIA_TextFlowDirectionsAttributeId,
4298 expected_variant.
Reset();
4306 UIA_AnnotationTypesAttributeId);
4313 AXPlatformNodeWin* owner =
4314 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(text_node));
4315 ComPtr<AXPlatformNodeTextRangeProviderWin> range_with_annotations;
4316 CreateTextRangeProviderWin(
4317 range_with_annotations, owner,
4324 EXPECT_HRESULT_SUCCEEDED(range_with_annotations->GetAttributeValue(
4325 UIA_AnnotationTypesAttributeId, annotation_types_variant.
Receive()));
4327 EXPECT_EQ(annotation_types_variant.
type(), VT_ARRAY | VT_I4);
4328 std::vector<int> expected_annotations = {AnnotationType_SpellingError,
4329 AnnotationType_GrammarError};
4331 expected_annotations);
4340 AXPlatformNodeWin* owner =
4341 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(text_node));
4342 ComPtr<AXPlatformNodeTextRangeProviderWin> range_with_annotations;
4343 CreateTextRangeProviderWin(
4344 range_with_annotations, owner,
4351 EXPECT_HRESULT_SUCCEEDED(range_with_annotations->GetAttributeValue(
4352 UIA_AnnotationTypesAttributeId, annotation_types_variant.
Receive()));
4354 EXPECT_EQ(annotation_types_variant.
type(), VT_ARRAY | VT_I4);
4355 std::vector<int> expected_annotations = {AnnotationType_GrammarError,
4356 AnnotationType_Highlighted};
4358 expected_annotations);
4367 AXPlatformNodeWin* owner =
4368 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(text_node));
4369 ComPtr<AXPlatformNodeTextRangeProviderWin> range_with_annotations;
4370 CreateTextRangeProviderWin(
4371 range_with_annotations, owner,
4378 EXPECT_HRESULT_SUCCEEDED(range_with_annotations->GetAttributeValue(
4379 UIA_AnnotationTypesAttributeId, annotation_types_variant.
Receive()));
4381 EXPECT_EQ(annotation_types_variant.
type(), VT_ARRAY | VT_I4);
4382 std::vector<int> expected_annotations = {AnnotationType_SpellingError};
4384 expected_annotations);
4393 AXPlatformNodeWin* owner =
4394 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(text_node));
4395 ComPtr<AXPlatformNodeTextRangeProviderWin> range_with_annotations;
4396 CreateTextRangeProviderWin(
4397 range_with_annotations, owner,
4404 EXPECT_HRESULT_SUCCEEDED(range_with_annotations->GetAttributeValue(
4405 UIA_AnnotationTypesAttributeId, annotation_types_variant.
Receive()));
4407 EXPECT_EQ(annotation_types_variant.
type(), VT_ARRAY | VT_I4);
4408 std::vector<int> expected_annotations = {AnnotationType_GrammarError};
4410 expected_annotations);
4417 UIA_AnnotationTypesAttributeId);
4423 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
4424 AXPlatformNodeFromNode(heading_text_node));
4425 ComPtr<AXPlatformNodeTextRangeProviderWin> range_with_annotations;
4426 CreateTextRangeProviderWin(
4427 range_with_annotations, owner,
4428 heading_text_node, 5,
4430 heading_text_node, 9,
4434 EXPECT_HRESULT_SUCCEEDED(range_with_annotations->GetAttributeValue(
4435 UIA_AnnotationTypesAttributeId, annotation_types_variant.
Receive()));
4437 std::vector<int> expected_annotations = {AnnotationType_SpellingError};
4439 expected_annotations);
4445 UIA_AnnotationTypesAttributeId, empty_variant);
4450 DISABLED_TestITextRangeProviderGetAttributeValueAnnotationObjects) {
4472 annotation_target.
id = 2;
4475 comment1_text.
id = 5;
4477 comment2_text.
id = 7;
4479 highlighted_text.
id = 9;
4482 root.SetName(
"root");
4483 root.child_ids = {annotation_target.
id, comment1.
id, comment2.
id,
4490 {comment1.
id, comment2.
id, highlighted.
id});
4493 some_text.
SetName(
"some text");
4496 comment1.
SetName(
"comment 1");
4500 comment1_text.
SetName(
"comment 1");
4503 comment2.
SetName(
"comment 2");
4507 comment2_text.
SetName(
"comment 2");
4510 highlighted.
SetName(
"highlighted");
4514 highlighted_text.
SetName(
"highlighted");
4517 update.has_tree_data =
true;
4519 update.nodes = {
root, annotation_target, some_text,
4520 comment1, comment1_text, comment2,
4521 comment2_text, highlighted, highlighted_text};
4526 AXNode* root_node = GetRootAsAXNode();
4532 ComPtr<AXPlatformNodeTextRangeProviderWin> some_text_range_provider;
4538 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
4539 AXPlatformNodeFromNode(annotation_target_node));
4540 CreateTextRangeProviderWin(
4541 some_text_range_provider, owner,
4542 annotation_target_node, 0,
4544 annotation_target_node, 9,
4546 ASSERT_NE(
nullptr, some_text_range_provider.Get());
4549 ComPtr<IRawElementProviderSimple> comment1_provider =
4550 QueryInterfaceFromNode<IRawElementProviderSimple>(comment1_node);
4551 ASSERT_NE(
nullptr, comment1_provider.Get());
4552 ComPtr<IRawElementProviderSimple> comment2_provider =
4553 QueryInterfaceFromNode<IRawElementProviderSimple>(comment2_node);
4554 ASSERT_NE(
nullptr, comment2_provider.Get());
4555 ComPtr<IRawElementProviderSimple> highlighted_provider =
4556 QueryInterfaceFromNode<IRawElementProviderSimple>(highlighted_node);
4557 ASSERT_NE(
nullptr, highlighted_provider.Get());
4559 ComPtr<IAnnotationProvider> annotation_provider;
4560 int annotation_type;
4563 EXPECT_HRESULT_SUCCEEDED(comment1_provider->GetPatternProvider(
4564 UIA_AnnotationPatternId, &annotation_provider));
4565 ASSERT_NE(
nullptr, annotation_provider.Get());
4566 EXPECT_HRESULT_SUCCEEDED(
4567 annotation_provider->get_AnnotationTypeId(&annotation_type));
4568 EXPECT_EQ(AnnotationType_Comment, annotation_type);
4569 annotation_provider.Reset();
4572 EXPECT_HRESULT_SUCCEEDED(comment2_provider->GetPatternProvider(
4573 UIA_AnnotationPatternId, &annotation_provider));
4574 ASSERT_NE(
nullptr, annotation_provider.Get());
4575 EXPECT_HRESULT_SUCCEEDED(
4576 annotation_provider->get_AnnotationTypeId(&annotation_type));
4577 EXPECT_EQ(AnnotationType_Comment, annotation_type);
4578 annotation_provider.Reset();
4582 EXPECT_HRESULT_SUCCEEDED(highlighted_provider->GetPatternProvider(
4583 UIA_AnnotationPatternId, &annotation_provider));
4584 ASSERT_NE(
nullptr, annotation_provider.Get());
4585 EXPECT_HRESULT_SUCCEEDED(
4586 annotation_provider->get_AnnotationTypeId(&annotation_type));
4587 EXPECT_EQ(AnnotationType_Highlighted, annotation_type);
4588 annotation_provider.Reset();
4591 EXPECT_HRESULT_SUCCEEDED(some_text_range_provider->GetAttributeValue(
4592 UIA_AnnotationObjectsAttributeId, annotation_objects_variant.
Receive()));
4593 EXPECT_EQ(VT_UNKNOWN | VT_ARRAY, annotation_objects_variant.
type());
4595 std::vector<std::wstring> expected_names = {
L"comment 1",
L"comment 2",
4598 UIA_NamePropertyId, expected_names);
4602 DISABLED_TestITextRangeProviderGetAttributeValueAnnotationObjectsMixed) {
4620 readonly_text.
id = 4;
4622 comment1_text.
id = 6;
4625 root.SetName(
"root");
4626 root.child_ids = {highlighted.
id, readonly_text.
id, comment1.
id};
4634 some_text.
SetName(
"some text");
4638 readonly_text.
SetName(
"read only");
4641 comment1.
SetName(
"comment 1");
4645 comment1_text.
SetName(
"comment 1");
4648 update.has_tree_data =
true;
4650 update.nodes = {
root, highlighted, some_text,
4651 readonly_text, comment1, comment1_text};
4656 AXNode* root_node = GetRootAsAXNode();
4666 ComPtr<AXPlatformNodeTextRangeProviderWin> some_text_range_provider;
4667 AXPlatformNodeWin* owner =
4668 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(highlighted_node));
4669 CreateTextRangeProviderWin(
4670 some_text_range_provider, owner,
4671 highlighted_node, 0,
4673 highlighted_node, 9,
4675 ASSERT_NE(
nullptr, some_text_range_provider.Get());
4678 ComPtr<ITextRangeProvider> readonly_text_range_provider;
4679 GetTextRangeProviderFromTextNode(readonly_text_range_provider,
4680 readonly_text_node);
4681 ASSERT_NE(
nullptr, readonly_text_range_provider.Get());
4683 ComPtr<IRawElementProviderSimple> comment1_provider =
4684 QueryInterfaceFromNode<IRawElementProviderSimple>(comment1_node);
4685 ASSERT_NE(
nullptr, comment1_provider.Get());
4687 ComPtr<IAnnotationProvider> annotation_provider;
4688 int annotation_type;
4692 EXPECT_HRESULT_SUCCEEDED(comment1_provider->GetPatternProvider(
4693 UIA_AnnotationPatternId, &annotation_provider));
4694 ASSERT_NE(
nullptr, annotation_provider.Get());
4695 EXPECT_HRESULT_SUCCEEDED(
4696 annotation_provider->get_AnnotationTypeId(&annotation_type));
4697 EXPECT_EQ(AnnotationType_Comment, annotation_type);
4698 annotation_provider.Reset();
4701 EXPECT_HRESULT_SUCCEEDED(some_text_range_provider->GetAttributeValue(
4702 UIA_AnnotationObjectsAttributeId, expected_variant.
Receive()));
4703 EXPECT_EQ(VT_UNKNOWN | VT_ARRAY, expected_variant.
type());
4705 std::vector<std::wstring> expected_names = {
L"comment 1"};
4707 UIA_NamePropertyId, expected_names);
4708 expected_variant.
Reset();
4713 expected_variant.
Set(
true);
4715 UIA_IsReadOnlyAttributeId, expected_variant);
4720 ComPtr<AXPlatformNodeTextRangeProviderWin> mixed_text_range_provider;
4721 CreateTextRangeProviderWin(
4722 mixed_text_range_provider, owner,
4725 readonly_text_node, 9,
4730 UIA_AnnotationObjectsAttributeId);
4734 TestITextRangeProviderGetAttributeValueNotSupported) {
4740 text_data_first.
id = 2;
4742 text_data_first.
SetName(
"first");
4743 root_data.
child_ids.push_back(text_data_first.
id);
4746 text_data_second.
id = 3;
4748 text_data_second.
SetName(
"second");
4749 root_data.
child_ids.push_back(text_data_second.
id);
4754 update.tree_data = tree_data;
4755 update.has_tree_data =
true;
4757 update.nodes.push_back(root_data);
4758 update.nodes.push_back(text_data_first);
4759 update.nodes.push_back(text_data_second);
4763 ComPtr<ITextRangeProvider> document_range_provider;
4764 GetTextRangeProviderFromTextNode(document_range_provider, GetRootAsAXNode());
4767 UIA_AfterParagraphSpacingAttributeId);
4769 UIA_AnimationStyleAttributeId);
4771 UIA_BeforeParagraphSpacingAttributeId);
4773 UIA_CapStyleAttributeId);
4775 UIA_CaretBidiModeAttributeId);
4777 UIA_CaretPositionAttributeId);
4779 UIA_IndentationFirstLineAttributeId);
4781 UIA_IndentationLeadingAttributeId);
4783 UIA_IndentationTrailingAttributeId);
4785 UIA_IsActiveAttributeId);
4787 UIA_LineSpacingAttributeId);
4789 UIA_LinkAttributeId);
4791 UIA_MarginBottomAttributeId);
4793 UIA_MarginLeadingAttributeId);
4795 UIA_MarginTopAttributeId);
4797 UIA_MarginTrailingAttributeId);
4799 UIA_OutlineStylesAttributeId);
4801 UIA_OverlineColorAttributeId);
4803 UIA_SelectionActiveEndAttributeId);
4805 UIA_StrikethroughColorAttributeId);
4807 UIA_TabsAttributeId);
4809 UIA_UnderlineColorAttributeId);
4813 TestITextRangeProviderGetAttributeValueWithAncestorTextPosition) {
4819 initial_state.
nodes.resize(5);
4820 initial_state.
nodes[0].id = 1;
4821 initial_state.
nodes[0].child_ids = {2};
4823 initial_state.
nodes[1].id = 2;
4824 initial_state.
nodes[1].child_ids = {3};
4826 initial_state.
nodes[2].id = 3;
4827 initial_state.
nodes[2].child_ids = {4, 5};
4829 initial_state.
nodes[3].id = 4;
4831 initial_state.
nodes[3].SetName(
"some text");
4832 initial_state.
nodes[3].AddIntAttribute(
4834 initial_state.
nodes[4].id = 5;
4836 initial_state.
nodes[4].SetName(
"more text");
4837 initial_state.
nodes[4].AddIntAttribute(
4840 Init(initial_state);
4841 const AXTree* tree = GetTree();
4847 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
4848 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 2)));
4853 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider_win;
4854 CreateTextRangeProviderWin(
4855 text_range_provider_win, owner,
4861 ASSERT_TRUE(GetStart(text_range_provider_win.Get())->IsTextPosition());
4862 ASSERT_EQ(4, GetStart(text_range_provider_win.Get())->anchor_id());
4863 ASSERT_EQ(0, GetStart(text_range_provider_win.Get())->text_offset());
4864 ASSERT_TRUE(GetEnd(text_range_provider_win.Get())->IsTextPosition());
4865 ASSERT_EQ(5, GetEnd(text_range_provider_win.Get())->anchor_id());
4866 ASSERT_EQ(8, GetEnd(text_range_provider_win.Get())->text_offset());
4870 expected_variant.
Set(
static_cast<int32_t
>(0x00EFBEADU));
4872 UIA_BackgroundColorAttributeId, expected_variant);
4876 Init(BuildTextDocument({
"some text",
"more text2"}));
4877 AXNode* root_node = GetRootAsAXNode();
4880 ComPtr<IRawElementProviderSimple> root_node_raw =
4881 QueryInterfaceFromNode<IRawElementProviderSimple>(root_node);
4882 ComPtr<ITextProvider> document_provider;
4883 ComPtr<ITextRangeProvider> document_text_range_provider;
4884 ComPtr<AXPlatformNodeTextRangeProviderWin> document_text_range;
4885 EXPECT_HRESULT_SUCCEEDED(
4886 root_node_raw->GetPatternProvider(UIA_TextPatternId, &document_provider));
4887 EXPECT_HRESULT_SUCCEEDED(
4888 document_provider->get_DocumentRange(&document_text_range_provider));
4889 document_text_range_provider->QueryInterface(
4890 IID_PPV_ARGS(&document_text_range));
4891 AXPlatformNodeWin* owner_platform =
4892 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(root_node));
4893 ASSERT_NE(owner_platform,
nullptr);
4894 SetOwner(owner_platform, document_text_range_provider.Get());
4897 ComPtr<ITextRangeProvider> text_range_provider;
4898 GetTextRangeProviderFromTextNode(text_range_provider,
4900 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range;
4901 EXPECT_HRESULT_SUCCEEDED(
4902 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range)));
4905 ComPtr<ITextRangeProvider> more_text_range_provider;
4906 GetTextRangeProviderFromTextNode(more_text_range_provider,
4908 SetOwner(owner_platform, more_text_range_provider.Get());
4909 ComPtr<AXPlatformNodeTextRangeProviderWin> more_text_range;
4910 more_text_range_provider->QueryInterface(IID_PPV_ARGS(&more_text_range));
4913 GetOwner(document_text_range.Get())->GetDelegate();
4915 ComPtr<ITextRangeProvider> selected_text_range_provider;
4923 text_range_provider->Select();
4933 document_provider->GetSelection(selection.
Receive());
4934 ASSERT_NE(
nullptr, selection.
Get());
4936 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetUBound(selection.
Get(), 1, &ubound));
4937 EXPECT_EQ(0, ubound);
4938 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetLBound(selection.
Get(), 1, &lbound));
4939 EXPECT_EQ(0, lbound);
4940 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetElement(
4941 selection.
Get(), &index,
4942 static_cast<void**
>(&selected_text_range_provider)));
4943 SetOwner(owner_platform, selected_text_range_provider.Get());
4946 selected_text_range_provider.Reset();
4952 more_text_range_provider->Select();
4962 document_provider->GetSelection(selection.
Receive());
4963 ASSERT_NE(
nullptr, selection.
Get());
4965 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetUBound(selection.
Get(), 1, &ubound));
4966 EXPECT_EQ(0, ubound);
4967 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetLBound(selection.
Get(), 1, &lbound));
4968 EXPECT_EQ(0, lbound);
4969 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetElement(
4970 selection.
Get(), &index,
4971 static_cast<void**
>(&selected_text_range_provider)));
4972 SetOwner(owner_platform, selected_text_range_provider.Get());
4975 selected_text_range_provider.Reset();
4981 document_text_range_provider->Select();
4991 document_provider->GetSelection(selection.
Receive());
4992 ASSERT_NE(
nullptr, selection.
Get());
4994 document_provider->GetSelection(selection.
Receive());
4995 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetUBound(selection.
Get(), 1, &ubound));
4996 EXPECT_EQ(0, ubound);
4997 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetLBound(selection.
Get(), 1, &lbound));
4998 EXPECT_EQ(0, lbound);
4999 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetElement(
5000 selection.
Get(), &index,
5001 static_cast<void**
>(&selected_text_range_provider)));
5002 SetOwner(owner_platform, selected_text_range_provider.Get());
5004 L"some textmore text2");
5010 text_range_provider->MoveEndpointByRange(TextPatternRangeEndpoint_Start,
5011 text_range_provider.Get(),
5012 TextPatternRangeEndpoint_End);
5013 text_range_provider->Select();
5023 document_provider->GetSelection(selection.
Receive());
5024 ASSERT_NE(
nullptr, selection.
Get());
5026 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetUBound(selection.
Get(), 1, &ubound));
5027 EXPECT_EQ(0, ubound);
5028 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetLBound(selection.
Get(), 1, &lbound));
5029 EXPECT_EQ(0, lbound);
5030 EXPECT_HRESULT_SUCCEEDED(SafeArrayGetElement(
5031 selection.
Get(), &index,
5032 static_cast<void**
>(&selected_text_range_provider)));
5033 SetOwner(owner_platform, selected_text_range_provider.Get());
5036 selected_text_range_provider.Reset();
5043 TestITextRangeProviderSelectListMarker) {
5054 list_item_data.
id = 3;
5061 list_item_data.
child_ids.push_back(list_marker.
id);
5064 static_text_data.
id = 5;
5066 static_text_data.
SetName(
"1. ");
5067 list_marker.
child_ids.push_back(static_text_data.
id);
5070 list_item_text_data.
id = 6;
5072 list_item_text_data.
SetName(
"First Item");
5073 list_item_data.
child_ids.push_back(list_item_text_data.
id);
5078 update.tree_data = tree_data;
5079 update.has_tree_data =
true;
5081 update.nodes = {root_data, list_data, list_item_data,
5082 list_marker, static_text_data, list_item_text_data};
5084 AXNode* root_node = GetRootAsAXNode();
5090 ComPtr<ITextRangeProvider> list_marker_text_range_provider;
5091 GetTextRangeProviderFromTextNode(list_marker_text_range_provider,
5095 EXPECT_HRESULT_SUCCEEDED(list_marker_text_range_provider->Select());
5099 ComPtr<IRawElementProviderSimple> root_node_raw =
5100 QueryInterfaceFromNode<IRawElementProviderSimple>(root_node);
5101 ComPtr<ITextProvider> document_provider;
5102 EXPECT_HRESULT_SUCCEEDED(
5103 root_node_raw->GetPatternProvider(UIA_TextPatternId, &document_provider));
5104 EXPECT_HRESULT_SUCCEEDED(
5105 document_provider->GetSelection(selection.
Receive()));
5106 ASSERT_EQ(
nullptr, selection.
Get());
5115 exec_path.remove_filename();
5116 exec_path.append(
"icudtl.dat");
5117 const std::string icudtl_path = exec_path.string();
5118 if (std::filesystem::exists(icudtl_path)) {
5123 Init(BuildTextDocument({
"some text",
"more text",
"resum\xC3\xA9"},
5127 AXNode* root_node = GetRootAsAXNode();
5128 AXPlatformNodeWin* owner =
5129 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(root_node));
5130 ASSERT_NE(owner,
nullptr);
5131 ComPtr<ITextRangeProvider> range;
5134 GetTextRangeProviderFromTextNode(range, root_node->
children()[0]);
5137 GetTextRangeProviderFromTextNode(range, root_node->
children()[1]);
5142 GetTextRangeProviderFromTextNode(range, root_node);
5161 GetTextRangeProviderFromTextNode(range, root_node->
children()[1]);
5163 Microsoft::WRL::ComPtr<ITextRangeProvider> text_range_provider_found;
5164 EXPECT_HRESULT_SUCCEEDED(range->FindText(
find_string.Get(),
false,
false,
5165 &text_range_provider_found));
5166 Microsoft::WRL::ComPtr<AXPlatformNodeTextRangeProviderWin>
5167 text_range_provider_win;
5168 text_range_provider_found->QueryInterface(
5169 IID_PPV_ARGS(&text_range_provider_win));
5170 ASSERT_TRUE(GetStart(text_range_provider_win.Get())->IsTextPosition());
5171 EXPECT_EQ(5, GetStart(text_range_provider_win.Get())->anchor_id());
5172 EXPECT_EQ(0, GetStart(text_range_provider_win.Get())->text_offset());
5173 ASSERT_TRUE(GetEnd(text_range_provider_win.Get())->IsTextPosition());
5174 EXPECT_EQ(5, GetEnd(text_range_provider_win.Get())->anchor_id());
5175 EXPECT_EQ(9, GetEnd(text_range_provider_win.Get())->text_offset());
5179 FindTextWithEmbeddedObjectCharacter) {
5200 static_text_4.
id = 4;
5201 inline_box_5.
id = 5;
5203 static_text_7.
id = 7;
5204 inline_box_8.
id = 8;
5235 update.tree_data = tree_data;
5236 update.has_tree_data =
true;
5238 update.nodes = {root_1, list_2, list_item_3, static_text_4,
5239 inline_box_5, list_item_6, static_text_7, inline_box_8};
5243 AXNode* root_node = GetRootAsAXNode();
5244 ComPtr<ITextRangeProvider> text_range_provider;
5245 GetTextRangeProviderFromTextNode(text_range_provider, root_node);
5248 Microsoft::WRL::ComPtr<ITextRangeProvider> text_range_provider_found;
5249 EXPECT_HRESULT_SUCCEEDED(text_range_provider->FindText(
5250 find_string.Get(),
false,
false, &text_range_provider_found));
5251 ASSERT_TRUE(text_range_provider_found.Get());
5252 Microsoft::WRL::ComPtr<AXPlatformNodeTextRangeProviderWin>
5253 text_range_provider_win;
5254 text_range_provider_found->QueryInterface(
5255 IID_PPV_ARGS(&text_range_provider_win));
5256 ASSERT_TRUE(GetStart(text_range_provider_win.Get())->IsTextPosition());
5257 EXPECT_EQ(5, GetStart(text_range_provider_win.Get())->anchor_id());
5258 EXPECT_EQ(1, GetStart(text_range_provider_win.Get())->text_offset());
5259 ASSERT_TRUE(GetEnd(text_range_provider_win.Get())->IsTextPosition());
5260 EXPECT_EQ(8, GetEnd(text_range_provider_win.Get())->anchor_id());
5261 EXPECT_EQ(3, GetEnd(text_range_provider_win.Get())->text_offset());
5265 TestITextRangeProviderFindTextBackwards) {
5266 Init(BuildTextDocument({
"text",
"some",
"text"},
5269 AXNode* root_node = GetRootAsAXNode();
5271 ComPtr<ITextRangeProvider> root_range_provider;
5272 GetTextRangeProviderFromTextNode(root_range_provider, root_node);
5273 ComPtr<ITextRangeProvider> text_node1_range;
5274 GetTextRangeProviderFromTextNode(text_node1_range, root_node->
children()[0]);
5275 ComPtr<ITextRangeProvider> text_node3_range;
5276 GetTextRangeProviderFromTextNode(text_node3_range, root_node->
children()[2]);
5278 ComPtr<ITextRangeProvider> text_range_provider_found;
5283 EXPECT_HRESULT_SUCCEEDED(root_range_provider->FindText(
5284 find_string.Get(),
false,
false, &text_range_provider_found));
5285 CopyOwnerToClone(root_range_provider.Get(), text_range_provider_found.Get());
5288 range_equal =
false;
5289 EXPECT_HRESULT_SUCCEEDED(
5290 text_range_provider_found->Compare(text_node1_range.Get(), &range_equal));
5294 EXPECT_HRESULT_SUCCEEDED(root_range_provider->FindText(
5295 find_string.Get(),
true,
false, &text_range_provider_found));
5296 CopyOwnerToClone(root_range_provider.Get(), text_range_provider_found.Get());
5299 range_equal =
false;
5300 EXPECT_HRESULT_SUCCEEDED(
5301 text_range_provider_found->Compare(text_node3_range.Get(), &range_equal));
5306 TestITextRangeProviderFindAttribute) {
5332 update.has_tree_data =
true;
5334 update.nodes = {root_data};
5338 bool is_search_backward;
5340 V_VT(&is_hidden_attr_val) = VT_BOOL;
5341 ComPtr<ITextRangeProvider> matched_range_provider;
5342 ComPtr<ITextRangeProvider> document_range_provider;
5343 GetTextRangeProviderFromTextNode(document_range_provider,
5348 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5349 is_search_backward =
false;
5350 document_range_provider->FindAttribute(
5351 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5352 &matched_range_provider);
5353 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5360 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5361 is_search_backward =
false;
5362 document_range_provider->FindAttribute(
5363 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5364 &matched_range_provider);
5365 ASSERT_NE(
nullptr, matched_range_provider.Get());
5366 CopyOwnerToClone(document_range_provider.Get(),
5367 matched_range_provider.Get());
5369 matched_range_provider.Reset();
5373 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5374 is_search_backward =
true;
5375 document_range_provider->FindAttribute(
5376 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5377 &matched_range_provider);
5378 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5385 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5386 is_search_backward =
true;
5387 document_range_provider->FindAttribute(
5388 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5389 &matched_range_provider);
5390 ASSERT_NE(
nullptr, matched_range_provider.Get());
5391 CopyOwnerToClone(document_range_provider.Get(),
5392 matched_range_provider.Get());
5421 update.has_tree_data =
true;
5423 update.nodes = {root_data, text_data1};
5427 bool is_search_backward;
5429 V_VT(&is_hidden_attr_val) = VT_BOOL;
5430 ComPtr<ITextRangeProvider> matched_range_provider;
5431 ComPtr<ITextRangeProvider> document_range_provider;
5432 GetTextRangeProviderFromTextNode(document_range_provider,
5437 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5438 is_search_backward =
false;
5439 document_range_provider->FindAttribute(
5440 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5441 &matched_range_provider);
5442 ASSERT_NE(
nullptr, matched_range_provider.Get());
5443 CopyOwnerToClone(document_range_provider.Get(),
5444 matched_range_provider.Get());
5446 matched_range_provider.Reset();
5450 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5451 is_search_backward =
false;
5452 document_range_provider->FindAttribute(
5453 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5454 &matched_range_provider);
5455 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5459 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5460 is_search_backward =
true;
5461 document_range_provider->FindAttribute(
5462 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5463 &matched_range_provider);
5464 ASSERT_NE(
nullptr, matched_range_provider.Get());
5465 CopyOwnerToClone(document_range_provider.Get(),
5466 matched_range_provider.Get());
5468 matched_range_provider.Reset();
5472 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5473 is_search_backward =
true;
5474 document_range_provider->FindAttribute(
5475 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5476 &matched_range_provider);
5477 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5510 update.has_tree_data =
true;
5512 update.nodes = {root_data, text_data1, text_data2};
5516 bool is_search_backward;
5518 V_VT(&is_hidden_attr_val) = VT_BOOL;
5519 ComPtr<ITextRangeProvider> matched_range_provider;
5520 ComPtr<ITextRangeProvider> document_range_provider;
5521 GetTextRangeProviderFromTextNode(document_range_provider,
5526 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5527 is_search_backward =
false;
5528 document_range_provider->FindAttribute(
5529 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5530 &matched_range_provider);
5531 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5535 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5536 is_search_backward =
false;
5537 document_range_provider->FindAttribute(
5538 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5539 &matched_range_provider);
5540 ASSERT_NE(
nullptr, matched_range_provider.Get());
5541 CopyOwnerToClone(document_range_provider.Get(),
5542 matched_range_provider.Get());
5544 matched_range_provider.Reset();
5548 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5549 is_search_backward =
true;
5550 document_range_provider->FindAttribute(
5551 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5552 &matched_range_provider);
5553 ASSERT_EQ(
nullptr, matched_range_provider.Get());
5557 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5558 is_search_backward =
true;
5559 document_range_provider->FindAttribute(
5560 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5561 &matched_range_provider);
5562 ASSERT_NE(
nullptr, matched_range_provider.Get());
5563 CopyOwnerToClone(document_range_provider.Get(),
5564 matched_range_provider.Get());
5619 update.has_tree_data =
true;
5621 update.nodes = {root_data, text_data1, text_data2,
5622 text_data3, text_data4, text_data5};
5626 bool is_search_backward;
5628 V_VT(&is_hidden_attr_val) = VT_BOOL;
5629 ComPtr<ITextRangeProvider> matched_range_provider;
5630 ComPtr<ITextRangeProvider> document_range_provider;
5631 GetTextRangeProviderFromTextNode(document_range_provider,
5636 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5637 is_search_backward =
false;
5638 document_range_provider->FindAttribute(
5639 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5640 &matched_range_provider);
5641 ASSERT_NE(
nullptr, matched_range_provider.Get());
5642 CopyOwnerToClone(document_range_provider.Get(),
5643 matched_range_provider.Get());
5645 matched_range_provider.Reset();
5649 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5650 is_search_backward =
false;
5651 document_range_provider->FindAttribute(
5652 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5653 &matched_range_provider);
5654 ASSERT_NE(
nullptr, matched_range_provider.Get());
5655 CopyOwnerToClone(document_range_provider.Get(),
5656 matched_range_provider.Get());
5658 matched_range_provider.Reset();
5662 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5663 is_search_backward =
true;
5664 document_range_provider->FindAttribute(
5665 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5666 &matched_range_provider);
5667 ASSERT_NE(
nullptr, matched_range_provider.Get());
5668 CopyOwnerToClone(document_range_provider.Get(),
5669 matched_range_provider.Get());
5671 matched_range_provider.Reset();
5675 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5676 is_search_backward =
true;
5677 document_range_provider->FindAttribute(
5678 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5679 &matched_range_provider);
5680 ASSERT_NE(
nullptr, matched_range_provider.Get());
5681 CopyOwnerToClone(document_range_provider.Get(),
5682 matched_range_provider.Get());
5737 update.has_tree_data =
true;
5739 update.nodes = {root_data, text_data1, text_data2,
5740 text_data3, text_data4, text_data5};
5744 bool is_search_backward;
5746 V_VT(&is_hidden_attr_val) = VT_BOOL;
5747 ComPtr<ITextRangeProvider> matched_range_provider;
5748 ComPtr<ITextRangeProvider> document_range_provider;
5749 GetTextRangeProviderFromTextNode(document_range_provider,
5754 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5755 is_search_backward =
false;
5756 document_range_provider->FindAttribute(
5757 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5758 &matched_range_provider);
5759 ASSERT_NE(
nullptr, matched_range_provider.Get());
5760 CopyOwnerToClone(document_range_provider.Get(),
5761 matched_range_provider.Get());
5763 matched_range_provider.Reset();
5767 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5768 is_search_backward =
false;
5769 document_range_provider->FindAttribute(
5770 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5771 &matched_range_provider);
5772 ASSERT_NE(
nullptr, matched_range_provider.Get());
5773 CopyOwnerToClone(document_range_provider.Get(),
5774 matched_range_provider.Get());
5776 matched_range_provider.Reset();
5780 V_BOOL(&is_hidden_attr_val) = VARIANT_TRUE;
5781 is_search_backward =
true;
5782 document_range_provider->FindAttribute(
5783 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5784 &matched_range_provider);
5785 ASSERT_NE(
nullptr, matched_range_provider.Get());
5786 CopyOwnerToClone(document_range_provider.Get(),
5787 matched_range_provider.Get());
5789 matched_range_provider.Reset();
5793 V_BOOL(&is_hidden_attr_val) = VARIANT_FALSE;
5794 is_search_backward =
true;
5795 document_range_provider->FindAttribute(
5796 UIA_IsHiddenAttributeId, is_hidden_attr_val, is_search_backward,
5797 &matched_range_provider);
5798 ASSERT_NE(
nullptr, matched_range_provider.Get());
5799 CopyOwnerToClone(document_range_provider.Get(),
5800 matched_range_provider.Get());
5807 root_ax_node_data.
id = 1;
5810 Init(root_ax_node_data);
5812 ComPtr<IRawElementProviderSimple> raw_element_provider_simple =
5813 QueryInterfaceFromNode<IRawElementProviderSimple>(GetRootAsAXNode());
5814 ASSERT_NE(
nullptr, raw_element_provider_simple.Get());
5816 ComPtr<ITextProvider> text_provider;
5817 ASSERT_HRESULT_SUCCEEDED(raw_element_provider_simple->GetPatternProvider(
5818 UIA_TextPatternId, &text_provider));
5819 ASSERT_NE(
nullptr, text_provider.Get());
5821 ComPtr<ITextRangeProvider> text_range_provider;
5822 ASSERT_HRESULT_SUCCEEDED(
5823 text_provider->get_DocumentRange(&text_range_provider));
5824 ASSERT_NE(
nullptr, text_range_provider.Get());
5827 SetTree(std::make_unique<AXTree>());
5830 ASSERT_EQ(
static_cast<HRESULT
>(UIA_E_ELEMENTNOTAVAILABLE),
5831 text_range_provider->ScrollIntoView(bool_arg));
5837 DISABLED_TestITextRangeProviderIgnoredNodes) {
5857 tree_update.
nodes.resize(14);
5858 tree_update.
nodes[0].id = 1;
5859 tree_update.
nodes[0].child_ids = {2};
5862 tree_update.
nodes[1].id = 2;
5863 tree_update.
nodes[1].child_ids = {3, 4, 5, 6, 7, 8};
5873 tree_update.
nodes[2].id = 3;
5875 tree_update.
nodes[2].SetName(
".3.");
5877 tree_update.
nodes[3].id = 4;
5879 tree_update.
nodes[3].SetName(
".4.");
5881 tree_update.
nodes[4].id = 5;
5883 tree_update.
nodes[4].SetName(
".5.");
5885 tree_update.
nodes[5].id = 6;
5887 tree_update.
nodes[5].child_ids = {9};
5889 tree_update.
nodes[6].id = 7;
5890 tree_update.
nodes[6].child_ids = {10, 11};
5894 tree_update.
nodes[7].id = 8;
5897 tree_update.
nodes[7].SetName(
".8.");
5899 tree_update.
nodes[8].id = 9;
5900 tree_update.
nodes[8].child_ids = {12};
5904 tree_update.
nodes[9].id = 10;
5905 tree_update.
nodes[9].child_ids = {13, 14};
5909 tree_update.
nodes[10].id = 11;
5911 tree_update.
nodes[10].SetName(
".11.");
5913 tree_update.
nodes[11].id = 12;
5916 tree_update.
nodes[11].SetName(
".12.");
5918 tree_update.
nodes[12].id = 13;
5920 tree_update.
nodes[12].SetName(
".13.");
5922 tree_update.
nodes[13].id = 14;
5924 tree_update.
nodes[13].SetName(
".14.");
5928 GetNodeFromTree(tree_id, 1));
5930 GetNodeFromTree(tree_id, 1));
5932 GetNodeFromTree(tree_id, 3));
5934 GetNodeFromTree(tree_id, 4));
5936 GetNodeFromTree(tree_id, 5));
5938 GetNodeFromTree(tree_id, 1));
5940 GetNodeFromTree(tree_id, 11));
5942 GetNodeFromTree(tree_id, 13));
5944 GetNodeFromTree(tree_id, 14));
5947 ComPtr<ITextRangeProvider> text_range_provider;
5948 GetTextRangeProviderFromTextNode(text_range_provider,
5949 GetNodeFromTree(tree_id, 1));
5951 ASSERT_HRESULT_SUCCEEDED(
5952 text_range_provider->ExpandToEnclosingUnit(TextUnit_Character));
5956 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
5962 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
5970 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
5972 L".3..4..5.\n\xFFFC\n.13..14..11.",
5977 TestNormalizeTextRangePastEndOfDocument) {
5983 initial_state.
nodes.resize(3);
5984 initial_state.
nodes[0].id = 1;
5985 initial_state.
nodes[0].child_ids = {2};
5987 initial_state.
nodes[1].id = 2;
5988 initial_state.
nodes[1].child_ids = {3};
5990 initial_state.
nodes[1].SetName(
"aaa");
5991 initial_state.
nodes[2].id = 3;
5993 initial_state.
nodes[2].SetName(
"aaa");
5995 Init(initial_state);
5997 ComPtr<ITextRangeProvider> text_range_provider;
5998 GetTextRangeProviderFromTextNode(text_range_provider,
5999 GetNodeFromTree(tree_id, 3));
6003 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
6008 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider_win;
6009 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range_provider_win));
6012 GetStart(text_range_provider_win.Get())->Clone();
6014 GetEnd(text_range_provider_win.Get())->Clone();
6015 EXPECT_LT(*start_after_move, *end_after_move);
6020 update.nodes[0].SetName(
"aa");
6022 update.nodes[1].SetName(
"aa");
6023 ASSERT_TRUE(GetTree()->Unserialize(
update));
6025 auto* text_range = text_range_provider_win.Get();
6027 auto original_start = GetStart(text_range)->Clone();
6028 auto original_end = GetEnd(text_range)->Clone();
6030 auto normalized_start = GetStart(text_range)->Clone();
6031 auto normalized_end = GetEnd(text_range)->Clone();
6032 NormalizeTextRange(text_range, normalized_start, normalized_end);
6034 ExpectPositionsEqual(original_start, GetStart(text_range));
6035 ExpectPositionsEqual(original_end, GetEnd(text_range));
6037 EXPECT_EQ(*start_after_move, *normalized_start);
6038 EXPECT_EQ(*end_after_move, *normalized_end);
6042 TestNormalizeTextRangePastEndOfDocumentWithIgnoredNodes) {
6048 initial_state.
nodes.resize(4);
6049 initial_state.
nodes[0].id = 1;
6050 initial_state.
nodes[0].child_ids = {2};
6052 initial_state.
nodes[1].id = 2;
6053 initial_state.
nodes[1].child_ids = {3, 4};
6055 initial_state.
nodes[1].SetName(
"aaa");
6056 initial_state.
nodes[2].id = 3;
6058 initial_state.
nodes[2].SetName(
"aaa");
6059 initial_state.
nodes[3].id = 4;
6062 initial_state.
nodes[3].SetName(
"ignored");
6064 Init(initial_state);
6066 ComPtr<ITextRangeProvider> text_range_provider;
6067 GetTextRangeProviderFromTextNode(text_range_provider,
6068 GetNodeFromTree(tree_id, 3));
6072 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
6077 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider_win;
6078 text_range_provider->QueryInterface(IID_PPV_ARGS(&text_range_provider_win));
6081 GetStart(text_range_provider_win.Get())->Clone();
6083 GetEnd(text_range_provider_win.Get())->Clone();
6084 EXPECT_LT(*start_after_move, *end_after_move);
6089 update.nodes[0].SetName(
"aa");
6091 update.nodes[1].SetName(
"aa");
6092 ASSERT_TRUE(GetTree()->Unserialize(
update));
6094 auto* text_range = text_range_provider_win.Get();
6096 auto original_start = GetStart(text_range)->Clone();
6097 auto original_end = GetEnd(text_range)->Clone();
6099 auto normalized_start = GetStart(text_range)->Clone();
6100 auto normalized_end = GetEnd(text_range)->Clone();
6101 NormalizeTextRange(text_range, normalized_start, normalized_end);
6103 ExpectPositionsEqual(original_start, GetStart(text_range));
6104 ExpectPositionsEqual(original_end, GetEnd(text_range));
6106 EXPECT_EQ(*start_after_move, *normalized_start);
6107 EXPECT_EQ(*end_after_move, *normalized_end);
6111 TestNormalizeTextRangeInsideIgnoredNodes) {
6117 initial_state.
nodes.resize(4);
6118 initial_state.
nodes[0].id = 1;
6119 initial_state.
nodes[0].child_ids = {2, 3, 4};
6121 initial_state.
nodes[1].id = 2;
6123 initial_state.
nodes[1].SetName(
"before");
6124 initial_state.
nodes[2].id = 3;
6127 initial_state.
nodes[2].SetName(
"ignored");
6128 initial_state.
nodes[3].id = 4;
6130 initial_state.
nodes[3].SetName(
"after");
6132 Init(initial_state);
6133 const AXTree* tree = GetTree();
6138 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6139 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6143 ComPtr<AXPlatformNodeTextRangeProviderWin> ignored_range_win;
6144 CreateTextRangeProviderWin(
6145 ignored_range_win, owner,
6151 EXPECT_TRUE(GetStart(ignored_range_win.Get())->IsIgnored());
6152 EXPECT_TRUE(GetEnd(ignored_range_win.Get())->IsIgnored());
6154 auto original_start = GetStart(ignored_range_win.Get())->Clone();
6155 auto original_end = GetEnd(ignored_range_win.Get())->Clone();
6157 auto normalized_start = GetStart(ignored_range_win.Get())->Clone();
6158 auto normalized_end = GetEnd(ignored_range_win.Get())->Clone();
6159 NormalizeTextRange(ignored_range_win.Get(), normalized_start, normalized_end);
6161 ExpectPositionsEqual(original_start, GetStart(ignored_range_win.Get()));
6162 ExpectPositionsEqual(original_end, GetEnd(ignored_range_win.Get()));
6164 EXPECT_FALSE(normalized_start->IsIgnored());
6165 EXPECT_FALSE(normalized_end->IsIgnored());
6166 EXPECT_LE(*GetStart(ignored_range_win.Get()), *normalized_start);
6167 EXPECT_LE(*GetEnd(ignored_range_win.Get()), *normalized_end);
6168 EXPECT_LE(*normalized_start, *normalized_end);
6175 update.nodes[0].child_ids = {2, 3};
6176 ASSERT_TRUE(GetTree()->Unserialize(
update));
6178 original_start = GetStart(ignored_range_win.Get())->Clone();
6179 original_end = GetEnd(ignored_range_win.Get())->Clone();
6181 normalized_start = GetStart(ignored_range_win.Get())->Clone();
6182 normalized_end = GetEnd(ignored_range_win.Get())->Clone();
6183 NormalizeTextRange(ignored_range_win.Get(), normalized_start, normalized_end);
6185 ExpectPositionsEqual(original_start, GetStart(ignored_range_win.Get()));
6186 ExpectPositionsEqual(original_end, GetEnd(ignored_range_win.Get()));
6188 EXPECT_FALSE(normalized_start->IsIgnored());
6189 EXPECT_FALSE(normalized_end->IsIgnored());
6190 EXPECT_GE(*GetStart(ignored_range_win.Get()), *normalized_start);
6191 EXPECT_GE(*GetEnd(ignored_range_win.Get()), *normalized_end);
6192 EXPECT_LE(*normalized_start, *normalized_end);
6196 TestNormalizeTextRangeSpanIgnoredNodes) {
6204 before_text.
SetName(
"before");
6208 ignored_text1.
id = 3;
6211 ignored_text1.
SetName(
"ignored1");
6215 ignored_text2.
id = 4;
6218 ignored_text2.
SetName(
"ignored2");
6230 update.tree_data.tree_id = tree_id;
6231 update.has_tree_data =
true;
6232 update.nodes = {root_data, before_text, ignored_text1, ignored_text2,
6236 const AXTree* tree = GetTree();
6243 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6244 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6251 ComPtr<AXPlatformNodeTextRangeProviderWin> range_span_ignored_nodes;
6252 CreateTextRangeProviderWin(
6253 range_span_ignored_nodes, owner,
6254 before_text_node, 6,
6259 auto original_start = GetStart(range_span_ignored_nodes.Get())->Clone();
6260 auto original_end = GetEnd(range_span_ignored_nodes.Get())->Clone();
6266 GetStart(range_span_ignored_nodes.Get())->Clone();
6268 GetEnd(range_span_ignored_nodes.Get())->Clone();
6269 NormalizeTextRange(range_span_ignored_nodes.Get(), normalized_start,
6272 ExpectPositionsEqual(original_start,
6273 GetStart(range_span_ignored_nodes.Get()));
6274 ExpectPositionsEqual(original_end, GetEnd(range_span_ignored_nodes.Get()));
6276 EXPECT_EQ(*normalized_start, *normalized_end);
6280 EXPECT_EQ(5, normalized_start->anchor_id());
6281 EXPECT_EQ(0, normalized_start->text_offset());
6285 EXPECT_EQ(5, normalized_end->anchor_id());
6286 EXPECT_EQ(0, normalized_end->text_offset());
6292 DISABLED_TestNormalizeTextRangeForceSameAnchorOnDegenerateRange) {
6309 generic_container_2.
id = 2;
6310 line_break_3.
id = 3;
6311 text_field_4.
id = 4;
6312 generic_container_5.
id = 5;
6313 static_text_6.
id = 6;
6314 inline_box_7.
id = 7;
6317 root_1.
child_ids = {generic_container_2.
id, text_field_4.
id};
6322 generic_container_2.
child_ids = {line_break_3.
id};
6328 text_field_4.
child_ids = {generic_container_5.
id};
6332 generic_container_5.
child_ids = {static_text_6.
id};
6336 static_text_6.
SetName(
"3.14");
6344 update.tree_data = tree_data;
6345 update.has_tree_data =
true;
6347 update.nodes.push_back(root_1);
6348 update.nodes.push_back(generic_container_2);
6349 update.nodes.push_back(line_break_3);
6350 update.nodes.push_back(text_field_4);
6351 update.nodes.push_back(generic_container_5);
6352 update.nodes.push_back(static_text_6);
6353 update.nodes.push_back(inline_box_7);
6356 const AXTree* tree = GetTree();
6361 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6362 AXPlatformNodeFromNode(GetNodeFromTree(tree_data.
tree_id, 1)));
6366 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
6367 CreateTextRangeProviderWin(
6369 line_break_3_node, 1,
6371 inline_box_7_node, 0,
6374 auto original_start = GetStart(range.Get())->Clone();
6375 auto original_end = GetEnd(range.Get())->Clone();
6378 GetStart(range.Get())->Clone();
6380 GetEnd(range.Get())->Clone();
6381 NormalizeTextRange(range.Get(), normalized_start, normalized_end);
6383 ExpectPositionsEqual(original_start, GetStart(range.Get()));
6384 ExpectPositionsEqual(original_end, GetEnd(range.Get()));
6386 EXPECT_EQ(*normalized_start, *normalized_start);
6390 EXPECT_EQ(7, normalized_start->anchor_id());
6391 EXPECT_EQ(7, normalized_end->anchor_id());
6406 text_data.
SetName(
"some text");
6409 more_text_data.
id = 3;
6411 more_text_data.
SetName(
"more text");
6418 update.tree_data.tree_id = tree_id;
6419 update.has_tree_data =
true;
6420 update.nodes = {root_data, text_data, more_text_data};
6423 const AXTree* tree = GetTree();
6431 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6432 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6436 ComPtr<AXPlatformNodeTextRangeProviderWin> text_range_provider;
6437 CreateTextRangeProviderWin(
6438 text_range_provider, owner,
6447 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
6449 L"some textmore text",
6455 more_text_data.
SetName(
"ore tex");
6457 test_update.
nodes = {more_text_data};
6458 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6461 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
6463 L"some textore tex",
6470 test_update2.
nodes = {text_data};
6471 ASSERT_TRUE(GetTree()->Unserialize(test_update2));
6474 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
6482 text_data.
SetName(
"some text");
6484 test_update3.
nodes = {text_data};
6485 ASSERT_TRUE(GetTree()->Unserialize(test_update3));
6488 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
6490 L"some textore tex",
6496 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
6503 text_range_provider, TextPatternRangeEndpoint_End, TextUnit_Character,
6512 text_data.
SetName(
"some tex");
6514 test_update4.
nodes = {text_data};
6515 ASSERT_TRUE(GetTree()->Unserialize(test_update4));
6518 text_range_provider, TextPatternRangeEndpoint_Start, TextUnit_Character,
6525 TestReplaceStartAndEndEndpointNode) {
6573 update.tree_data.tree_id = tree_id;
6574 update.has_tree_data =
true;
6575 update.nodes = {root_1, text_3, text_5};
6578 const AXTree* tree = GetTree();
6586 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6587 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6591 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
6592 CreateTextRangeProviderWin(
6606 test_update.
nodes = {root_1, text_4};
6607 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6611 range->GetChildren(children.
Receive());
6616 EXPECT_EQ(root_1.
id, GetStart(range.Get())->anchor_id());
6617 EXPECT_EQ(0, GetStart(range.Get())->text_offset());
6620 EXPECT_EQ(text_5.
id, GetEnd(range.Get())->anchor_id());
6621 EXPECT_EQ(9, GetEnd(range.Get())->text_offset());
6629 test_update.
nodes = {root_1, text_6};
6630 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6634 range->GetChildren(children.
Receive());
6638 EXPECT_EQ(root_1.
id, GetStart(range.Get())->anchor_id());
6639 EXPECT_EQ(0, GetStart(range.Get())->text_offset());
6642 EXPECT_EQ(root_1.
id, GetEnd(range.Get())->anchor_id());
6643 EXPECT_EQ(18, GetEnd(range.Get())->text_offset());
6651 ComPtr<AXPlatformNodeTextRangeProviderWin> range_2;
6652 CreateTextRangeProviderWin(
6664 test_update.
nodes = {root_1, text_3};
6665 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6669 range_2->GetChildren(children.
Receive());
6673 EXPECT_EQ(root_1.
id, GetStart(range_2.Get())->anchor_id());
6674 EXPECT_EQ(0, GetStart(range_2.Get())->text_offset());
6677 EXPECT_EQ(root_1.
id, GetEnd(range_2.Get())->anchor_id());
6678 EXPECT_EQ(4, GetEnd(range_2.Get())->text_offset());
6683 TestDeleteSubtreeThatIncludesEndpoints) {
6735 update.tree_data.tree_id = tree_id;
6736 update.has_tree_data =
true;
6737 update.nodes = {root_1, text_2, gc_3, gc_4, text_5, gc_6, text_7};
6740 const AXTree* tree = GetTree();
6747 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6748 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6754 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
6755 CreateTextRangeProviderWin(
6768 test_update.
nodes = {root_1};
6769 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6773 EXPECT_EQ(root_1.
id, GetStart(range.Get())->anchor_id());
6774 EXPECT_EQ(3, GetStart(range.Get())->text_offset());
6776 EXPECT_EQ(root_1.
id, GetEnd(range.Get())->anchor_id());
6777 EXPECT_EQ(3, GetEnd(range.Get())->text_offset());
6782 DISABLED_TestDeleteSubtreeWithIgnoredAncestors) {
6868 update.tree_data.tree_id = tree_id;
6869 update.has_tree_data =
true;
6870 update.nodes = {root_1, text_2, gc_3, gc_4, gc_5, text_6,
6871 gc_7, text_8, gc_9, text_10, gc_11, text_12};
6874 const AXTree* tree = GetTree();
6881 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
6882 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
6888 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
6889 CreateTextRangeProviderWin(
6902 test_update.
nodes = {gc_3};
6903 ASSERT_TRUE(GetTree()->Unserialize(test_update));
6907 EXPECT_TRUE(GetStart(range.Get())->IsNullPosition());
6908 EXPECT_TRUE(GetEnd(range.Get())->IsNullPosition());
6913 DISABLED_TestDeleteSubtreeThatIncludesEndpointsNormalizeMoves) {
6998 update.tree_data.tree_id = tree_id;
6999 update.has_tree_data =
true;
7000 update.nodes = {root_1, text_2, gc_3, gc_4, gc_5, text_6,
7001 gc_7, text_8, gc_9, text_10, gc_11, text_12};
7004 const AXTree* tree = GetTree();
7011 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
7012 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
7018 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
7019 CreateTextRangeProviderWin(
7032 test_update.
nodes = {gc_3};
7033 ASSERT_TRUE(GetTree()->Unserialize(test_update));
7037 EXPECT_EQ(text_12.
id, GetStart(range.Get())->anchor_id());
7038 EXPECT_EQ(0, GetStart(range.Get())->text_offset());
7040 EXPECT_EQ(text_12.
id, GetEnd(range.Get())->anchor_id());
7041 EXPECT_EQ(0, GetEnd(range.Get())->text_offset());
7045 TestDeleteTreePositionPreviousSibling) {
7067 generic_container_2.
id = 2;
7069 static_text_4.
id = 4;
7070 inline_box_5.
id = 5;
7071 generic_container_6.
id = 6;
7078 generic_container_2.
child_ids = {heading_3.
id, generic_container_6.
id,
7086 static_text_4.
SetName(
"3.14");
7100 update.tree_data = tree_data;
7101 update.has_tree_data =
true;
7103 update.nodes = {root_1, generic_container_2, heading_3, static_text_4,
7104 inline_box_5, generic_container_6, button_7};
7107 AXTree* tree = GetTree();
7109 AXNode* root_node = GetRootAsAXNode();
7112 generic_container_2.
id,
7116 AXPlatformNodeWin* owner =
7117 static_cast<AXPlatformNodeWin*
>(AXPlatformNodeFromNode(root_node));
7118 ComPtr<ITextRangeProvider> text_range_provider =
7119 AXPlatformNodeTextRangeProviderWin::CreateTextRangeProviderForTesting(
7120 owner, std::move(range_start), std::move(range_end));
7123 generic_container_2.
child_ids = {heading_3.
id, button_7.
id};
7125 test_update.
nodes = {generic_container_2};
7129 test_update.
nodes = {root_1};
7134 TestReplaceStartAndEndEndpointRepeatRemoval) {
7174 update.tree_data.tree_id = tree_id;
7175 update.has_tree_data =
true;
7176 update.nodes = {root_1, text_2, group_3, text_4, text_5};
7179 const AXTree* tree = GetTree();
7186 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
7187 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
7189 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
7190 CreateTextRangeProviderWin(
7206 test_update.
nodes = {root_1, group_3};
7207 ASSERT_TRUE(GetTree()->Unserialize(test_update));
7220 test_update.
nodes = {root_1, group_3};
7221 ASSERT_TRUE(GetTree()->Unserialize(test_update));
7234 test_update.
nodes = {root_1, group_3};
7235 ASSERT_TRUE(GetTree()->Unserialize(test_update));
7263 text_field_2.
id = 2;
7264 generic_container_3.
id = 3;
7265 static_text_4.
id = 4;
7266 inline_text_5.
id = 5;
7267 static_text_6.
id = 6;
7268 inline_text_7.
id = 7;
7276 text_field_2.
child_ids = {generic_container_3.
id};
7282 generic_container_3.
child_ids = {static_text_4.
id};
7285 static_text_4.
SetName(
"hello");
7290 inline_text_5.
SetName(
"hello");
7303 update.tree_data.tree_id = tree_id;
7304 update.has_tree_data =
true;
7305 update.nodes = {root_1, text_field_2, generic_container_3,
7306 static_text_4, inline_text_5, static_text_6,
7310 const AXTree* tree = GetTree();
7315 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
7316 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
7318 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
7321 CreateTextRangeProviderWin(
7323 inline_text_5_node, 3,
7325 inline_text_5_node, 4,
7330 expected_variant.
Set(
false);
7339 expected_variant.
Set(
false);
7348 expected_variant.
Set(
false);
7354 EXPECT_EQ(5,
start->anchor_id());
7355 EXPECT_EQ(5,
start->text_offset());
7358 EXPECT_EQ(5,
end->anchor_id());
7359 EXPECT_EQ(5,
end->text_offset());
7365 DISABLED_GeneratedNewlineReturnsCommonAnchorReadonly) {
7393 generic_container_2.
id = 2;
7395 text_field_4.
id = 4;
7396 generic_container_5.
id = 5;
7398 text_field_7.
id = 7;
7399 generic_container_8.
id = 8;
7400 text_field_9.
id = 9;
7401 text_field_10.
id = 10;
7404 root_1.
child_ids = {generic_container_2.
id, generic_container_5.
id,
7405 generic_container_8.
id};
7408 generic_container_2.
child_ids = {image_3.
id, text_field_4.
id};
7419 generic_container_5.
child_ids = {image_6.
id, text_field_7.
id};
7429 generic_container_8.
child_ids = {text_field_9.
id, text_field_10.
id};
7442 update.tree_data.tree_id = tree_id;
7443 update.has_tree_data =
true;
7444 update.nodes = {root_1, generic_container_2, image_3,
7445 text_field_4, generic_container_5, image_6,
7446 text_field_7, generic_container_8, text_field_9,
7450 const AXTree* tree = GetTree();
7461 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
7462 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
7466 ComPtr<AXPlatformNodeTextRangeProviderWin> range_1;
7467 CreateTextRangeProviderWin(
7471 text_field_4_node, 0,
7476 expected_variant.
Set(
true);
7479 expected_variant.
Reset();
7481 ComPtr<AXPlatformNodeTextRangeProviderWin> range_2;
7482 CreateTextRangeProviderWin(
7486 text_field_7_node, 0,
7491 expected_variant.
Set(
false);
7494 expected_variant.
Reset();
7500 ComPtr<AXPlatformNodeTextRangeProviderWin> range_3;
7501 CreateTextRangeProviderWin(
7503 text_field_9_node, 1,
7505 text_field_10_node, 0,
7510 expected_variant.
Set(
true);
7513 expected_variant.
Reset();
7518 DISABLED_MoveEndpointToLastIgnoredForTextNavigationNode) {
7534 static_text_2.
id = 2;
7535 inline_text_3.
id = 3;
7536 generic_container_4.
id = 4;
7539 root_1.
child_ids = {static_text_2.
id, generic_container_4.
id};
7553 update.tree_data.tree_id = tree_id;
7554 update.has_tree_data =
true;
7555 update.nodes = {root_1, static_text_2, inline_text_3, generic_container_4};
7558 const AXTree* tree = GetTree();
7563 AXPlatformNodeWin* owner =
static_cast<AXPlatformNodeWin*
>(
7564 AXPlatformNodeFromNode(GetNodeFromTree(tree_id, 1)));
7566 ComPtr<AXPlatformNodeTextRangeProviderWin> range;
7569 CreateTextRangeProviderWin(
7571 inline_text_3_node, 0,
7573 inline_text_3_node, 3,
static int find_string(const TArray< SkString > &strings, const char ext[])
void Reset(BSTR bstr=nullptr)
void Reset(SAFEARRAY *safearray=nullptr)
const VARIANT * ptr() const
void Set(const wchar_t *str)
void Reset(const VARIANT &var=kEmptyVariant)
virtual AXTreeID GetAXTreeID() const =0
const std::vector< AXNode * > & children() const
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > AXPositionInstance
static AXPositionInstance CreateTreePosition(AXTreeID tree_id, AXNode::AXID anchor_id, int child_index)
static AXPositionInstance CreateTextPosition(AXTreeID tree_id, AXNode::AXID anchor_id, int text_offset, ax::mojom::TextAffinity affinity)
static AXTreeID CreateNewAXTreeID()
AXTreeID GetAXTreeID() const override
virtual bool Unserialize(const AXTreeUpdate &update)
AXNode * GetFromId(int32_t id) const override
@ kPdfActionableHighlight
@ kTextStrikethroughStyle
std::string UTF16ToUTF8(std::u16string src)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir path
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot The VM snapshot data that will be memory mapped as read only SnapshotAssetPath must be present isolate snapshot The isolate snapshot data that will be memory mapped as read only SnapshotAssetPath must be present cache dir Path to the cache directory This is different from the persistent_cache_path in embedder which is used for Skia shader cache icu native lib Path to the library file that exports the ICU data vm service The hostname IP address on which the Dart VM Service should be served If not defaults to or::depending on whether ipv6 is specified vm service A custom Dart VM Service port The default is to pick a randomly available open port disable vm Disable the Dart VM Service The Dart VM Service is never available in release mode disable vm service Disable mDNS Dart VM Service publication Bind to the IPv6 localhost address for the Dart VM Service Ignored if vm service host is set endless trace buffer
void InitializeICU(const std::string &icu_data_path)
static bool StringCompareICU(BSTR left, BSTR right)
bool StringSearch(std::u16string_view search_string, std::u16string_view find_in, size_t *find_start, size_t *find_length, bool ignore_case, bool backwards)
TEST_F(AXPositionTest, Clone)
static AXNodePosition::AXPositionInstance CreateTextPosition(const AXNode &anchor, int text_offset, ax::mojom::TextAffinity affinity)
AXRelativeBounds relative_bounds
void AddFloatAttribute(ax::mojom::FloatAttribute attribute, float value)
void SetRestriction(ax::mojom::Restriction restriction)
void AddIntListAttribute(ax::mojom::IntListAttribute attribute, const std::vector< int32_t > &value)
void AddState(ax::mojom::State state)
void AddIntAttribute(ax::mojom::IntAttribute attribute, int32_t value)
void SetTextAlign(ax::mojom::TextAlign text_align)
std::vector< int32_t > child_ids
void SetValue(const std::string &value)
void SetHasPopup(ax::mojom::HasPopup has_popup)
void SetTextDirection(ax::mojom::WritingDirection text_direction)
void SetName(const std::string &name)
void AddStringAttribute(ax::mojom::StringAttribute attribute, const std::string &value)
void SetNameExplicitlyEmpty()
void AddTextStyle(ax::mojom::TextStyle text_style)
void AddBoolAttribute(ax::mojom::BoolAttribute attribute, bool value)
void SetTextPosition(ax::mojom::TextPosition text_position)
void SetCheckedState(ax::mojom::CheckedState checked_state)
std::vector< AXNodeData > nodes
#define EXPECT_TRUE(handle)