Flutter Engine
The Flutter Engine
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.
12TEST(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));
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.
46TEST(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.
55TEST(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.
70TEST(FlAccessibleNodeTest, SetFlags) {
71 g_autoptr(FlEngine) engine = make_mock_engine();
72
73 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
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.
89TEST(FlAccessibleNodeTest, GetRole) {
90 g_autoptr(FlEngine) engine = make_mock_engine();
91
92 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
93
96 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_PUSH_BUTTON);
97
100 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_CHECK_BOX);
101
103 node, static_cast<FlutterSemanticsFlag>(
106 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_RADIO_BUTTON);
107
110 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TOGGLE_BUTTON);
111
113 EXPECT_EQ(atk_object_get_role(ATK_OBJECT(node)), ATK_ROLE_TEXT);
114
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.
122TEST(FlAccessibleNodeTest, SetActions) {
123 g_autoptr(FlEngine) engine = make_mock_engine();
124
125 g_autoptr(FlAccessibleNode) node = fl_accessible_node_new(engine, 0);
127 node, static_cast<FlutterSemanticsAction>(
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}
FlutterSemanticsAction
Definition: embedder.h:113
@ kFlutterSemanticsActionLongPress
Definition: embedder.h:119
@ kFlutterSemanticsActionTap
Definition: embedder.h:116
FlutterSemanticsFlag
Definition: embedder.h:172
@ kFlutterSemanticsFlagHasToggledState
The semantics node has the quality of either being "on" or "off".
Definition: embedder.h:209
@ kFlutterSemanticsFlagIsInMutuallyExclusiveGroup
Whether a semantic node is in a mutually exclusive group.
Definition: embedder.h:192
@ kFlutterSemanticsFlagIsButton
Whether the semantic node represents a button.
Definition: embedder.h:181
@ kFlutterSemanticsFlagIsObscured
Whether the value of the semantics node is obscured.
Definition: embedder.h:196
@ kFlutterSemanticsFlagIsFocused
Whether the semantic node currently holds the user's focus.
Definition: embedder.h:185
@ kFlutterSemanticsFlagIsEnabled
Whether a semantic node that hasEnabledState is currently enabled.
Definition: embedder.h:190
@ kFlutterSemanticsFlagIsFocusable
Whether the semantic node can hold the user's focus.
Definition: embedder.h:232
@ kFlutterSemanticsFlagIsTextField
Whether the semantic node represents a text field.
Definition: embedder.h:183
@ kFlutterSemanticsFlagHasCheckedState
Definition: embedder.h:175
FlutterEngine engine
Definition: main.cc:68
void fl_accessible_node_set_name(FlAccessibleNode *self, const gchar *name)
void fl_accessible_node_set_actions(FlAccessibleNode *self, FlutterSemanticsAction actions)
void fl_accessible_node_set_children(FlAccessibleNode *self, GPtrArray *children)
void fl_accessible_node_set_extents(FlAccessibleNode *self, gint x, gint y, gint width, gint height)
AtkStateType state
void fl_accessible_node_set_flags(FlAccessibleNode *self, FlutterSemanticsFlag flags)
void fl_accessible_node_set_parent(FlAccessibleNode *self, AtkObject *parent, gint index)
FlAccessibleNode * fl_accessible_node_new(FlEngine *engine, int32_t id)
TEST(FlAccessibleNodeTest, BuildTree)
static FlEngine * make_mock_engine()
double y
double x
static void SetName(Thread *thread, JSONStream *js)
Definition: service.cc:5710
string root
Definition: scale_cpu.py:20
int32_t height
int32_t width
#define EXPECT_TRUE(handle)
Definition: unit_test.h:678