| Flutter Linux Embedder |

Functions
fl_window_state_monitor_test.cc File Reference
`#include "flutter/shell/platform/linux/fl_window_state_monitor.h"`
`#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"`
`#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"`
`#include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"`
`#include "flutter/shell/platform/linux/testing/mock_window.h"`
`#include "gtest/gtest.h"`

Go to the source code of this file.

## Functions
| TEST (FlWindowStateMonitorTest, GainFocus)
| TEST (FlWindowStateMonitorTest, LoseFocus)
| TEST (FlWindowStateMonitorTest, EnterIconified)
| TEST (FlWindowStateMonitorTest, LeaveIconified)
| TEST (FlWindowStateMonitorTest, LeaveIconifiedFocused)
| TEST (FlWindowStateMonitorTest, EnterWithdrawn)
| TEST (FlWindowStateMonitorTest, LeaveWithdrawn)
| TEST (FlWindowStateMonitorTest, LeaveWithdrawnFocused)

## Function Documentation

## ◆ TEST() [1/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | EnterIconified |
| ) |  |

Definition at line 83 of file fl_window_state_monitor_test.cc.

83 {
84 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
85 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
86
87 gtk_init(0, nullptr);
88
89 EXPECT_CALL(mock_window, gdk_window_get_state)
90 .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
91 gboolean called = TRUE;
92 fl_mock_binary_messenger_set_string_message_channel(
93 messenger, "flutter/lifecycle",
94 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
95 gpointer user_data) {
96 gboolean* called = static_cast<gboolean*>(user_data);
97 *called = TRUE;
98 EXPECT_STREQ(fl_value_get_string(message), "AppLifecycleState.hidden");
99 return fl_value_new_string("");
100 },
101 &called);
102
103 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
104 gtk_widget_show(GTK_WIDGET(window));
105 g_autoptr(FlWindowStateMonitor) monitor =
106 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
107
108 GdkEvent event = {
109 .window_state = {.new_window_state = GDK_WINDOW_STATE_ICONIFIED}};
110 gboolean handled;
111 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
112 EXPECT_TRUE(called);
113
114 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
115 }
fl_binary_messenger_shutdown
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
Definition: fl_binary_messenger.cc:500
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_value_new_string
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
fl_value_get_string
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
Definition: fl_value.cc:682
FlValue
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42
fl_window_state_monitor_new
FlWindowStateMonitor * fl_window_state_monitor_new(FlBinaryMessenger *messenger, GtkWindow *window)
Definition: fl_window_state_monitor.cc:104

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [2/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | EnterWithdrawn |
| ) |  |

Definition at line 187 of file fl_window_state_monitor_test.cc.

187 {
188 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
189 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
190
191 gtk_init(0, nullptr);
192
193 EXPECT_CALL(mock_window, gdk_window_get_state)
194 .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
195 gboolean called = TRUE;
196 fl_mock_binary_messenger_set_string_message_channel(
197 messenger, "flutter/lifecycle",
198 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
199 gpointer user_data) {
200 gboolean* called = static_cast<gboolean*>(user_data);
201 *called = TRUE;
202 EXPECT_STREQ(fl_value_get_string(message), "AppLifecycleState.hidden");
203 return fl_value_new_string("");
204 },
205 &called);
206
207 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
208 gtk_widget_show(GTK_WIDGET(window));
209 g_autoptr(FlWindowStateMonitor) monitor =
210 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
211
212 GdkEvent event = {
213 .window_state = {.new_window_state = GDK_WINDOW_STATE_WITHDRAWN}};
214 gboolean handled;
215 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
216 EXPECT_TRUE(called);
217
218 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
219 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [3/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | GainFocus |
| ) |  |

Definition at line 13 of file fl_window_state_monitor_test.cc.

13 {
14 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
15 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
16
17 gtk_init(0, nullptr);
18
19 EXPECT_CALL(mock_window, gdk_window_get_state)
20 .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
21
22 gboolean called = TRUE;
23 fl_mock_binary_messenger_set_string_message_channel(
24 messenger, "flutter/lifecycle",
25 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
26 gpointer user_data) {
27 gboolean* called = static_cast<gboolean*>(user_data);
28 *called = TRUE;
29 EXPECT_STREQ(fl_value_get_string(message), "AppLifecycleState.resumed");
30 return fl_value_new_string("");
31 },
32 &called);
33
34 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
35 gtk_widget_show(GTK_WIDGET(window));
36 g_autoptr(FlWindowStateMonitor) monitor =
37 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
38
39 GdkEvent event = {
40 .window_state = {.new_window_state = GDK_WINDOW_STATE_FOCUSED}};
41 gboolean handled;
42 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
43 EXPECT_TRUE(called);
44
45 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
46 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [4/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | LeaveIconified |
| ) |  |

Definition at line 117 of file fl_window_state_monitor_test.cc.

