Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
FlutterEnginePlatformViewTest.mm
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
5#include <memory>
6#define FML_USED_ON_EMBEDDER
7
8#import <OCMock/OCMock.h>
9#import <XCTest/XCTest.h>
10
16
18
19namespace flutter {
20namespace {
21
22class FakeDelegate : public PlatformView::Delegate {
23 public:
24 void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override {}
25 void OnPlatformViewDestroyed() override {}
26 void OnPlatformViewScheduleFrame() override {}
27 void OnPlatformViewAddView(int64_t view_id,
28 const ViewportMetrics& viewport_metrics,
29 AddViewCallback callback) override {}
30 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback) override {}
31 void OnPlatformViewSendViewFocusEvent(const ViewFocusEvent& event) override {}
32 void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
33 void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics) override {}
34 const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; }
35 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) override {}
36 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
37 }
38 HitTestResponse OnPlatformViewHitTest(int64_t view_id, const flutter::PointData offset) override {
39 return {.has_platform_view = false};
40 }
41 void OnPlatformViewDispatchSemanticsAction(int64_t view_id,
42 int32_t node_id,
44 fml::MallocMapping args) override {}
45 void OnPlatformViewSetSemanticsEnabled(bool enabled) override {}
46 void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override {}
47 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {}
48 void OnPlatformViewUnregisterTexture(int64_t texture_id) override {}
49 void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override {}
50
51 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
52 std::unique_ptr<const fml::Mapping> snapshot_data,
53 std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
54 }
55 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
56 const std::string error_message,
57 bool transient) override {}
58 void UpdateAssetResolverByType(std::unique_ptr<AssetResolver> updated_asset_resolver,
60
62};
63
64} // namespace
65} // namespace flutter
66
67@interface FlutterEnginePlatformViewTest : XCTestCase
68@end
69
71std::unique_ptr<flutter::PlatformViewIOS> platform_view;
72std::unique_ptr<fml::WeakPtrFactory<flutter::PlatformView>> weak_factory;
73flutter::FakeDelegate fake_delegate;
74
75- (void)setUp {
77 auto thread_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
78 auto sync_switch = std::make_shared<fml::SyncSwitch>();
79 flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
80 /*platform=*/thread_task_runner,
81 /*raster=*/thread_task_runner,
82 /*ui=*/thread_task_runner,
83 /*io=*/thread_task_runner);
84 platform_view = std::make_unique<flutter::PlatformViewIOS>(
85 /*delegate=*/fake_delegate,
86 /*rendering_api=*/fake_delegate.settings_.enable_impeller
89 /*platform_views_controller=*/nil,
90 /*task_runners=*/runners,
91 /*worker_task_runner=*/nil,
92 /*is_gpu_disabled_sync_switch=*/sync_switch);
93 weak_factory = std::make_unique<fml::WeakPtrFactory<flutter::PlatformView>>(platform_view.get());
94}
95
96- (void)tearDown {
97 weak_factory.reset();
98 platform_view.reset();
99}
100
101- (fml::WeakPtr<flutter::PlatformView>)platformViewReplacement {
102 return weak_factory->GetWeakPtr();
103}
104
105- (void)testCallsNotifyLowMemory {
106 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"tester"];
107 XCTAssertNotNil(engine);
108 id mockEngine = OCMPartialMock(engine);
109 OCMStub([mockEngine notifyLowMemory]);
110 OCMStub([mockEngine platformView]).andReturn(platform_view.get());
111
112 [engine setViewController:nil];
113 OCMVerify([mockEngine notifyLowMemory]);
114 OCMReject([mockEngine notifyLowMemory]);
115
116 XCTNSNotificationExpectation* memoryExpectation = [[XCTNSNotificationExpectation alloc]
117 initWithName:UIApplicationDidReceiveMemoryWarningNotification];
118 [[NSNotificationCenter defaultCenter]
119 postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
120 object:nil];
121 [self waitForExpectations:@[ memoryExpectation ] timeout:5.0];
122 OCMVerify([mockEngine notifyLowMemory]);
123 OCMReject([mockEngine notifyLowMemory]);
124
125 XCTNSNotificationExpectation* backgroundExpectation = [[XCTNSNotificationExpectation alloc]
126 initWithName:UIApplicationDidEnterBackgroundNotification];
127 [[NSNotificationCenter defaultCenter]
128 postNotificationName:UIApplicationDidEnterBackgroundNotification
129 object:nil];
130 [self waitForExpectations:@[ backgroundExpectation ] timeout:5.0];
131
132 OCMVerify([mockEngine notifyLowMemory]);
133}
134
135@end
flutter::FakeDelegate fake_delegate
std::unique_ptr< flutter::PlatformViewIOS > platform_view
std::unique_ptr< fml::WeakPtrFactory< flutter::PlatformView > > weak_factory
AssetResolverType
Identifies the type of AssetResolver an instance is.
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
static void EnsureInitializedForCurrentThread()
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Settings settings_
FlutterEngine engine
Definition main.cc:84
VkSurfaceKHR surface
Definition main.cc:65
const char * message
G_BEGIN_DECLS G_MODULE_EXPORT FlValue * args
G_BEGIN_DECLS FlutterViewId view_id
FlutterDesktopBinaryReply callback
FlTexture * texture
static void LoadDartDeferredLibrary(JNIEnv *env, jobject obj, jlong shell_holder, jint jLoadingUnitId, jobjectArray jSearchPaths)
std::function< void()> closure
Definition closure.h:14
impeller::ShaderType type
int64_t texture_id