| Flutter iOS Embedder |

FlutterEngineGroupTest.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/shell/platform/darwin/ios/framework/Headers/FlutterEngineGroup.h"
9 #import "flutter/shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h"
10
11 FLUTTER_ASSERT_ARC
12
13 @interface FlutterEngineGroup ()
14 - (FlutterEngine*)makeEngine;
15 @end
16
17 @interface FlutterEngineGroupTest : XCTestCase
18 @end
19
20 @implementation FlutterEngineGroupTest
21
22 - (void)testMake {
23 FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
24 FlutterEngine* engine = [group makeEngineWithEntrypoint:nil libraryURI:nil];
25 XCTAssertNotNil(engine);
26 }
27
28 - (void)testSpawn {
29 FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
30 FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil];
31 spawner.isGpuDisabled = YES;
32 FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil];
33 XCTAssertNotNil(spawner);
34 XCTAssertNotNil(spawnee);
35 XCTAssertEqual(&spawner.threadHost, &spawnee.threadHost);
36 XCTAssertEqual(spawner.isGpuDisabled, spawnee.isGpuDisabled);
37 }
38
39 - (void)testDeleteLastEngine {
40 __weak FlutterEngine* weakSpawner;
41 FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo" project:nil];
42 @autoreleasepool {
43 FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil];
44 weakSpawner = spawner;
45 XCTAssertNotNil(spawner);
46 XCTAssertNotNil(weakSpawner);
47 }
48 XCTAssertNil(weakSpawner);
49
50 FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil];
51 XCTAssertNotNil(spawnee);
52 }
53
54 - (void)testCustomEntrypoint {
55 FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
56 project:nil]);
57 FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
58 OCMStub([group makeEngine]).andReturn(mockEngine);
59 OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
60 libraryURI:[OCMArg any]
61 initialRoute:[OCMArg any]
62 entrypointArgs:[OCMArg any]])
63 .andReturn(OCMClassMock([FlutterEngine class]));
64 FlutterEngine* spawner = [group makeEngineWithEntrypoint:@"firstEntrypoint"
65 libraryURI:@"firstLibraryURI"];
66 XCTAssertNotNil(spawner);
67 OCMVerify([spawner runWithEntrypoint:@"firstEntrypoint"
68 libraryURI:@"firstLibraryURI"
69 initialRoute:nil
70 entrypointArgs:nil]);
71
72 FlutterEngine* spawnee = [group makeEngineWithEntrypoint:@"secondEntrypoint"
73 libraryURI:@"secondLibraryURI"];
74 XCTAssertNotNil(spawnee);
75 OCMVerify([spawner spawnWithEntrypoint:@"secondEntrypoint"
76 libraryURI:@"secondLibraryURI"
77 initialRoute:nil
78 entrypointArgs:nil]);
79 }
80
81 - (void)testCustomInitialRoute {
82 FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
83 project:nil]);
84 FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
85 OCMStub([group makeEngine]).andReturn(mockEngine);
86 OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
87 libraryURI:[OCMArg any]
88 initialRoute:[OCMArg any]
89 entrypointArgs:[OCMArg any]])
90 .andReturn(OCMClassMock([FlutterEngine class]));
91 FlutterEngine* spawner = [group makeEngineWithEntrypoint:nil libraryURI:nil initialRoute:@"foo"];
92 XCTAssertNotNil(spawner);
93 OCMVerify([spawner runWithEntrypoint:nil libraryURI:nil initialRoute:@"foo" entrypointArgs:nil]);
94
95 FlutterEngine* spawnee = [group makeEngineWithEntrypoint:nil libraryURI:nil initialRoute:@"bar"];
96 XCTAssertNotNil(spawnee);
97 OCMVerify([spawner spawnWithEntrypoint:nil
98 libraryURI:nil
99 initialRoute:@"bar"
100 entrypointArgs:nil]);
101 }
102
103 - (void)testCustomEntrypointArgs {
104 FlutterEngineGroup* group = OCMPartialMock([[FlutterEngineGroup alloc] initWithName:@"foo"
105 project:nil]);
106 FlutterEngine* mockEngine = OCMClassMock([FlutterEngine class]);
107 OCMStub([group makeEngine]).andReturn(mockEngine);
108 OCMStub([mockEngine spawnWithEntrypoint:[OCMArg any]
109 libraryURI:[OCMArg any]
110 initialRoute:[OCMArg any]
111 entrypointArgs:[OCMArg any]])
112 .andReturn(OCMClassMock([FlutterEngine class]));
113 FlutterEngineGroupOptions* firstOptions = [[FlutterEngineGroupOptions alloc] init];
114 NSArray* firstEntrypointArgs = @[ @"foo", @"first" ];
115 firstOptions.entrypointArgs = firstEntrypointArgs;
116 FlutterEngine* spawner = [group makeEngineWithOptions:firstOptions];
117 XCTAssertNotNil(spawner);
118 OCMVerify([spawner runWithEntrypoint:nil
119 libraryURI:nil
120 initialRoute:nil
121 entrypointArgs:firstEntrypointArgs]);
122
123 NSArray* secondEntrypointArgs = @[ @"bar", @"second" ];
124 FlutterEngineGroupOptions* secondOptions = [[FlutterEngineGroupOptions alloc] init];
125 secondOptions.entrypointArgs = secondEntrypointArgs;
126 FlutterEngine* spawnee = [group makeEngineWithOptions:secondOptions];
127 XCTAssertNotNil(spawnee);
128 OCMVerify([spawner spawnWithEntrypoint:nil
129 libraryURI:nil
130 initialRoute:nil
131 entrypointArgs:secondEntrypointArgs]);
132 }
133
134 - (void)testReleasesProjectOnDealloc {
135 __weak FlutterDartProject* weakProject;
136 @autoreleasepool {
137 FlutterDartProject* mockProject = OCMClassMock([FlutterDartProject class]);
138 FlutterEngineGroup* group = [[FlutterEngineGroup alloc] initWithName:@"foo"
139 project:mockProject];
140 XCTAssertNotNil(group);
141 weakProject = mockProject;
142 XCTAssertNotNil(weakProject);
143 group = nil;
144 mockProject = nil;
145 }
146 XCTAssertNil(weakProject);
147 }
148
149 @end
FlutterEngine_Test.h
FlutterEngineGroup.h
engine
id engine
Definition: FlutterTextInputPluginTest.mm:136
FlutterDartProject
Definition: FlutterDartProject.mm:268
FlutterEngineGroup
Definition: FlutterEngineGroup.h:57
-[FlutterEngineGroup makeEngineWithEntrypoint:libraryURI:initialRoute:]
FlutterEngine * makeEngineWithEntrypoint:libraryURI:initialRoute:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI,[initialRoute] nullable NSString *initialRoute)
Definition: FlutterEngineGroup.mm:37
-[FlutterEngineGroup makeEngineWithEntrypoint:libraryURI:]
FlutterEngine * makeEngineWithEntrypoint:libraryURI:(nullable NSString *entrypoint,[libraryURI] nullable NSString *libraryURI)
Definition: FlutterEngineGroup.mm:32
-[FlutterEngineGroup makeEngineWithOptions:]
FlutterEngine * makeEngineWithOptions:(nullable FlutterEngineGroupOptions *options)
Definition: FlutterEngineGroup.mm:47
FlutterEngineGroupOptions
Definition: FlutterEngineGroup.h:17
FlutterEngineGroupOptions::entrypointArgs
NSArray< NSString * > * entrypointArgs
Definition: FlutterEngineGroup.h:41
FlutterEngineGroupTest
Definition: FlutterEngineGroupTest.mm:18
FlutterEngine
Definition: FlutterEngine.h:61
-[FlutterEngine threadHost]
const flutter::ThreadHost & threadHost()
FlutterEngine::isGpuDisabled
BOOL isGpuDisabled
Definition: FlutterEngine.h:446
FLUTTER_ASSERT_ARC
Definition: FlutterChannelKeyResponder.mm:13