Flutter Engine
The Flutter Engine
Functions
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};
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 {
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};
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 {
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};
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 {
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};
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 {
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};
156 }
157
158 EXPECT_EQ(atk_object_get_n_accessible_children(root_object), 0);
159}
FlutterEngine engine
Definition: main.cc:68
static FlEngine * make_mock_engine()
FlViewAccessible * fl_view_accessible_new(FlEngine *engine)
void fl_view_accessible_handle_update_semantics(FlViewAccessible *self, const FlutterSemanticsUpdate2 *update)
#define EXPECT_SIGNAL2(mock, a1, a2)
Definition: update.py:1
const int32_t * children_in_traversal_order
Array of child node IDs in traversal order. Has length child_count.
Definition: embedder.h:1385
int32_t id
The unique identifier for this node.
Definition: embedder.h:1337
size_t child_count
The number of children this node has.
Definition: embedder.h:1383
A batch of updates to semantics nodes and custom actions.
Definition: embedder.h:1504

◆ 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};
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}