Flutter Linux Embedder
fl_window_state_monitor_test.cc File Reference
#include "flutter/shell/platform/linux/fl_window_state_monitor.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_string_codec.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/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.

Classes

class  FlValueStringMatcher
 

Functions

::testing::Matcher< GBytes * > LifecycleString (const std::string &value)
 
 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

◆ LifecycleString()

::testing::Matcher<GBytes*> LifecycleString ( const std::string &  value)

Definition at line 52 of file fl_window_state_monitor_test.cc.

52  {
53  return FlValueStringMatcher(::testing::StrEq(value));
54 }

References value.

Referenced by TEST().

◆ TEST() [1/8]

TEST ( FlWindowStateMonitorTest  ,
EnterIconified   
)

Definition at line 106 of file fl_window_state_monitor_test.cc.

106  {
107  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
108  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
109 
110  gtk_init(0, nullptr);
111 
112  EXPECT_CALL(mock_window, gdk_window_get_state)
113  .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
114  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
115  ::testing::Eq<FlBinaryMessenger*>(messenger),
116  ::testing::StrEq("flutter/lifecycle"),
117  LifecycleString("AppLifecycleState.hidden"),
118  ::testing::_, ::testing::_, ::testing::_));
119 
120  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
121  gtk_widget_show(GTK_WIDGET(window));
122  g_autoptr(FlWindowStateMonitor) monitor =
123  fl_window_state_monitor_new(messenger, window);
124 
125  GdkEvent event = {
126  .window_state = {.new_window_state = GDK_WINDOW_STATE_ICONIFIED}};
127  gboolean handled;
128  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
129 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [2/8]

TEST ( FlWindowStateMonitorTest  ,
EnterWithdrawn   
)

Definition at line 182 of file fl_window_state_monitor_test.cc.

182  {
183  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
184  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
185 
186  gtk_init(0, nullptr);
187 
188  EXPECT_CALL(mock_window, gdk_window_get_state)
189  .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
190  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
191  ::testing::Eq<FlBinaryMessenger*>(messenger),
192  ::testing::StrEq("flutter/lifecycle"),
193  LifecycleString("AppLifecycleState.hidden"),
194  ::testing::_, ::testing::_, ::testing::_));
195 
196  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
197  gtk_widget_show(GTK_WIDGET(window));
198  g_autoptr(FlWindowStateMonitor) monitor =
199  fl_window_state_monitor_new(messenger, window);
200 
201  GdkEvent event = {
202  .window_state = {.new_window_state = GDK_WINDOW_STATE_WITHDRAWN}};
203  gboolean handled;
204  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
205 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [3/8]

TEST ( FlWindowStateMonitorTest  ,
GainFocus   
)

Definition at line 56 of file fl_window_state_monitor_test.cc.

56  {
57  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
58  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
59 
60  gtk_init(0, nullptr);
61 
62  EXPECT_CALL(mock_window, gdk_window_get_state)
63  .WillOnce(::testing::Return(static_cast<GdkWindowState>(0)));
64  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
65  ::testing::Eq<FlBinaryMessenger*>(messenger),
66  ::testing::StrEq("flutter/lifecycle"),
67  LifecycleString("AppLifecycleState.resumed"),
68  ::testing::_, ::testing::_, ::testing::_));
69 
70  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
71  gtk_widget_show(GTK_WIDGET(window));
72  g_autoptr(FlWindowStateMonitor) monitor =
73  fl_window_state_monitor_new(messenger, window);
74 
75  GdkEvent event = {
76  .window_state = {.new_window_state = GDK_WINDOW_STATE_FOCUSED}};
77  gboolean handled;
78  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
79 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [4/8]

TEST ( FlWindowStateMonitorTest  ,
LeaveIconified   
)

Definition at line 131 of file fl_window_state_monitor_test.cc.

131  {
132  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
133  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
134 
135  gtk_init(0, nullptr);
136 
137  EXPECT_CALL(mock_window, gdk_window_get_state)
138  .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
139  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
140  ::testing::Eq<FlBinaryMessenger*>(messenger),
141  ::testing::StrEq("flutter/lifecycle"),
142  LifecycleString("AppLifecycleState.inactive"),
143  ::testing::_, ::testing::_, ::testing::_));
144 
145  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
146  gtk_widget_show(GTK_WIDGET(window));
147  g_autoptr(FlWindowStateMonitor) monitor =
148  fl_window_state_monitor_new(messenger, window);
149 
150  GdkEvent event = {
151  .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
152  gboolean handled;
153  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
154 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [5/8]

TEST ( FlWindowStateMonitorTest  ,
LeaveIconifiedFocused   
)

Definition at line 156 of file fl_window_state_monitor_test.cc.

156  {
157  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
158  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
159 
160  gtk_init(0, nullptr);
161 
162  EXPECT_CALL(mock_window, gdk_window_get_state)
163  .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
164  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
165  ::testing::Eq<FlBinaryMessenger*>(messenger),
166  ::testing::StrEq("flutter/lifecycle"),
167  LifecycleString("AppLifecycleState.resumed"),
168  ::testing::_, ::testing::_, ::testing::_));
169 
170  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
171  gtk_widget_show(GTK_WIDGET(window));
172  g_autoptr(FlWindowStateMonitor) monitor =
173  fl_window_state_monitor_new(messenger, window);
174 
175  GdkEvent event = {
176  .window_state = {.new_window_state = static_cast<GdkWindowState>(
177  GDK_WINDOW_STATE_FOCUSED)}};
178  gboolean handled;
179  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
180 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [6/8]

