6 #include "gtest/gtest.h"
10 #include "flutter/shell/platform/embedder/embedder.h"
11 #include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
16 #include "flutter/shell/platform/linux/testing/fl_test.h"
17 #include "flutter/shell/platform/linux/testing/mock_renderer.h"
22 TEST(FlBasicMessageChannelTest, SendMessageWithoutResponse) {
23 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
29 FlutterEngineSendPlatformMessageFnPtr old_handler =
30 embedder_api->SendPlatformMessage;
31 embedder_api->SendPlatformMessage = MOCK_ENGINE_PROC(
33 ([&called, old_handler](
auto engine,
34 const FlutterPlatformMessage* message) {
35 if (strcmp(message->channel,
"test") != 0) {
36 return old_handler(engine, message);
40 EXPECT_EQ(message->response_handle,
nullptr);
42 g_autoptr(GBytes) message_bytes =
43 g_bytes_new(message->message, message->message_size);
44 g_autoptr(FlStandardMessageCodec) codec =
47 FL_MESSAGE_CODEC(codec), message_bytes,
nullptr);
56 g_autoptr(FlBasicMessageChannel) channel =
70 g_autoptr(GError)
error =
nullptr;
73 EXPECT_NE(message,
nullptr);
74 EXPECT_EQ(
error,
nullptr);
79 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
83 TEST(FlBasicMessageChannelTest, SendMessageWithResponse) {
84 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
90 messenger,
"test/echo", FL_MESSAGE_CODEC(codec));
96 g_main_loop_run(loop);
103 g_autoptr(GError)
error =
nullptr;
106 EXPECT_EQ(message,
nullptr);
107 EXPECT_NE(
error,
nullptr);
109 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
113 TEST(FlBasicMessageChannelTest, SendFailure) {
114 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
120 messenger,
"test/failure", FL_MESSAGE_CODEC(codec));
126 g_main_loop_run(loop);
132 FlBasicMessageChannelResponseHandle* response_handle,
134 EXPECT_NE(message,
nullptr);
138 g_autoptr(GError)
error =
nullptr;
142 EXPECT_EQ(
error,
nullptr);
149 FlBasicMessageChannelResponseHandle* response_handle,
151 EXPECT_NE(message,
nullptr);
157 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
161 TEST(FlBasicMessageChannelTest, ReceiveMessage) {
162 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
169 g_autoptr(FlBasicMessageChannel) messages_channel =
171 FL_MESSAGE_CODEC(codec));
176 g_autoptr(FlBasicMessageChannel) responses_channel =
178 FL_MESSAGE_CODEC(codec));
183 g_autoptr(FlBasicMessageChannel) control_channel =
185 FL_MESSAGE_CODEC(codec));
191 g_main_loop_run(loop);
199 g_autoptr(GError)
error =
nullptr;
202 EXPECT_NE(message,
nullptr);
203 EXPECT_EQ(
error,
nullptr);
207 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
211 TEST(FlBasicMessageChannelTest, SendNullMessageWithResponse) {
212 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
218 messenger,
"test/echo", FL_MESSAGE_CODEC(codec));
223 g_main_loop_run(loop);