117 {
118 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
119 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
120
121 gtk_init(0, nullptr);
122
123 EXPECT_CALL(mock_window, gdk_window_get_state)
124 .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
125 gboolean called = TRUE;
126 fl_mock_binary_messenger_set_string_message_channel(
127 messenger, "flutter/lifecycle",
128 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
129 gpointer user_data) {
130 gboolean* called = static_cast<gboolean*>(user_data);
131 *called = TRUE;
132 EXPECT_STREQ(fl_value_get_string(message),
133 "AppLifecycleState.inactive");
134 return fl_value_new_string("");
135 },
136 &called);
137
138 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
139 gtk_widget_show(GTK_WIDGET(window));
140 g_autoptr(FlWindowStateMonitor) monitor =
141 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
142
143 GdkEvent event = {
144 .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
145 gboolean handled;
146 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
147 EXPECT_TRUE(called);
148
149 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
150 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [5/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | LeaveIconifiedFocused |
| ) |  |

Definition at line 152 of file fl_window_state_monitor_test.cc.

152 {
153 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
154 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
155
156 gtk_init(0, nullptr);
157
158 EXPECT_CALL(mock_window, gdk_window_get_state)
159 .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
160 gboolean called = TRUE;
161 fl_mock_binary_messenger_set_string_message_channel(
162 messenger, "flutter/lifecycle",
163 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
164 gpointer user_data) {
165 gboolean* called = static_cast<gboolean*>(user_data);
166 *called = TRUE;
167 EXPECT_STREQ(fl_value_get_string(message), "AppLifecycleState.resumed");
168 return fl_value_new_string("");
169 },
170 &called);
171
172 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
173 gtk_widget_show(GTK_WIDGET(window));
174 g_autoptr(FlWindowStateMonitor) monitor =
175 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
176
177 GdkEvent event = {
178 .window_state = {.new_window_state = static_cast<GdkWindowState>(
179 GDK_WINDOW_STATE_FOCUSED)}};
180 gboolean handled;
181 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
182 EXPECT_TRUE(called);
183
184 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
185 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [6/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | LeaveWithdrawn |
| ) |  |

Definition at line 221 of file fl_window_state_monitor_test.cc.

221 {
222 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
223 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
224
225 gtk_init(0, nullptr);
226
227 EXPECT_CALL(mock_window, gdk_window_get_state)
228 .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
229 gboolean called = TRUE;
230 fl_mock_binary_messenger_set_string_message_channel(
231 messenger, "flutter/lifecycle",
232 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
233 gpointer user_data) {
234 gboolean* called = static_cast<gboolean*>(user_data);
235 *called = TRUE;
236 EXPECT_STREQ(fl_value_get_string(message),
237 "AppLifecycleState.inactive");
238 return fl_value_new_string("");
239 },
240 &called);
241
242 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
243 gtk_widget_show(GTK_WIDGET(window));
244 g_autoptr(FlWindowStateMonitor) monitor =
245 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
246
247 GdkEvent event = {
248 .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
249 gboolean handled;
250 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
251 EXPECT_TRUE(called);
252
253 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
254 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [7/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | LeaveWithdrawnFocused |
| ) |  |

Definition at line 256 of file fl_window_state_monitor_test.cc.

256 {
257 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
258 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
259
260 gtk_init(0, nullptr);
261
262 EXPECT_CALL(mock_window, gdk_window_get_state)
263 .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
264 gboolean called = TRUE;
265 fl_mock_binary_messenger_set_string_message_channel(
266 messenger, "flutter/lifecycle",
267 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
268 gpointer user_data) {
269 gboolean* called = static_cast<gboolean*>(user_data);
270 *called = TRUE;
271 EXPECT_STREQ(fl_value_get_string(message), "AppLifecycleState.resumed");
272 return fl_value_new_string("");
273 },
274 &called);
275
276 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
277 gtk_widget_show(GTK_WIDGET(window));
278 g_autoptr(FlWindowStateMonitor) monitor =
279 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
280
281 GdkEvent event = {
282 .window_state = {.new_window_state = static_cast<GdkWindowState>(
283 GDK_WINDOW_STATE_FOCUSED)}};
284 gboolean handled;
285 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
286 EXPECT_TRUE(called);
287
288 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
289 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.

## ◆ TEST() [8/8]

TEST | ( | FlWindowStateMonitorTest | ,
|  | LoseFocus |
| ) |  |

Definition at line 48 of file fl_window_state_monitor_test.cc.

48 {
49 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
50 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
51
52 gtk_init(0, nullptr);
53
54 EXPECT_CALL(mock_window, gdk_window_get_state)
55 .WillOnce(::testing::Return(GDK_WINDOW_STATE_FOCUSED));
56 gboolean called = TRUE;
57 fl_mock_binary_messenger_set_string_message_channel(
58 messenger, "flutter/lifecycle",
59 [](FlMockBinaryMessenger* messenger, GTask* task, FlValue* message,
60 gpointer user_data) {
61 gboolean* called = static_cast<gboolean*>(user_data);
62 *called = TRUE;
63 EXPECT_STREQ(fl_value_get_string(message),
64 "AppLifecycleState.inactive");
65 return fl_value_new_string("");
66 },
67 &called);
68
69 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
70 gtk_widget_show(GTK_WIDGET(window));
71 g_autoptr(FlWindowStateMonitor) monitor =
72 fl_window_state_monitor_new(FL_BINARY_MESSENGER(messenger), window);
73
74 GdkEvent event = {
75 .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
76 gboolean handled;
77 g_signal_emit_by_name(window, "window-state-event", &event, &handled);
78 EXPECT_TRUE(called);
79
80 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
81 }

References fl_binary_messenger_shutdown(), fl_value_get_string(), fl_value_new_string(), fl_window_state_monitor_new(), TRUE, and user_data.