| Flutter Linux Embedder |

fl_accessible_node_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 // Included first as it collides with the X11 headers.
6 #include "gtest/gtest.h"
7
8 #include "flutter/shell/platform/linux/fl_accessible_node.h"
9
10 // Checks can build a tree of nodes.
11 TEST(FlAccessibleNodeTest, BuildTree) {
12 g_autoptr(FlDartProject) project = fl_dart_project_new();
13 g_autoptr(FlEngine) engine = fl_engine_new(project);
14
15 int64_t view_id = 123;
16 g_autoptr(FlAccessibleNode) root = fl_accessible_node_new(engine, view_id, 0);
17 g_autoptr(FlAccessibleNode) child1 =
18 fl_accessible_node_new(engine, view_id, 1);
19 fl_accessible_node_set_parent(child1, ATK_OBJECT(root), 0);
20 g_autoptr(FlAccessibleNode) child2 =
21 fl_accessible_node_new(engine, view_id, 1);
22 fl_accessible_node_set_parent(child2, ATK_OBJECT(root), 1);
23 g_autoptr(GPtrArray) children =
24 g_ptr_array_new_with_free_func(g_object_unref);
25 g_ptr_array_add(children, g_object_ref(child1));
26 g_ptr_array_add(children, g_object_ref(child2));
27 fl_accessible_node_set_children(root, children);
28
29 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(root)), 2);
30 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(root)), 0);
31 g_autoptr(AtkObject) c1 =
32 atk_object_ref_accessible_child(ATK_OBJECT(root), 0);
33 EXPECT_EQ(ATK_OBJECT(child1), c1);
34 g_autoptr(AtkObject) c2 =
35 atk_object_ref_accessible_child(ATK_OBJECT(root), 1);
36 EXPECT_EQ(ATK_OBJECT(child2), c2);
37 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(root)), nullptr);
38
39 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(child1)), ATK_OBJECT(root));
40 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(child1)), 0);
41 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(child1)), 0);
42
43 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(child2)), ATK_OBJECT(root));
44 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(child2)), 1);
45 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(child2)), 0);
46 }
47
48 // Checks node name is exposed to ATK.
49 TEST(FlAccessibleNodeTest, SetName) {
50 g_autoptr(FlDartProject) project = fl_dart_project_new();
51 g_autoptr(FlEngine) engine = fl_engine_new(project);
52
53 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
54 fl_accessible_node_set_name(node, "test");
55 EXPECT_STREQ(atk_object_get_name(ATK_OBJECT(node)), "test");
56 }
57
58 // Checks node extents are exposed to ATK.
59 TEST(FlAccessibleNodeTest, SetExtents) {
60 g_autoptr(FlDartProject) project = fl_dart_project_new();
61 g_autoptr(FlEngine) engine = fl_engine_new(project);
62
63 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
64 fl_accessible_node_set_extents(node, 1, 2, 3, 4);
65 gint x, y, width, height;
66 atk_component_get_extents(ATK_COMPONENT(node), &x, &y, &width, &height,
67 ATK_XY_PARENT);
68 EXPECT_EQ(x, 1);
69 EXPECT_EQ(y, 2);
70 EXPECT_EQ(width, 3);
71 EXPECT_EQ(height, 4);
72 }
73
74 // Checks Flutter flags are mapped to appropriate ATK state.
75 TEST(FlAccessibleNodeTest, SetFlags) {
76 g_autoptr(FlDartProject) project = fl_dart_project_new();
77 g_autoptr(FlEngine) engine = fl_engine_new(project);
78
79 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
80 fl_accessible_node_set_flags(
81 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsEnabled |
82 kFlutterSemanticsFlagIsFocusable |
83 kFlutterSemanticsFlagIsFocused));
84
85 AtkStateSet* state = atk_object_ref_state_set(ATK_OBJECT(node));
86 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_ENABLED));
87 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_SENSITIVE));
88 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_FOCUSABLE));
89 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_FOCUSED));
90 EXPECT_TRUE(!atk_state_set_contains_state(state, ATK_STATE_CHECKED));
91 g_object_unref(state);
92 }
93
94 // Checks Flutter flags are mapped to appropriate ATK roles.
95 TEST(FlAccessibleNodeTest, GetRole) {
96 g_autoptr(FlDartProject) project = fl_dart_project_new();
97 g_autoptr(FlEngine) engine = fl_engine_new(project);
98
99 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
100
101 fl_accessible_node_set_flags(
102 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsButton));
103 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PUSH_BUTTON);
104
105 fl_accessible_node_set_flags(node, static_cast<FlutterSemanticsFlag>(
106 kFlutterSemanticsFlagHasCheckedState));
107 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_CHECK_BOX);
108
109 fl_accessible_node_set_flags(
110 node, static_cast<FlutterSemanticsFlag>(
111 kFlutterSemanticsFlagHasCheckedState |
112 kFlutterSemanticsFlagIsInMutuallyExclusiveGroup));
113 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_RADIO_BUTTON);
114
115 fl_accessible_node_set_flags(node, static_cast<FlutterSemanticsFlag>(
116 kFlutterSemanticsFlagHasToggledState));
117 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TOGGLE_BUTTON);
118
119 fl_accessible_node_set_flags(node, kFlutterSemanticsFlagIsTextField);
120 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TEXT);
121
122 fl_accessible_node_set_flags(
123 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsTextField |
124 kFlutterSemanticsFlagIsObscured));
125 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PASSWORD_TEXT);
126 }
127
128 // Checks Flutter actions are mapped to the appropriate ATK actions.
129 TEST(FlAccessibleNodeTest, SetActions) {
130 g_autoptr(FlDartProject) project = fl_dart_project_new();
131 g_autoptr(FlEngine) engine = fl_engine_new(project);
132
133 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
134 fl_accessible_node_set_actions(
135 node, static_cast<FlutterSemanticsAction>(
136 kFlutterSemanticsActionTap | kFlutterSemanticsActionLongPress));
137
138 EXPECT_EQ(atk_action_get_n_actions(ATK_ACTION(node)), 2);
139 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 0), "Tap");
140 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 1), "LongPress");
141 }
fl_accessible_node_set_name
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
Definition: fl_accessible_node.cc:542
fl_accessible_node_set_actions
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
Definition: fl_accessible_node.cc:566
fl_accessible_node_set_children
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
Definition: fl_accessible_node.cc:515
fl_accessible_node_set_extents
void fl_accessible_node_set_extents(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
Definition: fl_accessible_node.cc:548
state
AtkStateType state
Definition: fl_accessible_node.cc:10
fl_accessible_node_set_flags
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlag flags)
Definition: fl_accessible_node.cc:559
fl_accessible_node_set_parent
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
Definition: fl_accessible_node.cc:504
fl_accessible_node_new
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, FlutterViewId view_id, int32_t node_id)
Definition: fl_accessible_node.cc:495
fl_accessible_node.h
TEST
TEST(FlAccessibleNodeTest, BuildTree)
Definition: fl_accessible_node_test.cc:11
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:584
height
const uint8_t uint32_t uint32_t * height
Definition: fl_pixel_buffer_texture_test.cc:39
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49