| 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 FlutterSemanticsFlags flags = {};
81 flags.is_enabled = kFlutterTristateTrue;
82 flags.is_focused = kFlutterTristateTrue;
83 fl_accessible_node_set_flags(node, &flags);
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 FlutterSemanticsFlags flags1 = {};
102 flags1.is_button = true;
103 fl_accessible_node_set_flags(node, &flags1);
104 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PUSH_BUTTON);
105
106 FlutterSemanticsFlags flags2 = {};
107 flags2.is_checked = kFlutterCheckStateFalse;
108 fl_accessible_node_set_flags(node, &flags2);
109 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_CHECK_BOX);
110
111 FlutterSemanticsFlags flags3 = {};
112 flags3.is_checked = kFlutterCheckStateFalse;
113 flags3.is_in_mutually_exclusive_group = true;
114 fl_accessible_node_set_flags(node, &flags3);
115 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_RADIO_BUTTON);
116
117 FlutterSemanticsFlags flags4 = {};
118 flags4.is_toggled = kFlutterTristateFalse;
119 fl_accessible_node_set_flags(node, &flags4);
120 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TOGGLE_BUTTON);
121
122 FlutterSemanticsFlags flags5 = {};
123 flags5.is_text_field = true;
124 fl_accessible_node_set_flags(node, &flags5);
125 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TEXT);
126
127 FlutterSemanticsFlags flags6 = {};
128 flags6.is_text_field = true;
129 flags6.is_obscured = true;
130 fl_accessible_node_set_flags(node, &flags6);
131 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PASSWORD_TEXT);
132 }
133
134 // Checks Flutter actions are mapped to the appropriate ATK actions.
135 TEST(FlAccessibleNodeTest, SetActions) {
136 g_autoptr(FlDartProject) project = fl_dart_project_new();
137 g_autoptr(FlEngine) engine = fl_engine_new(project);
138
139 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 123, 0);
140 fl_accessible_node_set_actions(
141 node, static_cast<FlutterSemanticsAction>(
142 kFlutterSemanticsActionTap | kFlutterSemanticsActionLongPress));
143
144 EXPECT_EQ(atk_action_get_n_actions(ATK_ACTION(node)), 2);
145 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 0), "Tap");
146 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 1), "LongPress");
147 }
fl_accessible_node_set_name
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
Definition: fl_accessible_node.cc:576
fl_accessible_node_set_actions
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
Definition: fl_accessible_node.cc:600
fl_accessible_node_set_children
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
Definition: fl_accessible_node.cc:549
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:582
fl_accessible_node_set_parent
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
Definition: fl_accessible_node.cc:538
fl_accessible_node_set_flags
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlags *flags)
Definition: fl_accessible_node.cc:593
fl_accessible_node_new
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, FlutterViewId view_id, int32_t node_id)
Definition: fl_accessible_node.cc:529
fl_accessible_node.h
TEST
TEST(FlAccessibleNodeTest, BuildTree)
Definition: fl_accessible_node_test.cc:11
height
self height
Definition: fl_compositor_software.cc:43
g_autoptr
g_autoptr(GMutexLocker) locker
width
self width
Definition: fl_compositor_software.cc:42
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_engine_new
G_MODULE_EXPORT FlEngine * fl_engine_new(FlDartProject *project)
Definition: fl_engine.cc:693
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49