| Flutter macOS Embedder |

FlutterEngineTestUtils.mm
Go to the documentation of this file.
1
2 // Copyright 2013 The Flutter Authors. All rights reserved.
3 // Use of this source code is governed by a BSD-style license that can be
4 // found in the LICENSE file.
5
6 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h"
7 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
8 #import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
9
10 #include "flutter/testing/testing.h"
11
12 namespace flutter::testing {
13
14 FlutterEngineTest::FlutterEngineTest() = default;
15
16 void FlutterEngineTest::SetUp() {
17 native_resolver_ = std::make_shared<TestDartNativeResolver>();
18 NSString* fixtures = @(testing::GetFixturesPath());
19 project_ = [[FlutterDartProject alloc]
20 initWithAssetsPath:fixtures
21 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
22 project_.rootIsolateCreateCallback = FlutterEngineTest::IsolateCreateCallback;
23 engine_ = [[FlutterEngine alloc] initWithName:@"test"
24 project:project_
25 allowHeadlessExecution:true];
26 }
27
28 void FlutterEngineTest::TearDown() {
29 [engine_ shutDownEngine];
30 engine_ = nil;
31 native_resolver_.reset();
32 }
33
34 void FlutterEngineTest::ShutDownEngine() {
35 [engine_ shutDownEngine];
36 engine_ = nil;
37 }
38
39 void FlutterEngineTest::IsolateCreateCallback(void* user_data) {
40 native_resolver_->SetNativeResolverForIsolate();
41 }
42
43 void FlutterEngineTest::AddNativeCallback(const char* name, Dart_NativeFunction function) {
44 native_resolver_->AddNativeCallback({name}, function);
45 }
46
47 id CreateMockFlutterEngine(NSString* pasteboardString) {
48 {
49 NSString* fixtures = @(testing::GetFixturesPath());
50 FlutterDartProject* project = [[FlutterDartProject alloc]
51 initWithAssetsPath:fixtures
52 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
53 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
54 project:project
55 allowHeadlessExecution:true];
56
57 // Mock pasteboard so that this test will work in environments without a
58 // real pasteboard.
59 id pasteboardMock = OCMClassMock([NSPasteboard class]);
60 OCMExpect([pasteboardMock stringForType:[OCMArg any]]).andDo(^(NSInvocation* invocation) {
61 NSString* returnValue = pasteboardString.length > 0 ? pasteboardString : nil;
62 [invocation setReturnValue:&returnValue];
63 });
64 id engineMock = OCMPartialMock(engine);
65 OCMStub([engineMock pasteboard]).andReturn(pasteboardMock);
66 return engineMock;
67 }
68 }
69
70 } // namespace flutter::testing
flutter::testing::FlutterEngineTest::FlutterEngineTest
FlutterEngineTest()
FlutterEngine
Definition: FlutterEngine.h:30
flutter::testing::FlutterEngineTest::ShutDownEngine
void ShutDownEngine()
Definition: FlutterEngineTestUtils.mm:34
flutter::testing::CreateMockFlutterEngine
id CreateMockFlutterEngine(NSString *pasteboardString)
Definition: FlutterEngineTestUtils.mm:47
flutter::testing::FlutterEngineTest::TearDown
void TearDown() override
Definition: FlutterEngineTestUtils.mm:28
user_data
void * user_data
Definition: texture_registrar_unittests.cc:27
FlutterEngine_Internal.h
flutter::testing
Definition: AccessibilityBridgeMacTest.mm:11
FlutterEngineTestUtils.h
flutter::testing::FlutterEngineTest::SetUp
void SetUp() override
Definition: FlutterEngineTestUtils.mm:16
flutter::testing::FlutterEngineTest::AddNativeCallback
void AddNativeCallback(const char *name, Dart_NativeFunction function)
Definition: FlutterEngineTestUtils.mm:43
FlutterDartProject_Internal.h
FlutterDartProject
Definition: FlutterDartProject.mm:24
flutter::testing::FlutterEngineTest::IsolateCreateCallback
static void IsolateCreateCallback(void *user_data)
Definition: FlutterEngineTestUtils.mm:39