Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
fl_platform_handler_test.cc File Reference

Go to the source code of this file.

Classes

class  FlPlatformHandlerTest
 

Functions

 G_DECLARE_FINAL_TYPE (FlTestApplication, fl_test_application, FL, TEST_APPLICATION, GtkApplication) struct _FlTestApplication
 
 G_DEFINE_TYPE (FlTestApplication, fl_test_application, gtk_application_get_type()) static void fl_test_application_startup(GApplication *application)
 
static void fl_test_application_activate (GApplication *application)
 
static void fl_test_application_dispose (GObject *object)
 
static void fl_test_application_class_init (FlTestApplicationClass *klass)
 
static void fl_test_application_init (FlTestApplication *self)
 
FlTestApplication * fl_test_application_new (gboolean *dispose_called)
 
 TEST_F (FlPlatformHandlerTest, PlaySound)
 
 TEST_F (FlPlatformHandlerTest, ExitApplication)
 
 TEST_F (FlPlatformHandlerTest, ExitApplicationDispose)
 

Function Documentation

◆ fl_test_application_activate()

static void fl_test_application_activate ( GApplication *  application)
static

Definition at line 41 of file fl_platform_handler_test.cc.

41 {
42 G_APPLICATION_CLASS(fl_test_application_parent_class)->activate(application);
43
44 g_autoptr(FlMockBinaryMessenger) messenger = fl_mock_binary_messenger_new();
45 g_autoptr(FlPlatformHandler) handler =
46 fl_platform_handler_new(FL_BINARY_MESSENGER(messenger));
47 EXPECT_NE(handler, nullptr);
48
49 // Request app exit.
50 gboolean called = FALSE;
54 messenger, "flutter/platform", "System.exitApplication", args,
55 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
56 gpointer user_data) {
57 gboolean* called = static_cast<gboolean*>(user_data);
58 *called = TRUE;
59
60 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
61
62 g_autoptr(FlValue) expected_result = fl_value_new_map();
63 fl_value_set_string_take(expected_result, "response",
64 fl_value_new_string("exit"));
66 FL_METHOD_SUCCESS_RESPONSE(response)),
67 expected_result));
68 },
69 &called);
70 EXPECT_TRUE(called);
71
72 fl_binary_messenger_shutdown(FL_BINARY_MESSENGER(messenger));
73}
g_autoptr(FlEngine) engine
void fl_binary_messenger_shutdown(FlBinaryMessenger *self)
return TRUE
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_MODULE_EXPORT FlValue * fl_method_success_response_get_result(FlMethodSuccessResponse *self)
void fl_mock_binary_messenger_invoke_json_method(FlMockBinaryMessenger *self, const gchar *channel, const char *name, FlValue *args, FlMockBinaryMessengerMethodCallback callback, gpointer user_data)
const gchar FlBinaryMessengerMessageHandler handler
FlMockBinaryMessenger * fl_mock_binary_messenger_new()
FlPlatformHandler * fl_platform_handler_new(FlBinaryMessenger *messenger)
G_MODULE_EXPORT FlValue * fl_value_new_map()
Definition fl_value.cc:366
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 bool fl_value_equal(FlValue *a, FlValue *b)
Definition fl_value.cc:471
typedefG_BEGIN_DECLS struct _FlValue FlValue
Definition fl_value.h:42

References args, fl_binary_messenger_shutdown(), fl_method_success_response_get_result(), fl_mock_binary_messenger_invoke_json_method(), fl_mock_binary_messenger_new(), fl_platform_handler_new(), fl_value_equal(), fl_value_new_map(), fl_value_new_string(), fl_value_set_string_take(), g_autoptr(), handler, TRUE, and user_data.

Referenced by fl_test_application_class_init().

◆ fl_test_application_class_init()

static void fl_test_application_class_init ( FlTestApplicationClass *  klass)
static

Definition at line 83 of file fl_platform_handler_test.cc.

