10#include "gtest/gtest.h"
25 std::unique_ptr<AXPosition<AXNodePosition, AXNode>>;
30bool ContainerEQ(std::vector<gfx::Rect> actual,
31 std::vector<gfx::Rect> expected) {
32 for (
size_t i = 0;
i < actual.size();
i++) {
33 if (actual[
i] != expected[
i])
59 : tree_manager_(tree_manager) {}
60 virtual ~TestAXRangeScreenRectDelegate() =
default;
61 TestAXRangeScreenRectDelegate(
const TestAXRangeScreenRectDelegate& delegate) =
63 TestAXRangeScreenRectDelegate& operator=(
64 const TestAXRangeScreenRectDelegate& delegate) =
delete;
73 if (tree_manager_->GetTreeID() != tree_id)
76 AXNode* node = tree_manager_->GetNodeFromTree(node_id);
84 clipping_behavior, offscreen_result);
90 if (tree_manager_->GetTreeID() != tree_id)
93 AXNode* node = tree_manager_->GetNodeFromTree(node_id);
115 const std::u16string TEXT_FIELD =
116 LINE_1.substr().append(NEWLINE).append(LINE_2).append(NEWLINE);
118 const std::u16string ALL_TEXT =
119 BUTTON.substr().append(TEXT_FIELD).append(AFTER_LINE);
121 AXRangeTest() =
default;
122 ~AXRangeTest()
override =
default;
125 void SetUp()
override;
148void AXRangeTest::SetUp() {
155 button_.id = BUTTON_ID;
156 check_box1_.id = CHECK_BOX1_ID;
157 check_box2_.id = CHECK_BOX2_ID;
158 text_field_.id = TEXT_FIELD_ID;
159 line_break1_.id = LINE_BREAK1_ID;
160 line_break2_.id = LINE_BREAK2_ID;
161 static_text1_.id = STATIC_TEXT1_ID;
162 static_text2_.id = STATIC_TEXT2_ID;
163 static_text3_.id = STATIC_TEXT3_ID;
164 inline_box1_.id = INLINE_BOX1_ID;
165 inline_box2_.id = INLINE_BOX2_ID;
166 inline_box3_.id = INLINE_BOX3_ID;
167 paragraph_.id = PARAGRAPH_ID;
171 root_.SetName(ALL_TEXT);
172 root_.relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
176 div1_.child_ids.push_back(button_.id);
177 div1_.child_ids.push_back(div2_.id);
178 root_.child_ids.push_back(div1_.id);
182 button_.SetName(BUTTON);
183 button_.SetValue(BUTTON);
184 button_.relative_bounds.bounds =
gfx::RectF(20, 20, 100, 30);
189 div2_.child_ids.push_back(check_box1_.id);
190 div2_.child_ids.push_back(check_box2_.id);
194 check_box1_.SetName(
"Checkbox 1");
195 check_box1_.relative_bounds.bounds =
gfx::RectF(120, 20, 30, 30);
203 check_box2_.SetName(
"Checkbox 2");
204 check_box2_.relative_bounds.bounds =
gfx::RectF(150, 20, 30, 30);
210 text_field_.SetValue(TEXT_FIELD);
211 text_field_.AddIntListAttribute(
213 std::vector<int32_t>{0, 7});
214 text_field_.child_ids.push_back(static_text1_.id);
215 text_field_.child_ids.push_back(line_break1_.id);
216 text_field_.child_ids.push_back(static_text2_.id);
217 text_field_.child_ids.push_back(line_break2_.id);
218 root_.child_ids.push_back(text_field_.id);
222 static_text1_.SetName(LINE_1);
223 static_text1_.child_ids.push_back(inline_box1_.id);
227 inline_box1_.SetName(LINE_1);
228 inline_box1_.relative_bounds.bounds =
gfx::RectF(20, 50, 30, 30);
229 std::vector<int32_t> character_offsets1;
231 character_offsets1.push_back(25);
232 character_offsets1.push_back(30);
233 character_offsets1.push_back(35);
234 character_offsets1.push_back(40);
235 character_offsets1.push_back(45);
236 character_offsets1.push_back(50);
237 inline_box1_.AddIntListAttribute(
240 std::vector<int32_t>{0, 5});
242 std::vector<int32_t>{4, 6});
248 line_break1_.SetName(NEWLINE);
249 line_break1_.relative_bounds.bounds =
gfx::RectF(50, 50, 0, 30);
255 static_text2_.SetName(LINE_2);
256 static_text2_.child_ids.push_back(inline_box2_.id);
260 inline_box2_.SetName(LINE_2);
261 inline_box2_.relative_bounds.bounds =
gfx::RectF(20, 80, 42, 30);
262 std::vector<int32_t> character_offsets2;
264 character_offsets2.push_back(27);
265 character_offsets2.push_back(34);
266 character_offsets2.push_back(41);
267 character_offsets2.push_back(48);
268 character_offsets2.push_back(55);
269 character_offsets2.push_back(62);
270 inline_box2_.AddIntListAttribute(
273 std::vector<int32_t>{0, 5});
275 std::vector<int32_t>{4, 6});
281 line_break2_.SetName(NEWLINE);
282 line_break2_.relative_bounds.bounds =
gfx::RectF(62, 80, 0, 30);
289 paragraph_.child_ids.push_back(static_text3_.id);
290 root_.child_ids.push_back(paragraph_.id);
293 static_text3_.SetName(AFTER_LINE);
294 static_text3_.child_ids.push_back(inline_box3_.id);
297 inline_box3_.SetName(AFTER_LINE);
298 inline_box3_.relative_bounds.bounds =
gfx::RectF(20, 110, 50, 30);
299 std::vector<int32_t> character_offsets3;
301 character_offsets3.push_back(30);
302 character_offsets3.push_back(40);
303 character_offsets3.push_back(50);
304 character_offsets3.push_back(60);
305 character_offsets3.push_back(70);
306 inline_box3_.AddIntListAttribute(
309 std::vector<int32_t>{0});
311 std::vector<int32_t>{5});
315 initial_state.
nodes = {
316 root_, div1_, button_, div2_,
317 check_box1_, check_box2_, text_field_, static_text1_,
318 inline_box1_, line_break1_, static_text2_, inline_box2_,
319 line_break2_, paragraph_, static_text3_, inline_box3_};
324 SetTree(std::make_unique<AXTree>(initial_state));
332 GetTreeID(), button_.id, 0 ,
335 GetTreeID(), line_break1_.id, 1 ,
338 GetTreeID(), inline_box2_.id, 0 ,
345 null_position->Clone());
348 test_position2->Clone());
350 test_position1->Clone());
352 test_position3->Clone());
354 test_position3->Clone());
356 test_position2->Clone());
358 EXPECT_EQ(null_position_and_nullptr, nullptr_and_test_position);
359 EXPECT_EQ(nullptr_and_test_position, test_position_and_null_position);
360 EXPECT_NE(null_position_and_nullptr, test_positions_2_and_1);
361 EXPECT_NE(test_positions_2_and_1, test_position_and_null_position);
362 EXPECT_EQ(test_positions_1_and_2, test_positions_1_and_2);
363 EXPECT_NE(test_positions_2_and_1, test_positions_1_and_2);
364 EXPECT_EQ(test_positions_3_and_2, test_positions_2_and_3);
365 EXPECT_NE(test_positions_1_and_2, test_positions_2_and_3);
366 EXPECT_EQ(test_positions_1_and_2, test_positions_1_and_3);
376 GetTreeID(), button_.id, 0 );
378 GetTreeID(), line_break1_.id, 1 ,
381 GetTreeID(), inline_box2_.id, 0 ,
385 tree_position->Clone());
387 EXPECT_EQ(*tree_position, *tree_to_text_range.
anchor());
388 EXPECT_EQ(*text_position1, *tree_to_text_range.
focus());
391 text_position1->Clone());
393 EXPECT_EQ(*text_position1, *text_to_text_range.
anchor());
394 EXPECT_EQ(*text_position2, *text_to_text_range.
focus());
404 GetTreeID(), text_field_.id, 0 );
410 GetTreeID(), inline_box1_.id, 0 );
413 GetTreeID(), static_text1_.id, 0 ,
416 GetTreeID(), inline_box1_.id, 0 ,
419 GetTreeID(), inline_box2_.id, 1 ,
428 text_position1->Clone());
433 tree_position1->Clone());
439 text_position1->Clone());
449 text_position1->Clone());
463TEST_F(AXRangeTest, BeginAndEndIterators) {
466 GetTreeID(), button_.id, 3 ,
469 GetTreeID(), check_box1_.id, 0 ,
472 GetTreeID(), check_box2_.id, 0 ,
475 GetTreeID(), inline_box1_.id, 0 ,
488 test_position2->Clone());
490 null_position_and_test_position2.
begin());
492 null_position_and_test_position2.
end());
495 test_position2->Clone());
497 test_position4->Clone()),
498 test_position1_and_test_position2.
begin());
500 test_position3->Clone()),
501 test_position1_and_test_position2.
begin());
503 test_position2->Clone()),
504 test_position1_and_test_position2.
begin());
506 test_position1_and_test_position2.
end());
509 test_position4->Clone());
511 test_position4->Clone()),
512 test_position3_and_test_position4.
begin());
514 test_position4->Clone()),
515 test_position3_and_test_position4.
begin());
517 test_position4->Clone()),
518 test_position3_and_test_position4.
begin());
520 test_position3_and_test_position4.
end());
522 test_position3_and_test_position4.
end());
524 test_position3_and_test_position4.
end());
527TEST_F(AXRangeTest, LeafTextRangeIteration) {
529 GetTreeID(), button_.id, 0 ,
532 GetTreeID(), button_.id, 3 ,
535 GetTreeID(), button_.id, 6 ,
541 GetTreeID(), check_box1_.id, 0 ,
544 GetTreeID(), check_box2_.id, 0 ,
548 GetTreeID(), inline_box1_.id, 0 ,
551 GetTreeID(), inline_box1_.id, 3 ,
554 GetTreeID(), inline_box1_.id, 6 ,
558 GetTreeID(), line_break1_.id, 0 ,
561 GetTreeID(), line_break1_.id, 1 ,
565 GetTreeID(), inline_box2_.id, 0 ,
568 GetTreeID(), inline_box2_.id, 3 ,
571 GetTreeID(), inline_box2_.id, 6 ,
575 GetTreeID(), line_break2_.id, 0 ,
578 GetTreeID(), line_break2_.id, 1 ,
582 GetTreeID(), inline_box3_.id, 0 ,
585 GetTreeID(), inline_box3_.id, 5 ,
588 std::vector<TestPositionRange> expected_ranges;
589 auto TestRangeIterator =
591 std::vector<TestPositionRange> actual_ranges;
594 actual_ranges.emplace_back(std::move(leaf_text_range));
597 EXPECT_EQ(expected_ranges.size(), actual_ranges.size());
598 size_t element_count =
599 std::min(expected_ranges.size(), actual_ranges.size());
600 for (
size_t i = 0;
i < element_count; ++
i) {
601 EXPECT_EQ(expected_ranges[
i], actual_ranges[
i]);
602 EXPECT_EQ(expected_ranges[
i].anchor()->GetAnchor(),
603 actual_ranges[
i].anchor()->GetAnchor());
611 check_box1->Clone());
612 expected_ranges.clear();
613 expected_ranges.emplace_back(check_box1->Clone(), check_box1->Clone());
614 TestRangeIterator(non_null_degenerate_range);
617 line1_start->Clone());
619 button_end->Clone());
620 expected_ranges.clear();
621 expected_ranges.emplace_back(button_end->Clone(), button_end->Clone());
622 expected_ranges.emplace_back(check_box1->Clone(), check_box1->Clone());
623 expected_ranges.emplace_back(check_box2->Clone(), check_box2->Clone());
624 expected_ranges.emplace_back(line1_start->Clone(), line1_start->Clone());
625 TestRangeIterator(empty_text_forward_range);
626 TestRangeIterator(empty_text_backward_range);
629 button_end->Clone());
631 button_start->Clone());
632 expected_ranges.clear();
633 expected_ranges.emplace_back(button_start->Clone(), button_end->Clone());
634 TestRangeIterator(entire_anchor_forward_range);
635 TestRangeIterator(entire_anchor_backward_range);
638 line1_middle->Clone());
640 button_middle->Clone());
641 expected_ranges.clear();
642 expected_ranges.emplace_back(button_middle->Clone(), button_end->Clone());
643 expected_ranges.emplace_back(check_box1->Clone(), check_box1->Clone());
644 expected_ranges.emplace_back(check_box2->Clone(), check_box2->Clone());
645 expected_ranges.emplace_back(line1_start->Clone(), line1_middle->Clone());
646 TestRangeIterator(across_anchors_forward_range);
647 TestRangeIterator(across_anchors_backward_range);
650 line1_end->Clone(), line2_middle->Clone());
652 line2_middle->Clone(), line1_end->Clone());
653 expected_ranges.clear();
654 expected_ranges.emplace_back(line1_end->Clone(), line1_end->Clone());
655 expected_ranges.emplace_back(line_break1_start->Clone(),
656 line_break1_end->Clone());
657 expected_ranges.emplace_back(line2_start->Clone(), line2_middle->Clone());
658 TestRangeIterator(starting_at_end_position_forward_range);
659 TestRangeIterator(starting_at_end_position_backward_range);
662 line1_middle->Clone(), line2_start->Clone());
664 line2_start->Clone(), line1_middle->Clone());
665 expected_ranges.clear();
666 expected_ranges.emplace_back(line1_middle->Clone(), line1_end->Clone());
667 expected_ranges.emplace_back(line_break1_start->Clone(),
668 line_break1_end->Clone());
669 expected_ranges.emplace_back(line2_start->Clone(), line2_start->Clone());
670 TestRangeIterator(ending_at_start_position_forward_range);
671 TestRangeIterator(ending_at_start_position_backward_range);
674 GetTreeID(), root_.id, 0 );
676 GetTreeID(), root_.id, ALL_TEXT.length() ,
682 range_start->Clone());
683 expected_ranges.clear();
684 expected_ranges.emplace_back(button_start->Clone(), button_end->Clone());
685 expected_ranges.emplace_back(check_box1->Clone(), check_box1->Clone());
686 expected_ranges.emplace_back(check_box2->Clone(), check_box2->Clone());
687 expected_ranges.emplace_back(line1_start->Clone(), line1_end->Clone());
688 expected_ranges.emplace_back(line_break1_start->Clone(),
689 line_break1_end->Clone());
690 expected_ranges.emplace_back(line2_start->Clone(), line2_end->Clone());
691 expected_ranges.emplace_back(line_break2_start->Clone(),
692 line_break2_end->Clone());
693 expected_ranges.emplace_back(after_line_start->Clone(),
694 after_line_end->Clone());
695 TestRangeIterator(entire_test_forward_range);
696 TestRangeIterator(entire_test_backward_range);
699TEST_F(AXRangeTest, GetTextWithWholeObjects) {
704 GetTreeID(), root_.id, 0 );
706 GetTreeID(), root_.id, ALL_TEXT.length() ,
708 ASSERT_TRUE(
end->IsTextPosition());
710 EXPECT_EQ(ALL_TEXT, forward_range.
GetText());
712 EXPECT_EQ(ALL_TEXT, backward_range.
GetText());
716 GetTreeID(), button_.id, 0 ,
718 ASSERT_TRUE(
start->IsTextPosition());
720 GetTreeID(), button_.id, BUTTON.length() ,
722 ASSERT_TRUE(
end->IsTextPosition());
724 EXPECT_EQ(BUTTON, button_range.
GetText());
726 EXPECT_EQ(BUTTON, button_range_backward.
GetText());
730 GetTreeID(), text_field_.id, 0 ,
733 GetTreeID(), text_field_.id, TEXT_FIELD.length() ,
735 ASSERT_TRUE(
start->IsTextPosition());
736 ASSERT_TRUE(
end->IsTextPosition());
738 EXPECT_EQ(TEXT_FIELD, text_field_range.
GetText());
740 EXPECT_EQ(TEXT_FIELD, text_field_range_backward.
GetText());
744 GetTreeID(), static_text1_.id, 0 ,
746 ASSERT_TRUE(
start->IsTextPosition());
748 GetTreeID(), static_text1_.id, LINE_1.length() ,
750 ASSERT_TRUE(
end->IsTextPosition());
752 EXPECT_EQ(LINE_1, static_text1_range.
GetText());
755 EXPECT_EQ(LINE_1, static_text1_range_backward.
GetText());
759 GetTreeID(), static_text2_.id, 0 ,
761 ASSERT_TRUE(
start->IsTextPosition());
763 GetTreeID(), static_text2_.id, LINE_2.length() ,
765 ASSERT_TRUE(
end->IsTextPosition());
767 EXPECT_EQ(LINE_2, static_text2_range.
GetText());
770 EXPECT_EQ(LINE_2, static_text2_range_backward.
GetText());
773 std::u16string text_between_text1_start_and_text2_end =
774 LINE_1.substr().append(NEWLINE).append(LINE_2);
776 GetTreeID(), static_text1_.id, 0 ,
778 ASSERT_TRUE(
start->IsTextPosition());
780 GetTreeID(), static_text2_.id, LINE_2.length() ,
782 ASSERT_TRUE(
end->IsTextPosition());
784 EXPECT_EQ(text_between_text1_start_and_text2_end,
788 EXPECT_EQ(text_between_text1_start_and_text2_end,
789 static_text_range_backward.
GetText());
792 std::u16string text_up_to_text2_end =
793 BUTTON.substr(0).append(LINE_1).append(NEWLINE).append(LINE_2);
797 GetTreeID(), static_text2_.id, LINE_2.length() ,
799 ASSERT_TRUE(
end->IsTextPosition());
801 EXPECT_EQ(text_up_to_text2_end, root_to_static2_text_range.
GetText());
804 EXPECT_EQ(text_up_to_text2_end,
805 root_to_static2_text_range_backward.
GetText());
808 std::u16string text_up_to_text2_start =
809 BUTTON.substr(0).append(LINE_1).append(NEWLINE);
815 EXPECT_EQ(text_up_to_text2_start, root_to_static2_tree_range.
GetText());
818 EXPECT_EQ(text_up_to_text2_start,
819 root_to_static2_tree_range_backward.
GetText());
822TEST_F(AXRangeTest, GetTextWithTextOffsets) {
823 std::u16string most_text = BUTTON.substr(2).append(TEXT_FIELD.substr(0, 11));
827 GetTreeID(), button_.id, 2 ,
829 ASSERT_TRUE(
start->IsTextPosition());
831 GetTreeID(), static_text2_.id, 4 ,
833 ASSERT_TRUE(
end->IsTextPosition());
835 EXPECT_EQ(most_text, forward_range.
GetText());
837 EXPECT_EQ(most_text, backward_range.
GetText());
840 std::u16string text_up_to_text2_tree_start =
841 BUTTON.substr(0).append(TEXT_FIELD.substr(0, 10));
845 GetTreeID(), static_text2_.id, 3 ,
847 ASSERT_TRUE(
end->IsTextPosition());
849 EXPECT_EQ(text_up_to_text2_tree_start, root_to_static2_tree_range.
GetText());
852 EXPECT_EQ(text_up_to_text2_tree_start,
853 root_to_static2_tree_range_backward.
GetText());
856TEST_F(AXRangeTest, GetTextWithEmptyRanges) {
859 GetTreeID(), root_.id, 0 );
861 EXPECT_EQ(EMPTY, non_leaf_tree_range.
GetText());
867 EXPECT_EQ(EMPTY, leaf_empty_range.
GetText());
871 GetTreeID(), inline_box1_.id, 0 ,
874 EXPECT_EQ(EMPTY, leaf_text_no_offset.
GetText());
878 GetTreeID(), inline_box1_.id, 3 ,
881 EXPECT_EQ(EMPTY, leaf_text_offset.
GetText());
885 GetTreeID(), root_.id, 0 ,
888 EXPECT_EQ(EMPTY, non_leaf_text_no_offset.
GetText());
892 GetTreeID(), root_.id, 3 ,
895 EXPECT_EQ(EMPTY, non_leaf_text_offset.
GetText());
899 GetTreeID(), line_break1_.id, 1 ,
902 GetTreeID(), static_text2_.id, 0 ,
906 after_end->Clone(), before_start->Clone());
907 EXPECT_EQ(EMPTY, same_position_different_anchors_forward.
GetText());
909 before_start->Clone(), after_end->Clone());
910 EXPECT_EQ(EMPTY, same_position_different_anchors_backward.
GetText());
913TEST_F(AXRangeTest, GetTextAddingNewlineBetweenParagraphs) {
915 GetTreeID(), button_.id, 0 ,
918 GetTreeID(), button_.id, 6 ,
922 GetTreeID(), inline_box1_.id, 0 ,
925 GetTreeID(), inline_box1_.id, 6 ,
929 GetTreeID(), inline_box2_.id, 0 ,
932 GetTreeID(), inline_box2_.id, 6 ,
936 GetTreeID(), inline_box3_.id, 0 ,
939 GetTreeID(), inline_box3_.id, 5 ,
944 const std::u16string& expected_text,
945 const size_t expected_appended_newlines_count) {
949 std::move(range_start));
950 size_t appended_newlines_count = 0;
951 EXPECT_EQ(expected_text, forward_test_range.
GetText(
953 false, &appended_newlines_count));
954 EXPECT_EQ(expected_appended_newlines_count, appended_newlines_count);
955 EXPECT_EQ(expected_text, backward_test_range.
GetText(
957 false, &appended_newlines_count));
958 EXPECT_EQ(expected_appended_newlines_count, appended_newlines_count);
961 std::u16string button_start_to_line1_end =
962 BUTTON.substr().append(NEWLINE).append(LINE_1);
963 TestGetTextForRange(button_start->Clone(), line1_end->Clone(),
964 button_start_to_line1_end, 1);
965 std::u16string button_start_to_line1_start = BUTTON.substr().append(NEWLINE);
966 TestGetTextForRange(button_start->Clone(), line1_start->Clone(),
967 button_start_to_line1_start, 1);
968 std::u16string button_end_to_line1_end = NEWLINE.substr().append(LINE_1);
969 TestGetTextForRange(button_end->Clone(), line1_end->Clone(),
970 button_end_to_line1_end, 1);
971 std::u16string button_end_to_line1_start = NEWLINE;
972 TestGetTextForRange(button_end->Clone(), line1_start->Clone(),
973 button_end_to_line1_start, 1);
975 std::u16string line2_start_to_after_line_end =
976 LINE_2.substr().append(NEWLINE).append(AFTER_LINE);
977 TestGetTextForRange(line2_start->Clone(), after_line_end->Clone(),
978 line2_start_to_after_line_end, 0);
979 std::u16string line2_start_to_after_line_start =
980 LINE_2.substr().append(NEWLINE);
981 TestGetTextForRange(line2_start->Clone(), after_line_start->Clone(),
982 line2_start_to_after_line_start, 0);
983 std::u16string line2_end_to_after_line_end =
984 NEWLINE.substr().append(AFTER_LINE);
985 TestGetTextForRange(line2_end->Clone(), after_line_end->Clone(),
986 line2_end_to_after_line_end, 0);
987 std::u16string line2_end_to_after_line_start = NEWLINE;
988 TestGetTextForRange(line2_end->Clone(), after_line_start->Clone(),
989 line2_end_to_after_line_start, 0);
991 std::u16string all_text =
992 BUTTON.substr().append(NEWLINE).append(TEXT_FIELD).append(AFTER_LINE);
994 GetTreeID(), root_.id, 0 ,
997 GetTreeID(), root_.id, ALL_TEXT.length() ,
999 TestGetTextForRange(std::move(
start), std::move(
end), all_text, 1);
1004 GetTreeID(), inline_box1_.id, 0 ,
1007 GetTreeID(), inline_box2_.id, 6 ,
1011 EXPECT_EQ(LINE_1.substr(0, 2),
1015 EXPECT_EQ(LINE_1.substr().append(NEWLINE),
1019 EXPECT_EQ(LINE_1.substr().append(NEWLINE).append(LINE_2),
1028 const std::u16string kAllText = kListMarker1.substr()
1029 .append(kListItemContent)
1031 .append(kListMarker2)
1033 .append(kAfterList);
1071 list_marker1.
id = 4;
1072 static_text1.
id = 5;
1074 static_text2.
id = 7;
1077 list_marker2.
id = 10;
1078 static_text3.
id = 11;
1079 inline_box3.
id = 12;
1080 static_text4.
id = 13;
1081 inline_box4.
id = 14;
1084 root.child_ids = {list.
id, static_text4.
id};
1098 static_text1.
SetName(kListMarker1);
1102 inline_box1.
SetName(kListMarker1);
1105 static_text2.
SetName(kListItemContent);
1109 inline_box2.
SetName(kListItemContent);
1120 static_text3.
SetName(kListMarker2);
1124 inline_box3.
SetName(kListMarker2);
1127 static_text4.
SetName(kAfterList);
1131 inline_box4.
SetName(kAfterList);
1135 initial_state.
nodes = {
root, list, list_item1, list_marker1,
1136 static_text1, inline_box1, static_text2, inline_box2,
1137 list_item2, list_marker2, static_text3, inline_box3,
1138 static_text4, inline_box4};
1143 SetTree(std::make_unique<AXTree>(initial_state));
1146 GetTreeID(), inline_box1.
id, 0 ,
1148 ASSERT_TRUE(
start->IsTextPosition());
1150 GetTreeID(), inline_box4.
id, 10 ,
1152 ASSERT_TRUE(
end->IsTextPosition());
1162 TestAXRangeScreenRectDelegate delegate(
this);
1166 GetTreeID(), button_.id, 0 ,
1170 GetTreeID(), check_box1_.id, 0 ,
1173 GetTreeID(), check_box2_.id, 0 ,
1177 GetTreeID(), inline_box1_.id, 0 ,
1180 GetTreeID(), inline_box1_.id, 1 ,
1183 GetTreeID(), inline_box1_.id, 3 ,
1190 GetTreeID(), inline_box1_.id, 6 ,
1194 GetTreeID(), inline_box2_.id, 0 ,
1197 GetTreeID(), inline_box2_.id, 1 ,
1200 GetTreeID(), inline_box2_.id, 3 ,
1207 GetTreeID(), inline_box2_.id, 6 ,
1211 GetTreeID(), inline_box3_.id, 5 ,
1217 std::vector<gfx::Rect> expected_screen_rects = {
gfx::Rect(20, 20, 100, 30)};
1219 ContainerEQ(button_range.
GetRects(&delegate), expected_screen_rects));
1224 expected_screen_rects = {
gfx::Rect(120, 20, 30, 30)};
1226 ContainerEQ(check_box1_range.
GetRects(&delegate), expected_screen_rects));
1230 check_box2->Clone());
1231 expected_screen_rects = {
gfx::Rect(20, 20, 100, 30),
1235 expected_screen_rects));
1242 expected_screen_rects = {
gfx::Rect(20, 50, 30, 30)};
1244 expected_screen_rects));
1251 line1_middle->Clone());
1252 expected_screen_rects = {
gfx::Rect(20, 50, 15, 30)};
1254 expected_screen_rects));
1261 line1_end->Clone());
1262 expected_screen_rects = {
gfx::Rect(35, 50, 15, 30)};
1264 expected_screen_rects));
1271 line1_second_to_last_char->Clone());
1272 expected_screen_rects = {
gfx::Rect(25, 50, 20, 30)};
1274 ContainerEQ(line1_mid_range.
GetRects(&delegate), expected_screen_rects));
1281 expected_screen_rects = {
gfx::Rect(20, 80, 42, 30)};
1283 expected_screen_rects));
1290 line2_middle->Clone());
1291 expected_screen_rects = {
gfx::Rect(20, 80, 21, 30)};
1293 expected_screen_rects));
1300 line2_end->Clone());
1301 expected_screen_rects = {
gfx::Rect(41, 80, 21, 30)};
1303 expected_screen_rects));
1310 line2_second_to_last_char->Clone());
1311 expected_screen_rects = {
gfx::Rect(27, 80, 28, 30)};
1313 ContainerEQ(line2_mid_range.
GetRects(&delegate), expected_screen_rects));
1319 line2_end->Clone());
1320 expected_screen_rects = {
gfx::Rect(20, 50, 30, 30),
1323 expected_screen_rects));
1330 line2_middle->Clone());
1331 expected_screen_rects = {
gfx::Rect(35, 50, 15, 30),
1334 expected_screen_rects));
1341 line2_middle->Clone());
1342 expected_screen_rects = {
gfx::Rect(150, 20, 30, 30),
1346 expected_screen_rects));
1352 expected_screen_rects = {
1357 expected_screen_rects));
1363 AXNodeData old_root_node_data = GetRootAsAXNode()->data();
1364 AXNodeData new_root_node_data = old_root_node_data;
1366 GetRootAsAXNode()->SetData(new_root_node_data);
1368 TestAXRangeScreenRectDelegate delegate(
this);
1371 GetTreeID(), button_.id, 0 ,
1375 GetTreeID(), inline_box3_.id, 5 ,
1394 std::vector<gfx::Rect> expected_screen_rects = {
gfx::Rect(20, 50, 30, 30),
1397 expected_screen_rects));
1401 GetRootAsAXNode()->SetData(old_root_node_data);
1402 expected_screen_rects = {
1407 expected_screen_rects));
static void test_range(skiatest::Reporter *reporter)
static AXPositionInstance CreateNullPosition()
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)
AXPositionType * anchor() const
std::vector< gfx::Rect > GetRects(AXRangeRectDelegate *delegate) const
AXRange AsForwardRange() const
std::u16string GetText(AXTextConcatenationBehavior concatenation_behavior=AXTextConcatenationBehavior::kAsTextContent, int max_count=-1, bool include_ignored=false, size_t *appended_newlines_count=nullptr) const
AXPositionType * focus() const
static AXTreeID CreateNewAXTreeID()
gfx::Rect GetBoundsRect(const AXCoordinateSystem coordinate_system, const AXClippingBehavior clipping_behavior, AXOffscreenResult *offscreen_result) const
gfx::Rect GetInnerTextRangeBoundsRect(const int start_offset, const int end_offset, const AXCoordinateSystem coordinate_system, const AXClippingBehavior clipping_behavior, AXOffscreenResult *offscreen_result) const
static TestAXNodeHelper * GetOrCreate(AXTree *tree, AXNode *node)
static float min(float r, float g, float b)
std::u16string ASCIIToUTF16(std::string src)
std::unique_ptr< AXPosition< AXNodePosition, AXNode > > TestPositionInstance
AXEmbeddedObjectBehavior g_ax_embedded_object_behavior
AXRange< AXPosition< AXNodePosition, AXNode > > TestPositionRange
TEST_F(AXPositionTest, Clone)
AXRelativeBounds relative_bounds
std::vector< int32_t > child_ids
void SetName(const std::string &name)
void AddBoolAttribute(ax::mojom::BoolAttribute attribute, bool value)
std::vector< AXNodeData > nodes
#define BASE_DISALLOW_COPY_AND_ASSIGN(TypeName)
#define EXPECT_TRUE(handle)