Flutter Linux Embedder
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/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/fl_test_gtk_logs.h"
#include "flutter/shell/platform/linux/testing/mock_window.h"
#include "gtest/gtest.h"

Go to the source code of this file.

Functions

static void first_frame_cb (FlView *view, gboolean *first_frame_emitted)
 
 TEST (FlViewTest, GetEngine)
 
 TEST (FlViewTest, StateUpdateDoesNotHappenInInit)
 
 TEST (FlViewTest, FirstFrameSignal)
 
 TEST (FlViewTest, SecondaryView)
 
 TEST (FlViewTest, SecondaryViewError)
 
 TEST (FlViewTest, ViewDestroy)
 
 TEST (FlViewTest, ViewDestroyError)
 

Function Documentation

◆ first_frame_cb()

static void first_frame_cb ( FlView *  view,
gboolean *  first_frame_emitted 
)
static

Definition at line 14 of file fl_view_test.cc.

14  {
15  *first_frame_emitted = TRUE;
16 }

References TRUE.

Referenced by TEST().

◆ TEST() [1/7]

TEST ( FlViewTest  ,
FirstFrameSignal   
)

Definition at line 42 of file fl_view_test.cc.

42  {
43  flutter::testing::fl_ensure_gtk_init();
44 
45  g_autoptr(FlDartProject) project = fl_dart_project_new();
46  FlView* view = fl_view_new(project);
47  gboolean first_frame_emitted = FALSE;
48  g_signal_connect(view, "first-frame", G_CALLBACK(first_frame_cb),
49  &first_frame_emitted);
50 
51  EXPECT_FALSE(first_frame_emitted);
52 
53  fl_renderable_redraw(FL_RENDERABLE(view));
54 
55  // Signal is emitted in idle, clear the main loop.
56  while (g_main_context_iteration(g_main_context_default(), FALSE)) {
57  // Repeat until nothing to iterate on.
58  }
59 
60  // Check view has detected frame.
61  EXPECT_TRUE(first_frame_emitted);
62 }

References first_frame_cb(), fl_dart_project_new(), fl_renderable_redraw(), fl_view_new(), and view.

◆ TEST() [2/7]

TEST ( FlViewTest  ,
GetEngine   
)

Definition at line 18 of file fl_view_test.cc.

18  {
19  flutter::testing::fl_ensure_gtk_init();
20  g_autoptr(FlDartProject) project = fl_dart_project_new();
21  FlView* view = fl_view_new(project);
22 
23  // Check the engine is immediately available (i.e. before the widget is
24  // realized).
25  FlEngine* engine = fl_view_get_engine(view);
26  EXPECT_NE(engine, nullptr);
27 }

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

◆ TEST() [3/7]

TEST ( FlViewTest  ,
SecondaryView   
)

Definition at line 65 of file fl_view_test.cc.

65  {
66  flutter::testing::fl_ensure_gtk_init();
67 
68  g_autoptr(FlDartProject) project = fl_dart_project_new();
69  FlView* implicit_view = fl_view_new(project);
70 
71  FlEngine* engine = fl_view_get_engine(implicit_view);
72 
73  FlutterViewId view_id = -1;
74  fl_engine_get_embedder_api(engine)->AddView = MOCK_ENGINE_PROC(
75  AddView, ([&view_id](auto engine, const FlutterAddViewInfo* info) {
76  view_id = info->view_id;
77  FlutterAddViewResult result = {
78  .struct_size = sizeof(FlutterAddViewResult),
79  .added = true,
80  .user_data = info->user_data};
81  info->add_view_callback(&result);
82  return kSuccess;
83  }));
84 
85  g_autoptr(GError) error = nullptr;
86  EXPECT_TRUE(fl_engine_start(engine, &error));
87 
88  FlView* secondary_view = fl_view_new_for_engine(engine);
89  EXPECT_EQ(view_id, fl_view_get_id(secondary_view));
90 }

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 user_data.

◆ TEST() [4/7]

TEST ( FlViewTest  ,
SecondaryViewError   
)

Definition at line 93 of file fl_view_test.cc.

