-
Notifications
You must be signed in to change notification settings - Fork 6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix incorrect response to platform SystemSound.play (#39992)
* Fix incorrect response to platform SystemSound.play * Add tests for FlPlatformPlugin
- Loading branch information
1 parent
b053d74
commit 03a95cf
Showing
4 changed files
with
51 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<flutter::testing::MockBinaryMessenger> 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<FlBinaryMessenger*>(messenger), | ||
::testing::_, SuccessResponse(null), ::testing::_)) | ||
.WillOnce(::testing::Return(true)); | ||
|
||
messenger.ReceiveMessage("flutter/platform", message); | ||
} |