5#include "flutter/shell/platform/common/client_wrapper/include/flutter/plugin_registrar.h"
10#include "flutter/shell/platform/common/client_wrapper/testing/stub_flutter_api.h"
11#include "gtest/gtest.h"
18class TestApi :
public testing::StubFlutterApi {
21 bool MessengerSend(
const char* channel,
23 const size_t message_size)
override {
25 return message_engine_result;
28 bool MessengerSendWithReply(
const char* channel,
30 const size_t message_size,
34 return message_engine_result;
37 void MessengerSetCallback(
const char* channel,
40 last_message_callback_set_ =
callback;
43 void PluginRegistrarSetDestructionHandler(
45 last_destruction_callback_set_ =
callback;
48 const uint8_t* last_data_sent() {
return last_data_sent_; }
50 return last_message_callback_set_;
53 return last_destruction_callback_set_;
57 const uint8_t* last_data_sent_ =
nullptr;
64class TestPluginRegistrar :
public PluginRegistrar {
67 : PluginRegistrar(core_registrar) {}
69 virtual ~TestPluginRegistrar() {
70 if (destruction_callback_) {
71 destruction_callback_();
76 destruction_callback_ = std::move(
callback);
85class TestPlugin :
public Plugin {
89 TestPlugin(PluginRegistrar* registrar,
bool* registrar_valid_at_destruction)
90 : registrar_(registrar),
91 registrar_valid_at_destruction_(registrar_valid_at_destruction) {}
92 virtual ~TestPlugin() {
93 *registrar_valid_at_destruction_ = registrar_->messenger() !=
nullptr;
97 PluginRegistrar* registrar_;
98 bool* registrar_valid_at_destruction_;
104TEST(PluginRegistrarTest, PluginDestroyedBeforeRegistrar) {
105 auto dummy_registrar_handle =
107 bool registrar_valid_at_destruction =
false;
111 auto plugin = std::make_unique<TestPlugin>(®istrar,
112 ®istrar_valid_at_destruction);
120TEST(PluginRegistrarTest, MessengerSend) {
122 auto test_api =
static_cast<TestApi*
>(scoped_api_stub.
stub());
124 auto dummy_registrar_handle =
129 std::vector<uint8_t>
message = {1, 2, 3, 4};
131 EXPECT_EQ(test_api->last_data_sent(), &
message[0]);
136TEST(PluginRegistrarTest, MessengerSetMessageHandler) {
138 auto test_api =
static_cast<TestApi*
>(scoped_api_stub.
stub());
140 auto dummy_registrar_handle =
144 const std::string channel_name(
"foo");
148 const size_t message_size,
151 EXPECT_NE(test_api->last_message_callback_set(),
nullptr);
155 EXPECT_EQ(test_api->last_message_callback_set(),
nullptr);
160TEST(PluginRegistrarTest, ManagerSameInstance) {
166 auto dummy_registrar_handle =
175TEST(PluginRegistrarTest, ManagerDifferentInstances) {
181 auto dummy_registrar_handle_a =
183 auto dummy_registrar_handle_b =
192TEST(PluginRegistrarTest, ManagerRemovesOnDestruction) {
197 auto test_api =
static_cast<TestApi*
>(scoped_api_stub.
stub());
199 auto dummy_registrar_handle =
202 manager->GetRegistrar<TestPluginRegistrar>(dummy_registrar_handle);
206 EXPECT_NE(test_api->last_destruction_callback_set(),
nullptr);
207 bool destroyed =
false;
208 wrapper->SetDestructionCallback([&destroyed]() { destroyed =
true; });
209 test_api->last_destruction_callback_set()(dummy_registrar_handle);
210 EXPECT_EQ(destroyed,
true);
213 EXPECT_NE(
manager->GetRegistrar<TestPluginRegistrar>(dummy_registrar_handle),
218TEST(PluginRegistrarTest, TextureRegistrarNotNull) {
219 auto dummy_registrar_handle =
virtual void Send(const std::string &channel, const uint8_t *message, size_t message_size, BinaryReply reply=nullptr) const =0
virtual void SetMessageHandler(const std::string &channel, BinaryMessageHandler handler)=0
static PluginRegistrarManager * GetInstance()
void AddPlugin(std::unique_ptr< Plugin > plugin)
TextureRegistrar * texture_registrar()
BinaryMessenger * messenger()
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
void(* FlutterDesktopBinaryReply)(const uint8_t *data, size_t data_size, void *user_data)
void(* FlutterDesktopMessageCallback)(FlutterDesktopMessengerRef, const FlutterDesktopMessage *, void *)
void(* FlutterDesktopOnPluginRegistrarDestroyed)(FlutterDesktopPluginRegistrarRef)
Dart_NativeFunction function
G_BEGIN_DECLS FlTextureRegistrar * texture_registrar
std::function< void(const uint8_t *message, size_t message_size, BinaryReply reply)> BinaryMessageHandler
TEST(FrameTimingsRecorderTest, RecordVsync)
it will be possible to load the file into Perfetto s trace viewer disable asset Prevents usage of any non test fonts unless they were explicitly Loaded via prefetched default font manager
std::function< void(const uint8_t *reply, size_t reply_size)> BinaryReply
#define EXPECT_TRUE(handle)