Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit d24eb35

Browse files
committed
Add test
1 parent 0e1feaf commit d24eb35

File tree

3 files changed

+18
-8
lines changed

3 files changed

+18
-8
lines changed

shell/platform/linux/fl_platform_plugin.cc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,7 @@ static void request_app_exit(FlPlatformPlugin* self, const char* type) {
244244
if (!self->app_initialization_complete ||
245245
g_str_equal(type, kExitTypeRequired)) {
246246
quit_application();
247+
return;
247248
}
248249

249250
fl_value_set_string_take(args, kExitTypeKey, fl_value_new_string(type));

shell/platform/linux/fl_platform_plugin.h

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,12 @@ FlPlatformPlugin* fl_platform_plugin_new(FlBinaryMessenger* messenger);
3838
* @plugin: an #FlPlatformPlugin
3939
*
4040
* Request the application exits (i.e. due to the window being requested to be
41-
* closed). Will only actually send a request to the framework to ask if it
42-
* should exit if the framework has indicated that it is ready to receive
43-
* requests.
41+
* closed).
42+
*
43+
* Calling this will only send an exit request to the framework if the framework
44+
* has already indicated that it is ready to receive requests by sending a
45+
* "System.initializationComplete" method call on the platform channel. Calls
46+
* before initialization is complete will result in an immediate exit.
4447
*/
4548
void fl_platform_plugin_request_app_exit(FlPlatformPlugin* plugin);
4649

shell/platform/linux/fl_platform_plugin_test.cc

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -112,22 +112,28 @@ TEST(FlPlatformPluginTest, ExitApplication) {
112112

113113
g_autoptr(FlPlatformPlugin) plugin = fl_platform_plugin_new(messenger);
114114
EXPECT_NE(plugin, nullptr);
115-
116-
g_autoptr(FlValue) args = fl_value_new_map();
117-
fl_value_set_string_take(args, "type", fl_value_new_string("cancelable"));
118115
g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
119-
g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
120-
FL_METHOD_CODEC(codec), "System.exitApplication", args, nullptr);
121116

122117
g_autoptr(FlValue) requestArgs = fl_value_new_map();
123118
fl_value_set_string_take(requestArgs, "type",
124119
fl_value_new_string("cancelable"));
120+
121+
// Indicate that the binding is initialized.
122+
g_autoptr(GBytes) init_message = fl_method_codec_encode_method_call(
123+
FL_METHOD_CODEC(codec), "System.initializationComplete", nullptr,
124+
nullptr);
125+
messenger.ReceiveMessage("flutter/platform", init_message);
126+
125127
EXPECT_CALL(messenger,
126128
fl_binary_messenger_send_on_channel(
127129
::testing::Eq<FlBinaryMessenger*>(messenger),
128130
::testing::StrEq("flutter/platform"),
129131
MethodCall("System.requestAppExit", FlValueEq(requestArgs)),
130132
::testing::_, ::testing::_, ::testing::_));
131133

134+
g_autoptr(FlValue) args = fl_value_new_map();
135+
fl_value_set_string_take(args, "type", fl_value_new_string("cancelable"));
136+
g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
137+
FL_METHOD_CODEC(codec), "System.exitApplication", args, nullptr);
132138
messenger.ReceiveMessage("flutter/platform", message);
133139
}

0 commit comments

Comments
 (0)