18#include "gtest/gtest.h"
23#define TEST_SELECTION(tree_update, tree, input, expected) \
25 tree_update.has_tree_data = true; \
26 tree_update.tree_data.sel_anchor_object_id = input.anchor_id; \
27 tree_update.tree_data.sel_anchor_offset = input.anchor_offset; \
28 tree_update.tree_data.sel_focus_object_id = input.focus_id; \
29 tree_update.tree_data.sel_focus_offset = input.focus_offset; \
30 EXPECT_TRUE(tree->Unserialize(tree_update)); \
31 AXTree::Selection actual = tree->GetUnignoredSelection(); \
32 EXPECT_EQ(expected.anchor_id, actual.anchor_object_id); \
33 EXPECT_EQ(expected.anchor_offset, actual.anchor_offset); \
34 EXPECT_EQ(expected.focus_id, actual.focus_object_id); \
35 EXPECT_EQ(expected.focus_offset, actual.focus_offset); \
42std::string IntVectorToString(
const std::vector<int>& items) {
44 for (
size_t i = 0;
i < items.size(); ++
i) {
52std::string GetBoundsAsString(
const AXTree& tree, int32_t
id) {
53 AXNode* node = tree.GetFromId(
id);
59std::string GetUnclippedBoundsAsString(
const AXTree& tree, int32_t
id) {
60 AXNode* node = tree.GetFromId(
id);
66bool IsNodeOffscreen(
const AXTree& tree, int32_t
id) {
67 AXNode* node = tree.GetFromId(
id);
69 tree.GetTreeBounds(node, &
result);
73class TestAXTreeObserver :
public AXTreeObserver {
75 TestAXTreeObserver(AXTree* tree)
76 : tree_(tree), tree_data_changed_(
false), root_changed_(
false) {
77 tree_->AddObserver(
this);
79 ~TestAXTreeObserver() { tree_->RemoveObserver(
this); }
81 void OnNodeDataWillChange(AXTree* tree,
82 const AXNodeData& old_node_data,
83 const AXNodeData& new_node_data)
override {}
84 void OnNodeDataChanged(AXTree* tree,
85 const AXNodeData& old_node_data,
86 const AXNodeData& new_node_data)
override {}
87 void OnTreeDataChanged(AXTree* tree,
90 tree_data_changed_ =
true;
93 std::optional<AXNode::AXID> unignored_parent_id_before_node_deleted;
94 void OnNodeWillBeDeleted(AXTree* tree, AXNode* node)
override {
97 ASSERT_NE(
nullptr, tree->GetFromId(node->id()));
98 node_will_be_deleted_ids_.push_back(node->id());
100 if (unignored_parent_id_before_node_deleted) {
101 ASSERT_NE(
nullptr, node->GetUnignoredParent());
102 ASSERT_EQ(*unignored_parent_id_before_node_deleted,
103 node->GetUnignoredParent()->id());
107 void OnSubtreeWillBeDeleted(AXTree* tree, AXNode* node)
override {
108 subtree_deleted_ids_.push_back(node->id());
111 void OnNodeWillBeReparented(AXTree* tree, AXNode* node)
override {
112 node_will_be_reparented_ids_.push_back(node->id());
115 void OnSubtreeWillBeReparented(AXTree* tree, AXNode* node)
override {
116 subtree_will_be_reparented_ids_.push_back(node->id());
119 void OnNodeCreated(AXTree* tree, AXNode* node)
override {
120 created_ids_.push_back(node->id());
123 void OnNodeDeleted(AXTree* tree, int32_t node_id)
override {
126 ASSERT_EQ(
nullptr, tree->GetFromId(node_id));
127 deleted_ids_.push_back(node_id);
130 void OnNodeReparented(AXTree* tree, AXNode* node)
override {
131 node_reparented_ids_.push_back(node->id());
134 void OnNodeChanged(AXTree* tree, AXNode* node)
override {
135 changed_ids_.push_back(node->id());
138 void OnAtomicUpdateFinished(AXTree* tree,
140 const std::vector<Change>& changes)
override {
141 root_changed_ = root_changed;
143 for (
size_t i = 0;
i < changes.size(); ++
i) {
144 int id = changes[
i].node->id();
145 switch (changes[
i].
type) {
147 node_creation_finished_ids_.push_back(
id);
149 case SUBTREE_CREATED:
150 subtree_creation_finished_ids_.push_back(
id);
152 case NODE_REPARENTED:
153 node_reparented_finished_ids_.push_back(
id);
155 case SUBTREE_REPARENTED:
156 subtree_reparented_finished_ids_.push_back(
id);
159 change_finished_ids_.push_back(
id);
165 void OnRoleChanged(AXTree* tree,
173 void OnStateChanged(AXTree* tree,
176 bool new_value)
override {
178 "%s changed to %s",
ToString(
state), new_value ?
"true" :
"false"));
181 void OnStringAttributeChanged(AXTree* tree,
184 const std::string& old_value,
185 const std::string& new_value)
override {
186 attribute_change_log_.push_back(
188 old_value.c_str(), new_value.c_str()));
191 void OnIntAttributeChanged(AXTree* tree,
195 int32_t new_value)
override {
197 "%s changed from %d to %d",
ToString(attr), old_value, new_value));
200 void OnFloatAttributeChanged(AXTree* tree,
204 float new_value)
override {
206 "%s changed from %.1f to %.1f",
ToString(attr), old_value, new_value));
209 void OnBoolAttributeChanged(AXTree* tree,
212 bool new_value)
override {
214 "%s changed to %s",
ToString(attr), new_value ?
"true" :
"false"));
217 void OnIntListAttributeChanged(
221 const std::vector<int32_t>& old_value,
222 const std::vector<int32_t>& new_value)
override {
223 attribute_change_log_.push_back(
225 IntVectorToString(old_value).c_str(),
226 IntVectorToString(new_value).c_str()));
229 bool tree_data_changed()
const {
return tree_data_changed_; }
230 bool root_changed()
const {
return root_changed_; }
231 const std::vector<int32_t>& deleted_ids() {
return deleted_ids_; }
232 const std::vector<int32_t>& subtree_deleted_ids() {
233 return subtree_deleted_ids_;
235 const std::vector<int32_t>& created_ids() {
return created_ids_; }
236 const std::vector<int32_t>& node_creation_finished_ids() {
237 return node_creation_finished_ids_;
239 const std::vector<int32_t>& subtree_creation_finished_ids() {
240 return subtree_creation_finished_ids_;
242 const std::vector<int32_t>& node_reparented_finished_ids() {
243 return node_reparented_finished_ids_;
245 const std::vector<int32_t>& subtree_will_be_reparented_ids() {
246 return subtree_will_be_reparented_ids_;
248 const std::vector<int32_t>& node_will_be_reparented_ids() {
249 return node_will_be_reparented_ids_;
251 const std::vector<int32_t>& node_will_be_deleted_ids() {
252 return node_will_be_deleted_ids_;
254 const std::vector<int32_t>& node_reparented_ids() {
255 return node_reparented_ids_;
257 const std::vector<int32_t>& subtree_reparented_finished_ids() {
258 return subtree_reparented_finished_ids_;
260 const std::vector<int32_t>& change_finished_ids() {
261 return change_finished_ids_;
263 const std::vector<std::string>& attribute_change_log() {
264 return attribute_change_log_;
269 bool tree_data_changed_;
271 std::vector<int32_t> deleted_ids_;
272 std::vector<int32_t> subtree_deleted_ids_;
273 std::vector<int32_t> created_ids_;
274 std::vector<int32_t> changed_ids_;
275 std::vector<int32_t> subtree_will_be_reparented_ids_;
276 std::vector<int32_t> node_will_be_reparented_ids_;
277 std::vector<int32_t> node_will_be_deleted_ids_;
278 std::vector<int32_t> node_creation_finished_ids_;
279 std::vector<int32_t> subtree_creation_finished_ids_;
280 std::vector<int32_t> node_reparented_ids_;
281 std::vector<int32_t> node_reparented_finished_ids_;
282 std::vector<int32_t> subtree_reparented_finished_ids_;
283 std::vector<int32_t> change_finished_ids_;
284 std::vector<std::string> attribute_change_log_;
291#define EXPECT_OPTIONAL_EQ(expected, actual) \
292 EXPECT_TRUE(actual.has_value()); \
294 EXPECT_EQ(expected, actual.value()); \
297TEST(AXTreeTest, SerializeAXTreeUpdate) {
319 update.nodes.push_back(list);
320 update.nodes.push_back(list_item_2);
321 update.nodes.push_back(list_item_3);
322 update.nodes.push_back(button);
325 "AXTreeUpdate: root id 3\n"
326 "id=3 list (0, 0)-(0, 0) child_ids=4,5,6\n"
327 " id=5 listItem (0, 0)-(0, 0)\n"
328 " id=6 listItem (0, 0)-(0, 0)\n"
329 "id=7 button (0, 0)-(0, 0)\n",
333TEST(AXTreeTest, LeaveOrphanedDeletedSubtreeFails) {
336 initial_state.
nodes.resize(3);
337 initial_state.
nodes[0].id = 1;
338 initial_state.
nodes[0].child_ids.push_back(2);
339 initial_state.
nodes[0].child_ids.push_back(3);
340 initial_state.
nodes[1].id = 2;
341 initial_state.
nodes[2].id = 3;
342 AXTree tree(initial_state);
347 update.node_id_to_clear = 2;
351 ASSERT_EQ(
"Nodes left pending by the update: 2", tree.
error());
354TEST(AXTreeTest, LeaveOrphanedNewChildFails) {
357 initial_state.
nodes.resize(1);
358 initial_state.
nodes[0].id = 1;
359 AXTree tree(initial_state);
366 update.nodes[0].child_ids.push_back(2);
368 ASSERT_EQ(
"Nodes left pending by the update: 2", tree.
error());
371TEST(AXTreeTest, DuplicateChildIdFails) {
374 initial_state.
nodes.resize(1);
375 initial_state.
nodes[0].id = 1;
376 AXTree tree(initial_state);
382 update.nodes[0].child_ids.push_back(2);
383 update.nodes[0].child_ids.push_back(2);
386 ASSERT_EQ(
"Node 1 has duplicate child id 2", tree.
error());
389TEST(AXTreeTest, InvalidReparentingFails) {
392 initial_state.
nodes.resize(3);
393 initial_state.
nodes[0].id = 1;
394 initial_state.
nodes[0].child_ids.push_back(2);
395 initial_state.
nodes[1].id = 2;
396 initial_state.
nodes[1].child_ids.push_back(3);
397 initial_state.
nodes[2].id = 3;
399 AXTree tree(initial_state);
406 update.nodes[0].child_ids.push_back(3);
407 update.nodes[0].child_ids.push_back(2);
411 ASSERT_EQ(
"Node 3 is not marked for destruction, would be reparented to 1",
415TEST(AXTreeTest, NoReparentingOfRootIfNoNewRoot) {
423 root.child_ids = {child1.
id};
428 initial_state.
nodes = {
root, child1, child2};
430 AXTree tree(initial_state);
434 root.child_ids = {child1.
id, child2.
id};
442 TestAXTreeObserver test_observer(&tree);
445 EXPECT_EQ(0
U, test_observer.deleted_ids().size());
446 EXPECT_EQ(0
U, test_observer.subtree_deleted_ids().size());
447 EXPECT_EQ(0
U, test_observer.created_ids().size());
449 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
450 EXPECT_EQ(0
U, test_observer.subtree_creation_finished_ids().size());
451 EXPECT_EQ(0
U, test_observer.node_reparented_finished_ids().size());
453 ASSERT_EQ(2U, test_observer.subtree_reparented_finished_ids().size());
454 EXPECT_EQ(child1.
id, test_observer.subtree_reparented_finished_ids()[0]);
455 EXPECT_EQ(child2.
id, test_observer.subtree_reparented_finished_ids()[1]);
457 ASSERT_EQ(1U, test_observer.change_finished_ids().size());
458 EXPECT_EQ(
root.id, test_observer.change_finished_ids()[0]);
460 EXPECT_FALSE(test_observer.root_changed());
461 EXPECT_FALSE(test_observer.tree_data_changed());
464TEST(AXTreeTest, NoReparentingIfOnlyRemovedAndChangedNotReAdded) {
472 root.child_ids = {child1.
id};
477 initial_state.
nodes = {
root, child1, child2};
479 AXTree tree(initial_state);
489 TestAXTreeObserver test_observer(&tree);
492 EXPECT_EQ(2U, test_observer.deleted_ids().size());
493 EXPECT_EQ(2U, test_observer.subtree_deleted_ids().size());
494 EXPECT_EQ(0
U, test_observer.created_ids().size());
496 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
497 EXPECT_EQ(0
U, test_observer.subtree_creation_finished_ids().size());
498 EXPECT_EQ(0
U, test_observer.node_will_be_reparented_ids().size());
499 EXPECT_EQ(2U, test_observer.node_will_be_deleted_ids().size());
500 EXPECT_EQ(0
U, test_observer.subtree_will_be_reparented_ids().size());
501 EXPECT_EQ(0
U, test_observer.node_reparented_ids().size());
502 EXPECT_EQ(0
U, test_observer.node_reparented_finished_ids().size());
503 EXPECT_EQ(0
U, test_observer.subtree_reparented_finished_ids().size());
505 EXPECT_FALSE(test_observer.root_changed());
506 EXPECT_FALSE(test_observer.tree_data_changed());
512TEST(AXTreeTest, NoReparentingIfRemovedMultipleTimesAndNotInFinalTree) {
515 initial_state.
nodes.resize(4);
516 initial_state.
nodes[0].id = 1;
517 initial_state.
nodes[0].child_ids = {2, 4};
518 initial_state.
nodes[1].id = 2;
519 initial_state.
nodes[1].child_ids = {3};
520 initial_state.
nodes[2].id = 3;
521 initial_state.
nodes[3].id = 4;
523 AXTree tree(initial_state);
531 update.nodes[1].child_ids = {3};
536 TestAXTreeObserver test_observer(&tree);
539 EXPECT_EQ(1U, test_observer.deleted_ids().size());
540 EXPECT_EQ(1U, test_observer.subtree_deleted_ids().size());
541 EXPECT_EQ(0
U, test_observer.created_ids().size());
543 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
544 EXPECT_EQ(0
U, test_observer.subtree_creation_finished_ids().size());
545 EXPECT_EQ(0
U, test_observer.node_will_be_reparented_ids().size());
546 EXPECT_EQ(1U, test_observer.node_will_be_deleted_ids().size());
547 EXPECT_EQ(0
U, test_observer.subtree_will_be_reparented_ids().size());
548 EXPECT_EQ(0
U, test_observer.node_reparented_ids().size());
549 EXPECT_EQ(0
U, test_observer.node_reparented_finished_ids().size());
550 EXPECT_EQ(0
U, test_observer.subtree_reparented_finished_ids().size());
552 EXPECT_FALSE(test_observer.root_changed());
553 EXPECT_FALSE(test_observer.tree_data_changed());
559TEST(AXTreeTest, ReparentIfRemovedMultipleTimesButExistsInFinalTree) {
562 initial_state.
nodes.resize(4);
563 initial_state.
nodes[0].id = 1;
564 initial_state.
nodes[0].child_ids = {2, 4};
565 initial_state.
nodes[1].id = 2;
566 initial_state.
nodes[1].child_ids = {3};
567 initial_state.
nodes[2].id = 3;
568 initial_state.
nodes[3].id = 4;
570 AXTree tree(initial_state);
578 update.nodes[1].child_ids = {3};
584 update.nodes[4].child_ids = {3};
587 TestAXTreeObserver test_observer(&tree);
590 EXPECT_EQ(0
U, test_observer.deleted_ids().size());
591 EXPECT_EQ(0
U, test_observer.subtree_deleted_ids().size());
592 EXPECT_EQ(0
U, test_observer.created_ids().size());
594 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
595 EXPECT_EQ(0
U, test_observer.subtree_creation_finished_ids().size());
596 EXPECT_EQ(1U, test_observer.node_will_be_reparented_ids().size());
597 EXPECT_EQ(0
U, test_observer.node_will_be_deleted_ids().size());
598 EXPECT_EQ(1U, test_observer.subtree_will_be_reparented_ids().size());
599 EXPECT_EQ(1U, test_observer.node_reparented_ids().size());
600 EXPECT_EQ(0
U, test_observer.node_reparented_finished_ids().size());
601 EXPECT_EQ(1U, test_observer.subtree_reparented_finished_ids().size());
603 EXPECT_FALSE(test_observer.root_changed());
604 EXPECT_FALSE(test_observer.tree_data_changed());
607TEST(AXTreeTest, ReparentRootIfRootChanged) {
615 root.child_ids = {child1.
id};
620 initial_state.
nodes = {
root, child1, child2};
622 AXTree tree(initial_state);
633 update.nodes = {root2, child1, child2};
635 TestAXTreeObserver test_observer(&tree);
638 ASSERT_EQ(1U, test_observer.deleted_ids().size());
639 EXPECT_EQ(
root.id, test_observer.deleted_ids()[0]);
641 ASSERT_EQ(1U, test_observer.subtree_deleted_ids().size());
642 EXPECT_EQ(
root.id, test_observer.subtree_deleted_ids()[0]);
644 ASSERT_EQ(1U, test_observer.created_ids().size());
645 EXPECT_EQ(root2.
id, test_observer.created_ids()[0]);
647 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
649 ASSERT_EQ(1U, test_observer.subtree_creation_finished_ids().size());
650 EXPECT_EQ(root2.
id, test_observer.subtree_creation_finished_ids()[0]);
652 ASSERT_EQ(2U, test_observer.node_reparented_finished_ids().size());
653 EXPECT_EQ(child1.
id, test_observer.node_reparented_finished_ids()[0]);
654 EXPECT_EQ(child2.
id, test_observer.node_reparented_finished_ids()[1]);
656 EXPECT_EQ(0
U, test_observer.subtree_reparented_finished_ids().size());
658 EXPECT_EQ(0
U, test_observer.change_finished_ids().size());
661 EXPECT_FALSE(test_observer.tree_data_changed());
664TEST(AXTreeTest, ImplicitChildrenDelete) {
675 initial_state.
nodes.resize(3);
676 initial_state.
nodes[0].id = 1;
677 initial_state.
nodes[0].child_ids.resize(2);
678 initial_state.
nodes[0].child_ids[0] = 2;
679 initial_state.
nodes[0].child_ids[1] = 3;
680 initial_state.
nodes[1].id = 2;
681 initial_state.
nodes[2].id = 3;
682 AXTree tree(initial_state);
702TEST(AXTreeTest, IndexInParentAfterReorder) {
713 initial_state.
nodes.resize(4);
714 initial_state.
nodes[0].id = 1;
715 initial_state.
nodes[0].child_ids.resize(3);
716 initial_state.
nodes[0].child_ids[0] = 2;
717 initial_state.
nodes[0].child_ids[1] = 3;
718 initial_state.
nodes[0].child_ids[2] = 4;
719 initial_state.
nodes[1].id = 2;
720 initial_state.
nodes[2].id = 3;
721 initial_state.
nodes[3].id = 4;
722 AXTree tree(initial_state);
734 update.nodes[0].child_ids.resize(3);
735 update.nodes[0].child_ids[0] = 4;
736 update.nodes[0].child_ids[1] = 3;
737 update.nodes[0].child_ids[2] = 2;
750TEST(AXTreeTest, IndexInParentAfterReorderIgnoredNode) {
762 initial_state.
nodes.resize(6);
763 initial_state.
nodes[0].id = 1;
764 initial_state.
nodes[0].child_ids.resize(3);
765 initial_state.
nodes[0].child_ids[0] = 2;
766 initial_state.
nodes[0].child_ids[1] = 3;
767 initial_state.
nodes[0].child_ids[2] = 4;
768 initial_state.
nodes[1].id = 2;
769 initial_state.
nodes[2].id = 3;
771 initial_state.
nodes[2].child_ids.resize(2);
772 initial_state.
nodes[2].child_ids[0] = 5;
773 initial_state.
nodes[2].child_ids[1] = 6;
774 initial_state.
nodes[3].id = 4;
775 initial_state.
nodes[4].id = 5;
776 initial_state.
nodes[5].id = 6;
777 AXTree tree(initial_state);
792 update.nodes[0].child_ids.resize(3);
793 update.nodes[0].child_ids[0] = 3;
794 update.nodes[0].child_ids[1] = 2;
795 update.nodes[0].child_ids[2] = 4;
799 update.nodes[2].child_ids.resize(2);
800 update.nodes[2].child_ids[0] = 5;
801 update.nodes[2].child_ids[1] = 6;
814TEST(AXTreeTest, ImplicitAttributeDelete) {
821 initial_state.
nodes.resize(1);
822 initial_state.
nodes[0].id = 1;
823 initial_state.
nodes[0].SetName(
"Node 1 name");
824 AXTree tree(initial_state);
844TEST(AXTreeTest, TreeObserverIsCalled) {
847 initial_state.
nodes.resize(2);
848 initial_state.
nodes[0].id = 1;
849 initial_state.
nodes[0].child_ids.push_back(2);
850 initial_state.
nodes[1].id = 2;
852 AXTree tree(initial_state);
855 update.node_id_to_clear = 1;
858 update.nodes[0].child_ids.push_back(4);
861 TestAXTreeObserver test_observer(&tree);
864 ASSERT_EQ(2U, test_observer.deleted_ids().size());
865 EXPECT_EQ(1, test_observer.deleted_ids()[0]);
866 EXPECT_EQ(2, test_observer.deleted_ids()[1]);
868 ASSERT_EQ(1U, test_observer.subtree_deleted_ids().size());
869 EXPECT_EQ(1, test_observer.subtree_deleted_ids()[0]);
871 ASSERT_EQ(2U, test_observer.created_ids().size());
872 EXPECT_EQ(3, test_observer.created_ids()[0]);
873 EXPECT_EQ(4, test_observer.created_ids()[1]);
875 ASSERT_EQ(1U, test_observer.subtree_creation_finished_ids().size());
876 EXPECT_EQ(3, test_observer.subtree_creation_finished_ids()[0]);
878 ASSERT_EQ(1U, test_observer.node_creation_finished_ids().size());
879 EXPECT_EQ(4, test_observer.node_creation_finished_ids()[0]);
881 ASSERT_TRUE(test_observer.root_changed());
884TEST(AXTreeTest, TreeObserverIsCalledForTreeDataChanges) {
887 initial_state.
nodes.resize(1);
888 initial_state.
nodes[0].id = 1;
891 AXTree tree(initial_state);
893 TestAXTreeObserver test_observer(&tree);
898 EXPECT_FALSE(test_observer.tree_data_changed());
906 EXPECT_FALSE(test_observer.tree_data_changed());
915 EXPECT_EQ(
"New Title", tree.
data().
title);
918TEST(AXTreeTest, ReparentingDoesNotTriggerNodeCreated) {
921 initial_state.
nodes.resize(3);
922 initial_state.
nodes[0].id = 1;
923 initial_state.
nodes[0].child_ids.push_back(2);
924 initial_state.
nodes[1].id = 2;
925 initial_state.
nodes[1].child_ids.push_back(3);
926 initial_state.
nodes[2].id = 3;
928 AXTree tree(initial_state);
929 TestAXTreeObserver test_observer(&tree);
933 update.node_id_to_clear = 2;
936 update.nodes[0].child_ids.push_back(3);
939 std::vector<int> created = test_observer.node_creation_finished_ids();
940 std::vector<int> subtree_reparented =
941 test_observer.subtree_reparented_finished_ids();
942 std::vector<int> node_reparented =
943 test_observer.node_reparented_finished_ids();
949TEST(AXTreeTest, MultipleIgnoredChangesDoesNotBreakCache) {
952 initial_state.
nodes.resize(3);
953 initial_state.
nodes[0].id = 1;
954 initial_state.
nodes[0].child_ids.push_back(2);
956 initial_state.
nodes[1].id = 2;
958 initial_state.
nodes[1].child_ids.push_back(3);
960 initial_state.
nodes[2].id = 3;
962 AXTree tree(initial_state);
963 TestAXTreeObserver test_observer(&tree);
972 update.nodes[1].child_ids.push_back(3);
980TEST(AXTreeTest, NodeToClearUpdatesParentUnignoredCount) {
983 initial_state.
nodes.resize(4);
984 initial_state.
nodes[0].id = 1;
985 initial_state.
nodes[0].child_ids.push_back(2);
986 initial_state.
nodes[1].id = 2;
988 initial_state.
nodes[1].child_ids.push_back(3);
989 initial_state.
nodes[1].child_ids.push_back(4);
990 initial_state.
nodes[2].id = 3;
991 initial_state.
nodes[3].id = 4;
993 AXTree tree(initial_state);
999 update.node_id_to_clear = 2;
1002 update.nodes[0].state = 0;
1003 update.nodes[0].child_ids.resize(0);
1009TEST(AXTreeTest, TreeObserverIsNotCalledForReparenting) {
1012 initial_state.
nodes.resize(2);
1013 initial_state.
nodes[0].id = 1;
1014 initial_state.
nodes[0].child_ids.push_back(2);
1015 initial_state.
nodes[1].id = 2;
1017 AXTree tree(initial_state);
1019 update.node_id_to_clear = 1;
1023 update.nodes[0].child_ids.push_back(4);
1026 TestAXTreeObserver test_observer(&tree);
1030 ASSERT_EQ(1U, test_observer.deleted_ids().size());
1031 EXPECT_EQ(1, test_observer.deleted_ids()[0]);
1033 ASSERT_EQ(1U, test_observer.subtree_deleted_ids().size());
1034 EXPECT_EQ(1, test_observer.subtree_deleted_ids()[0]);
1036 ASSERT_EQ(1U, test_observer.created_ids().size());
1037 EXPECT_EQ(4, test_observer.created_ids()[0]);
1039 ASSERT_EQ(1U, test_observer.subtree_creation_finished_ids().size());
1040 EXPECT_EQ(4, test_observer.subtree_creation_finished_ids()[0]);
1042 ASSERT_EQ(1U, test_observer.subtree_reparented_finished_ids().size());
1043 EXPECT_EQ(2, test_observer.subtree_reparented_finished_ids()[0]);
1045 EXPECT_EQ(0
U, test_observer.node_creation_finished_ids().size());
1046 EXPECT_EQ(0
U, test_observer.node_reparented_finished_ids().size());
1048 ASSERT_TRUE(test_observer.root_changed());
1056 initial_state.
nodes.push_back(node);
1057 initial_state.
nodes.push_back(node);
1067 initial_state.
nodes.push_back(node);
1072 initial_state.
nodes.push_back(node2);
1083 initial_state.
nodes.push_back(node);
1089 initial_state.
nodes.push_back(node2);
1095TEST(AXTreeTest, RoleAndStateChangeCallbacks) {
1098 initial_state.
nodes.resize(1);
1099 initial_state.
nodes[0].id = 1;
1103 AXTree tree(initial_state);
1105 TestAXTreeObserver test_observer(&tree);
1118 const std::vector<std::string>& change_log =
1119 test_observer.attribute_change_log();
1120 ASSERT_EQ(3U, change_log.size());
1121 EXPECT_EQ(
"Role changed from button to checkBox", change_log[0]);
1122 EXPECT_EQ(
"visited changed to true", change_log[1]);
1123 EXPECT_EQ(
"checkedState changed from 2 to 1", change_log[2]);
1126TEST(AXTreeTest, AttributeChangeCallbacks) {
1129 initial_state.
nodes.resize(1);
1130 initial_state.
nodes[0].id = 1;
1133 initial_state.
nodes[0].AddStringAttribute(
1139 initial_state.
nodes[0].AddFloatAttribute(
1141 initial_state.
nodes[0].AddFloatAttribute(
1143 initial_state.
nodes[0].AddFloatAttribute(
1148 AXTree tree(initial_state);
1150 TestAXTreeObserver test_observer(&tree);
1155 update0.
nodes.resize(1);
1156 update0.
nodes[0].id = 1;
1163 update0.
nodes[0].AddFloatAttribute(
1165 update0.
nodes[0].AddFloatAttribute(
1167 update0.
nodes[0].AddFloatAttribute(
1173 const std::vector<std::string>& change_log =
1174 test_observer.attribute_change_log();
1175 ASSERT_EQ(9U, change_log.size());
1176 EXPECT_EQ(
"name changed from N1 to N2", change_log[0]);
1177 EXPECT_EQ(
"description changed from D1 to D2", change_log[1]);
1178 EXPECT_EQ(
"liveAtomic changed to false", change_log[2]);
1179 EXPECT_EQ(
"busy changed to true", change_log[3]);
1180 EXPECT_EQ(
"minValueForRange changed from 1.0 to 2.0", change_log[4]);
1181 EXPECT_EQ(
"maxValueForRange changed from 10.0 to 9.0", change_log[5]);
1182 EXPECT_EQ(
"stepValueForRange changed from 3.0 to 0.5", change_log[6]);
1183 EXPECT_EQ(
"scrollX changed from 5 to 6", change_log[7]);
1184 EXPECT_EQ(
"scrollXMin changed from 1 to 2", change_log[8]);
1186 TestAXTreeObserver test_observer2(&tree);
1191 update1.
nodes.resize(1);
1192 update1.
nodes[0].id = 1;
1199 update1.
nodes[0].AddFloatAttribute(
1205 const std::vector<std::string>& change_log2 =
1206 test_observer2.attribute_change_log();
1207 ASSERT_EQ(11U, change_log2.size());
1208 EXPECT_EQ(
"name changed from N2 to ", change_log2[0]);
1209 EXPECT_EQ(
"description changed from D2 to D3", change_log2[1]);
1210 EXPECT_EQ(
"value changed from to V3", change_log2[2]);
1211 EXPECT_EQ(
"busy changed to false", change_log2[3]);
1212 EXPECT_EQ(
"modal changed to true", change_log2[4]);
1213 EXPECT_EQ(
"minValueForRange changed from 2.0 to 0.0", change_log2[5]);
1214 EXPECT_EQ(
"stepValueForRange changed from 3.0 to 0.5", change_log[6]);
1215 EXPECT_EQ(
"valueForRange changed from 0.0 to 5.0", change_log2[7]);
1216 EXPECT_EQ(
"scrollXMin changed from 2 to 0", change_log2[8]);
1217 EXPECT_EQ(
"scrollX changed from 6 to 7", change_log2[9]);
1218 EXPECT_EQ(
"scrollXMax changed from 0 to 10", change_log2[10]);
1221TEST(AXTreeTest, IntListChangeCallbacks) {
1222 std::vector<int32_t> one;
1225 std::vector<int32_t>
two;
1229 std::vector<int32_t> three;
1234 initial_state.
nodes.resize(1);
1235 initial_state.
nodes[0].id = 1;
1236 initial_state.
nodes[0].AddIntListAttribute(
1238 initial_state.
nodes[0].AddIntListAttribute(
1240 AXTree tree(initial_state);
1242 TestAXTreeObserver test_observer(&tree);
1247 update0.
nodes.resize(1);
1248 update0.
nodes[0].id = 1;
1249 update0.
nodes[0].AddIntListAttribute(
1251 update0.
nodes[0].AddIntListAttribute(
1255 const std::vector<std::string>& change_log =
1256 test_observer.attribute_change_log();
1257 ASSERT_EQ(2U, change_log.size());
1258 EXPECT_EQ(
"controlsIds changed from 1 to 2,2", change_log[0]);
1259 EXPECT_EQ(
"radioGroupIds changed from 2,2 to 3", change_log[1]);
1261 TestAXTreeObserver test_observer2(&tree);
1266 update1.
nodes.resize(1);
1267 update1.
nodes[0].id = 1;
1268 update1.
nodes[0].AddIntListAttribute(
1274 const std::vector<std::string>& change_log2 =
1275 test_observer2.attribute_change_log();
1276 ASSERT_EQ(3U, change_log2.size());
1277 EXPECT_EQ(
"controlsIds changed from 2,2 to ", change_log2[0]);
1278 EXPECT_EQ(
"radioGroupIds changed from 3 to 2,2", change_log2[1]);
1279 EXPECT_EQ(
"flowtoIds changed from to 3", change_log2[2]);
1287 tree_update.
nodes.resize(2);
1288 tree_update.
nodes[0].id = 1;
1289 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1290 tree_update.
nodes[0].child_ids.push_back(2);
1291 tree_update.
nodes[1].id = 2;
1292 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(100, 10, 400, 300);
1293 AXTree tree(tree_update);
1295 EXPECT_EQ(
"(0, 0) size (800 x 600)", GetBoundsAsString(tree, 1));
1296 EXPECT_EQ(
"(100, 10) size (400 x 300)", GetBoundsAsString(tree, 2));
1301TEST(AXTreeTest, EmptyNodeBoundsIsUnionOfChildren) {
1304 tree_update.
nodes.resize(4);
1305 tree_update.
nodes[0].id = 1;
1306 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1307 tree_update.
nodes[0].child_ids.push_back(2);
1308 tree_update.
nodes[1].id = 2;
1309 tree_update.
nodes[1].relative_bounds.bounds =
1311 tree_update.
nodes[1].child_ids.push_back(3);
1312 tree_update.
nodes[1].child_ids.push_back(4);
1313 tree_update.
nodes[2].id = 3;
1314 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(100, 10, 400, 20);
1315 tree_update.
nodes[3].id = 4;
1316 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(200, 30, 400, 20);
1318 AXTree tree(tree_update);
1319 EXPECT_EQ(
"(100, 10) size (500 x 40)", GetBoundsAsString(tree, 2));
1324TEST(AXTreeTest, EmptyNodeNotOffscreenEvenIfAllChildrenOffscreen) {
1327 tree_update.
nodes.resize(4);
1328 tree_update.
nodes[0].id = 1;
1329 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1331 tree_update.
nodes[0].AddBoolAttribute(
1333 tree_update.
nodes[0].child_ids.push_back(2);
1334 tree_update.
nodes[1].id = 2;
1335 tree_update.
nodes[1].relative_bounds.bounds =
1337 tree_update.
nodes[1].child_ids.push_back(3);
1338 tree_update.
nodes[1].child_ids.push_back(4);
1340 tree_update.
nodes[2].id = 3;
1341 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(900, 10, 400, 20);
1342 tree_update.
nodes[3].id = 4;
1343 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(1000, 30, 400, 20);
1345 AXTree tree(tree_update);
1346 EXPECT_FALSE(IsNodeOffscreen(tree, 2));
1352TEST(AXTreeTest, GetBoundsWithTransform) {
1355 tree_update.
nodes.resize(3);
1356 tree_update.
nodes[0].id = 1;
1357 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 400, 300);
1358 tree_update.
nodes[0].relative_bounds.transform =
1359 std::make_unique<gfx::Transform>();
1360 tree_update.
nodes[0].relative_bounds.transform->Scale(2.0, 2.0);
1361 tree_update.
nodes[0].child_ids.push_back(2);
1362 tree_update.
nodes[0].child_ids.push_back(3);
1363 tree_update.
nodes[1].id = 2;
1364 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(20, 10, 50, 5);
1365 tree_update.
nodes[2].id = 3;
1366 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(20, 30, 50, 5);
1367 tree_update.
nodes[2].relative_bounds.transform =
1368 std::make_unique<gfx::Transform>();
1369 tree_update.
nodes[2].relative_bounds.transform->Scale(2.0, 2.0);
1371 AXTree tree(tree_update);
1372 EXPECT_EQ(
"(0, 0) size (800 x 600)", GetBoundsAsString(tree, 1));
1373 EXPECT_EQ(
"(40, 20) size (100 x 10)", GetBoundsAsString(tree, 2));
1374 EXPECT_EQ(
"(80, 120) size (200 x 20)", GetBoundsAsString(tree, 3));
1379TEST(AXTreeTest, GetBoundsWithContainerId) {
1382 tree_update.
nodes.resize(4);
1383 tree_update.
nodes[0].id = 1;
1384 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1385 tree_update.
nodes[0].child_ids.push_back(2);
1386 tree_update.
nodes[1].id = 2;
1387 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(100, 50, 600, 500);
1388 tree_update.
nodes[1].child_ids.push_back(3);
1389 tree_update.
nodes[1].child_ids.push_back(4);
1390 tree_update.
nodes[2].id = 3;
1391 tree_update.
nodes[2].relative_bounds.offset_container_id = 2;
1392 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(20, 30, 50, 5);
1393 tree_update.
nodes[3].id = 4;
1394 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(20, 30, 50, 5);
1396 AXTree tree(tree_update);
1397 EXPECT_EQ(
"(120, 80) size (50 x 5)", GetBoundsAsString(tree, 3));
1398 EXPECT_EQ(
"(20, 30) size (50 x 5)", GetBoundsAsString(tree, 4));
1403TEST(AXTreeTest, GetBoundsWithScrolling) {
1406 tree_update.
nodes.resize(3);
1407 tree_update.
nodes[0].id = 1;
1408 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1409 tree_update.
nodes[0].child_ids.push_back(2);
1410 tree_update.
nodes[1].id = 2;
1411 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(100, 50, 600, 500);
1414 tree_update.
nodes[1].child_ids.push_back(3);
1415 tree_update.
nodes[2].id = 3;
1416 tree_update.
nodes[2].relative_bounds.offset_container_id = 2;
1417 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(20, 30, 50, 5);
1419 AXTree tree(tree_update);
1420 EXPECT_EQ(
"(115, 70) size (50 x 5)", GetBoundsAsString(tree, 3));
1424TEST(AXTreeTest, GetBoundsOfNodeWithZeroSize) {
1427 tree_update.
nodes.resize(5);
1428 tree_update.
nodes[0].id = 1;
1429 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1430 tree_update.
nodes[0].child_ids = {2};
1431 tree_update.
nodes[1].id = 2;
1432 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(100, 100, 300, 200);
1433 tree_update.
nodes[1].child_ids = {3, 4, 5};
1436 tree_update.
nodes[2].id = 3;
1437 tree_update.
nodes[2].relative_bounds.offset_container_id = 2;
1441 tree_update.
nodes[3].id = 4;
1442 tree_update.
nodes[3].relative_bounds.offset_container_id = 2;
1443 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(20, 20, 0, 0);
1446 tree_update.
nodes[4].id = 5;
1447 tree_update.
nodes[4].relative_bounds.bounds =
gfx::RectF(120, 120, 0, 0);
1449 AXTree tree(tree_update);
1450 EXPECT_EQ(
"(100, 100) size (300 x 200)", GetBoundsAsString(tree, 3));
1451 EXPECT_EQ(
"(120, 120) size (280 x 180)", GetBoundsAsString(tree, 4));
1452 EXPECT_EQ(
"(120, 120) size (280 x 180)", GetBoundsAsString(tree, 5));
1455TEST(AXTreeTest, GetBoundsEmptyBoundsInheritsFromParent) {
1458 tree_update.
nodes.resize(3);
1459 tree_update.
nodes[0].id = 1;
1460 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1461 tree_update.
nodes[1].AddBoolAttribute(
1463 tree_update.
nodes[0].child_ids.push_back(2);
1464 tree_update.
nodes[1].id = 2;
1465 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(300, 200, 100, 100);
1466 tree_update.
nodes[1].child_ids.push_back(3);
1467 tree_update.
nodes[2].id = 3;
1470 AXTree tree(tree_update);
1471 EXPECT_EQ(
"(0, 0) size (800 x 600)", GetBoundsAsString(tree, 1));
1472 EXPECT_EQ(
"(300, 200) size (100 x 100)", GetBoundsAsString(tree, 2));
1473 EXPECT_EQ(
"(300, 200) size (100 x 100)", GetBoundsAsString(tree, 3));
1474 EXPECT_EQ(
"(0, 0) size (800 x 600)", GetUnclippedBoundsAsString(tree, 1));
1475 EXPECT_EQ(
"(300, 200) size (100 x 100)", GetUnclippedBoundsAsString(tree, 2));
1476 EXPECT_EQ(
"(300, 200) size (100 x 100)", GetUnclippedBoundsAsString(tree, 3));
1477 EXPECT_FALSE(IsNodeOffscreen(tree, 1));
1478 EXPECT_FALSE(IsNodeOffscreen(tree, 2));
1482TEST(AXTreeTest, GetBoundsCropsChildToRoot) {
1485 tree_update.
nodes.resize(5);
1486 tree_update.
nodes[0].id = 1;
1487 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1488 tree_update.
nodes[0].AddBoolAttribute(
1490 tree_update.
nodes[0].child_ids.push_back(2);
1491 tree_update.
nodes[0].child_ids.push_back(3);
1492 tree_update.
nodes[0].child_ids.push_back(4);
1493 tree_update.
nodes[0].child_ids.push_back(5);
1495 tree_update.
nodes[1].id = 2;
1496 tree_update.
nodes[1].relative_bounds.bounds =
1499 tree_update.
nodes[2].id = 3;
1500 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(700, 500, 150, 150);
1502 tree_update.
nodes[3].id = 4;
1503 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(50, -200, 150, 150);
1505 tree_update.
nodes[4].id = 5;
1506 tree_update.
nodes[4].relative_bounds.bounds =
gfx::RectF(50, 700, 150, 150);
1508 AXTree tree(tree_update);
1509 EXPECT_EQ(
"(0, 0) size (50 x 50)", GetBoundsAsString(tree, 2));
1510 EXPECT_EQ(
"(700, 500) size (100 x 100)", GetBoundsAsString(tree, 3));
1511 EXPECT_EQ(
"(50, 0) size (150 x 1)", GetBoundsAsString(tree, 4));
1512 EXPECT_EQ(
"(50, 599) size (150 x 1)", GetBoundsAsString(tree, 5));
1515 EXPECT_EQ(
"(-100, -100) size (150 x 150)",
1516 GetUnclippedBoundsAsString(tree, 2));
1517 EXPECT_EQ(
"(700, 500) size (150 x 150)", GetUnclippedBoundsAsString(tree, 3));
1518 EXPECT_EQ(
"(50, -200) size (150 x 150)", GetUnclippedBoundsAsString(tree, 4));
1519 EXPECT_EQ(
"(50, 700) size (150 x 150)", GetUnclippedBoundsAsString(tree, 5));
1522TEST(AXTreeTest, GetBoundsSetsOffscreenIfClipsChildren) {
1525 tree_update.
nodes.resize(5);
1526 tree_update.
nodes[0].id = 1;
1527 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1528 tree_update.
nodes[0].AddBoolAttribute(
1530 tree_update.
nodes[0].child_ids.push_back(2);
1531 tree_update.
nodes[0].child_ids.push_back(3);
1533 tree_update.
nodes[1].id = 2;
1534 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(0, 0, 200, 200);
1535 tree_update.
nodes[1].AddBoolAttribute(
1537 tree_update.
nodes[1].child_ids.push_back(4);
1539 tree_update.
nodes[2].id = 3;
1540 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(0, 0, 200, 200);
1541 tree_update.
nodes[2].child_ids.push_back(5);
1544 tree_update.
nodes[3].id = 4;
1545 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(250, 250, 100, 100);
1546 tree_update.
nodes[3].relative_bounds.offset_container_id = 2;
1550 tree_update.
nodes[4].id = 5;
1551 tree_update.
nodes[4].relative_bounds.bounds =
gfx::RectF(250, 250, 100, 100);
1552 tree_update.
nodes[4].relative_bounds.offset_container_id = 3;
1554 AXTree tree(tree_update);
1556 EXPECT_FALSE(IsNodeOffscreen(tree, 5));
1559TEST(AXTreeTest, GetBoundsUpdatesOffscreen) {
1562 tree_update.
nodes.resize(5);
1563 tree_update.
nodes[0].id = 1;
1564 tree_update.
nodes[0].relative_bounds.bounds =
gfx::RectF(0, 0, 800, 600);
1566 tree_update.
nodes[0].AddBoolAttribute(
1568 tree_update.
nodes[0].child_ids.push_back(2);
1569 tree_update.
nodes[0].child_ids.push_back(3);
1570 tree_update.
nodes[0].child_ids.push_back(4);
1571 tree_update.
nodes[0].child_ids.push_back(5);
1573 tree_update.
nodes[1].id = 2;
1574 tree_update.
nodes[1].relative_bounds.bounds =
gfx::RectF(10, 10, 150, 150);
1576 tree_update.
nodes[2].id = 3;
1577 tree_update.
nodes[2].relative_bounds.bounds =
gfx::RectF(700, 500, 150, 150);
1579 tree_update.
nodes[3].id = 4;
1580 tree_update.
nodes[3].relative_bounds.bounds =
gfx::RectF(50, -200, 150, 150);
1582 tree_update.
nodes[4].id = 5;
1583 tree_update.
nodes[4].relative_bounds.bounds =
gfx::RectF(50, 700, 150, 150);
1585 AXTree tree(tree_update);
1586 EXPECT_FALSE(IsNodeOffscreen(tree, 2));
1587 EXPECT_FALSE(IsNodeOffscreen(tree, 3));
1592TEST(AXTreeTest, IntReverseRelations) {
1595 initial_state.
nodes.resize(4);
1596 initial_state.
nodes[0].id = 1;
1597 initial_state.
nodes[0].AddIntAttribute(
1599 initial_state.
nodes[0].child_ids.push_back(2);
1600 initial_state.
nodes[0].child_ids.push_back(3);
1601 initial_state.
nodes[0].child_ids.push_back(4);
1602 initial_state.
nodes[1].id = 2;
1603 initial_state.
nodes[2].id = 3;
1606 initial_state.
nodes[3].id = 4;
1609 AXTree tree(initial_state);
1611 auto reverse_active_descendant =
1613 ASSERT_EQ(1U, reverse_active_descendant.size());
1616 reverse_active_descendant =
1618 ASSERT_EQ(0
U, reverse_active_descendant.size());
1620 auto reverse_errormessage =
1622 ASSERT_EQ(0
U, reverse_errormessage.size());
1624 auto reverse_member_of =
1626 ASSERT_EQ(2U, reverse_member_of.size());
1632 update.nodes[0].int_attributes.clear();
1635 update.nodes[0].child_ids.push_back(5);
1636 update.nodes[2].int_attributes.clear();
1642 reverse_active_descendant =
1644 ASSERT_EQ(0
U, reverse_active_descendant.size());
1646 reverse_active_descendant =
1648 ASSERT_EQ(1U, reverse_active_descendant.size());
1653 ASSERT_EQ(2U, reverse_member_of.size());
1658TEST(AXTreeTest, IntListReverseRelations) {
1659 std::vector<int32_t> node_two;
1660 node_two.push_back(2);
1662 std::vector<int32_t> nodes_two_three;
1663 nodes_two_three.push_back(2);
1664 nodes_two_three.push_back(3);
1668 initial_state.
nodes.resize(3);
1669 initial_state.
nodes[0].id = 1;
1670 initial_state.
nodes[0].AddIntListAttribute(
1672 initial_state.
nodes[0].child_ids.push_back(2);
1673 initial_state.
nodes[0].child_ids.push_back(3);
1674 initial_state.
nodes[1].id = 2;
1675 initial_state.
nodes[2].id = 3;
1677 AXTree tree(initial_state);
1679 auto reverse_labelled_by =
1681 ASSERT_EQ(1U, reverse_labelled_by.size());
1684 reverse_labelled_by =
1686 ASSERT_EQ(0
U, reverse_labelled_by.size());
1690 update.nodes[0].intlist_attributes.clear();
1691 update.nodes[0].AddIntListAttribute(
1695 reverse_labelled_by =
1697 ASSERT_EQ(1U, reverse_labelled_by.size());
1701TEST(AXTreeTest, DeletingNodeUpdatesReverseRelations) {
1704 initial_state.
nodes.resize(3);
1705 initial_state.
nodes[0].id = 1;
1706 initial_state.
nodes[0].child_ids = {2, 3};
1707 initial_state.
nodes[1].id = 2;
1708 initial_state.
nodes[2].id = 3;
1709 initial_state.
nodes[2].AddIntAttribute(
1711 AXTree tree(initial_state);
1713 auto reverse_active_descendant =
1715 ASSERT_EQ(1U, reverse_active_descendant.size());
1722 update.nodes[0].child_ids = {2};
1725 reverse_active_descendant =
1727 ASSERT_EQ(0
U, reverse_active_descendant.size());
1730TEST(AXTreeTest, ReverseRelationsDoNotKeepGrowing) {
1737 initial_state.
nodes.resize(2);
1738 initial_state.
nodes[0].id = 1;
1739 initial_state.
nodes[0].AddIntAttribute(
1741 initial_state.
nodes[0].AddIntListAttribute(
1743 initial_state.
nodes[0].child_ids.push_back(2);
1744 initial_state.
nodes[1].id = 2;
1745 AXTree tree(initial_state);
1747 for (
int i = 0;
i < 1000; ++
i) {
1753 update.nodes[0].AddIntAttribute(
1755 update.nodes[0].AddIntListAttribute(
1758 update.nodes[0].child_ids.push_back(
update.nodes[1].id);
1762 size_t map_key_count = 0;
1763 size_t set_entry_count = 0;
1765 map_key_count += iter.second.size() + 1;
1766 for (
auto it2 = iter.second.begin(); it2 != iter.second.end(); ++it2) {
1767 set_entry_count += it2->second.size();
1774 EXPECT_LT(map_key_count, 10U);
1775 EXPECT_LT(set_entry_count, 10U);
1778 set_entry_count = 0;
1780 map_key_count += iter.second.size() + 1;
1781 for (
auto it2 = iter.second.begin(); it2 != iter.second.end(); ++it2) {
1782 set_entry_count += it2->second.size();
1785 EXPECT_LT(map_key_count, 10U);
1786 EXPECT_LT(set_entry_count, 10U);
1789TEST(AXTreeTest, SkipIgnoredNodes) {
1792 tree_update.
nodes.resize(5);
1793 tree_update.
nodes[0].id = 1;
1794 tree_update.
nodes[0].child_ids = {2, 3};
1795 tree_update.
nodes[1].id = 2;
1797 tree_update.
nodes[1].child_ids = {4, 5};
1798 tree_update.
nodes[2].id = 3;
1799 tree_update.
nodes[3].id = 4;
1800 tree_update.
nodes[4].id = 5;
1802 AXTree tree(tree_update);
1804 ASSERT_EQ(2u,
root->children().size());
1805 ASSERT_EQ(2,
root->children()[0]->id());
1806 ASSERT_EQ(3,
root->children()[1]->id());
1808 EXPECT_EQ(3u,
root->GetUnignoredChildCount());
1809 EXPECT_EQ(4,
root->GetUnignoredChildAtIndex(0)->id());
1810 EXPECT_EQ(5,
root->GetUnignoredChildAtIndex(1)->id());
1811 EXPECT_EQ(3,
root->GetUnignoredChildAtIndex(2)->id());
1812 EXPECT_EQ(0u,
root->GetUnignoredChildAtIndex(0)->GetUnignoredIndexInParent());
1813 EXPECT_EQ(1u,
root->GetUnignoredChildAtIndex(1)->GetUnignoredIndexInParent());
1814 EXPECT_EQ(2u,
root->GetUnignoredChildAtIndex(2)->GetUnignoredIndexInParent());
1816 EXPECT_EQ(1,
root->GetUnignoredChildAtIndex(0)->GetUnignoredParent()->id());
1819TEST(AXTreeTest, CachedUnignoredValues) {
1822 initial_state.
nodes.resize(5);
1823 initial_state.
nodes[0].id = 1;
1824 initial_state.
nodes[0].child_ids = {2, 3};
1825 initial_state.
nodes[1].id = 2;
1827 initial_state.
nodes[1].child_ids = {4, 5};
1828 initial_state.
nodes[2].id = 3;
1829 initial_state.
nodes[3].id = 4;
1830 initial_state.
nodes[4].id = 5;
1832 AXTree tree(initial_state);
1834 ASSERT_EQ(2u,
root->children().size());
1835 ASSERT_EQ(2,
root->children()[0]->id());
1836 ASSERT_EQ(3,
root->children()[1]->id());
1838 EXPECT_EQ(3u,
root->GetUnignoredChildCount());
1839 EXPECT_EQ(4,
root->GetUnignoredChildAtIndex(0)->id());
1840 EXPECT_EQ(5,
root->GetUnignoredChildAtIndex(1)->id());
1841 EXPECT_EQ(3,
root->GetUnignoredChildAtIndex(2)->id());
1842 EXPECT_EQ(0u,
root->GetUnignoredChildAtIndex(0)->GetUnignoredIndexInParent());
1843 EXPECT_EQ(1u,
root->GetUnignoredChildAtIndex(1)->GetUnignoredIndexInParent());
1844 EXPECT_EQ(2u,
root->GetUnignoredChildAtIndex(2)->GetUnignoredIndexInParent());
1846 EXPECT_EQ(1,
root->GetUnignoredChildAtIndex(0)->GetUnignoredParent()->id());
1856 EXPECT_EQ(2u,
root->GetUnignoredChildCount());
1857 EXPECT_EQ(2,
root->GetUnignoredChildAtIndex(0)->id());
1874 update3.
nodes.resize(1);
1875 update3.
nodes[0].id = 1;
1876 update3.
nodes[0].child_ids = {3};
1885 update4.
nodes.resize(3);
1886 update4.
nodes[0].id = 1;
1887 update4.
nodes[0].child_ids = {3, 6};
1888 update4.
nodes[1].id = 6;
1889 update4.
nodes[1].child_ids = {7};
1890 update4.
nodes[2].id = 7;
1901 update5.
nodes.resize(2);
1903 update5.
nodes[0].id = 1;
1904 update5.
nodes[0].child_ids = {3, 7};
1905 update5.
nodes[1].id = 7;
1906 update5.
nodes[1].child_ids = {};
1915 update6.
nodes.resize(1);
1916 update6.
nodes[0].id = 7;
1925 update7.
nodes.resize(2);
1926 update7.
nodes[0].id = 7;
1927 update7.
nodes[0].child_ids = {8};
1928 update7.
nodes[1].id = 8;
1936TEST(AXTreeTest, TestRecursionUnignoredChildCount) {
1939 tree_update.
nodes.resize(5);
1940 tree_update.
nodes[0].id = 1;
1941 tree_update.
nodes[0].child_ids = {2, 3};
1942 tree_update.
nodes[1].id = 2;
1944 tree_update.
nodes[1].child_ids = {4};
1945 tree_update.
nodes[2].id = 3;
1947 tree_update.
nodes[3].id = 4;
1948 tree_update.
nodes[3].child_ids = {5};
1950 tree_update.
nodes[4].id = 5;
1951 AXTree tree(tree_update);
1954 EXPECT_EQ(2u,
root->children().size());
1955 EXPECT_EQ(1u,
root->GetUnignoredChildCount());
1956 EXPECT_EQ(5,
root->GetUnignoredChildAtIndex(0)->id());
1961TEST(AXTreeTest, NullUnignoredChildren) {
1964 tree_update.
nodes.resize(3);
1965 tree_update.
nodes[0].id = 1;
1966 tree_update.
nodes[0].child_ids = {2, 3};
1967 tree_update.
nodes[1].id = 2;
1969 tree_update.
nodes[2].id = 3;
1971 AXTree tree(tree_update);
1974 EXPECT_EQ(2u,
root->children().size());
1975 EXPECT_EQ(0u,
root->GetUnignoredChildCount());
1976 EXPECT_EQ(
nullptr,
root->GetUnignoredChildAtIndex(0));
1977 EXPECT_EQ(
nullptr,
root->GetUnignoredChildAtIndex(1));
1980TEST(AXTreeTest, UnignoredChildIteratorIncrementDecrementPastEnd) {
1987 tree_update.
nodes.resize(2);
1989 tree_update.
nodes[0].id = 1;
1991 tree_update.
nodes[0].child_ids = {2};
1993 tree_update.
nodes[1].id = 2;
1995 tree_update.
nodes[1].SetName(
"text1");
1997 AXTree tree(tree_update);
2003 root->UnignoredChildrenBegin();
2004 EXPECT_EQ(2, root_unignored_iter->id());
2005 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2010 EXPECT_EQ(
root->UnignoredChildrenEnd(), ++root_unignored_iter);
2013 EXPECT_EQ(
root->UnignoredChildrenEnd(), ++root_unignored_iter);
2017 --root_unignored_iter;
2018 EXPECT_EQ(2, root_unignored_iter->id());
2019 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2025 root->UnignoredChildrenBegin();
2026 EXPECT_EQ(2, root_unignored_iter->id());
2027 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2032 --root_unignored_iter;
2033 EXPECT_EQ(2, root_unignored_iter->id());
2034 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2039 --root_unignored_iter;
2040 EXPECT_EQ(2, root_unignored_iter->id());
2041 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2045 EXPECT_EQ(
root->UnignoredChildrenEnd(), ++root_unignored_iter);
2050TEST(AXTreeTest, UnignoredChildIteratorIgnoredContainerSiblings) {
2062 tree_update.
nodes.resize(7);
2064 tree_update.
nodes[0].id = 1;
2066 tree_update.
nodes[0].child_ids = {2, 4, 6};
2068 tree_update.
nodes[1].id = 2;
2069 tree_update.
nodes[1].child_ids = {3};
2073 tree_update.
nodes[2].id = 3;
2075 tree_update.
nodes[2].SetName(
"text1");
2077 tree_update.
nodes[3].id = 4;
2078 tree_update.
nodes[3].child_ids = {5};
2082 tree_update.
nodes[4].id = 5;
2084 tree_update.
nodes[4].SetName(
"text2");
2086 tree_update.
nodes[5].id = 6;
2087 tree_update.
nodes[5].child_ids = {7};
2091 tree_update.
nodes[6].id = 7;
2093 tree_update.
nodes[6].SetName(
"text3");
2095 AXTree tree(tree_update);
2103 root->UnignoredChildrenBegin();
2104 EXPECT_EQ(3, root_unignored_iter->id());
2105 EXPECT_EQ(
"text1", root_unignored_iter->GetStringAttribute(
2108 EXPECT_EQ(5, (++root_unignored_iter)->
id());
2110 (*root_unignored_iter)
2113 EXPECT_EQ(7, (++root_unignored_iter)->
id());
2114 EXPECT_EQ(
"text3", root_unignored_iter->GetStringAttribute(
2116 EXPECT_EQ(
root->UnignoredChildrenEnd(), ++root_unignored_iter);
2127 EXPECT_EQ(3, unignored_iter->id());
2128 EXPECT_EQ(
"text1", unignored_iter->GetStringAttribute(
2140 EXPECT_EQ(5, unignored_iter->id());
2141 EXPECT_EQ(
"text2", unignored_iter->GetStringAttribute(
2146 EXPECT_EQ(5, unignored_iter->id());
2147 EXPECT_EQ(
"text2", unignored_iter->GetStringAttribute(
2152TEST(AXTreeTest, UnignoredChildIterator) {
2169 tree_update.
nodes.resize(15);
2170 tree_update.
nodes[0].id = 1;
2171 tree_update.
nodes[0].child_ids = {2, 3, 4};
2173 tree_update.
nodes[1].id = 2;
2174 tree_update.
nodes[1].child_ids = {5, 6, 7, 8};
2177 tree_update.
nodes[2].id = 3;
2178 tree_update.
nodes[3].id = 4;
2180 tree_update.
nodes[4].id = 5;
2181 tree_update.
nodes[4].child_ids = {9};
2183 tree_update.
nodes[5].id = 6;
2184 tree_update.
nodes[5].child_ids = {10};
2186 tree_update.
nodes[6].id = 7;
2187 tree_update.
nodes[6].child_ids = {11, 12};
2190 tree_update.
nodes[7].id = 8;
2193 tree_update.
nodes[8].id = 9;
2195 tree_update.
nodes[9].id = 10;
2196 tree_update.
nodes[9].child_ids = {13};
2199 tree_update.
nodes[10].id = 11;
2200 tree_update.
nodes[10].child_ids = {14, 15};
2203 tree_update.
nodes[11].id = 12;
2205 tree_update.
nodes[12].id = 13;
2208 tree_update.
nodes[13].id = 14;
2210 tree_update.
nodes[14].id = 15;
2212 AXTree tree(tree_update);
2218 root->UnignoredChildrenBegin();
2219 EXPECT_EQ(5, unignored_iterator->id());
2221 EXPECT_EQ(6, (++unignored_iterator)->
id());
2223 EXPECT_EQ(14, (++unignored_iterator)->
id());
2225 EXPECT_EQ(15, (++unignored_iterator)->
id());
2227 EXPECT_EQ(14, (--unignored_iterator)->
id());
2229 EXPECT_EQ(6, (--unignored_iterator)->
id());
2231 EXPECT_EQ(14, (++unignored_iterator)->
id());
2233 EXPECT_EQ(15, (++unignored_iterator)->
id());
2235 EXPECT_EQ(12, (++unignored_iterator)->
id());
2237 EXPECT_EQ(3, (++unignored_iterator)->
id());
2239 EXPECT_EQ(4, (++unignored_iterator)->
id());
2241 EXPECT_EQ(
root->UnignoredChildrenEnd(), ++unignored_iterator);
2259 EXPECT_EQ(14, unignored_iterator->id());
2263 unignored_iterator =
root->UnignoredChildrenBegin();
2265 root->UnignoredChildrenBegin();
2266 auto end =
root->UnignoredChildrenEnd();
2267 while (unignored_iterator !=
end) {
2268 ASSERT_EQ(unignored_iterator, unignored_iterator2);
2269 ++unignored_iterator;
2270 ++unignored_iterator2;
2272 ASSERT_EQ(unignored_iterator, unignored_iterator2);
2275TEST(AXTreeTest, UnignoredAccessors) {
2294 tree_update.
nodes.resize(17);
2295 tree_update.
nodes[0].id = 1;
2296 tree_update.
nodes[0].child_ids = {2, 3, 4};
2298 tree_update.
nodes[1].id = 2;
2299 tree_update.
nodes[1].child_ids = {5, 6, 7, 8};
2302 tree_update.
nodes[2].id = 3;
2303 tree_update.
nodes[3].id = 4;
2305 tree_update.
nodes[4].id = 5;
2306 tree_update.
nodes[4].child_ids = {9};
2308 tree_update.
nodes[5].id = 6;
2309 tree_update.
nodes[5].child_ids = {10};
2311 tree_update.
nodes[6].id = 7;
2312 tree_update.
nodes[6].child_ids = {11, 12};
2315 tree_update.
nodes[7].id = 8;
2318 tree_update.
nodes[8].id = 9;
2320 tree_update.
nodes[9].id = 10;
2321 tree_update.
nodes[9].child_ids = {13};
2324 tree_update.
nodes[10].id = 11;
2325 tree_update.
nodes[10].child_ids = {14, 15};
2328 tree_update.
nodes[11].id = 12;
2330 tree_update.
nodes[12].id = 13;
2331 tree_update.
nodes[12].child_ids = {16};
2334 tree_update.
nodes[13].id = 14;
2335 tree_update.
nodes[13].child_ids = {17};
2337 tree_update.
nodes[14].id = 15;
2339 tree_update.
nodes[15].id = 16;
2341 tree_update.
nodes[16].id = 17;
2344 AXTree tree(tree_update);
2365TEST(AXTreeTest, UnignoredNextPreviousChild) {
2384 tree_update.
nodes.resize(16);
2385 tree_update.
nodes[0].id = 1;
2386 tree_update.
nodes[0].child_ids = {2, 3, 4};
2388 tree_update.
nodes[1].id = 2;
2389 tree_update.
nodes[1].child_ids = {5, 6, 7, 8};
2392 tree_update.
nodes[2].id = 3;
2393 tree_update.
nodes[3].id = 4;
2395 tree_update.
nodes[4].id = 5;
2396 tree_update.
nodes[4].child_ids = {9};
2398 tree_update.
nodes[5].id = 6;
2399 tree_update.
nodes[5].child_ids = {10};
2401 tree_update.
nodes[6].id = 7;
2402 tree_update.
nodes[6].child_ids = {11, 12};
2405 tree_update.
nodes[7].id = 8;
2408 tree_update.
nodes[8].id = 9;
2410 tree_update.
nodes[9].id = 10;
2411 tree_update.
nodes[9].child_ids = {13};
2414 tree_update.
nodes[10].id = 11;
2415 tree_update.
nodes[10].child_ids = {14, 15};
2418 tree_update.
nodes[11].id = 12;
2420 tree_update.
nodes[12].id = 13;
2421 tree_update.
nodes[12].child_ids = {16};
2424 tree_update.
nodes[13].id = 14;
2426 tree_update.
nodes[14].id = 15;
2428 tree_update.
nodes[15].id = 16;
2430 AXTree tree(tree_update);
2490TEST(AXTreeTest, GetSiblingsNoIgnored) {
2500 tree_update.
nodes.resize(4);
2501 tree_update.
nodes[0].id = 1;
2502 tree_update.
nodes[0].child_ids = {2, 3};
2503 tree_update.
nodes[1].id = 2;
2504 tree_update.
nodes[1].child_ids = {4};
2505 tree_update.
nodes[2].id = 3;
2506 tree_update.
nodes[3].id = 4;
2508 AXTree tree(tree_update);
2532TEST(AXTreeTest, GetUnignoredSiblingsChildrenPromoted) {
2545 tree_update.
nodes.resize(5);
2546 tree_update.
nodes[0].id = 1;
2547 tree_update.
nodes[0].child_ids = {2, 3};
2548 tree_update.
nodes[1].id = 2;
2550 tree_update.
nodes[1].child_ids = {4, 5};
2551 tree_update.
nodes[2].id = 3;
2552 tree_update.
nodes[3].id = 4;
2553 tree_update.
nodes[4].id = 5;
2555 AXTree tree(tree_update);
2596TEST(AXTreeTest, GetUnignoredSiblingsIgnoredChildSkipped) {
2608 tree_update.
nodes.resize(5);
2609 tree_update.
nodes[0].id = 1;
2610 tree_update.
nodes[0].child_ids = {2, 3};
2611 tree_update.
nodes[1].id = 2;
2613 tree_update.
nodes[1].child_ids = {4, 5};
2614 tree_update.
nodes[2].id = 3;
2615 tree_update.
nodes[3].id = 4;
2616 tree_update.
nodes[4].id = 5;
2619 AXTree tree(tree_update);
2660TEST(AXTreeTest, GetUnignoredSiblingIgnoredParentIrrelevant) {
2671 tree_update.
nodes.resize(3);
2672 tree_update.
nodes[0].id = 1;
2674 tree_update.
nodes[0].child_ids = {2, 3};
2675 tree_update.
nodes[1].id = 2;
2676 tree_update.
nodes[2].id = 3;
2678 AXTree tree(tree_update);
2687TEST(AXTreeTest, GetUnignoredSiblingsAllIgnored) {
2696 tree_update.
nodes.resize(2);
2697 tree_update.
nodes[0].id = 1;
2699 tree_update.
nodes[0].child_ids = {2};
2700 tree_update.
nodes[1].id = 2;
2703 AXTree tree(tree_update);
2711TEST(AXTreeTest, GetUnignoredSiblingsNestedIgnored) {
2723 tree_update.
nodes.resize(6);
2724 tree_update.
nodes[0].id = 1;
2725 tree_update.
nodes[0].child_ids = {2, 3, 4};
2726 tree_update.
nodes[1].id = 2;
2727 tree_update.
nodes[2].id = 3;
2729 tree_update.
nodes[2].child_ids = {5};
2730 tree_update.
nodes[3].id = 4;
2731 tree_update.
nodes[4].id = 5;
2733 tree_update.
nodes[4].child_ids = {6};
2734 tree_update.
nodes[5].id = 6;
2736 AXTree tree(tree_update);
2746 ASSERT_NE(
nullptr, node2);
2747 ASSERT_NE(
nullptr, node3);
2748 ASSERT_NE(
nullptr, node4);
2749 ASSERT_NE(
nullptr, node5);
2750 ASSERT_NE(
nullptr, node6);
2793TEST(AXTreeTest, UnignoredSelection) {
2821 tree_update.
nodes.resize(16);
2822 tree_update.
nodes[0].id = 1;
2824 tree_update.
nodes[0].child_ids = {2, 3, 4};
2826 tree_update.
nodes[1].id = 2;
2827 tree_update.
nodes[1].child_ids = {5, 6, 7, 8};
2831 tree_update.
nodes[2].id = 3;
2833 tree_update.
nodes[2].SetName(
"text");
2835 tree_update.
nodes[3].id = 4;
2837 tree_update.
nodes[3].SetName(
"text");
2839 tree_update.
nodes[4].id = 5;
2841 tree_update.
nodes[4].child_ids = {9};
2843 tree_update.
nodes[5].id = 6;
2845 tree_update.
nodes[5].child_ids = {10};
2847 tree_update.
nodes[6].id = 7;
2848 tree_update.
nodes[6].child_ids = {11, 12};
2852 tree_update.
nodes[7].id = 8;
2856 tree_update.
nodes[8].id = 9;
2858 tree_update.
nodes[8].SetName(
"text");
2860 tree_update.
nodes[9].id = 10;
2861 tree_update.
nodes[9].child_ids = {13};
2865 tree_update.
nodes[10].id = 11;
2866 tree_update.
nodes[10].child_ids = {14, 15};
2870 tree_update.
nodes[11].id = 12;
2872 tree_update.
nodes[11].SetName(
"text");
2874 tree_update.
nodes[12].id = 13;
2875 tree_update.
nodes[12].child_ids = {16};
2879 tree_update.
nodes[13].id = 14;
2881 tree_update.
nodes[13].SetName(
"text");
2883 tree_update.
nodes[14].id = 15;
2885 tree_update.
nodes[14].SetName(
"text");
2887 tree_update.
nodes[15].id = 16;
2889 tree_update.
nodes[15].SetName(
"text");
2899 struct SelectionData {
2901 int32_t anchor_offset;
2903 int32_t focus_offset;
2906 SelectionData input = {1, 0, 1, 0};
2907 SelectionData expected = {9, 0, 9, 0};
2910 input = {1, 0, 2, 2};
2911 expected = {9, 0, 14, 0};
2914 input = {2, 1, 5, 0};
2915 expected = {16, 0, 5, 0};
2918 input = {5, 0, 9, 0};
2919 expected = {5, 0, 9, 0};
2922 input = {9, 0, 6, 0};
2923 expected = {9, 0, 16, 0};
2926 input = {6, 0, 10, 0};
2927 expected = {16, 0, 16, 0};
2930 input = {10, 0, 13, 0};
2931 expected = {16, 0, 16, 0};
2934 input = {13, 0, 16, 0};
2935 expected = {16, 0, 16, 0};
2938 input = {16, 0, 7, 0};
2939 expected = {16, 0, 14, 0};
2942 input = {7, 0, 11, 0};
2943 expected = {14, 0, 14, 0};
2946 input = {11, 1, 14, 2};
2947 expected = {15, 0, 14, 2};
2950 input = {14, 2, 15, 3};
2951 expected = {14, 2, 15, 3};
2954 input = {15, 0, 12, 0};
2955 expected = {15, 0, 12, 0};
2958 input = {12, 0, 8, 0};
2959 expected = {12, 0, 3, 0};
2962 input = {8, 0, 3, 0};
2963 expected = {12, 4, 3, 0};
2966 input = {3, 0, 4, 0};
2967 expected = {3, 0, 4, 0};
2970 input = {4, 0, 4, 0};
2971 expected = {4, 0, 4, 0};
2975TEST(AXTreeTest, GetChildrenOrSiblings) {
2983 tree_update.
nodes.resize(5);
2984 tree_update.
nodes[0].id = 1;
2985 tree_update.
nodes[0].child_ids = {2, 3, 4};
2986 tree_update.
nodes[1].id = 2;
2987 tree_update.
nodes[1].child_ids = {5};
2988 tree_update.
nodes[2].id = 3;
2989 tree_update.
nodes[3].id = 4;
2990 tree_update.
nodes[4].id = 5;
2992 AXTree tree(tree_update);
3020TEST(AXTreeTest, SetSizePosInSetAssigned) {
3023 tree_update.
nodes.resize(4);
3024 tree_update.
nodes[0].id = 1;
3026 tree_update.
nodes[0].child_ids = {2, 3, 4};
3027 tree_update.
nodes[1].id = 2;
3031 tree_update.
nodes[2].id = 3;
3035 tree_update.
nodes[3].id = 4;
3039 AXTree tree(tree_update);
3053TEST(AXTreeTest, SetSizePosInSetUnassigned) {
3056 tree_update.
nodes.resize(4);
3057 tree_update.
nodes[0].id = 1;
3059 tree_update.
nodes[0].child_ids = {2, 3, 4};
3060 tree_update.
nodes[1].id = 2;
3062 tree_update.
nodes[2].id = 3;
3064 tree_update.
nodes[3].id = 4;
3066 AXTree tree(tree_update);
3081TEST(AXTreeTest, SetSizeAssignedOnContainer) {
3084 tree_update.
nodes.resize(4);
3085 tree_update.
nodes[0].id = 1;
3087 tree_update.
nodes[0].child_ids = {2, 3, 4};
3089 tree_update.
nodes[1].id = 2;
3091 tree_update.
nodes[2].id = 3;
3093 tree_update.
nodes[3].id = 4;
3095 AXTree tree(tree_update);
3111TEST(AXTreeTest, SetSizePosInSetDiverseList) {
3114 tree_update.
nodes.resize(6);
3115 tree_update.
nodes[0].id = 1;
3117 tree_update.
nodes[0].child_ids = {2, 3, 4, 5, 6};
3118 tree_update.
nodes[1].id = 2;
3120 tree_update.
nodes[2].id = 3;
3122 tree_update.
nodes[3].id = 4;
3124 tree_update.
nodes[4].id = 5;
3126 tree_update.
nodes[5].id = 6;
3128 AXTree tree(tree_update);
3151TEST(AXTreeTest, SetSizePosInSetNestedList) {
3154 tree_update.
nodes.resize(7);
3155 tree_update.
nodes[0].id = 1;
3157 tree_update.
nodes[0].child_ids = {2, 3, 4, 7};
3158 tree_update.
nodes[1].id = 2;
3160 tree_update.
nodes[2].id = 3;
3162 tree_update.
nodes[3].id = 4;
3164 tree_update.
nodes[3].child_ids = {5, 6};
3165 tree_update.
nodes[4].id = 5;
3167 tree_update.
nodes[5].id = 6;
3169 tree_update.
nodes[6].id = 7;
3171 AXTree tree(tree_update);
3197 tree_update.
nodes.resize(4);
3198 tree_update.
nodes[0].id = 1;
3200 tree_update.
nodes[0].child_ids = {2, 3, 4};
3202 tree_update.
nodes[1].id = 2;
3204 tree_update.
nodes[2].id = 3;
3207 tree_update.
nodes[3].id = 4;
3209 AXTree tree(tree_update);
3225TEST(AXTreeTest, SetSizePosInSetMissingDifficult) {
3228 tree_update.
nodes.resize(6);
3229 tree_update.
nodes[0].id = 1;
3231 tree_update.
nodes[0].child_ids = {2, 3, 4, 5, 6};
3232 tree_update.
nodes[1].id = 2;
3234 tree_update.
nodes[2].id = 3;
3238 tree_update.
nodes[3].id = 4;
3240 tree_update.
nodes[4].id = 5;
3244 tree_update.
nodes[5].id = 6;
3246 AXTree tree(tree_update);
3267TEST(AXTreeTest, SetSizeDecreasing) {
3270 tree_update.
nodes.resize(4);
3271 tree_update.
nodes[0].id = 1;
3273 tree_update.
nodes[0].child_ids = {2, 3, 4};
3274 tree_update.
nodes[1].id = 2;
3276 tree_update.
nodes[2].id = 3;
3279 tree_update.
nodes[3].id = 4;
3282 AXTree tree(tree_update);
3296TEST(AXTreeTest, PosInSetDecreasing) {
3299 tree_update.
nodes.resize(4);
3300 tree_update.
nodes[0].id = 1;
3302 tree_update.
nodes[0].child_ids = {2, 3, 4};
3303 tree_update.
nodes[1].id = 2;
3305 tree_update.
nodes[2].id = 3;
3308 tree_update.
nodes[3].id = 4;
3311 AXTree tree(tree_update);
3327TEST(AXTreeTest, PosInSetDuplicates) {
3330 tree_update.
nodes.resize(4);
3331 tree_update.
nodes[0].id = 1;
3333 tree_update.
nodes[0].child_ids = {2, 3, 4};
3334 tree_update.
nodes[1].id = 2;
3337 tree_update.
nodes[2].id = 3;
3340 tree_update.
nodes[3].id = 4;
3343 AXTree tree(tree_update);
3358TEST(AXTreeTest, SetSizePosInSetNestedContainer) {
3361 tree_update.
nodes.resize(7);
3362 tree_update.
nodes[0].id = 1;
3364 tree_update.
nodes[0].child_ids = {2, 3, 7};
3365 tree_update.
nodes[1].id = 2;
3367 tree_update.
nodes[2].id = 3;
3369 tree_update.
nodes[2].child_ids = {4, 5};
3370 tree_update.
nodes[3].id = 4;
3372 tree_update.
nodes[4].id = 5;
3374 tree_update.
nodes[4].child_ids = {6};
3375 tree_update.
nodes[5].id = 6;
3377 tree_update.
nodes[6].id = 7;
3379 AXTree tree(tree_update);
3403TEST(AXTreeTest, SetSizePosInSetDeleteItem) {
3406 initial_state.
nodes.resize(4);
3407 initial_state.
nodes[0].id = 1;
3409 initial_state.
nodes[0].child_ids = {2, 3, 4};
3410 initial_state.
nodes[1].id = 2;
3412 initial_state.
nodes[2].id = 3;
3414 initial_state.
nodes[3].id = 4;
3416 AXTree tree(initial_state);
3431 update.nodes[0].child_ids = {2, 4};
3446TEST(AXTreeTest, SetSizePosInSetAddItem) {
3449 initial_state.
nodes.resize(4);
3450 initial_state.
nodes[0].id = 1;
3452 initial_state.
nodes[0].child_ids = {2, 3, 4};
3453 initial_state.
nodes[1].id = 2;
3455 initial_state.
nodes[2].id = 3;
3457 initial_state.
nodes[3].id = 4;
3459 AXTree tree(initial_state);
3475 update.nodes[0].child_ids = {5, 2, 3, 4};
3497TEST(AXTreeTest, OrderedSetReportsSetSize) {
3500 tree_update.
nodes.resize(12);
3501 tree_update.
nodes[0].id = 1;
3503 tree_update.
nodes[0].child_ids = {2, 3, 4, 7, 8, 9, 12};
3504 tree_update.
nodes[1].id = 2;
3506 tree_update.
nodes[2].id = 3;
3508 tree_update.
nodes[3].id = 4;
3510 tree_update.
nodes[3].child_ids = {5, 6};
3511 tree_update.
nodes[4].id = 5;
3513 tree_update.
nodes[5].id = 6;
3515 tree_update.
nodes[6].id = 7;
3517 tree_update.
nodes[7].id = 8;
3519 tree_update.
nodes[8].id = 9;
3520 tree_update.
nodes[8].role =
3523 tree_update.
nodes[8].child_ids = {10, 11};
3524 tree_update.
nodes[9].id = 10;
3526 tree_update.
nodes[10].id = 11;
3528 tree_update.
nodes[11].id = 12;
3531 AXTree tree(tree_update);
3565 EXPECT_FALSE(inner_list3_article1->
GetPosInSet());
3566 EXPECT_FALSE(inner_list3_article1->
GetSetSize());
3579TEST(AXTreeTest, SetSizePosInSetInvalid) {
3582 tree_update.
nodes.resize(3);
3583 tree_update.
nodes[0].id = 1;
3585 tree_update.
nodes[0].child_ids = {2, 3};
3586 tree_update.
nodes[1].id = 2;
3590 tree_update.
nodes[2].id = 3;
3592 AXTree tree(tree_update);
3608TEST(AXTreeTest, SetSizePosInSetRadioButtons) {
3611 tree_update.
nodes.resize(13);
3612 tree_update.
nodes[0].id = 1;
3613 tree_update.
nodes[0].child_ids = {2, 3, 4, 10, 13};
3618 tree_update.
nodes[1].id = 2;
3623 tree_update.
nodes[2].id = 3;
3631 tree_update.
nodes[3].id = 4;
3633 tree_update.
nodes[3].child_ids = {5, 6, 7};
3634 tree_update.
nodes[4].id = 5;
3638 tree_update.
nodes[5].id = 6;
3642 tree_update.
nodes[6].id = 7;
3644 tree_update.
nodes[6].child_ids = {8, 9};
3645 tree_update.
nodes[7].id = 8;
3649 tree_update.
nodes[8].id = 9;
3655 tree_update.
nodes[9].id = 10;
3657 tree_update.
nodes[9].child_ids = {11, 12};
3658 tree_update.
nodes[10].id = 11;
3662 tree_update.
nodes[11].id = 12;
3666 tree_update.
nodes[12].id = 13;
3672 AXTree tree(tree_update);
3693 EXPECT_FALSE(generic_container->
GetSetSize());
3720TEST(AXTreeTest, SetSizePosInSetRadioButtonsInList) {
3723 tree_update.
nodes.resize(6);
3724 tree_update.
nodes[0].id = 1;
3725 tree_update.
nodes[0].role =
3728 tree_update.
nodes[0].child_ids = {2, 3, 4, 5, 6};
3730 tree_update.
nodes[1].id = 2;
3732 tree_update.
nodes[2].id = 3;
3734 tree_update.
nodes[3].id = 4;
3736 tree_update.
nodes[4].id = 5;
3738 tree_update.
nodes[5].id = 6;
3740 AXTree tree(tree_update);
3772TEST(AXTreeTest, SetSizePosInSetFlatTree) {
3775 tree_update.
nodes.resize(4);
3776 tree_update.
nodes[0].id = 1;
3778 tree_update.
nodes[0].child_ids = {2, 3, 4};
3779 tree_update.
nodes[1].id = 2;
3781 tree_update.
nodes[1].AddIntAttribute(
3783 tree_update.
nodes[2].id = 3;
3785 tree_update.
nodes[2].AddIntAttribute(
3787 tree_update.
nodes[3].id = 4;
3789 tree_update.
nodes[3].AddIntAttribute(
3791 AXTree tree(tree_update);
3806TEST(AXTreeTest, SetSizePosInSetFlatTreeLevelsOnly) {
3809 tree_update.
nodes.resize(9);
3810 tree_update.
nodes[0].id = 1;
3812 tree_update.
nodes[0].child_ids = {2, 3, 4, 5, 6, 7, 8, 9};
3813 tree_update.
nodes[1].id = 2;
3815 tree_update.
nodes[1].AddIntAttribute(
3817 tree_update.
nodes[2].id = 3;
3819 tree_update.
nodes[2].AddIntAttribute(
3821 tree_update.
nodes[3].id = 4;
3823 tree_update.
nodes[3].AddIntAttribute(
3825 tree_update.
nodes[4].id = 5;
3827 tree_update.
nodes[4].AddIntAttribute(
3829 tree_update.
nodes[5].id = 6;
3831 tree_update.
nodes[5].AddIntAttribute(
3833 tree_update.
nodes[6].id = 7;
3835 tree_update.
nodes[6].AddIntAttribute(
3837 tree_update.
nodes[7].id = 8;
3839 tree_update.
nodes[7].AddIntAttribute(
3841 tree_update.
nodes[8].id = 9;
3843 tree_update.
nodes[8].AddIntAttribute(
3845 AXTree tree(tree_update);
3878TEST(AXTreeTest, SetSizePosInSetSubtreeDeleted) {
3881 initial_state.
nodes.resize(3);
3882 initial_state.
nodes[0].id = 1;
3884 initial_state.
nodes[0].child_ids = {2, 3};
3885 initial_state.
nodes[1].id = 2;
3887 initial_state.
nodes[2].id = 3;
3889 AXTree tree(initial_state);
3900 tree_update.
nodes.resize(1);
3901 tree_update.
nodes[0].child_ids = {2};
3919TEST(AXTreeTest, SetSizePosInSetIgnoredItem) {
3922 initial_state.
nodes.resize(3);
3923 initial_state.
nodes[0].id = 1;
3925 initial_state.
nodes[0].child_ids = {2, 3};
3926 initial_state.
nodes[1].id = 2;
3928 initial_state.
nodes[2].id = 3;
3930 AXTree tree(initial_state);
3948 tree_update.
nodes.resize(1);
3949 tree_update.
nodes[0] = initial_state.
nodes[1];
3967TEST(AXTreeTest, SetSizePosInSetPopUpButton) {
3970 initial_state.
nodes.resize(6);
3971 initial_state.
nodes[0].id = 1;
3972 initial_state.
nodes[0].child_ids = {2, 3};
3973 initial_state.
nodes[1].id = 2;
3975 initial_state.
nodes[2].id = 3;
3977 initial_state.
nodes[2].child_ids = {4};
3978 initial_state.
nodes[3].id = 4;
3980 initial_state.
nodes[3].child_ids = {5, 6};
3981 initial_state.
nodes[4].id = 5;
3983 initial_state.
nodes[5].id = 6;
3985 AXTree tree(initial_state);
3998TEST(AXTreeTest, SetSizePosInSetUnkown) {
4001 initial_state.
nodes.resize(5);
4002 initial_state.
nodes[0].id = 1;
4003 initial_state.
nodes[0].child_ids = {2};
4005 initial_state.
nodes[1].id = 2;
4007 initial_state.
nodes[1].child_ids = {3};
4008 initial_state.
nodes[2].id = 3;
4010 initial_state.
nodes[2].child_ids = {4, 5};
4011 initial_state.
nodes[3].id = 4;
4013 initial_state.
nodes[4].id = 5;
4015 AXTree tree(initial_state);
4027TEST(AXTreeTest, SetSizePosInSetMenuItemValidChildOfMenuListPopup) {
4030 initial_state.
nodes.resize(3);
4031 initial_state.
nodes[0].id = 1;
4032 initial_state.
nodes[0].child_ids = {2, 3};
4034 initial_state.
nodes[1].id = 2;
4036 initial_state.
nodes[2].id = 3;
4038 AXTree tree(initial_state);
4050TEST(AXTreeTest, SetSizePostInSetListBoxOptionWithGroup) {
4053 initial_state.
nodes.resize(7);
4054 initial_state.
nodes[0].id = 1;
4055 initial_state.
nodes[0].child_ids = {2, 3};
4057 initial_state.
nodes[1].id = 2;
4058 initial_state.
nodes[1].child_ids = {4, 5};
4060 initial_state.
nodes[2].id = 3;
4061 initial_state.
nodes[2].child_ids = {6, 7};
4063 initial_state.
nodes[3].id = 4;
4065 initial_state.
nodes[4].id = 5;
4067 initial_state.
nodes[5].id = 6;
4069 initial_state.
nodes[6].id = 7;
4071 AXTree tree(initial_state);
4087TEST(AXTreeTest, SetSizePosInSetGroup) {
4115 tree_update.
nodes.resize(6);
4116 tree_update.
nodes[0].id = 1;
4118 tree_update.
nodes[0].child_ids = {2, 6};
4119 tree_update.
nodes[1].id = 2;
4121 tree_update.
nodes[1].child_ids = {3, 4, 5};
4122 tree_update.
nodes[2].id = 3;
4124 tree_update.
nodes[3].id = 4;
4126 tree_update.
nodes[4].id = 5;
4128 tree_update.
nodes[5].id = 6;
4130 AXTree tree(tree_update);
4136 EXPECT_FALSE(
group->GetSetSize());
4147 next_tree_update.
nodes.resize(6);
4148 next_tree_update.
nodes[0].id = 1;
4150 next_tree_update.
nodes[0].child_ids = {2, 6};
4151 next_tree_update.
nodes[1].id = 2;
4153 next_tree_update.
nodes[1].child_ids = {3, 4, 5};
4154 next_tree_update.
nodes[2].id = 3;
4156 next_tree_update.
nodes[3].id = 4;
4158 next_tree_update.
nodes[4].id = 5;
4160 next_tree_update.
nodes[5].id = 6;
4162 AXTree next_tree(next_tree_update);
4185 third_tree_update.
root_id = 1;
4186 third_tree_update.
nodes.resize(3);
4187 third_tree_update.
nodes[0].id = 1;
4189 third_tree_update.
nodes[0].child_ids = {2, 3};
4190 third_tree_update.
nodes[1].id = 2;
4192 third_tree_update.
nodes[2].id = 3;
4194 AXTree third_tree(third_tree_update);
4209 last_tree_update.
nodes.resize(6);
4210 last_tree_update.
nodes[0].id = 1;
4212 last_tree_update.
nodes[0].child_ids = {2};
4213 last_tree_update.
nodes[1].id = 2;
4215 last_tree_update.
nodes[1].child_ids = {3, 4};
4216 last_tree_update.
nodes[2].id = 3;
4218 last_tree_update.
nodes[3].id = 4;
4220 last_tree_update.
nodes[3].child_ids = {5, 6};
4221 last_tree_update.
nodes[4].id = 5;
4223 last_tree_update.
nodes[5].id = 6;
4225 AXTree last_tree(last_tree_update);
4244TEST(AXTreeTest, SetSizePosInSetHidden) {
4247 tree_update.
nodes.resize(6);
4248 tree_update.
nodes[0].id = 1;
4250 tree_update.
nodes[0].child_ids = {2, 3, 4, 5, 6};
4251 tree_update.
nodes[1].id = 2;
4253 tree_update.
nodes[2].id = 3;
4255 tree_update.
nodes[3].id = 4;
4258 tree_update.
nodes[4].id = 5;
4260 tree_update.
nodes[5].id = 6;
4262 AXTree tree(tree_update);
4285TEST(AXTreeTest, SetSizePosInSetControls) {
4286 std::vector<int32_t> three;
4288 std::vector<int32_t> hundred;
4289 hundred.push_back(100);
4290 std::vector<int32_t> eight;
4294 tree_update.
nodes.resize(8);
4295 tree_update.
nodes[0].id = 1;
4297 tree_update.
nodes[0].child_ids = {2, 3, 7, 8};
4298 tree_update.
nodes[1].id = 2;
4300 tree_update.
nodes[1].AddIntListAttribute(
4303 tree_update.
nodes[2].id = 3;
4305 tree_update.
nodes[2].child_ids = {4, 5, 6};
4306 tree_update.
nodes[3].id = 4;
4308 tree_update.
nodes[4].id = 5;
4310 tree_update.
nodes[5].id = 6;
4312 tree_update.
nodes[6].id = 7;
4313 tree_update.
nodes[6].role =
4315 tree_update.
nodes[6].AddIntListAttribute(
4319 tree_update.
nodes[7].id = 8;
4321 tree_update.
nodes[7].AddIntListAttribute(
4323 AXTree tree(tree_update);
4347TEST(AXTreeTest, SetSizePosInSetLeafPopUpButton) {
4350 tree_update.
nodes.resize(2);
4351 tree_update.
nodes[0].id = 1;
4353 tree_update.
nodes[0].child_ids = {2};
4354 tree_update.
nodes[1].id = 2;
4358 AXTree tree(tree_update);
4365TEST(AXTreeTest, OnNodeWillBeDeletedHasValidUnignoredParent) {
4368 initial_state.
nodes.resize(3);
4369 initial_state.
nodes[0].id = 1;
4371 initial_state.
nodes[0].child_ids = {2};
4372 initial_state.
nodes[1].id = 2;
4374 initial_state.
nodes[1].child_ids = {3};
4375 initial_state.
nodes[2].id = 3;
4377 AXTree tree(initial_state);
4380 tree_update.
nodes.resize(1);
4382 tree_update.
nodes[0] = initial_state.
nodes[1];
4384 tree_update.
nodes[0].child_ids.clear();
4388 TestAXTreeObserver test_observer(&tree);
4389 test_observer.unignored_parent_id_before_node_deleted = 2;
4393TEST(AXTreeTest, OnNodeHasBeenDeleted) {
4397 initial_state.
nodes.resize(6);
4398 initial_state.
nodes[0].id = 1;
4400 initial_state.
nodes[0].child_ids = {2};
4401 initial_state.
nodes[1].id = 2;
4403 initial_state.
nodes[1].child_ids = {3, 4};
4404 initial_state.
nodes[2].id = 3;
4406 initial_state.
nodes[3].id = 4;
4408 initial_state.
nodes[3].child_ids = {5, 6};
4409 initial_state.
nodes[4].id = 5;
4411 initial_state.
nodes[5].id = 6;
4414 AXTree tree(initial_state);
4419 update.nodes[0].child_ids = {4};
4421 update.nodes[1].child_ids = {};
4423 TestAXTreeObserver test_observer(&tree);
4426 EXPECT_EQ(3U, test_observer.deleted_ids().size());
4427 EXPECT_EQ(3, test_observer.deleted_ids()[0]);
4428 EXPECT_EQ(5, test_observer.deleted_ids()[1]);
4429 EXPECT_EQ(6, test_observer.deleted_ids()[2]);
4433 for (
auto id : test_observer.deleted_ids()) {
4434 SCOPED_TRACE(testing::Message()
4435 <<
"Node with id=" <<
id <<
", should not exist in the tree");
4443TEST(AXTreeTest, SingleUpdateDeletesNewlyCreatedChildNode) {
4446 initial_state.
nodes.resize(1);
4447 initial_state.
nodes[0].id = 1;
4449 AXTree tree(initial_state);
4452 tree_update.
nodes.resize(6);
4454 tree_update.
nodes[0] = initial_state.
nodes[0];
4455 tree_update.
nodes[0].child_ids = {2};
4456 tree_update.
nodes[1].id = 2;
4459 tree_update.
nodes[2] = initial_state.
nodes[0];
4461 tree_update.
nodes[3] = initial_state.
nodes[0];
4462 tree_update.
nodes[3].child_ids = {2};
4463 tree_update.
nodes[4].id = 2;
4466 tree_update.
nodes[5] = initial_state.
nodes[0];
4472 "id=1 rootWebArea (0, 0)-(0, 0)\n",
4476 tree_update.
nodes.resize(8);
4477 tree_update.
nodes[6] = initial_state.
nodes[0];
4478 tree_update.
nodes[6].child_ids = {2};
4479 tree_update.
nodes[7].id = 2;
4485 "id=1 rootWebArea (0, 0)-(0, 0) child_ids=2\n"
4486 " id=2 genericContainer (0, 0)-(0, 0)\n",
4493TEST(AXTreeTest, SingleUpdateReparentsNodeMultipleTimes) {
4500 initial_state.
nodes.resize(4);
4501 initial_state.
nodes[0].id = 1;
4503 initial_state.
nodes[0].child_ids = {2, 3};
4504 initial_state.
nodes[1].id = 2;
4506 initial_state.
nodes[1].child_ids = {4};
4507 initial_state.
nodes[2].id = 3;
4509 initial_state.
nodes[3].id = 4;
4511 AXTree tree(initial_state);
4514 tree_update.
nodes.resize(6);
4516 tree_update.
nodes[0].id = 2;
4519 tree_update.
nodes[1].id = 3;
4521 tree_update.
nodes[1].child_ids = {4};
4522 tree_update.
nodes[2].id = 4;
4525 tree_update.
nodes[3].id = 3;
4528 tree_update.
nodes[4].id = 2;
4530 tree_update.
nodes[4].child_ids = {4};
4531 tree_update.
nodes[5].id = 4;
4536 "AXTree\nid=1 rootWebArea (0, 0)-(0, 0) child_ids=2,3\n"
4537 " id=2 list (0, 0)-(0, 0) child_ids=4\n"
4538 " id=4 listItem (0, 0)-(0, 0)\n"
4539 " id=3 list (0, 0)-(0, 0)\n",
4543 tree_update.
nodes.resize(9);
4550 "AXTree\nid=1 rootWebArea (0, 0)-(0, 0) child_ids=2,3\n"
4551 " id=2 list (0, 0)-(0, 0)\n"
4552 " id=3 list (0, 0)-(0, 0) child_ids=4\n"
4553 " id=4 listItem (0, 0)-(0, 0)\n",
4560TEST(AXTreeTest, SingleUpdateIgnoresNewlyCreatedUnignoredChildNode) {
4563 initial_state.
nodes.resize(1);
4564 initial_state.
nodes[0].id = 1;
4566 AXTree tree(initial_state);
4569 tree_update.
nodes.resize(3);
4571 tree_update.
nodes[0] = initial_state.
nodes[0];
4572 tree_update.
nodes[0].child_ids = {2};
4573 tree_update.
nodes[1].id = 2;
4583 "id=1 rootWebArea (0, 0)-(0, 0) child_ids=2\n"
4584 " id=2 genericContainer IGNORED (0, 0)-(0, 0)\n",
4591TEST(AXTreeTest, SingleUpdateTogglesIgnoredStateAfterCreatingNode) {
4594 initial_state.
nodes.resize(1);
4595 initial_state.
nodes[0].id = 1;
4597 AXTree tree(initial_state);
4601 "id=1 rootWebArea (0, 0)-(0, 0)\n",
4605 tree_update.
nodes.resize(5);
4607 tree_update.
nodes[0] = initial_state.
nodes[0];
4608 tree_update.
nodes[0].child_ids = {2, 3};
4609 tree_update.
nodes[1].id = 2;
4611 tree_update.
nodes[2].id = 3;
4625 "id=1 rootWebArea (0, 0)-(0, 0) child_ids=2,3\n"
4626 " id=2 genericContainer IGNORED (0, 0)-(0, 0)\n"
4627 " id=3 genericContainer (0, 0)-(0, 0)\n",
4634TEST(AXTreeTest, SingleUpdateTogglesIgnoredStateBeforeDestroyingNode) {
4637 initial_state.
nodes.resize(3);
4638 initial_state.
nodes[0].id = 1;
4640 initial_state.
nodes[0].child_ids = {2, 3};
4641 initial_state.
nodes[1].id = 2;
4643 initial_state.
nodes[2].id = 3;
4646 AXTree tree(initial_state);
4650 "id=1 rootWebArea (0, 0)-(0, 0) child_ids=2,3\n"
4651 " id=2 genericContainer (0, 0)-(0, 0)\n"
4652 " id=3 genericContainer IGNORED (0, 0)-(0, 0)\n",
4656 tree_update.
nodes.resize(3);
4658 tree_update.
nodes[0] = initial_state.
nodes[1];
4661 tree_update.
nodes[1] = initial_state.
nodes[2];
4664 tree_update.
nodes[2] = initial_state.
nodes[0];
4665 tree_update.
nodes[2].child_ids.clear();
4671 "id=1 rootWebArea (0, 0)-(0, 0)\n",
4677TEST(AXTreeTest, TestIsInListMarker) {
4681 tree_update.
nodes.resize(8);
4682 tree_update.
nodes[0].id = 1;
4684 tree_update.
nodes[0].child_ids = {2, 3};
4685 tree_update.
nodes[1].id = 2;
4687 tree_update.
nodes[2].id = 3;
4688 tree_update.
nodes[2].child_ids = {4, 7};
4689 tree_update.
nodes[3].id = 4;
4691 tree_update.
nodes[3].child_ids = {5};
4692 tree_update.
nodes[4].id = 5;
4694 tree_update.
nodes[4].child_ids = {6};
4695 tree_update.
nodes[5].id = 6;
4697 tree_update.
nodes[6].id = 7;
4699 tree_update.
nodes[6].child_ids = {8};
4700 tree_update.
nodes[7].id = 8;
4702 AXTree tree(tree_update);
#define EXPECT_OPTIONAL_EQ(expected, actual)
#define TEST_SELECTION(tree_update, tree, input, expected)
std::optional< int > GetSetSize()
size_t GetUnignoredChildCount() const
bool HasStringAttribute(ax::mojom::StringAttribute attribute) const
UnignoredChildIterator UnignoredChildrenEnd() const
size_t GetUnignoredIndexInParent() const
AXNode * GetLastUnignoredChild() const
static constexpr AXID kInvalidAXID
const std::string & GetStringAttribute(ax::mojom::StringAttribute attribute) const
bool IsInListMarker() const
AXNode * GetNextSibling() const
AXNode * GetLastChild() const
AXNode * GetPreviousUnignoredSibling() const
UnignoredChildIterator UnignoredChildrenBegin() const
AXNode * GetFirstChild() const
AXNode * GetPreviousSibling() const
AXNode * GetNextUnignoredSibling() const
std::optional< int > GetPosInSet()
const AXNodeData & data() const
static AXTreeID CreateNewAXTreeID()
void SetTreeUpdateInProgressState(bool set_tree_update_value)
std::string ToString() const
const std::string & error() const
const AXTreeData & data() const
virtual bool Unserialize(const AXTreeUpdate &update)
std::set< int32_t > GetReverseRelations(ax::mojom::IntAttribute attr, int32_t dst_id) const
const IntReverseRelationMap & int_reverse_relations()
AXNode * GetFromId(int32_t id) const override
Selection GetUnignoredSelection() const override
const IntListReverseRelationMap & intlist_reverse_relations()
Optional< SkRect > bounds
std::string StringPrintf(const std::string &format, Args... args)
bool Contains(const Container &container, const Value &value)
std::string NumberToString(int32_t number)
TEST(AXEnumUtilTest, Event)
const char * ToString(ax::mojom::Event event)
bool HasState(ax::mojom::State state) const
std::vector< int32_t > child_ids
std::vector< AXNodeData > nodes
#define EXPECT_TRUE(handle)