|
| 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