Flutter Linux Embedder
fl_view_accessible_test.cc File Reference
#include "gtest/gtest.h"
#include "flutter/shell/platform/linux/fl_view_accessible.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_engine.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_signal_handler.h"

Go to the source code of this file.

Functions

 TEST (FlViewAccessibleTest, BuildTree)
 
 TEST (FlViewAccessibleTest, AddRemoveChildren)
 

Function Documentation

◆ TEST() [1/2]

TEST ( FlViewAccessibleTest  ,
AddRemoveChildren   
)

Definition at line 49 of file fl_view_accessible_test.cc.

49  {
50  g_autoptr(FlEngine) engine = make_mock_engine();
51  g_autoptr(FlViewAccessible) accessible = fl_view_accessible_new(engine);
52 
53  FlutterSemanticsNode2 root_node = {
54  .id = 0,
55  .label = "root",
56  .child_count = 0,
57  };
58  FlutterSemanticsNode2* nodes[1] = {&root_node};
59  FlutterSemanticsUpdate2 update = {.node_count = 1, .nodes = nodes};
60  fl_view_accessible_handle_update_semantics(accessible, &update);
61 
62  AtkObject* root_object =
63  atk_object_ref_accessible_child(ATK_OBJECT(accessible), 0);
64  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 0);
65 
66  // add child1
67  AtkObject* child1_object = nullptr;
68  FlutterSemanticsNode2 child1_node = {.id = 111, .label = "child 1"};
69  {
70  flutter::testing::MockSignalHandler2<gint, AtkObject*> child1_added(
71  root_object, "children-changed::add");
72  EXPECT_SIGNAL2(child1_added, ::testing::Eq(0), ::testing::A<AtkObject*>())
73  .WillOnce(::testing::SaveArg<1>(&child1_object));
74 
75  int32_t children[] = {111};
76  root_node.child_count = 1;
77  root_node.children_in_traversal_order = children;
78  FlutterSemanticsNode2* nodes[2] = {&root_node, &child1_node};
79  FlutterSemanticsUpdate2 update = {.node_count = 2, .nodes = nodes};
80  fl_view_accessible_handle_update_semantics(accessible, &update);
81  }
82 
83  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 1);
84  EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child1_object);
85 
86  EXPECT_STREQ(atk_object_get_name(child1_object), "child 1");
87  EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
88  EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
89  EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
90 
91  // add child2
92  AtkObject* child2_object = nullptr;
93  FlutterSemanticsNode2 child2_node = {.id = 222, .label = "child 2"};
94  {
95  flutter::testing::MockSignalHandler2<gint, AtkObject*> child2_added(
96  root_object, "children-changed::add");
97  EXPECT_SIGNAL2(child2_added, ::testing::Eq(1), ::testing::A<AtkObject*>())
98  .WillOnce(::testing::SaveArg<1>(&child2_object));
99 
100  int32_t children[] = {111, 222};
101  root_node.child_count = 2;
102  root_node.children_in_traversal_order = children;
103  FlutterSemanticsNode2* nodes[3] = {&root_node, &child1_node, &child2_node};
104  FlutterSemanticsUpdate2 update = {.node_count = 3, .nodes = nodes};
105  fl_view_accessible_handle_update_semantics(accessible, &update);
106  }
107 
108  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 2);
109  EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child1_object);
110  EXPECT_EQ(atk_object_ref_accessible_child(root_object, 1), child2_object);
111 
112  EXPECT_STREQ(atk_object_get_name(child1_object), "child 1");
113  EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
114  EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
115  EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
116 
117  EXPECT_STREQ(atk_object_get_name(child2_object), "child 2");
118  EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
119  EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 1);
120  EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
121 
122  // remove child1
123  {
124  flutter::testing::MockSignalHandler2<gint, AtkObject*> child1_removed(
125  root_object, "children-changed::remove");
126  EXPECT_SIGNAL2(child1_removed, ::testing::Eq(0),
127  ::testing::Eq(child1_object));
128 
129  const int32_t children[] = {222};
130  root_node.child_count = 1;
131  root_node.children_in_traversal_order = children;
132  FlutterSemanticsNode2* nodes[3] = {&root_node, &child2_node};
133  FlutterSemanticsUpdate2 update = {.node_count = 2, .nodes = nodes};
134  fl_view_accessible_handle_update_semantics(accessible, &update);
135  }
136 
137  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 1);
138  EXPECT_EQ(atk_object_ref_accessible_child(root_object, 0), child2_object);
139 
140  EXPECT_STREQ(atk_object_get_name(child2_object), "child 2");
141  EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
142  EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 0);
143  EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
144 
145  // remove child2
146  {
147  flutter::testing::MockSignalHandler2<gint, AtkObject*> child2_removed(
148  root_object, "children-changed::remove");
149  EXPECT_SIGNAL2(child2_removed, ::testing::Eq(0),
150  ::testing::Eq(child2_object));
151 
152  root_node.child_count = 0;
153  FlutterSemanticsNode2* nodes[1] = {&root_node};
154  FlutterSemanticsUpdate2 update = {.node_count = 1, .nodes = nodes};
155  fl_view_accessible_handle_update_semantics(accessible, &update);
156  }
157 
158  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 0);
159 }