83 {
84 G_OBJECT_CLASS(klass)->dispose = fl_test_application_dispose;
85 G_APPLICATION_CLASS(klass)->startup = fl_test_application_startup;
86 G_APPLICATION_CLASS(klass)->activate = fl_test_application_activate;
87}
static void fl_test_application_activate(GApplication *application)
static void fl_test_application_dispose(GObject *object)

References fl_test_application_activate(), and fl_test_application_dispose().

◆ fl_test_application_dispose()

static void fl_test_application_dispose ( GObject *  object)
static

Definition at line 75 of file fl_platform_handler_test.cc.

75 {
76 FlTestApplication* self = FL_TEST_APPLICATION(object);
77
78 *self->dispose_called = true;
79
80 G_OBJECT_CLASS(fl_test_application_parent_class)->dispose(object);
81}

References self.

Referenced by fl_test_application_class_init().

◆ fl_test_application_init()

static void fl_test_application_init ( FlTestApplication *  self)
static

Definition at line 89 of file fl_platform_handler_test.cc.

89{}

◆ fl_test_application_new()

FlTestApplication * fl_test_application_new ( gboolean *  dispose_called)

Definition at line 91 of file fl_platform_handler_test.cc.

91 {
92 FlTestApplication* self = FL_TEST_APPLICATION(
93 g_object_new(fl_test_application_get_type(), nullptr));
94
95 // Don't try and register on D-Bus.
96 g_application_set_application_id(G_APPLICATION(self), "dev.flutter.GtkTest");
97 g_application_set_flags(G_APPLICATION(self), G_APPLICATION_NON_UNIQUE);
98
99 // Added to stop compiler complaining about an unused function.
100 FL_IS_TEST_APPLICATION(self);
101
102 self->dispose_called = dispose_called;
103
104 return self;
105}

References self.

Referenced by TEST_F().

◆ G_DECLARE_FINAL_TYPE()

G_DECLARE_FINAL_TYPE ( FlTestApplication  ,
fl_test_application  ,
FL  ,
TEST_APPLICATION  ,
GtkApplication   
)

Definition at line 17 of file fl_platform_handler_test.cc.

23 {
24 GtkApplication parent_instance;
25 gboolean* dispose_called;
26};

◆ G_DEFINE_TYPE()

G_DEFINE_TYPE ( FlTestApplication  ,
fl_test_application  ,
gtk_application_get_type()   
)

Definition at line 28 of file fl_platform_handler_test.cc.

32 {
33 G_APPLICATION_CLASS(fl_test_application_parent_class)->startup(application);
34
35 // Add a window to this application, which will hold a reference to the
36 // application and stop it disposing. See
37 // https://gitlab.gnome.org/GNOME/gtk/-/issues/6190
38 gtk_application_window_new(GTK_APPLICATION(application));
39}

◆ TEST_F() [1/3]

TEST_F ( FlPlatformHandlerTest  ,
ExitApplication   
)

Definition at line 145 of file fl_platform_handler_test.cc.

