6#include "gtest/gtest.h"
8#include "flutter/shell/platform/linux/public/flutter_linux/fl_basic_message_channel.h"
10#include "flutter/shell/platform/embedder/embedder.h"
11#include "flutter/shell/platform/embedder/test_utils/proc_table_replacement.h"
12#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
13#include "flutter/shell/platform/linux/fl_engine_private.h"
14#include "flutter/shell/platform/linux/public/flutter_linux/fl_message_codec.h"
15#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_message_codec.h"
16#include "flutter/shell/platform/linux/testing/fl_test.h"
17#include "flutter/shell/platform/linux/testing/mock_renderer.h"
22TEST(FlBasicMessageChannelTest, SendMessageWithoutResponse) {
23 g_autoptr(GMainLoop) loop = g_main_loop_new(
nullptr, 0);
33 ([&called, old_handler](
auto engine,
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 =
44 g_autoptr(FlStandardMessageCodec) codec =
47 FL_MESSAGE_CODEC(codec), message_bytes,
nullptr);
56 g_autoptr(FlBasicMessageChannel) channel =
70 g_autoptr(GError)
error =
nullptr;
74 EXPECT_EQ(
error,
nullptr);
79 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
83TEST(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;
107 EXPECT_NE(
error,
nullptr);
109 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
113TEST(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,
138 g_autoptr(GError)
error =
nullptr;
142 EXPECT_EQ(
error,
nullptr);
149 FlBasicMessageChannelResponseHandle* response_handle,
157 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
161TEST(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;
203 EXPECT_EQ(
error,
nullptr);
207 g_main_loop_quit(
static_cast<GMainLoop*
>(
user_data));
211TEST(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);
FlutterEngineResult(* FlutterEngineSendPlatformMessageFnPtr)(FLUTTER_API_SYMBOL(FlutterEngine) engine, const FlutterPlatformMessage *message)
G_MODULE_EXPORT FlBasicMessageChannel * fl_basic_message_channel_new(FlBinaryMessenger *messenger, const gchar *name, FlMessageCodec *codec)
G_MODULE_EXPORT void fl_basic_message_channel_set_message_handler(FlBasicMessageChannel *self, FlBasicMessageChannelMessageHandler handler, gpointer user_data, GDestroyNotify destroy_notify)
G_MODULE_EXPORT gboolean fl_basic_message_channel_respond(FlBasicMessageChannel *self, FlBasicMessageChannelResponseHandle *response_handle, FlValue *message, GError **error)
G_MODULE_EXPORT FlValue * fl_basic_message_channel_send_finish(FlBasicMessageChannel *self, GAsyncResult *result, GError **error)
G_MODULE_EXPORT void fl_basic_message_channel_send(FlBasicMessageChannel *self, FlValue *message, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
static void message_cb(FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
TEST(FlBasicMessageChannelTest, SendMessageWithoutResponse)
static void response_cb(FlBasicMessageChannel *channel, FlValue *message, FlBasicMessageChannelResponseHandle *response_handle, gpointer user_data)
static void failure_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void echo_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
static void null_message_response_cb(GObject *object, GAsyncResult *result, gpointer user_data)
FlBinaryMessenger * fl_binary_messenger_new(FlEngine *engine)
FlutterEngineProcTable * fl_engine_get_embedder_api(FlEngine *self)
static FlEngine * make_mock_engine()
G_MODULE_EXPORT FlValue * fl_message_codec_decode_message(FlMessageCodec *self, GBytes *message, GError **error)
const uint8_t uint32_t uint32_t GError ** error
G_MODULE_EXPORT FlStandardMessageCodec * fl_standard_message_codec_new()
G_MODULE_EXPORT FlValueType fl_value_get_type(FlValue *self)
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
G_MODULE_EXPORT const gchar * fl_value_get_string(FlValue *self)
typedefG_BEGIN_DECLS struct _FlValue FlValue
#define MOCK_ENGINE_PROC(proc, mock_impl)
Function-pointer-based versions of the APIs above.
FlutterEngineSendPlatformMessageFnPtr SendPlatformMessage
#define EXPECT_TRUE(handle)