5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
8 #import "flutter/fml/thread.h"
18 class MockDelegate :
public PlatformView::Delegate {
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 {
33 HitTestResponse OnPlatformViewHitTest(int64_t view_id,
const flutter::PointData offset)
override {
34 return {.has_platform_view =
false};
36 void OnPlatformViewSendViewFocusEvent(
const ViewFocusEvent& event)
override {}
37 void OnPlatformViewDispatchSemanticsAction(int64_t view_id,
39 SemanticsAction action,
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 {}
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 {
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,
55 flutter::AssetResolver::AssetResolverType type)
override {}
68 - (void)testSetSemanticsTreeEnabled {
69 flutter::MockDelegate mock_delegate;
70 auto thread = std::make_unique<fml::Thread>(
"PlatformViewIOSTest");
71 auto thread_task_runner = thread->GetTaskRunner();
72 flutter::TaskRunners runners(
self.name.UTF8String,
82 OCMStub([flutterViewController isViewLoaded]).andReturn(NO);
83 OCMStub([flutterViewController
engine]).andReturn(
engine);
84 OCMStub([
engine binaryMessenger]).andReturn(messenger);
86 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
92 std::make_shared<fml::SyncSwitch>());
93 fml::AutoResetWaitableEvent latch;
94 thread_task_runner->PostTask([&] {
105 [engine stopMocking];
108 - (void)testLocaleCanBeSetWithoutViewController {
109 flutter::MockDelegate mock_delegate;
110 auto thread = std::make_unique<fml::Thread>(
"PlatformViewIOSTest");
111 auto thread_task_runner = thread->GetTaskRunner();
112 flutter::TaskRunners runners(
self.name.UTF8String,
122 OCMStub([flutterViewController isViewLoaded]).andReturn(NO);
123 OCMStub([flutterViewController
engine]).andReturn(
engine);
124 OCMStub([
engine binaryMessenger]).andReturn(messenger);
126 auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
132 std::make_shared<fml::SyncSwitch>());
133 fml::AutoResetWaitableEvent latch;
134 thread_task_runner->PostTask([&] {
135 std::string locale =
"en-US";
137 platform_view->SetOwnerViewController(flutterViewController);
138 OCMVerify([flutterViewController setApplicationLocale:
@"en-US"]);
143 [engine stopMocking];