| 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 #include "flutter/shell/platform/linux/testing/fl_test.h"
10
11 // Checks can build a tree of nodes.
12 TEST(FlAccessibleNodeTest, BuildTree) {
13 g_autoptr(FlEngine) engine = make_mock_engine();
14
15 g_autoptr(FlAccessibleNode) root = fl_accessible_node_new(engine, 0);
16 g_autoptr(FlAccessibleNode) child1 = fl_accessible_node_new(engine, 1);
17 fl_accessible_node_set_parent(child1, ATK_OBJECT(root), 0);
18 g_autoptr(FlAccessibleNode) child2 = fl_accessible_node_new(engine, 1);
19 fl_accessible_node_set_parent(child2, ATK_OBJECT(root), 1);
20 g_autoptr(GPtrArray) children =
21 g_ptr_array_new_with_free_func(g_object_unref);
22 g_ptr_array_add(children, g_object_ref(child1));
23 g_ptr_array_add(children, g_object_ref(child2));
24 fl_accessible_node_set_children(root, children);
25
26 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(root)), 2);
27 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(root)), 0);
28 g_autoptr(AtkObject) c1 =
29 atk_object_ref_accessible_child(ATK_OBJECT(root), 0);
30 EXPECT_EQ(ATK_OBJECT(child1), c1);
31 g_autoptr(AtkObject) c2 =
32 atk_object_ref_accessible_child(ATK_OBJECT(root), 1);
33 EXPECT_EQ(ATK_OBJECT(child2), c2);
34 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(root)), nullptr);
35
36 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(child1)), ATK_OBJECT(root));
37 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(child1)), 0);
38 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(child1)), 0);
39
40 EXPECT_EQ(atk_object_get_parent(ATK_OBJECT(child2)), ATK_OBJECT(root));
41 EXPECT_EQ(atk_object_get_index_in_parent(ATK_OBJECT(child2)), 1);
42 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(child2)), 0);
43 }
44
45 // Checks node name is exposed to ATK.
46 TEST(FlAccessibleNodeTest, SetName) {
47 g_autoptr(FlEngine) engine = make_mock_engine();
48
49 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
50 fl_accessible_node_set_name(node, "test");
51 EXPECT_STREQ(atk_object_get_name(ATK_OBJECT(node)), "test");
52 }
53
54 // Checks node extents are exposed to ATK.
55 TEST(FlAccessibleNodeTest, SetExtents) {
56 g_autoptr(FlEngine) engine = make_mock_engine();
57
58 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
59 fl_accessible_node_set_extents(node, 1, 2, 3, 4);
60 gint x, y, width, height;
61 atk_component_get_extents(ATK_COMPONENT(node), &x, &y, &width, &height,
62 ATK_XY_PARENT);
63 EXPECT_EQ(x, 1);
64 EXPECT_EQ(y, 2);
65 EXPECT_EQ(width, 3);
66 EXPECT_EQ(height, 4);
67 }
68
69 // Checks Flutter flags are mapped to appropriate ATK state.
70 TEST(FlAccessibleNodeTest, SetFlags) {
71 g_autoptr(FlEngine) engine = make_mock_engine();
72
73 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
74 fl_accessible_node_set_flags(
75 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsEnabled |
76 kFlutterSemanticsFlagIsFocusable |
77 kFlutterSemanticsFlagIsFocused));
78
79 AtkStateSet* state = atk_object_ref_state_set(ATK_OBJECT(node));
80 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_ENABLED));
81 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_SENSITIVE));
82 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_FOCUSABLE));
83 EXPECT_TRUE(atk_state_set_contains_state(state, ATK_STATE_FOCUSED));
84 EXPECT_TRUE(!atk_state_set_contains_state(state, ATK_STATE_CHECKED));
85 g_object_unref(state);
86 }
87
88 // Checks Flutter flags are mapped to appropriate ATK roles.
89 TEST(FlAccessibleNodeTest, GetRole) {
90 g_autoptr(FlEngine) engine = make_mock_engine();
91
92 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
93
94 fl_accessible_node_set_flags(
95 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsButton));
96 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PUSH_BUTTON);
97
98 fl_accessible_node_set_flags(node, static_cast<FlutterSemanticsFlag>(
99 kFlutterSemanticsFlagHasCheckedState));
100 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_CHECK_BOX);
101
102 fl_accessible_node_set_flags(
103 node, static_cast<FlutterSemanticsFlag>(
104 kFlutterSemanticsFlagHasCheckedState |
105 kFlutterSemanticsFlagIsInMutuallyExclusiveGroup));
106 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_RADIO_BUTTON);
107
108 fl_accessible_node_set_flags(node, static_cast<FlutterSemanticsFlag>(
109 kFlutterSemanticsFlagHasToggledState));
110 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TOGGLE_BUTTON);
111
112 fl_accessible_node_set_flags(node, kFlutterSemanticsFlagIsTextField);
113 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TEXT);
114
115 fl_accessible_node_set_flags(
116 node, static_cast<FlutterSemanticsFlag>(kFlutterSemanticsFlagIsTextField |
117 kFlutterSemanticsFlagIsObscured));
118 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PASSWORD_TEXT);
119 }
120
121 // Checks Flutter actions are mapped to the appropriate ATK actions.
122 TEST(FlAccessibleNodeTest, SetActions) {
123 g_autoptr(FlEngine) engine = make_mock_engine();
124
125 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
126 fl_accessible_node_set_actions(
127 node, static_cast<FlutterSemanticsAction>(
128 kFlutterSemanticsActionTap | kFlutterSemanticsActionLongPress));
129
130 EXPECT_EQ(atk_action_get_n_actions(ATK_ACTION(node)), 2);
131 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 0), "Tap");
132 EXPECT_STREQ(atk_action_get_name(ATK_ACTION(node), 1), "LongPress");
133 }
fl_accessible_node_set_flags
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlag flags)
Definition: fl_accessible_node.cc:542
fl_accessible_node_set_parent
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
Definition: fl_accessible_node.cc:487
fl_accessible_node_set_children
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
Definition: fl_accessible_node.cc:498
height
G_BEGIN_DECLS int height
Definition: fl_backing_store_provider.h:37
state
AtkStateType state
Definition: fl_accessible_node.cc:10
make_mock_engine
static FlEngine * make_mock_engine()
Definition: fl_event_channel_test.cc:24
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:531
fl_accessible_node.h
fl_accessible_node_new
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, int32_t id)
Definition: fl_accessible_node.cc:481
TEST
TEST(FlAccessibleNodeTest, BuildTree)
Definition: fl_accessible_node_test.cc:12
engine
FlEngine * engine
Definition: fl_view_accessible.cc:29
fl_accessible_node_set_name
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
Definition: fl_accessible_node.cc:525
fl_accessible_node_set_actions
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
Definition: fl_accessible_node.cc:549
width
const uint8_t uint32_t * width
Definition: fl_pixel_buffer_texture_test.cc:38
node
G_BEGIN_DECLS const FlutterSemanticsNode * node
Definition: fl_view_accessible.h:40