From 82e41285c8c675d50374bb8e4c5f84df7ed82d51 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 2 Mar 2023 11:02:06 +1300 Subject: [PATCH 1/2] Fix incorrect response to platform SystemSound.play --- shell/platform/linux/fl_platform_plugin.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/shell/platform/linux/fl_platform_plugin.cc b/shell/platform/linux/fl_platform_plugin.cc index 86fee31da8d79..15076266cb190 100644 --- a/shell/platform/linux/fl_platform_plugin.cc +++ b/shell/platform/linux/fl_platform_plugin.cc @@ -160,7 +160,7 @@ static FlMethodResponse* system_sound_play(FlPlatformPlugin* self, g_warning("Ignoring unknown sound type %s in SystemSound.play.\n", type); } - return FL_METHOD_RESPONSE(fl_method_not_implemented_response_new()); + return FL_METHOD_RESPONSE(fl_method_success_response_new(nullptr)); } // Called when Flutter wants to quit the application. From 5b5d8d391f0571fedd8b789537f55e46cefb5d14 Mon Sep 17 00:00:00 2001 From: Robert Ancell Date: Thu, 2 Mar 2023 13:44:45 +1300 Subject: [PATCH 2/2] Add tests for FlPlatformPlugin --- ci/licenses_golden/licenses_flutter | 2 + shell/platform/linux/BUILD.gn | 1 + .../platform/linux/fl_platform_plugin_test.cc | 47 +++++++++++++++++++ 3 files changed, 50 insertions(+) create mode 100644 shell/platform/linux/fl_platform_plugin_test.cc diff --git a/ci/licenses_golden/licenses_flutter b/ci/licenses_golden/licenses_flutter index fbf31268b6c09..c00b5a5ce0699 100644 --- a/ci/licenses_golden/licenses_flutter +++ b/ci/licenses_golden/licenses_flutter @@ -2917,6 +2917,7 @@ ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h ORIGIN: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin.h + ../../../flutter/LICENSE +ORIGIN: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h + ../../../flutter/LICENSE ORIGIN: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc + ../../../flutter/LICENSE @@ -5459,6 +5460,7 @@ FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_private.h FILE: ../../../flutter/shell/platform/linux/fl_pixel_buffer_texture_test.cc FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.cc FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin.h +FILE: ../../../flutter/shell/platform/linux/fl_platform_plugin_test.cc FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar.cc FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_private.h FILE: ../../../flutter/shell/platform/linux/fl_plugin_registrar_test.cc diff --git a/shell/platform/linux/BUILD.gn b/shell/platform/linux/BUILD.gn index 4c1cbc4a75dea..d559efb5a6c7f 100644 --- a/shell/platform/linux/BUILD.gn +++ b/shell/platform/linux/BUILD.gn @@ -212,6 +212,7 @@ executable("flutter_linux_unittests") { "fl_method_codec_test.cc", "fl_method_response_test.cc", "fl_pixel_buffer_texture_test.cc", + "fl_platform_plugin_test.cc", "fl_plugin_registrar_test.cc", "fl_scrolling_manager_test.cc", "fl_settings_plugin_test.cc", diff --git a/shell/platform/linux/fl_platform_plugin_test.cc b/shell/platform/linux/fl_platform_plugin_test.cc new file mode 100644 index 0000000000000..88051e829443c --- /dev/null +++ b/shell/platform/linux/fl_platform_plugin_test.cc @@ -0,0 +1,47 @@ +// Copyright 2013 The Flutter Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "flutter/shell/platform/linux/fl_platform_plugin.h" +#include "flutter/shell/platform/linux/fl_binary_messenger_private.h" +#include "flutter/shell/platform/linux/fl_method_codec_private.h" +#include "flutter/shell/platform/linux/public/flutter_linux/fl_json_method_codec.h" +#include "flutter/shell/platform/linux/public/flutter_linux/fl_method_codec.h" +#include "flutter/shell/platform/linux/testing/fl_test.h" +#include "flutter/shell/platform/linux/testing/mock_binary_messenger.h" +#include "flutter/testing/testing.h" + +#include "gmock/gmock.h" +#include "gtest/gtest.h" + +MATCHER_P(SuccessResponse, result, "") { + g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new(); + g_autoptr(FlMethodResponse) response = + fl_method_codec_decode_response(FL_METHOD_CODEC(codec), arg, nullptr); + if (fl_value_equal(fl_method_response_get_result(response, nullptr), + result)) { + return true; + } + *result_listener << ::testing::PrintToString(response); + return false; +} + +TEST(FlPlatformPluginTest, PlaySound) { + ::testing::NiceMock messenger; + + g_autoptr(FlPlatformPlugin) plugin = fl_platform_plugin_new(messenger); + EXPECT_NE(plugin, nullptr); + + g_autoptr(FlValue) args = fl_value_new_string("SystemSoundType.alert"); + g_autoptr(FlJsonMethodCodec) codec = fl_json_method_codec_new(); + g_autoptr(GBytes) message = fl_method_codec_encode_method_call( + FL_METHOD_CODEC(codec), "SystemSound.play", args, nullptr); + + g_autoptr(FlValue) null = fl_value_new_null(); + EXPECT_CALL(messenger, fl_binary_messenger_send_response( + ::testing::Eq(messenger), + ::testing::_, SuccessResponse(null), ::testing::_)) + .WillOnce(::testing::Return(true)); + + messenger.ReceiveMessage("flutter/platform", message); +}