93  {
94  flutter::testing::fl_ensure_gtk_init();
95 
96  g_autoptr(FlDartProject) project = fl_dart_project_new();
97  FlView* implicit_view = fl_view_new(project);
98 
99  FlEngine* engine = fl_view_get_engine(implicit_view);
100 
101  FlutterViewId view_id = -1;
102  fl_engine_get_embedder_api(engine)->AddView = MOCK_ENGINE_PROC(
103  AddView, ([&view_id](auto engine, const FlutterAddViewInfo* info) {
104  view_id = info->view_id;
105  return kInvalidArguments;
106  }));
107 
108  g_autoptr(GError) error = nullptr;
109  EXPECT_TRUE(fl_engine_start(engine, &error));
110 
111  FlView* secondary_view = fl_view_new_for_engine(engine);
112  EXPECT_EQ(view_id, fl_view_get_id(secondary_view));
113 }

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(), and fl_view_new_for_engine().

◆ TEST() [5/7]

TEST ( FlViewTest  ,
StateUpdateDoesNotHappenInInit   
)

Definition at line 29 of file fl_view_test.cc.

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

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

◆ TEST() [6/7]

TEST ( FlViewTest  ,
ViewDestroy   
)

Definition at line 116 of file fl_view_test.cc.

116  {
117  flutter::testing::fl_ensure_gtk_init();
118 
119  g_autoptr(FlDartProject) project = fl_dart_project_new();
120  FlView* implicit_view = fl_view_new(project);
121 
122  FlEngine* engine = fl_view_get_engine(implicit_view);
123 
124  g_autoptr(GPtrArray) removed_views = g_ptr_array_new();
125  fl_engine_get_embedder_api(engine)->RemoveView = MOCK_ENGINE_PROC(
126  RemoveView,
127  ([removed_views](auto engine, const FlutterRemoveViewInfo* info) {
128  g_ptr_array_add(removed_views, GINT_TO_POINTER(info->view_id));
129  return kSuccess;
130  }));
131 
132  g_autoptr(GError) error = nullptr;
133  EXPECT_TRUE(fl_engine_start(engine, &error));
134 
135  FlView* secondary_view = fl_view_new_for_engine(engine);
136 
137  int64_t implicit_view_id = fl_view_get_id(implicit_view);
138  int64_t secondary_view_id = fl_view_get_id(secondary_view);
139 
140  fl_gtk_widget_destroy(GTK_WIDGET(secondary_view));
141  fl_gtk_widget_destroy(GTK_WIDGET(implicit_view));
142 
143  EXPECT_EQ(removed_views->len, 2u);
144  EXPECT_EQ(GPOINTER_TO_INT(g_ptr_array_index(removed_views, 0)),
145  secondary_view_id);
146  EXPECT_EQ(GPOINTER_TO_INT(g_ptr_array_index(removed_views, 1)),
147  implicit_view_id);
148 }

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(), and fl_view_new_for_engine().

◆ TEST() [7/7]

TEST ( FlViewTest  ,
ViewDestroyError   
)

Definition at line 151 of file fl_view_test.cc.

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

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

fl_engine_get_embedder_api
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
Definition: fl_engine.cc:721
fl_view_get_id
G_MODULE_EXPORT int64_t fl_view_get_id(FlView *self)
Definition: fl_view.cc:795
fl_view_new_for_engine
G_MODULE_EXPORT FlView * fl_view_new_for_engine(FlEngine *engine)
Definition: fl_view.cc:764
fl_dart_project_new
G_MODULE_EXPORT FlDartProject * fl_dart_project_new()
Definition: fl_dart_project.cc:50
fl_view_new
G_MODULE_EXPORT FlView * fl_view_new(FlDartProject *project)
Definition: fl_view.cc:736
user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue gpointer user_data
Definition: fl_event_channel.h:90
TRUE
return TRUE
Definition: fl_pixel_buffer_texture_test.cc:53
fl_view_get_engine
G_MODULE_EXPORT FlEngine * fl_view_get_engine(FlView *self)
Definition: fl_view.cc:789
view
FlView * view
Definition: fl_application.cc:36
error
const uint8_t uint32_t uint32_t GError ** error
Definition: fl_pixel_buffer_texture_test.cc:40
fl_renderable_redraw
void fl_renderable_redraw(FlRenderable *self)
Definition: fl_renderable.cc:11
fl_engine_start
gboolean fl_engine_start(FlEngine *self, GError **error)
Definition: fl_engine.cc:607
first_frame_cb
static void first_frame_cb(FlView *view, gboolean *first_frame_emitted)
Definition: fl_view_test.cc:14