TEST ( FlWindowStateMonitorTest  ,
LeaveWithdrawn   
)

Definition at line 207 of file fl_window_state_monitor_test.cc.

207  {
208  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
209  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
210 
211  gtk_init(0, nullptr);
212 
213  EXPECT_CALL(mock_window, gdk_window_get_state)
214  .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
215  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
216  ::testing::Eq<FlBinaryMessenger*>(messenger),
217  ::testing::StrEq("flutter/lifecycle"),
218  LifecycleString("AppLifecycleState.inactive"),
219  ::testing::_, ::testing::_, ::testing::_));
220 
221  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
222  gtk_widget_show(GTK_WIDGET(window));
223  g_autoptr(FlWindowStateMonitor) monitor =
224  fl_window_state_monitor_new(messenger, window);
225 
226  GdkEvent event = {
227  .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
228  gboolean handled;
229  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
230 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [7/8]

TEST ( FlWindowStateMonitorTest  ,
LeaveWithdrawnFocused   
)

Definition at line 232 of file fl_window_state_monitor_test.cc.

232  {
233  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
234  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
235 
236  gtk_init(0, nullptr);
237 
238  EXPECT_CALL(mock_window, gdk_window_get_state)
239  .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
240  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
241  ::testing::Eq<FlBinaryMessenger*>(messenger),
242  ::testing::StrEq("flutter/lifecycle"),
243  LifecycleString("AppLifecycleState.resumed"),
244  ::testing::_, ::testing::_, ::testing::_));
245 
246  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
247  gtk_widget_show(GTK_WIDGET(window));
248  g_autoptr(FlWindowStateMonitor) monitor =
249  fl_window_state_monitor_new(messenger, window);
250 
251  GdkEvent event = {
252  .window_state = {.new_window_state = static_cast<GdkWindowState>(
253  GDK_WINDOW_STATE_FOCUSED)}};
254  gboolean handled;
255  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
256 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

◆ TEST() [8/8]

TEST ( FlWindowStateMonitorTest  ,
LoseFocus   
)

Definition at line 81 of file fl_window_state_monitor_test.cc.

81  {
82  ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
83  ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
84 
85  gtk_init(0, nullptr);
86 
87  EXPECT_CALL(mock_window, gdk_window_get_state)
88  .WillOnce(::testing::Return(GDK_WINDOW_STATE_FOCUSED));
89  EXPECT_CALL(messenger, fl_binary_messenger_send_on_channel(
90  ::testing::Eq<FlBinaryMessenger*>(messenger),
91  ::testing::StrEq("flutter/lifecycle"),
92  LifecycleString("AppLifecycleState.inactive"),
93  ::testing::_, ::testing::_, ::testing::_));
94 
95  GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
96  gtk_widget_show(GTK_WIDGET(window));
97  g_autoptr(FlWindowStateMonitor) monitor =
98  fl_window_state_monitor_new(messenger, window);
99 
100  GdkEvent event = {
101  .window_state = {.new_window_state = static_cast<GdkWindowState>(0)}};
102  gboolean handled;
103  g_signal_emit_by_name(window, "window-state-event", &event, &handled);
104 }

References event, fl_binary_messenger_send_on_channel(), fl_window_state_monitor_new(), and LifecycleString().

event
FlKeyEvent * event
Definition: fl_key_channel_responder.cc:118
LifecycleString
::testing::Matcher< GBytes * > LifecycleString(const std::string &value)
Definition: fl_window_state_monitor_test.cc:52
FlValueStringMatcher
Definition: fl_window_state_monitor_test.cc:14
fl_window_state_monitor_new
FlWindowStateMonitor * fl_window_state_monitor_new(FlBinaryMessenger *messenger, GtkWindow *window)
Definition: fl_window_state_monitor.cc:104
value
uint8_t value
Definition: fl_standard_message_codec.cc:36
fl_binary_messenger_send_on_channel
G_MODULE_EXPORT void fl_binary_messenger_send_on_channel(FlBinaryMessenger *self, const gchar *channel, GBytes *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
Definition: fl_binary_messenger.cc:443