References fl_view_accessible_handle_update_semantics(), fl_view_accessible_new(), and make_mock_engine().

◆ TEST() [2/2]

TEST ( FlViewAccessibleTest  ,
BuildTree   
)

Definition at line 13 of file fl_view_accessible_test.cc.

13  {
14  g_autoptr(FlEngine) engine = make_mock_engine();
15  g_autoptr(FlViewAccessible) accessible = fl_view_accessible_new(engine);
16 
17  int32_t children[] = {111, 222};
18  FlutterSemanticsNode2 root_node = {
19  .id = 0,
20  .label = "root",
21  .child_count = 2,
22  .children_in_traversal_order = children,
23  };
24  FlutterSemanticsNode2 child1_node = {.id = 111, .label = "child 1"};
25  FlutterSemanticsNode2 child2_node = {.id = 222, .label = "child 2"};
26  FlutterSemanticsNode2* nodes[3] = {&root_node, &child1_node, &child2_node};
27  FlutterSemanticsUpdate2 update = {.node_count = 3, .nodes = nodes};
28  fl_view_accessible_handle_update_semantics(accessible, &update);
29 
30  AtkObject* root_object =
31  atk_object_ref_accessible_child(ATK_OBJECT(accessible), 0);
32  EXPECT_STREQ(atk_object_get_name(root_object), "root");
33  EXPECT_EQ(atk_object_get_index_in_parent(root_object), 0);
34  EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 2);
35 
36  AtkObject* child1_object = atk_object_ref_accessible_child(root_object, 0);
37  EXPECT_STREQ(atk_object_get_name(child1_object), "child 1");
38  EXPECT_EQ(atk_object_get_parent(child1_object), root_object);
39  EXPECT_EQ(atk_object_get_index_in_parent(child1_object), 0);
40  EXPECT_EQ(atk_object_get_n_accessible_children(child1_object), 0);
41 
42  AtkObject* child2_object = atk_object_ref_accessible_child(root_object, 1);
43  EXPECT_STREQ(atk_object_get_name(child2_object), "child 2");
44  EXPECT_EQ(atk_object_get_parent(child2_object), root_object);
45  EXPECT_EQ(atk_object_get_index_in_parent(child2_object), 1);
46  EXPECT_EQ(atk_object_get_n_accessible_children(child2_object), 0);
47 }

References fl_view_accessible_handle_update_semantics(), fl_view_accessible_new(), and make_mock_engine().

fl_view_accessible_handle_update_semantics
void fl_view_accessible_handle_update_semantics(FlViewAccessible *self, const FlutterSemanticsUpdate2 *update)
Definition: fl_view_accessible.cc:142
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
fl_view_accessible_new
FlViewAccessible * fl_view_accessible_new(FlEngine *engine)
Definition: fl_view_accessible.cc:133