6 #include "gtest/gtest.h"
10 #include "flutter/shell/platform/linux/testing/fl_test.h"
11 #include "flutter/shell/platform/linux/testing/mock_signal_handler.h"
14 .id = kFlutterSemanticsNodeIdBatchEnd};
16 TEST(FlViewAccessibleTest, BuildTree) {
18 g_autoptr(FlViewAccessible) accessible = FL_VIEW_ACCESSIBLE(
19 g_object_new(fl_view_accessible_get_type(),
"engine",
engine,
nullptr));
21 const int32_t children[] = {111, 222};
22 const FlutterSemanticsNode root_node = {
26 .children_in_traversal_order = children,
30 const FlutterSemanticsNode child1_node = {.id = 111, .label =
"child 1"};
33 const FlutterSemanticsNode child2_node = {.id = 222, .label =
"child 2"};
38 AtkObject* root_object =
39 atk_object_ref_accessible_child(ATK_OBJECT(accessible), 0);
40 EXPECT_STREQ(atk_object_get_name(root_object),
"root");
41 EXPECT_EQ(atk_object_get_index_in_parent(root_object), 0);
42 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 2);
44 AtkObject* child1_object = atk_object_ref_accessible_child(root_object, 0);
45 EXPECT_STREQ(atk_object_get_name(child1_object),
"child 1");
46 EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
47 EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
48 EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
50 AtkObject* child2_object = atk_object_ref_accessible_child(root_object, 1);
51 EXPECT_STREQ(atk_object_get_name(child2_object),
"child 2");
52 EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
53 EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 1);
54 EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
57 TEST(FlViewAccessibleTest, AddRemoveChildren) {
59 g_autoptr(FlViewAccessible) accessible = FL_VIEW_ACCESSIBLE(
60 g_object_new(fl_view_accessible_get_type(),
"engine",
engine,
nullptr));
62 FlutterSemanticsNode root_node = {
71 AtkObject* root_object =
72 atk_object_ref_accessible_child(ATK_OBJECT(accessible), 0);
73 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 0);
76 AtkObject* child1_object =
nullptr;
78 flutter::testing::MockSignalHandler2<gint, AtkObject*> child1_added(
79 root_object,
"children-changed::add");
80 EXPECT_SIGNAL2(child1_added, ::testing::Eq(0), ::testing::A<AtkObject*>())
81 .WillOnce(::testing::SaveArg<1>(&child1_object));
83 const int32_t children[] = {111};
84 root_node.child_count = 1;
85 root_node.children_in_traversal_order = children;
88 const FlutterSemanticsNode child1_node = {.id = 111, .label =
"child 1"};
94 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 1);
95 EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child1_object);
97 EXPECT_STREQ(atk_object_get_name(child1_object),
"child 1");
98 EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
99 EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
100 EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
103 AtkObject* child2_object =
nullptr;
105 flutter::testing::MockSignalHandler2<gint, AtkObject*> child2_added(
106 root_object,
"children-changed::add");
107 EXPECT_SIGNAL2(child2_added, ::testing::Eq(1), ::testing::A<AtkObject*>())
108 .WillOnce(::testing::SaveArg<1>(&child2_object));
110 const int32_t children[] = {111, 222};
111 root_node.child_count = 2;
112 root_node.children_in_traversal_order = children;
115 const FlutterSemanticsNode child2_node = {.id = 222, .label =
"child 2"};
121 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 2);
122 EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child1_object);
123 EXPECT_EQ(atk_object_ref_accessible_child(root_object, 1), child2_object);
125 EXPECT_STREQ(atk_object_get_name(child1_object),
"child 1");
126 EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
127 EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
128 EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
130 EXPECT_STREQ(atk_object_get_name(child2_object),
"child 2");
131 EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
132 EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 1);
133 EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
137 flutter::testing::MockSignalHandler2<gint, AtkObject*> child1_removed(
138 root_object,
"children-changed::remove");
139 EXPECT_SIGNAL2(child1_removed, ::testing::Eq(0),
140 ::testing::Eq(child1_object));
142 const int32_t children[] = {222};
143 root_node.child_count = 1;
144 root_node.children_in_traversal_order = children;
150 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 1);
151 EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child2_object);
153 EXPECT_STREQ(atk_object_get_name(child2_object),
"child 2");
154 EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
155 EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 0);
156 EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
160 flutter::testing::MockSignalHandler2<gint, AtkObject*> child2_removed(
161 root_object,
"children-changed::remove");
162 EXPECT_SIGNAL2(child2_removed, ::testing::Eq(0),
163 ::testing::Eq(child2_object));
165 root_node.child_count = 0;
171 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 0);