12 #include "flutter/shell/platform/linux/testing/fl_test.h"
13 #include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
14 #include "flutter/testing/testing.h"
16 #include "gmock/gmock.h"
17 #include "gtest/gtest.h"
21 g_autoptr(FlMethodResponse) response =
27 *result_listener << ::testing::PrintToString(response);
36 ::testing::Matcher<FlValue*>
args)
37 : name_(std::move(name)), args_(std::move(
args)) {}
40 ::testing::MatchResultListener* result_listener)
const {
42 g_autoptr(GError)
error =
nullptr;
43 g_autofree gchar* name =
nullptr;
48 *result_listener << ::testing::PrintToString(
error->message);
51 if (!name_.MatchAndExplain(name, result_listener)) {
52 *result_listener <<
" where the name doesn't match: \"" << name <<
"\"";
55 if (!args_.MatchAndExplain(
args, result_listener)) {
56 *result_listener <<
" where the args don't match: "
57 << ::testing::PrintToString(
args);
64 *os <<
"method name ";
71 *os <<
"method name ";
72 name_.DescribeNegationTo(os);
74 args_.DescribeNegationTo(os);
78 ::testing::Matcher<std::string> name_;
79 ::testing::Matcher<FlValue*> args_;
83 const std::string& name,
84 ::testing::Matcher<FlValue*>
args) {
98 struct _FlTestApplication {
99 GtkApplication parent_instance;
100 gboolean* dispose_called;
105 gtk_application_get_type())
107 static
void fl_test_application_startup(GApplication* application) {
108 G_APPLICATION_CLASS(fl_test_application_parent_class)->startup(application);
113 gtk_application_window_new(GTK_APPLICATION(application));
117 G_APPLICATION_CLASS(fl_test_application_parent_class)->activate(application);
119 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
121 EXPECT_NE(handler,
nullptr);
127 EXPECT_CALL(messenger,
129 ::testing::Eq<FlBinaryMessenger*>(messenger), ::testing::_,
130 SuccessResponse(exit_result), ::testing::_))
131 .WillOnce(::testing::Return(
true));
137 FL_METHOD_CODEC(codec),
"System.exitApplication",
args,
nullptr);
138 messenger.ReceiveMessage(
"flutter/platform", message);
142 FlTestApplication*
self = FL_TEST_APPLICATION(
object);
144 *
self->dispose_called =
true;
146 G_OBJECT_CLASS(fl_test_application_parent_class)->dispose(
object);
151 G_APPLICATION_CLASS(klass)->startup = fl_test_application_startup;
158 FlTestApplication*
self = FL_TEST_APPLICATION(
159 g_object_new(fl_test_application_get_type(),
nullptr));
162 g_application_set_application_id(G_APPLICATION(
self),
"dev.flutter.GtkTest");
163 g_application_set_flags(G_APPLICATION(
self), G_APPLICATION_NON_UNIQUE);
166 FL_IS_TEST_APPLICATION(
self);
168 self->dispose_called = dispose_called;
173 TEST(FlPlatformHandlerTest, PlaySound) {
174 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
177 EXPECT_NE(handler,
nullptr);
182 FL_METHOD_CODEC(codec),
"SystemSound.play",
args,
nullptr);
186 ::testing::Eq<FlBinaryMessenger*>(messenger),
187 ::testing::_, SuccessResponse(
null), ::testing::_))
188 .WillOnce(::testing::Return(
true));
190 messenger.ReceiveMessage(
"flutter/platform", message);
193 TEST(FlPlatformHandlerTest, ExitApplication) {
194 ::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
197 EXPECT_NE(handler,
nullptr);
202 ::testing::Eq<FlBinaryMessenger*>(messenger),
203 ::testing::_, SuccessResponse(
null), ::testing::_))
204 .WillByDefault(testing::Return(
TRUE));
207 g_autoptr(GError)
error =
nullptr;
209 FL_METHOD_CODEC(codec),
"System.initializationComplete",
nullptr, &
error);
210 messenger.ReceiveMessage(
"flutter/platform", init_message);
215 EXPECT_CALL(messenger,
217 ::testing::Eq<FlBinaryMessenger*>(messenger),
218 ::testing::StrEq(
"flutter/platform"),
219 MethodCall(
"System.requestAppExit", FlValueEq(request_args)),
220 ::testing::_, ::testing::_, ::testing::_));
225 FL_METHOD_CODEC(codec),
"System.exitApplication",
args,
nullptr);
226 messenger.ReceiveMessage(
"flutter/platform", message);
229 TEST(FlPlatformHandlerTest, ExitApplicationDispose) {
230 gtk_init(0,
nullptr);
232 gboolean dispose_called =
false;
236 g_application_run(G_APPLICATION(application), 0,
nullptr);
238 EXPECT_FALSE(dispose_called);
239 g_object_unref(application);
240 EXPECT_TRUE(dispose_called);