5#include "flutter/shell/platform/embedder/platform_view_embedder.h"
7#include "flutter/shell/common/thread_host.h"
8#include "flutter/testing/testing.h"
10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
18class MockDelegate :
public PlatformView::Delegate {
20 OnPlatformViewCreated,
21 (std::unique_ptr<Surface>),
23 MOCK_METHOD(
void, OnPlatformViewDestroyed, (), (
override));
24 MOCK_METHOD(
void, OnPlatformViewScheduleFrame, (), (
override));
26 OnPlatformViewAddView,
28 const ViewportMetrics& viewport_metrics,
32 OnPlatformViewRemoveView,
33 (int64_t view_id, RemoveViewCallback
callback),
36 OnPlatformViewSetNextFrameCallback,
40 OnPlatformViewSetViewportMetrics,
41 (int64_t view_id,
const ViewportMetrics& metrics),
44 OnPlatformViewDispatchPlatformMessage,
45 (std::unique_ptr<PlatformMessage>
message),
48 OnPlatformViewDispatchPointerDataPacket,
49 (std::unique_ptr<PointerDataPacket> packet),
52 OnPlatformViewDispatchSemanticsAction,
56 OnPlatformViewSetSemanticsEnabled,
60 OnPlatformViewSetAccessibilityFeatures,
64 OnPlatformViewRegisterTexture,
65 (std::shared_ptr<Texture>
texture),
68 OnPlatformViewUnregisterTexture,
72 OnPlatformViewMarkTextureFrameAvailable,
77 (intptr_t loading_unit_id,
78 std::unique_ptr<const fml::Mapping> snapshot_data,
79 std::unique_ptr<const fml::Mapping> snapshot_instructions),
82 LoadDartDeferredLibraryError,
83 (intptr_t loading_unit_id,
84 const std::string error_message,
88 UpdateAssetResolverByType,
89 (std::unique_ptr<AssetResolver> updated_asset_resolver,
92 MOCK_METHOD(
const Settings&,
93 OnPlatformViewGetSettings,
100 MOCK_METHOD(
void, Complete, (std::unique_ptr<fml::Mapping>
data), (
override));
101 MOCK_METHOD(
void, CompleteEmpty, (), (
override));
105TEST(PlatformViewEmbedderTest, HasPlatformMessageHandler) {
107 ThreadHost::Type::kPlatform);
109 "HasPlatformMessageHandler", thread_host.
platform_thread->GetTaskRunner(),
110 nullptr,
nullptr,
nullptr);
113 MockDelegate delegate;
116 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
117 auto embedder = std::make_unique<PlatformViewEmbedder>(
118 delegate, task_runners, software_dispatch_table,
119 platform_dispatch_table, external_view_embedder);
121 ASSERT_TRUE(embedder->GetPlatformMessageHandler());
127TEST(PlatformViewEmbedderTest, Dispatches) {
129 ThreadHost::Type::kPlatform);
131 "HasPlatformMessageHandler", thread_host.
platform_thread->GetTaskRunner(),
132 nullptr,
nullptr,
nullptr);
133 bool did_call =
false;
134 std::unique_ptr<PlatformViewEmbedder> embedder;
138 &did_call, &embedder] {
139 MockDelegate delegate;
143 [&did_call](std::unique_ptr<PlatformMessage>
message) {
146 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
147 embedder = std::make_unique<PlatformViewEmbedder>(
148 delegate, task_runners, software_dispatch_table,
149 platform_dispatch_table, external_view_embedder);
150 auto platform_message_handler = embedder->GetPlatformMessageHandler();
152 fml::MakeRefCounted<MockResponse>();
153 std::unique_ptr<PlatformMessage>
message =
154 std::make_unique<PlatformMessage>(
"foo", response);
155 platform_message_handler->HandlePlatformMessage(std::move(
message));
162 thread_host.
platform_thread->GetTaskRunner()->PostTask([&latch, &embedder] {
172TEST(PlatformViewEmbedderTest, DeletionDisabledDispatch) {
174 ThreadHost::Type::kPlatform);
176 "HasPlatformMessageHandler", thread_host.
platform_thread->GetTaskRunner(),
177 nullptr,
nullptr,
nullptr);
178 bool did_call =
false;
183 MockDelegate delegate;
187 [&did_call](std::unique_ptr<PlatformMessage>
message) {
190 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
191 auto embedder = std::make_unique<PlatformViewEmbedder>(
192 delegate, task_runners, software_dispatch_table,
193 platform_dispatch_table, external_view_embedder);
194 auto platform_message_handler = embedder->GetPlatformMessageHandler();
196 fml::MakeRefCounted<MockResponse>();
197 std::unique_ptr<PlatformMessage>
message =
198 std::make_unique<PlatformMessage>(
"foo", response);
199 platform_message_handler->HandlePlatformMessage(std::move(
message));
208 [&latch] { latch.
Signal(); });
212 EXPECT_FALSE(did_call);
AssetResolverType
Identifies the type of AssetResolver an instance is.
fml::RefPtr< fml::TaskRunner > GetPlatformTaskRunner() const
A Mapping like NonOwnedMapping, but uses Free as its release proc.
virtual void PostTask(const fml::closure &task) override
FlutterSemanticsFlag flags
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
TEST(DisplayListComplexity, EmptyDisplayList)
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
DEF_SWITCHES_START aot vmservice shared library Name of the *so containing AOT compiled Dart assets for launching the service isolate vm snapshot data
std::function< void()> closure
The collection of all the threads used by the engine.
std::unique_ptr< fml::Thread > platform_thread
#define EXPECT_TRUE(handle)