Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -249,11 +249,10 @@ executable("flutter_linux_unittests") {
"fl_view_test.cc",
"fl_window_state_monitor_test.cc",
"key_mapping_test.cc",
"testing/fl_mock_binary_messenger.cc",
"testing/fl_test.cc",
"testing/fl_test_gtk_logs.cc",
"testing/fl_test_gtk_logs.h",
"testing/mock_binary_messenger.cc",
"testing/mock_binary_messenger_response_handle.cc",
"testing/mock_engine.cc",
"testing/mock_epoxy.cc",
"testing/mock_im_context.cc",
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/linux/fl_basic_message_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ static void message_cb(FlBinaryMessenger* messenger,
static void message_response_cb(GObject* object,
GAsyncResult* result,
gpointer user_data) {
GTask* task = G_TASK(user_data);
g_task_return_pointer(task, result, g_object_unref);
g_autoptr(GTask) task = G_TASK(user_data);
g_task_return_pointer(task, g_object_ref(result), g_object_unref);
}

// Called when the channel handler is closed.
Expand Down Expand Up @@ -257,8 +257,9 @@ G_MODULE_EXPORT FlValue* fl_basic_message_channel_send_finish(
g_return_val_if_fail(FL_IS_BASIC_MESSAGE_CHANNEL(self), nullptr);
g_return_val_if_fail(g_task_is_valid(result, self), nullptr);

g_autoptr(GTask) task = G_TASK(result);
GAsyncResult* r = G_ASYNC_RESULT(g_task_propagate_pointer(task, error));
GTask* task = G_TASK(result);
g_autoptr(GAsyncResult) r =
G_ASYNC_RESULT(g_task_propagate_pointer(task, error));
if (r == nullptr) {
return nullptr;
}
Expand Down
9 changes: 5 additions & 4 deletions shell/platform/linux/fl_binary_messenger.cc
Original file line number Diff line number Diff line change
Expand Up @@ -260,8 +260,8 @@ static gboolean send_response(FlBinaryMessenger* messenger,
static void platform_message_ready_cb(GObject* object,
GAsyncResult* result,
gpointer user_data) {
GTask* task = G_TASK(user_data);
g_task_return_pointer(task, result, g_object_unref);
g_autoptr(GTask) task = G_TASK(user_data);
g_task_return_pointer(task, g_object_ref(result), g_object_unref);
}

static void send_on_channel(FlBinaryMessenger* messenger,
Expand Down Expand Up @@ -290,8 +290,9 @@ static GBytes* send_on_channel_finish(FlBinaryMessenger* messenger,
FlBinaryMessengerImpl* self = FL_BINARY_MESSENGER_IMPL(messenger);
g_return_val_if_fail(g_task_is_valid(result, self), FALSE);

g_autoptr(GTask) task = G_TASK(result);
GAsyncResult* r = G_ASYNC_RESULT(g_task_propagate_pointer(task, error));
GTask* task = G_TASK(result);
g_autoptr(GAsyncResult) r =
G_ASYNC_RESULT(g_task_propagate_pointer(task, error));
if (r == nullptr) {
return nullptr;
}
Expand Down
31 changes: 28 additions & 3 deletions shell/platform/linux/fl_binary_messenger_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,34 @@
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_channel.h"
#include "flutter/shell/platform/linux/public/flutter_linux/fl_standard_method_codec.h"
#include "flutter/shell/platform/linux/testing/fl_test.h"
#include "flutter/shell/platform/linux/testing/mock_binary_messenger_response_handle.h"
#include "flutter/shell/platform/linux/testing/mock_renderer.h"

G_DECLARE_FINAL_TYPE(FlFakeBinaryMessengerResponseHandle,
fl_fake_binary_messenger_response_handle,
FL,
FAKE_BINARY_MESSENGER_RESPONSE_HANDLE,
FlBinaryMessengerResponseHandle)

struct _FlFakeBinaryMessengerResponseHandle {
FlBinaryMessengerResponseHandle parent_instance;
};

G_DEFINE_TYPE(FlFakeBinaryMessengerResponseHandle,
fl_fake_binary_messenger_response_handle,
fl_binary_messenger_response_handle_get_type());

static void fl_fake_binary_messenger_response_handle_class_init(
FlFakeBinaryMessengerResponseHandleClass* klass) {}

static void fl_fake_binary_messenger_response_handle_init(
FlFakeBinaryMessengerResponseHandle* self) {}

FlFakeBinaryMessengerResponseHandle*
fl_fake_binary_messenger_response_handle_new() {
return FL_FAKE_BINARY_MESSENGER_RESPONSE_HANDLE(
g_object_new(fl_fake_binary_messenger_response_handle_get_type(), NULL));
}

G_DECLARE_FINAL_TYPE(FlFakeBinaryMessenger,
fl_fake_binary_messenger,
FL,
Expand Down Expand Up @@ -55,7 +80,7 @@ static gboolean send_message_cb(gpointer user_data) {
g_autoptr(GBytes) message = g_bytes_new(text, strlen(text));
self->message_handler(FL_BINARY_MESSENGER(self), "CHANNEL", message,
FL_BINARY_MESSENGER_RESPONSE_HANDLE(
fl_mock_binary_messenger_response_handle_new()),
fl_fake_binary_messenger_response_handle_new()),
self->message_handler_user_data);

return FALSE;
Expand Down Expand Up @@ -83,7 +108,7 @@ static gboolean send_response(FlBinaryMessenger* messenger,
GError** error) {
FlFakeBinaryMessenger* self = FL_FAKE_BINARY_MESSENGER(messenger);

EXPECT_TRUE(FL_IS_MOCK_BINARY_MESSENGER_RESPONSE_HANDLE(response_handle));
EXPECT_TRUE(FL_IS_FAKE_BINARY_MESSENGER_RESPONSE_HANDLE(response_handle));

g_autofree gchar* text =
g_strndup(static_cast<const gchar*>(g_bytes_get_data(response, nullptr)),
Expand Down
17 changes: 3 additions & 14 deletions shell/platform/linux/fl_key_channel_responder.cc
Original file line number Diff line number Diff line change
Expand Up @@ -94,8 +94,6 @@ struct _FlKeyChannelResponder {
GObject parent_instance;

FlBasicMessageChannel* channel;

FlKeyChannelResponderMock* mock;
};

G_DEFINE_TYPE(FlKeyChannelResponder, fl_key_channel_responder, G_TYPE_OBJECT)
Expand All @@ -117,9 +115,6 @@ static void handle_response(GObject* object,
FlBasicMessageChannel* messageChannel = FL_BASIC_MESSAGE_CHANNEL(object);
FlValue* message =
fl_basic_message_channel_send_finish(messageChannel, result, &error);
if (self->mock != nullptr && self->mock->value_converter != nullptr) {
message = self->mock->value_converter(message);
}
bool handled = false;
if (error != nullptr) {
g_warning("Unable to retrieve framework response: %s", error->message);
Expand Down Expand Up @@ -152,22 +147,16 @@ static void fl_key_channel_responder_init(FlKeyChannelResponder* self) {}

// Creates a new FlKeyChannelResponder instance, with a messenger used to send
// messages to the framework, and an FlTextInputHandler that is used to handle
// key events that the framework doesn't handle. Mainly for testing purposes, it
// also takes an optional callback to call when a response is received, and an
// optional channel name to use when sending messages.
// key events that the framework doesn't handle.
FlKeyChannelResponder* fl_key_channel_responder_new(
FlBinaryMessenger* messenger,
FlKeyChannelResponderMock* mock) {
FlBinaryMessenger* messenger) {
g_return_val_if_fail(FL_IS_BINARY_MESSENGER(messenger), nullptr);

FlKeyChannelResponder* self = FL_KEY_CHANNEL_RESPONDER(
g_object_new(fl_key_channel_responder_get_type(), nullptr));
self->mock = mock;

g_autoptr(FlJsonMessageCodec) codec = fl_json_message_codec_new();
const char* channel_name =
mock == nullptr ? kChannelName : mock->channel_name;
self->channel = fl_basic_message_channel_new(messenger, channel_name,
self->channel = fl_basic_message_channel_new(messenger, kChannelName,
FL_MESSAGE_CODEC(codec));

return self;
Expand Down
25 changes: 1 addition & 24 deletions shell/platform/linux/fl_key_channel_responder.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,27 +11,6 @@

typedef FlValue* (*FlValueConverter)(FlValue*);

/**
* FlKeyChannelResponderMock:
*
* Allows mocking of FlKeyChannelResponder methods and values. Only used in
* unittests.
*/
typedef struct _FlKeyChannelResponderMock {
/**
* FlKeyChannelResponderMock::value_converter:
* If #value_converter is not nullptr, then this function is applied to the
* reply of the message, whose return value is taken as the message reply.
*/
FlValueConverter value_converter;

/**
* FlKeyChannelResponderMock::channel_name:
* Mocks the channel name to send the message.
*/
const char* channel_name;
} FlKeyChannelResponderMock;

G_BEGIN_DECLS

G_DECLARE_FINAL_TYPE(FlKeyChannelResponder,
Expand Down Expand Up @@ -64,15 +43,13 @@ typedef void (*FlKeyChannelResponderAsyncCallback)(bool handled,
/**
* fl_key_channel_responder_new:
* @messenger: the messenger that the message channel should be built on.
* @mock: options to mock several functionalities. Only used in unittests.
*
* Creates a new #FlKeyChannelResponder.
*
* Returns: a new #FlKeyChannelResponder.
*/
FlKeyChannelResponder* fl_key_channel_responder_new(
FlBinaryMessenger* messenger,
FlKeyChannelResponderMock* mock = nullptr);
FlBinaryMessenger* messenger);

/**
* fl_key_channel_responder_handle_event:
Expand Down
Loading
Loading