Flutter Engine Uber Docs
Docs for the entire Flutter Engine repo.
 
Loading...
Searching...
No Matches
platform_view_ios_test.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#import <OCMock/OCMock.h>
6#import <XCTest/XCTest.h>
7
11
13
14namespace flutter {
15
16namespace {
17
18class MockDelegate : public PlatformView::Delegate {
19 public:
20 void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override {}
21 void OnPlatformViewDestroyed() override {}
22 void OnPlatformViewScheduleFrame() override {}
23 void OnPlatformViewAddView(int64_t view_id,
24 const ViewportMetrics& viewport_metrics,
25 AddViewCallback callback) override {}
26 void OnPlatformViewRemoveView(int64_t view_id, RemoveViewCallback callback) override {}
27 void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
28 void OnPlatformViewSetViewportMetrics(int64_t view_id, const ViewportMetrics& metrics) override {}
29 const flutter::Settings& OnPlatformViewGetSettings() const override { return settings_; }
30 void OnPlatformViewDispatchPlatformMessage(std::unique_ptr<PlatformMessage> message) override {}
31 void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
32 }
33 HitTestResponse OnPlatformViewHitTest(int64_t view_id, const flutter::PointData offset) override {
34 return {.has_platform_view = false};
35 }
36 void OnPlatformViewSendViewFocusEvent(const ViewFocusEvent& event) override {}
37 void OnPlatformViewDispatchSemanticsAction(int64_t view_id,
38 int32_t node_id,
40 fml::MallocMapping args) override {}
41 void OnPlatformViewSetSemanticsEnabled(bool enabled) override {}
42 void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override {}
43 void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {}
44 void OnPlatformViewUnregisterTexture(int64_t texture_id) override {}
45 void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override {}
46
47 void LoadDartDeferredLibrary(intptr_t loading_unit_id,
48 std::unique_ptr<const fml::Mapping> snapshot_data,
49 std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
50 }
51 void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
52 const std::string error_message,
53 bool transient) override {}
54 void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
56 std::shared_ptr<fml::BasicTaskRunner> OnPlatformViewGetShutdownSafeIOTaskRunner() const override {
57 return nullptr;
58 }
59
61};
62
63} // namespace
64} // namespace flutter
65
66@interface PlatformViewIOSTest : XCTestCase
67@end
68
69@implementation PlatformViewIOSTest
70
71- (void)testSetSemanticsTreeEnabled {
72 flutter::MockDelegate mock_delegate;
73 auto thread = std::make_unique<fml::Thread>("PlatformViewIOSTest");
74 auto thread_task_runner = thread->GetTaskRunner();
75 flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
76 /*platform=*/thread_task_runner,
77 /*raster=*/thread_task_runner,
78 /*ui=*/thread_task_runner,
79 /*io=*/thread_task_runner);
80 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
81 id engine = OCMClassMock([FlutterEngine class]);
82
83 id flutterViewController = OCMClassMock([FlutterViewController class]);
84
85 OCMStub([flutterViewController isViewLoaded]).andReturn(NO);
86 OCMStub([flutterViewController engine]).andReturn(engine);
87 OCMStub([engine binaryMessenger]).andReturn(messenger);
88
89 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
90 /*delegate=*/mock_delegate,
91 /*rendering_api=*/flutter::IOSRenderingAPI::kMetal,
92 /*platform_views_controller=*/nil,
93 /*task_runners=*/runners,
94 /*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
96 thread_task_runner->PostTask([&] {
97 platform_view->SetOwnerViewController(flutterViewController);
98 XCTAssertFalse(platform_view->GetAccessibilityBridge());
99 platform_view->SetSemanticsTreeEnabled(true);
100 XCTAssertTrue(platform_view->GetAccessibilityBridge());
101 platform_view->SetSemanticsTreeEnabled(false);
102 XCTAssertFalse(platform_view->GetAccessibilityBridge());
103 latch.Signal();
104 });
105 latch.Wait();
106
107 [engine stopMocking];
108}
109
110- (void)testLocaleCanBeSetWithoutViewController {
111 flutter::MockDelegate mock_delegate;
112 auto thread = std::make_unique<fml::Thread>("PlatformViewIOSTest");
113 auto thread_task_runner = thread->GetTaskRunner();
114 flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
115 /*platform=*/thread_task_runner,
116 /*raster=*/thread_task_runner,
117 /*ui=*/thread_task_runner,
118 /*io=*/thread_task_runner);
119 id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
120 id engine = OCMClassMock([FlutterEngine class]);
121
122 id flutterViewController = OCMClassMock([FlutterViewController class]);
123
124 OCMStub([flutterViewController isViewLoaded]).andReturn(NO);
125 OCMStub([flutterViewController engine]).andReturn(engine);
126 OCMStub([engine binaryMessenger]).andReturn(messenger);
127
128 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
129 /*delegate=*/mock_delegate,
130 /*rendering_api=*/flutter::IOSRenderingAPI::kMetal,
131 /*platform_views_controller=*/nil,
132 /*task_runners=*/runners,
133 /*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
135 thread_task_runner->PostTask([&] {
136 std::string locale = "en-US";
137 platform_view->SetApplicationLocale(locale);
138 platform_view->SetOwnerViewController(flutterViewController);
139 OCMVerify([flutterViewController setApplicationLocale:@"en-US"]);
140 latch.Signal();
141 });
142 latch.Wait();
143
144 [engine stopMocking];
145}
146
147@end
std::unique_ptr< flutter::PlatformViewIOS > platform_view
AssetResolverType
Identifies the type of AssetResolver an instance is.
A Mapping like NonOwnedMapping, but uses Free as its release proc.
Definition mapping.h:144
Settings settings_
FlutterEngine engine
Definition main.cc:84
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