7 #include "flutter/shell/platform/linux/testing/fl_test.h"
8 #include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
9 #include "flutter/shell/platform/linux/testing/mock_window.h"
11 #include "gtest/gtest.h"
19 : value_(std::move(
value)) {}
22 ::testing::MatchResultListener* result_listener)
const {
24 g_autoptr(GError)
error =
nullptr;
27 if (
value ==
nullptr) {
28 *result_listener << ::testing::PrintToString(
error->message);
32 *result_listener <<
" where the value doesn't match: \"" <<
value <<
"\"";
40 value_.DescribeTo(os);
45 value_.DescribeNegationTo(os);
49 ::testing::Matcher<std::string> value_;
56 TEST(FlWindowStateMonitorTest, GainFocus) {
57 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
58 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
62 EXPECT_CALL(mock_window, gdk_window_get_state)
63 .WillOnce(::testing::Return(
static_cast<GdkWindowState
>(0)));
65 ::testing::Eq<FlBinaryMessenger*>(messenger),
66 ::testing::StrEq(
"flutter/lifecycle"),
68 ::testing::_, ::testing::_, ::testing::_));
70 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
71 gtk_widget_show(GTK_WIDGET(window));
72 g_autoptr(FlWindowStateMonitor) monitor =
76 .window_state = {.new_window_state = GDK_WINDOW_STATE_FOCUSED}};
78 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
81 TEST(FlWindowStateMonitorTest, LoseFocus) {
82 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
83 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
87 EXPECT_CALL(mock_window, gdk_window_get_state)
88 .WillOnce(::testing::Return(GDK_WINDOW_STATE_FOCUSED));
90 ::testing::Eq<FlBinaryMessenger*>(messenger),
91 ::testing::StrEq(
"flutter/lifecycle"),
93 ::testing::_, ::testing::_, ::testing::_));
95 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
96 gtk_widget_show(GTK_WIDGET(window));
97 g_autoptr(FlWindowStateMonitor) monitor =
101 .window_state = {.new_window_state =
static_cast<GdkWindowState
>(0)}};
103 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
106 TEST(FlWindowStateMonitorTest, EnterIconified) {
107 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
108 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
110 gtk_init(0,
nullptr);
112 EXPECT_CALL(mock_window, gdk_window_get_state)
113 .WillOnce(::testing::Return(
static_cast<GdkWindowState
>(0)));
115 ::testing::Eq<FlBinaryMessenger*>(messenger),
116 ::testing::StrEq(
"flutter/lifecycle"),
118 ::testing::_, ::testing::_, ::testing::_));
120 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
121 gtk_widget_show(GTK_WIDGET(window));
122 g_autoptr(FlWindowStateMonitor) monitor =
126 .window_state = {.new_window_state = GDK_WINDOW_STATE_ICONIFIED}};
128 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
131 TEST(FlWindowStateMonitorTest, LeaveIconified) {
132 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
133 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
135 gtk_init(0,
nullptr);
137 EXPECT_CALL(mock_window, gdk_window_get_state)
138 .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
140 ::testing::Eq<FlBinaryMessenger*>(messenger),
141 ::testing::StrEq(
"flutter/lifecycle"),
143 ::testing::_, ::testing::_, ::testing::_));
145 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
146 gtk_widget_show(GTK_WIDGET(window));
147 g_autoptr(FlWindowStateMonitor) monitor =
151 .window_state = {.new_window_state =
static_cast<GdkWindowState
>(0)}};
153 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
156 TEST(FlWindowStateMonitorTest, LeaveIconifiedFocused) {
157 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
158 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
160 gtk_init(0,
nullptr);
162 EXPECT_CALL(mock_window, gdk_window_get_state)
163 .WillOnce(::testing::Return(GDK_WINDOW_STATE_ICONIFIED));
165 ::testing::Eq<FlBinaryMessenger*>(messenger),
166 ::testing::StrEq(
"flutter/lifecycle"),
168 ::testing::_, ::testing::_, ::testing::_));
170 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
171 gtk_widget_show(GTK_WIDGET(window));
172 g_autoptr(FlWindowStateMonitor) monitor =
176 .window_state = {.new_window_state =
static_cast<GdkWindowState
>(
177 GDK_WINDOW_STATE_FOCUSED)}};
179 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
182 TEST(FlWindowStateMonitorTest, EnterWithdrawn) {
183 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
184 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
186 gtk_init(0,
nullptr);
188 EXPECT_CALL(mock_window, gdk_window_get_state)
189 .WillOnce(::testing::Return(
static_cast<GdkWindowState
>(0)));
191 ::testing::Eq<FlBinaryMessenger*>(messenger),
192 ::testing::StrEq(
"flutter/lifecycle"),
194 ::testing::_, ::testing::_, ::testing::_));
196 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
197 gtk_widget_show(GTK_WIDGET(window));
198 g_autoptr(FlWindowStateMonitor) monitor =
202 .window_state = {.new_window_state = GDK_WINDOW_STATE_WITHDRAWN}};
204 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
207 TEST(FlWindowStateMonitorTest, LeaveWithdrawn) {
208 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
209 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
211 gtk_init(0,
nullptr);
213 EXPECT_CALL(mock_window, gdk_window_get_state)
214 .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
216 ::testing::Eq<FlBinaryMessenger*>(messenger),
217 ::testing::StrEq(
"flutter/lifecycle"),
219 ::testing::_, ::testing::_, ::testing::_));
221 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
222 gtk_widget_show(GTK_WIDGET(window));
223 g_autoptr(FlWindowStateMonitor) monitor =
227 .window_state = {.new_window_state =
static_cast<GdkWindowState
>(0)}};
229 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);
232 TEST(FlWindowStateMonitorTest, LeaveWithdrawnFocused) {
233 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
234 ::testing::NiceMock<flutter::testing::MockWindow> mock_window;
236 gtk_init(0,
nullptr);
238 EXPECT_CALL(mock_window, gdk_window_get_state)
239 .WillOnce(::testing::Return(GDK_WINDOW_STATE_WITHDRAWN));
241 ::testing::Eq<FlBinaryMessenger*>(messenger),
242 ::testing::StrEq(
"flutter/lifecycle"),
244 ::testing::_, ::testing::_, ::testing::_));
246 GtkWindow* window = GTK_WINDOW(gtk_window_new(GTK_WINDOW_TOPLEVEL));
247 gtk_widget_show(GTK_WIDGET(window));
248 g_autoptr(FlWindowStateMonitor) monitor =
252 .window_state = {.new_window_state =
static_cast<GdkWindowState
>(
253 GDK_WINDOW_STATE_FOCUSED)}};
255 g_signal_emit_by_name(window,
"window-state-event", &
event, &handled);