Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix the mapping from exit response strings to the FlPlatformChannelExitResponse enum #56769

Merged
merged 2 commits into from
Nov 25, 2024
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
2 changes: 2 additions & 0 deletions ci/licenses_golden/licenses_flutter
Original file line number Diff line number Diff line change
Expand Up @@ -45022,6 +45022,7 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_channel.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_channel.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_channel_test.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler.cc + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler.h + ../../../flutter/LICENSE
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_handler_test.cc + ../../../flutter/LICENSE
Expand Down Expand Up @@ -47932,6 +47933,7 @@ FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_channel.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_channel.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_channel_test.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler.cc
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler.h
FILE: ../../../flutter/shell/platform/linux/fl_platform_handler_test.cc
Expand Down
1 change: 1 addition & 0 deletions shell/platform/linux/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,7 @@ executable("flutter_linux_unittests") {
"fl_method_codec_test.cc",
"fl_method_response_test.cc",
"fl_pixel_buffer_texture_test.cc",
"fl_platform_channel_test.cc",
"fl_platform_handler_test.cc",
"fl_plugin_registrar_test.cc",
"fl_pointer_manager_test.cc",
Expand Down
2 changes: 1 addition & 1 deletion shell/platform/linux/fl_platform_channel.cc
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ FlPlatformChannelExitResponse get_exit_response(FlMethodResponse* response) {
if (strcmp(response_string, kExitResponseCancel) == 0) {
return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL;
} else if (strcmp(response_string, kExitResponseExit) == 0) {
return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_CANCEL;
return FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT;
}

// If something went wrong, then just exit.
Expand Down
43 changes: 43 additions & 0 deletions shell/platform/linux/fl_platform_channel_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// Copyright 2013 The Flutter Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "flutter/shell/platform/linux/fl_platform_channel.h"
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
#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 "gtest/gtest.h"

static void exit_method_response_cb(GObject* object,
GAsyncResult* result,
gpointer user_data) {
g_autoptr(GError) error = nullptr;
FlPlatformChannelExitResponse response;
gboolean success = fl_platform_channel_system_request_app_exit_finish(
object, result, &response, &error);

EXPECT_TRUE(success);
EXPECT_EQ(response, FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT);

g_main_loop_quit(static_cast<GMainLoop*>(user_data));
}

TEST(FlPlatformChannelTest, ExitResponse) {
g_autoptr(GMainLoop) loop = g_main_loop_new(nullptr, 0);

g_autoptr(FlEngine) engine = make_mock_engine();
g_autoptr(FlBinaryMessenger) messenger = fl_binary_messenger_new(engine);
g_autoptr(FlStandardMethodCodec) codec = fl_standard_method_codec_new();
g_autoptr(FlMethodChannel) channel = fl_method_channel_new(
messenger, "test/standard-method", FL_METHOD_CODEC(codec));

g_autoptr(FlValue) args = fl_value_new_map();
fl_value_set_string_take(args, "response", fl_value_new_string("exit"));

fl_method_channel_invoke_method(channel, "Echo", args, nullptr,
exit_method_response_cb, loop);

// Blocks here until method_response_cb is called.
g_main_loop_run(loop);
}