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

Commit 03a95cf

Browse files
Fix incorrect response to platform SystemSound.play (#39992)
* Fix incorrect response to platform SystemSound.play * Add tests for FlPlatformPlugin
1 parent b053d74 commit 03a95cf

File tree

4 files changed

+51
-1
lines changed

4 files changed

+51
-1
lines changed

ci/licenses_golden/licenses_flutter

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2927,6 +2927,7 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
29272927
ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc + ../../../flutter/LICENSE
29282928
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc + ../../../flutter/LICENSE
29292929
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.h + ../../../flutter/LICENSE
2930+
ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc + ../../../flutter/LICENSE
29302931
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc + ../../../flutter/LICENSE
29312932
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h + ../../../flutter/LICENSE
29322933
ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc + ../../../flutter/LICENSE
@@ -5480,6 +5481,7 @@ FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h
54805481
FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc
54815482
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc
54825483
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.h
5484+
FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc
54835485
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc
54845486
FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h
54855487
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",

shell/platform/linux/fl_platform_plugin.cc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -160,7 +160,7 @@ static FlMethodResponse* system_sound_play(FlPlatformPlugin* self,
160160
g_warning("Ignoring unknown sound type %s in SystemSound.play.\n", type);
161161
}
162162

163-
return FL_METHOD_RESPONSE(fl_method_not_implemented_response_new());
163+
return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr));
164164
}
165165

166166
// Called when Flutter wants to quit the application.
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)