145 {
146 // Indicate that the binding is initialized.
147 gboolean called = FALSE;
149 messenger, "flutter/platform", "System.initializationComplete", nullptr,
150 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
151 gpointer user_data) {
152 gboolean* called = static_cast<gboolean*>(user_data);
153 *called = TRUE;
154
155 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
156
157 g_autoptr(FlValue) expected_result = fl_value_new_null();
159 FL_METHOD_SUCCESS_RESPONSE(response)),
160 expected_result));
161 },
162 &called);
163 EXPECT_TRUE(called);
164
165 gboolean request_exit_called = FALSE;
167 messenger, "flutter/platform",
168 [](FlMockBinaryMessenger* messenger, GTask* task, const gchar* name,
169 FlValue* args, gpointer user_data) {
170 gboolean* called = static_cast<gboolean*>(user_data);
171 *called = TRUE;
172
173 EXPECT_STREQ(name, "System.requestAppExit");
174
175 g_autoptr(FlValue) expected_args = fl_value_new_map();
176 fl_value_set_string_take(expected_args, "type",
177 fl_value_new_string("cancelable"));
178 EXPECT_TRUE(fl_value_equal(args, expected_args));
179
180 // Cancel so it doesn't try and exit this app (i.e. the current test)
182 fl_value_set_string_take(result, "response",
183 fl_value_new_string("cancel"));
184 return FL_METHOD_RESPONSE(fl_method_success_response_new(result));
185 },
186 &request_exit_called);
187
189 fl_value_set_string_take(args, "type", fl_value_new_string("cancelable"));
191 messenger, "flutter/platform", "System.exitApplication", args,
192 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
193 gpointer user_data) {
194 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
195
196 g_autoptr(FlValue) expected_result = fl_value_new_map();
197 fl_value_set_string_take(expected_result, "response",
198 fl_value_new_string("cancel"));
200 FL_METHOD_SUCCESS_RESPONSE(response)),
201 expected_result));
202
203 g_main_loop_quit(static_cast<GMainLoop*>(user_data));
204 },
205 loop);
206
207 g_main_loop_run(loop);
208
209 EXPECT_TRUE(request_exit_called);
210}
G_MODULE_EXPORT FlMethodSuccessResponse * fl_method_success_response_new(FlValue *result)
void fl_mock_binary_messenger_set_json_method_channel(FlMockBinaryMessenger *self, const gchar *channel, FlMockBinaryMessengerMethodChannelHandler handler, gpointer user_data)
G_MODULE_EXPORT FlValue * fl_value_new_null()
Definition fl_value.cc:251
const char * name
Definition fuchsia.cc:50

References args, fl_method_success_response_get_result(), fl_method_success_response_new(), fl_mock_binary_messenger_invoke_json_method(), fl_mock_binary_messenger_set_json_method_channel(), fl_value_equal(), fl_value_new_map(), fl_value_new_null(), fl_value_new_string(), fl_value_set_string_take(), g_autoptr(), name, TRUE, and user_data.

◆ TEST_F() [2/3]

TEST_F ( FlPlatformHandlerTest  ,
ExitApplicationDispose   
)

Definition at line 212 of file fl_platform_handler_test.cc.

212 {
213 gtk_init(0, nullptr);
214
215 gboolean dispose_called = false;
216 FlTestApplication* application = fl_test_application_new(&dispose_called);
217
218 // Run the application, it will quit after startup.
219 g_application_run(G_APPLICATION(application), 0, nullptr);
220
221 EXPECT_FALSE(dispose_called);
222 g_object_unref(application);
223 EXPECT_TRUE(dispose_called);
224}
FlTestApplication * fl_test_application_new(gboolean *dispose_called)

References fl_test_application_new().

◆ TEST_F() [3/3]

TEST_F ( FlPlatformHandlerTest  ,
PlaySound   
)

Definition at line 124 of file fl_platform_handler_test.cc.

124 {
125 gboolean called = FALSE;
126 g_autoptr(FlValue) args = fl_value_new_string("SystemSoundType.alert");
128 messenger, "flutter/platform", "SystemSound.play", args,
129 [](FlMockBinaryMessenger* messenger, FlMethodResponse* response,
130 gpointer user_data) {
131 gboolean* called = static_cast<gboolean*>(user_data);
132 *called = TRUE;
133
134 EXPECT_TRUE(FL_IS_METHOD_SUCCESS_RESPONSE(response));
135
136 g_autoptr(FlValue) expected_result = fl_value_new_null();
138 FL_METHOD_SUCCESS_RESPONSE(response)),
139 expected_result));
140 },
141 &called);
142 EXPECT_TRUE(called);
143}

References args, fl_method_success_response_get_result(), fl_mock_binary_messenger_invoke_json_method(), fl_value_equal(), fl_value_new_null(), fl_value_new_string(), g_autoptr(), TRUE, and user_data.