Flutter Engine
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 #define FML_USED_ON_EMBEDDER
6 
7 #import <OCMock/OCMock.h>
8 #import <XCTest/XCTest.h>
9 
10 #include "flutter/fml/message_loop.h"
11 #import "flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
12 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Internal.h"
13 #import "flutter/shell/platform/darwin/ios/platform_view_ios.h"
14 
16 
17 namespace flutter {
18 namespace {
19 
20 class MockDelegate : public PlatformView::Delegate {
21  void OnPlatformViewCreated(std::unique_ptr<Surface> surface) override {}
22  void OnPlatformViewDestroyed() override {}
23  void OnPlatformViewSetNextFrameCallback(const fml::closure& closure) override {}
24  void OnPlatformViewSetViewportMetrics(const ViewportMetrics& metrics) override {}
25  void OnPlatformViewDispatchPlatformMessage(fml::RefPtr<PlatformMessage> message) override {}
26  void OnPlatformViewDispatchPointerDataPacket(std::unique_ptr<PointerDataPacket> packet) override {
27  }
28  void OnPlatformViewDispatchSemanticsAction(int32_t id,
30  std::vector<uint8_t> args) override {}
31  void OnPlatformViewSetSemanticsEnabled(bool enabled) override {}
32  void OnPlatformViewSetAccessibilityFeatures(int32_t flags) override {}
33  void OnPlatformViewRegisterTexture(std::shared_ptr<Texture> texture) override {}
34  void OnPlatformViewUnregisterTexture(int64_t texture_id) override {}
35  void OnPlatformViewMarkTextureFrameAvailable(int64_t texture_id) override {}
36 
37  std::unique_ptr<std::vector<std::string>> ComputePlatformViewResolvedLocale(
38  const std::vector<std::string>& supported_locale_data) override {
39  std::unique_ptr<std::vector<std::string>> out = std::make_unique<std::vector<std::string>>();
40  return out;
41  }
42 };
43 
44 } // namespace
45 } // namespace flutter
46 
47 @interface FlutterEnginePlatformViewTest : XCTestCase
48 @end
49 
50 @implementation FlutterEnginePlatformViewTest
51 
52 - (void)setUp {
54 }
55 
56 - (void)tearDown {
57 }
58 
59 - (void)testCallsNotifyLowMemory {
60  flutter::MockDelegate mock_delegate;
61  auto thread_task_runner = fml::MessageLoop::GetCurrent().GetTaskRunner();
62  flutter::TaskRunners runners(/*label=*/self.name.UTF8String,
63  /*platform=*/thread_task_runner,
64  /*raster=*/thread_task_runner,
65  /*ui=*/thread_task_runner,
66  /*io=*/thread_task_runner);
67  auto platform_view = std::make_unique<flutter::PlatformViewIOS>(
68  /*delegate=*/mock_delegate,
69  /*rendering_api=*/flutter::IOSRenderingAPI::kSoftware,
70  flutter::IOSSurfaceFactory::Create(flutter::IOSRenderingAPI::kSoftware),
71  /*task_runners=*/runners);
72 
73  id project = OCMClassMock([FlutterDartProject class]);
74  FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"tester" project:project];
75  XCTAssertNotNil(engine);
76  id mockEngine = OCMPartialMock(engine);
77  OCMStub([mockEngine notifyLowMemory]);
78  OCMStub([mockEngine iosPlatformView]).andReturn(platform_view.get());
79 
80  [engine setViewController:nil];
81  OCMVerify([mockEngine notifyLowMemory]);
82  OCMReject([mockEngine notifyLowMemory]);
83 
84  [[NSNotificationCenter defaultCenter]
85  postNotificationName:UIApplicationDidReceiveMemoryWarningNotification
86  object:nil];
87  OCMVerify([mockEngine notifyLowMemory]);
88  OCMReject([mockEngine notifyLowMemory]);
89 
90  [[NSNotificationCenter defaultCenter]
91  postNotificationName:UIApplicationDidEnterBackgroundNotification
92  object:nil];
93 
94  OCMVerify([mockEngine notifyLowMemory]);
95 }
96 
97 @end
G_BEGIN_DECLS FlValue * args
#define FLUTTER_ASSERT_NOT_ARC
Definition: FlutterMacros.h:45
static std::shared_ptr< IOSSurfaceFactory > Create(IOSRenderingAPI rendering_api)
static FML_EMBEDDER_ONLY MessageLoop & GetCurrent()
Definition: message_loop.cc:19
static void EnsureInitializedForCurrentThread()
Definition: message_loop.cc:27
fml::RefPtr< fml::TaskRunner > GetTaskRunner() const
Definition: message_loop.cc:56
std::function< void()> closure
Definition: closure.h:14
SemanticsAction action
const char * name
Definition: fuchsia.cc:50
DEF_SWITCHES_START snapshot asset Path to the directory containing the four files specified by VmSnapshotInstructions and IsolateSnapshotInstructions vm snapshot The VM instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present isolate snapshot The isolate instructions snapshot that will be memory mapped as read and executable SnapshotAssetPath must be present icu symbol Prefix for the symbols representing ICU data linked into the Flutter library dart flags
Definition: switches.h:66