Flutter iOS Embedder
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 
8 #import "flutter/fml/thread.h"
11 
13 
14 namespace flutter {
15 
16 namespace {
17 
18 class 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  void OnPlatformViewSendViewFocusEvent(const ViewFocusEvent& event) override {}
34  void OnPlatformViewDispatchSemanticsAction(int64_t view_id,
35  int32_t node_id,
36  SemanticsAction action,
37  fml::MallocMapping args) override {}
38  void OnPlatformViewSetSemanticsEnabled(bool enabled) override {}
39  void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override {}
40  void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {}
41  void OnPlatformViewUnregisterTexture(int64_t texture_id) override {}
42  void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override {}
43 
44  void LoadDartDeferredLibrary(intptr_t loading_unit_id,
45  std::unique_ptr<const fml::Mapping> snapshot_data,
46  std::unique_ptr<const fml::Mapping> snapshot_instructions) override {
47  }
48  void LoadDartDeferredLibraryError(intptr_t loading_unit_id,
49  const std::string error_message,
50  bool transient) override {}
51  void UpdateAssetResolverByType(std::unique_ptr<flutter::AssetResolver> updated_asset_resolver,
52  flutter::AssetResolver::AssetResolverType type) override {}
53 
54  flutter::Settings settings_;
55 };
56 
57 } // namespace
58 } // namespace flutter
59 
60 @interface PlatformViewIOSTest : XCTestCase
61 @end
62 
63 @implementation PlatformViewIOSTest
64 
65 - (void)testSetSemanticsTreeEnabled {
66  flutter::MockDelegate mock_delegate;
67  auto thread = std::make_unique<fml::Thread>("PlatformViewIOSTest");
68  auto thread_task_runner = thread->GetTaskRunner();
69  flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
70  /*platform=*/thread_task_runner,
71  /*raster=*/thread_task_runner,
72  /*ui=*/thread_task_runner,
73  /*io=*/thread_task_runner);
74  id messenger = OCMProtocolMock(@protocol(FlutterBinaryMessenger));
75  id engine = OCMClassMock([FlutterEngine class]);
76 
77  id flutterViewController = OCMClassMock([FlutterViewController class]);
78 
79  OCMStub([flutterViewController isViewLoaded]).andReturn(NO);
80  OCMStub([flutterViewController engine]).andReturn(engine);
81  OCMStub([engine binaryMessenger]).andReturn(messenger);
82 
83  auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
84  /*delegate=*/mock_delegate,
85  /*rendering_api=*/flutter::IOSRenderingAPI::kMetal,
86  /*platform_views_controller=*/nil,
87  /*task_runners=*/runners,
88  /*worker_task_runner=*/nil,
89  /*is_gpu_disabled_sync_switch=*/std::make_shared<fml::SyncSwitch>());
90  fml::AutoResetWaitableEvent latch;
91  thread_task_runner->PostTask([&] {
92  platform_view->SetOwnerViewController(flutterViewController);
93  XCTAssertFalse(platform_view->GetAccessibilityBridge());
94  platform_view->SetSemanticsTreeEnabled(true);
95  XCTAssertTrue(platform_view->GetAccessibilityBridge());
96  platform_view->SetSemanticsTreeEnabled(false);
97  XCTAssertFalse(platform_view->GetAccessibilityBridge());
98  latch.Signal();
99  });
100  latch.Wait();
101 
102  [engine stopMocking];
103 }
104 
105 @end
std::unique_ptr< flutter::PlatformViewIOS > platform_view
flutter::Settings settings_
int64_t texture_id