| Flutter Linux Embedder |

Functions
fl_view_test.cc File Reference
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_view.h"`
`#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"`
`#include "flutter/shell/platform/linux/fl_engine_private.h"`
`#include "flutter/shell/platform/linux/fl_view_private.h"`
`#include "flutter/shell/platform/linux/testing/fl_test.h"`
`#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"`
`#include "flutter/shell/platform/linux/testing/mock_gtk.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Functions
| TEST (FlViewTest, GetEngine)
| TEST (FlViewTest, StateUpdateDoesNotHappenInInit)
| TEST (FlViewTest, SemanticsUpdate)
| TEST (FlViewTest, SemanticsUpdateOtherView)
| TEST (FlViewTest, SecondaryView)
| TEST (FlViewTest, SecondaryViewError)
| TEST (FlViewTest, ViewDestroy)
| TEST (FlViewTest, ViewDestroyError)

## Function Documentation

## ◆ TEST() [1/8]

TEST | ( | FlViewTest | ,
|  | GetEngine |
| ) |  |

Definition at line 22 of file fl_view_test.cc.

22 {
23 flutter::testing::fl_ensure_gtk_init();
24 g_autoptr(FlDartProject) project = fl_dart_project_new();
25 FlView* view = fl_view_new(project);
26
27 // Check the engine is immediately available (i.e. before the widget is
28 // realized).
29 FlEngine* engine = fl_view_get_engine(view);
30 EXPECT_NE(engine, nullptr);
31 }
view
FlView * view
Definition: fl_application.cc:36
g_autoptr
g_autoptr(GMutexLocker) locker
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:52
fl_view_new
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition: fl_view.cc:761
fl_view_get_engine
G_MODULE_EXPORT FlEngine * fl_view_get_engine(FlView *self)
Definition: fl_view.cc:788

References fl_dart_project_new(), fl_view_get_engine(), fl_view_new(), g_autoptr(), and view.

## ◆ TEST() [2/8]

TEST | ( | FlViewTest | ,
|  | SecondaryView |
| ) |  |

Definition at line 124 of file fl_view_test.cc.

124 {
125 flutter::testing::fl_ensure_gtk_init();
126
127 g_autoptr(FlDartProject) project = fl_dart_project_new();
128 FlView* implicit_view = fl_view_new(project);
129
130 FlEngine* engine = fl_view_get_engine(implicit_view);
131
132 FlutterViewId view_id = -1;
133 fl_engine_get_embedder_api(engine)->AddView = MOCK_ENGINE_PROC(
134 AddView, ([&view_id](auto engine, const FlutterAddViewInfo* info) {
135 view_id = info->view_id;
136 FlutterAddViewResult result = {
137 .struct_size = sizeof(FlutterAddViewResult),
138 .added = true,
139 .user_data = info->user_data};
140 info->add_view_callback(&result);
141 return kSuccess;
142 }));
143
144 g_autoptr(GError) error = nullptr;
145 EXPECT_TRUE(fl_engine_start(engine, &error));
146
147 FlView* secondary_view = fl_view_new_for_engine(engine);
148 EXPECT_EQ(view_id, fl_view_get_id(secondary_view));
149 }
fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:859
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:721
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_view_new_for_engine
G_MODULE_EXPORT FlView * fl_view_new_for_engine(FlEngine *engine)
Definition: fl_view.cc:775
fl_view_get_id
G_MODULE_EXPORT int64_t fl_view_get_id(FlView *self)
Definition: fl_view.cc:794
view_id
G_BEGIN_DECLS FlutterViewId view_id
Definition: fl_view_accessible.h:49

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), fl_view_get_engine(), fl_view_get_id(), fl_view_new(), fl_view_new_for_engine(), g_autoptr(), user_data, and view_id.

## ◆ TEST() [3/8]

TEST | ( | FlViewTest | ,
|  | SecondaryViewError |
| ) |  |

Definition at line 152 of file fl_view_test.cc.

152 {
153 flutter::testing::fl_ensure_gtk_init();
154
155 g_autoptr(FlDartProject) project = fl_dart_project_new();
156 FlView* implicit_view = fl_view_new(project);
157
158 FlEngine* engine = fl_view_get_engine(implicit_view);
159
160 FlutterViewId view_id = -1;
161 fl_engine_get_embedder_api(engine)->AddView = MOCK_ENGINE_PROC(
162 AddView, ([&view_id](auto engine, const FlutterAddViewInfo* info) {
163 view_id = info->view_id;
164 return kInvalidArguments;
165 }));
166
167 g_autoptr(GError) error = nullptr;
168 EXPECT_TRUE(fl_engine_start(engine, &error));
169
170 FlView* secondary_view = fl_view_new_for_engine(engine);
171 EXPECT_EQ(view_id, fl_view_get_id(secondary_view));
172 }

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), fl_view_get_engine(), fl_view_get_id(), fl_view_new(), fl_view_new_for_engine(), g_autoptr(), and view_id.

## ◆ TEST() [4/8]

TEST | ( | FlViewTest | ,
|  | SemanticsUpdate |
| ) |  |

Definition at line 75 of file fl_view_test.cc.

75 {
76 flutter::testing::fl_ensure_gtk_init();
77
78 g_autoptr(FlDartProject) project = fl_dart_project_new();
79 FlView* view = fl_view_new(project);
80
81 FlEngine* engine = fl_view_get_engine(view);
82 g_autoptr(GError) error = nullptr;
83 EXPECT_TRUE(fl_engine_start(engine, &error));
84
85 FlutterSemanticsFlags flags = {};
86 FlutterSemanticsNode2 root_node = {
87 .id = 0, .label = "root", .flags2 = &flags};
88 FlutterSemanticsNode2* nodes[1] = {&root_node};
89 FlutterSemanticsUpdate2 update = {
90 .node_count = 1, .nodes = nodes, .view_id = 0};
91 g_signal_emit_by_name(engine, "update-semantics", &update);
92
93 FlViewAccessible* accessible = fl_view_get_accessible(view);
94 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(accessible)), 1);
95 AtkObject* root_object =
96 atk_object_ref_accessible_child(ATK_OBJECT(accessible), 0);
97 EXPECT_STREQ(atk_object_get_name(root_object), "root");
98 }
fl_view_get_accessible
FlViewAccessible * fl_view_get_accessible(FlView *self)
Definition: fl_view.cc:806

References error, fl_dart_project_new(), fl_engine_start(), fl_view_get_accessible(), fl_view_get_engine(), fl_view_new(), g_autoptr(), and view.

## ◆ TEST() [5/8]

TEST | ( | FlViewTest | ,
|  | SemanticsUpdateOtherView |
| ) |  |

Definition at line 101 of file fl_view_test.cc.

101 {
102 flutter::testing::fl_ensure_gtk_init();
103
104 g_autoptr(FlDartProject) project = fl_dart_project_new();
105 FlView* view = fl_view_new(project);
106
107 FlEngine* engine = fl_view_get_engine(view);
108 g_autoptr(GError) error = nullptr;
109 EXPECT_TRUE(fl_engine_start(engine, &error));
110
111 FlutterSemanticsFlags flags = {};
112 FlutterSemanticsNode2 root_node = {
113 .id = 0, .label = "root", .flags2 = &flags};
114 FlutterSemanticsNode2* nodes[1] = {&root_node};
115 FlutterSemanticsUpdate2 update = {
116 .node_count = 1, .nodes = nodes, .view_id = 99};
117 g_signal_emit_by_name(engine, "update-semantics", &update);
118
119 FlViewAccessible* accessible = fl_view_get_accessible(view);
120 EXPECT_EQ(atk_object_get_n_accessible_children(ATK_OBJECT(accessible)), 0);
121 }

References error, fl_dart_project_new(), fl_engine_start(), fl_view_get_accessible(), fl_view_get_engine(), fl_view_new(), g_autoptr(), and view.

## ◆ TEST() [6/8]

TEST | ( | FlViewTest | ,
|  | StateUpdateDoesNotHappenInInit |
| ) |  |

Definition at line 33 of file fl_view_test.cc.

33 {
34 flutter::testing::fl_ensure_gtk_init();
35 g_autoptr(FlDartProject) project = fl_dart_project_new();
36 FlView* view = fl_view_new(project);
37 // Check that creating a view doesn't try to query the window state in
38 // initialization, causing a critical log to be issued.
39 EXPECT_EQ(
40 flutter::testing::fl_get_received_gtk_log_levels() & G_LOG_LEVEL_CRITICAL,
41 (GLogLevelFlags)0x0);
42
43 (void)view;
44 }

References fl_dart_project_new(), fl_view_new(), g_autoptr(), and view.

## ◆ TEST() [7/8]

TEST | ( | FlViewTest | ,
|  | ViewDestroy |
| ) |  |

Definition at line 175 of file fl_view_test.cc.

175 {
176 flutter::testing::fl_ensure_gtk_init();
177
178 g_autoptr(FlDartProject) project = fl_dart_project_new();
179 FlView* implicit_view = fl_view_new(project);
180
181 FlEngine* engine = fl_view_get_engine(implicit_view);
182
183 g_autoptr(GPtrArray) removed_views = g_ptr_array_new();
184 fl_engine_get_embedder_api(engine)->RemoveView = MOCK_ENGINE_PROC(
185 RemoveView,
186 ([removed_views](auto engine, const FlutterRemoveViewInfo* info) {
187 g_ptr_array_add(removed_views, GINT_TO_POINTER(info->view_id));
188 return kSuccess;
189 }));
190
191 g_autoptr(GError) error = nullptr;
192 EXPECT_TRUE(fl_engine_start(engine, &error));
193
194 FlView* secondary_view = fl_view_new_for_engine(engine);
195
196 int64_t implicit_view_id = fl_view_get_id(implicit_view);
197 int64_t secondary_view_id = fl_view_get_id(secondary_view);
198
199 fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
200 fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
201
202 EXPECT_EQ(removed_views->len, 2u);
203 EXPECT_EQ(GPOINTER_TO_INT(g_ptr_array_index(removed_views, 0)),
204 secondary_view_id);
205 EXPECT_EQ(GPOINTER_TO_INT(g_ptr_array_index(removed_views, 1)),
206 implicit_view_id);
207 }

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), fl_view_get_engine(), fl_view_get_id(), fl_view_new(), fl_view_new_for_engine(), and g_autoptr().

## ◆ TEST() [8/8]

TEST | ( | FlViewTest | ,
|  | ViewDestroyError |
| ) |  |

Definition at line 210 of file fl_view_test.cc.

210 {
211 flutter::testing::fl_ensure_gtk_init();
212
213 g_autoptr(FlDartProject) project = fl_dart_project_new();
214 FlView* implicit_view = fl_view_new(project);
215
216 FlEngine* engine = fl_view_get_engine(implicit_view);
217
218 fl_engine_get_embedder_api(engine)->RemoveView = MOCK_ENGINE_PROC(
219 RemoveView, ([](auto engine, const FlutterRemoveViewInfo* info) {
220 return kInvalidArguments;
221 }));
222
223 g_autoptr(GError) error = nullptr;
224 EXPECT_TRUE(fl_engine_start(engine, &error));
225
226 FlView* secondary_view = fl_view_new_for_engine(engine);
227
228 fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
229 fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
230 }

References error, fl_dart_project_new(), fl_engine_get_embedder_api(), fl_engine_start(), fl_view_get_engine(), fl_view_new(), fl_view_new_for_engine(), and g_autoptr().