Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
platform_view_embedder_unittests.cc
Go to the documentation of this file.
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
6
9
10#include "gmock/gmock.h"
11#include "gtest/gtest.h"
12
13#include <cstring>
14
15namespace flutter {
16namespace testing {
17namespace {
18class MockDelegate : public PlatformView::Delegate {
19 MOCK_METHOD(void,
20 OnPlatformViewCreated,
21 (std::unique_ptr<Surface>),
22 (override));
23 MOCK_METHOD(void, OnPlatformViewDestroyed, (), (override));
24 MOCK_METHOD(void, OnPlatformViewScheduleFrame, (), (override));
25 MOCK_METHOD(void,
26 OnPlatformViewAddView,
27 (int64_t view_id,
28 const ViewportMetrics& viewport_metrics,
29 AddViewCallback callback),
30 (override));
31 MOCK_METHOD(void,
32 OnPlatformViewRemoveView,
33 (int64_t view_id, RemoveViewCallback callback),
34 (override));
35 MOCK_METHOD(void,
36 OnPlatformViewSendViewFocusEvent,
37 (const ViewFocusEvent& event),
38 (override));
39 MOCK_METHOD(void,
40 OnPlatformViewSetNextFrameCallback,
41 (const fml::closure& closure),
42 (override));
43 MOCK_METHOD(void,
44 OnPlatformViewSetViewportMetrics,
45 (int64_t view_id, const ViewportMetrics& metrics),
46 (override));
47 MOCK_METHOD(void,
48 OnPlatformViewDispatchPlatformMessage,
49 (std::unique_ptr<PlatformMessage> message),
50 (override));
51 MOCK_METHOD(void,
52 OnPlatformViewDispatchPointerDataPacket,
53 (std::unique_ptr<PointerDataPacket> packet),
54 (override));
55 MOCK_METHOD(HitTestResponse,
56 OnPlatformViewHitTest,
57 (int64_t view_id, const flutter::PointData offset),
58 (override));
59 MOCK_METHOD(void,
60 OnPlatformViewDispatchSemanticsAction,
61 (int64_t view_id,
62 int32_t node_id,
65 (override));
66 MOCK_METHOD(void,
67 OnPlatformViewSetSemanticsEnabled,
68 (bool enabled),
69 (override));
70 MOCK_METHOD(void,
71 OnPlatformViewSetAccessibilityFeatures,
72 (int32_t flags),
73 (override));
74 MOCK_METHOD(void,
75 OnPlatformViewRegisterTexture,
76 (std::shared_ptr<Texture> texture),
77 (override));
78 MOCK_METHOD(void,
79 OnPlatformViewUnregisterTexture,
80 (int64_t texture_id),
81 (override));
82 MOCK_METHOD(void,
83 OnPlatformViewMarkTextureFrameAvailable,
84 (int64_t texture_id),
85 (override));
86 MOCK_METHOD(void,
88 (intptr_t loading_unit_id,
89 std::unique_ptr<const fml::Mapping> snapshot_data,
90 std::unique_ptr<const fml::Mapping> snapshot_instructions),
91 (override));
92 MOCK_METHOD(void,
93 LoadDartDeferredLibraryError,
94 (intptr_t loading_unit_id,
95 const std::string error_message,
96 bool transient),
97 (override));
98 MOCK_METHOD(void,
99 UpdateAssetResolverByType,
100 (std::unique_ptr<AssetResolver> updated_asset_resolver,
102 (override));
103 MOCK_METHOD(const Settings&,
104 OnPlatformViewGetSettings,
105 (),
106 (const, override));
107};
108
109class MockResponse : public PlatformMessageResponse {
110 public:
111 MOCK_METHOD(void, Complete, (std::unique_ptr<fml::Mapping> data), (override));
112 MOCK_METHOD(void, CompleteEmpty, (), (override));
113};
114} // namespace
115
116TEST(PlatformViewEmbedderTest, HasPlatformMessageHandler) {
117 ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
120 "HasPlatformMessageHandler", thread_host.platform_thread->GetTaskRunner(),
121 nullptr, nullptr, nullptr);
123 task_runners.GetPlatformTaskRunner()->PostTask([&latch, task_runners] {
124 MockDelegate delegate;
126 PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table;
127 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
128 auto embedder = std::make_unique<PlatformViewEmbedder>(
129 delegate, task_runners, software_dispatch_table,
130 platform_dispatch_table, external_view_embedder);
131
132 ASSERT_TRUE(embedder->GetPlatformMessageHandler());
133 latch.Signal();
134 });
135 latch.Wait();
136}
137
138TEST(PlatformViewEmbedderTest, Dispatches) {
139 ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
142 "HasPlatformMessageHandler", thread_host.platform_thread->GetTaskRunner(),
143 nullptr, nullptr, nullptr);
144 bool did_call = false;
145 std::unique_ptr<PlatformViewEmbedder> embedder;
146 {
148 task_runners.GetPlatformTaskRunner()->PostTask([&latch, task_runners,
149 &did_call, &embedder] {
150 MockDelegate delegate;
152 PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table;
153 platform_dispatch_table.platform_message_response_callback =
154 [&did_call](std::unique_ptr<PlatformMessage> message) {
155 did_call = true;
156 };
157 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
158 embedder = std::make_unique<PlatformViewEmbedder>(
159 delegate, task_runners, software_dispatch_table,
160 platform_dispatch_table, external_view_embedder);
161 auto platform_message_handler = embedder->GetPlatformMessageHandler();
163 fml::MakeRefCounted<MockResponse>();
164 std::unique_ptr<PlatformMessage> message =
165 std::make_unique<PlatformMessage>("foo", response);
166 platform_message_handler->HandlePlatformMessage(std::move(message));
167 latch.Signal();
168 });
169 latch.Wait();
170 }
171 {
173 thread_host.platform_thread->GetTaskRunner()->PostTask([&latch, &embedder] {
174 embedder.reset();
175 latch.Signal();
176 });
177 latch.Wait();
178 }
179
180 EXPECT_TRUE(did_call);
181}
182
183TEST(PlatformViewEmbedderTest, DeletionDisabledDispatch) {
184 ThreadHost thread_host("io.flutter.test." + GetCurrentTestName() + ".",
187 "HasPlatformMessageHandler", thread_host.platform_thread->GetTaskRunner(),
188 nullptr, nullptr, nullptr);
189 bool did_call = false;
190 {
192 task_runners.GetPlatformTaskRunner()->PostTask([&latch, task_runners,
193 &did_call] {
194 MockDelegate delegate;
196 PlatformViewEmbedder::PlatformDispatchTable platform_dispatch_table;
197 platform_dispatch_table.platform_message_response_callback =
198 [&did_call](std::unique_ptr<PlatformMessage> message) {
199 did_call = true;
200 };
201 std::shared_ptr<EmbedderExternalViewEmbedder> external_view_embedder;
202 auto embedder = std::make_unique<PlatformViewEmbedder>(
203 delegate, task_runners, software_dispatch_table,
204 platform_dispatch_table, external_view_embedder);
205 auto platform_message_handler = embedder->GetPlatformMessageHandler();
207 fml::MakeRefCounted<MockResponse>();
208 std::unique_ptr<PlatformMessage> message =
209 std::make_unique<PlatformMessage>("foo", response);
210 platform_message_handler->HandlePlatformMessage(std::move(message));
211 embedder.reset();
212 latch.Signal();
213 });
214 latch.Wait();
215 }
216 {
218 thread_host.platform_thread->GetTaskRunner()->PostTask(
219 [&latch] { latch.Signal(); });
220 latch.Wait();
221 }
222
223 EXPECT_FALSE(did_call);
224}
225
226} // namespace testing
227} // namespace flutter
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.
Definition mapping.h:144
virtual void PostTask(const fml::closure &task) override
const char * message
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
FlTexture * texture
std::string GetCurrentTestName()
Gets the name of the currently running test. This is useful in generating logs or assets based on tes...
Definition testing.cc:14
TEST(NativeAssetsManagerTest, NoAvailableAssets)
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
Definition switch_defs.h:36
std::function< void()> closure
Definition closure.h:14
impeller::ShaderType type
PlatformMessageResponseCallback platform_message_response_callback
The collection of all the threads used by the engine.
Definition thread_host.h:21
std::unique_ptr< fml::Thread > platform_thread
Definition thread_host.h:83
int64_t texture_id