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

Commit 9c961aa

Browse files
committed
Add tests for FlPlatformPlugin
1 parent d256cb9 commit 9c961aa

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2893,6 +2893,7 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
28932893
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc + ../../../flutter/LICENSE
28942894
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc + ../../../flutter/LICENSE
28952895
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.h + ../../../flutter/LICENSE
2896+
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc + ../../../flutter/LICENSE
28962897
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc + ../../../flutter/LICENSE
28972898
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h + ../../../flutter/LICENSE
28982899
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc + ../../../flutter/LICENSE
@@ -5419,6 +5420,7 @@ FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
54195420
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc
54205421
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc
54215422
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.h
5423+
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc
54225424
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc
54235425
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h
54245426
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc

shell/platform/linux/BUILD.gn

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -212,6 +212,7 @@ executable("flutter_linux_unittests") {
212212
"fl_method_codec_test.cc",
213213
"fl_method_response_test.cc",
214214
"fl_pixel_buffer_texture_test.cc",
215+
"fl_platform_plugin_test.cc",
215216
"fl_plugin_registrar_test.cc",
216217
"fl_scrolling_manager_test.cc",
217218
"fl_settings_plugin_test.cc",
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
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+
5+
#include "flutter/shell/platform/linux/fl_platform_plugin.h"
6+
#include "flutter/shell/platform/linux/fl_binary_messenger_private.h"
7+
#include "flutter/shell/platform/linux/fl_method_codec_private.h"
8+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h"
9+
#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h"
10+
#include "flutter/shell/platform/linux/testing/fl_test.h"
11+
#include "flutter/shell/platform/linux/testing/mock_binary_messenger.h"
12+
#include "flutter/testing/testing.h"
13+
14+
#include "gmock/gmock.h"
15+
#include "gtest/gtest.h"
16+
17+
MATCHER_P(SuccessResponse, result, "") {
18+
g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
19+
g_autoptr(FlMethodResponse) response =
20+
fl_method_codec_decode_response(FL_METHOD_CODEC(codec), arg, nullptr);
21+
if (fl_value_equal(fl_method_response_get_result(response, nullptr),
22+
result)) {
23+
return true;
24+
}
25+
*result_listener << ::testing::PrintToString(response);
26+
return false;
27+
}
28+
29+
TEST(FlPlatformPluginTest, PlaySound) {
30+
::testing::NiceMock<flutter::testing::MockBinaryMessenger> messenger;
31+
32+
g_autoptr(FlPlatformPlugin) plugin = fl_platform_plugin_new(messenger);
33+
EXPECT_NE(plugin, nullptr);
34+
35+
g_autoptr(FlValue) args = fl_value_new_string("SystemSoundType.alert");
36+
g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new();
37+
g_autoptr(GBytes) message = fl_method_codec_encode_method_call(
38+
FL_METHOD_CODEC(codec), "SystemSound.play", args, nullptr);
39+
40+
g_autoptr(FlValue) null = fl_value_new_null();
41+
EXPECT_CALL(messenger, fl_binary_messenger_send_response(
42+
::testing::Eq<FlBinaryMessenger*>(messenger),
43+
::testing::_, SuccessResponse(null), ::testing::_))
44+
.WillOnce(::testing::Return(true));
45+
46+
messenger.ReceiveMessage("flutter/platform", message);
47+
}

0 commit comments

Comments
 (0)