Flutter Linux Embedder
fl_platform_channel_test.cc
Go to the documentation of this file.
1 // Copyright 2013 The Flutter Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4 
8 #include "flutter/shell/platform/linux/testing/fl_mock_binary_messenger.h"
9 
10 #include "flutter/shell/platform/linux/testing/linux_test.h"
11 #include "gtest/gtest.h"
12 
13 class FlPlatformChannelTest : public flutter::testing::LinuxTest {
14  protected:
15  void SetUp() override { messenger = fl_mock_binary_messenger_new(); }
16 
17  ~FlPlatformChannelTest() { g_clear_object(&messenger); }
18 
19  FlMockBinaryMessenger* messenger = nullptr;
20 };
21 
22 TEST_F(FlPlatformChannelTest, ExitResponse) {
23  fl_mock_binary_messenger_set_json_method_channel(
24  messenger, "flutter/platform",
25  [](FlMockBinaryMessenger* messenger, GTask* task, const gchar* name,
26  FlValue* args, gpointer user_data) {
27  EXPECT_STREQ(name, "System.requestAppExit");
28  g_autoptr(FlValue) return_value = fl_value_new_map();
29  fl_value_set_string_take(return_value, "response",
30  fl_value_new_string("exit"));
31  return FL_METHOD_RESPONSE(fl_method_success_response_new(return_value));
32  },
33  nullptr);
34 
36  g_autoptr(FlPlatformChannel) channel =
37  fl_platform_channel_new(FL_BINARY_MESSENGER(messenger), &vtable, nullptr);
40  [](GObject* object, GAsyncResult* result, gpointer user_data) {
41  g_autoptr(GError) error = nullptr;
44  object, result, &response, &error);
45 
46  EXPECT_TRUE(success);
47  EXPECT_EQ(response, FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT);
48 
49  g_main_loop_quit(static_cast<GMainLoop*>(user_data));
50  },
51  loop);
52 
53  g_main_loop_run(loop);
54 }
FlMockBinaryMessenger * messenger
g_autoptr(FlEngine) engine
const char FlTextDirection FlAssertiveness gpointer user_data
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
const uint8_t uint32_t uint32_t GError ** error
gboolean fl_platform_channel_system_request_app_exit_finish(GObject *object, GAsyncResult *result, FlPlatformChannelExitResponse *exit_response, GError **error)
void fl_platform_channel_system_request_app_exit(FlPlatformChannel *self, FlPlatformChannelExitType type, GCancellable *cancellable, GAsyncReadyCallback callback, gpointer user_data)
FlPlatformChannel * fl_platform_channel_new(FlBinaryMessenger *messenger, FlPlatformChannelVTable *vtable, gpointer user_data)
FlPlatformChannelExitResponse
@ FL_PLATFORM_CHANNEL_EXIT_RESPONSE_EXIT
@ FL_PLATFORM_CHANNEL_EXIT_TYPE_REQUIRED
TEST_F(FlPlatformChannelTest, ExitResponse)
G_MODULE_EXPORT void fl_value_set_string_take(FlValue *self, const gchar *key, FlValue *value)
Definition: fl_value.cc:650
G_MODULE_EXPORT FlValue * fl_value_new_string(const gchar *value)
Definition: fl_value.cc:276
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition: fl_value.cc:366
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition: fl_value.h:42