Flutter Engine
The Flutter Engine
FlutterEngineTest.m
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 <Flutter/Flutter.h>
6#import <XCTest/XCTest.h>
7
8#import "AppDelegate.h"
9
10@interface FlutterEngineTest : XCTestCase
11@end
12
13@implementation FlutterEngineTest
14
15extern NSNotificationName const FlutterViewControllerWillDealloc;
16
17- (void)testIsolateId {
18 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
19 XCTAssertNil(engine.isolateId);
20 [self keyValueObservingExpectationForObject:engine keyPath:@"isolateId" handler:nil];
21
22 XCTAssertTrue([engine runWithEntrypoint:nil]);
23
24 [self waitForExpectationsWithTimeout:30.0 handler:nil];
25
26 XCTAssertNotNil(engine.isolateId);
27 XCTAssertTrue([engine.isolateId hasPrefix:@"isolates/"]);
28
29 [engine destroyContext];
30
31 XCTAssertNil(engine.isolateId);
32}
33
34- (void)testChannelSetup {
35 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test" project:nil];
36 XCTAssertNil(engine.navigationChannel);
37 XCTAssertNil(engine.platformChannel);
38 XCTAssertNil(engine.lifecycleChannel);
39
40 XCTAssertTrue([engine run]);
41
42 XCTAssertNotNil(engine.navigationChannel);
43 XCTAssertNotNil(engine.platformChannel);
44 XCTAssertNotNil(engine.lifecycleChannel);
45
46 [engine destroyContext];
47
48 XCTAssertNil(engine.navigationChannel);
49 XCTAssertNil(engine.platformChannel);
50 XCTAssertNil(engine.lifecycleChannel);
51}
52
53// https://github.com/flutter/flutter/issues/123776
55 FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"test"
56 project:nil
57 allowHeadlessExecution:YES];
58 XCTAssertNil(engine.navigationChannel);
59 XCTAssertNil(engine.platformChannel);
60 XCTAssertNil(engine.lifecycleChannel);
61
62 XCTAssertTrue([engine run]);
63
64 XCTAssertNotNil(engine.navigationChannel);
65 XCTAssertNotNil(engine.platformChannel);
66 XCTAssertNotNil(engine.lifecycleChannel);
67 XCTestExpectation* expectation =
68 [[XCTestExpectation alloc] initWithDescription:@"notification called"];
69 @autoreleasepool {
70 FlutterViewController* viewController = [[FlutterViewController alloc] initWithEngine:engine
71 nibName:nil
72 bundle:nil];
73 [engine setViewController:viewController];
74 [engine destroyContext];
75 [[NSNotificationCenter defaultCenter] addObserverForName:FlutterViewControllerWillDealloc
76 object:nil
77 queue:[NSOperationQueue mainQueue]
78 usingBlock:^(NSNotification* _Nonnull note) {
79 [expectation fulfill];
80 }];
81 viewController = nil;
82 }
83 [self waitForExpectations:@[ expectation ] timeout:30.0];
84 XCTAssertNil(engine.navigationChannel);
85 XCTAssertNil(engine.platformChannel);
86 XCTAssertNil(engine.lifecycleChannel);
87}
88
89@end
NSNotificationName const FlutterViewControllerWillDealloc
FlutterEngine engine
Definition: main.cc:68
void testReleaseViewControllerAfterDestroyContextInHeadlessMode()
FlutterMethodChannel * navigationChannel
FlutterBasicMessageChannel * lifecycleChannel
FlutterMethodChannel * platformChannel
void setViewController:(FlutterViewController *viewController)
NSString * isolateId
FlutterViewController * viewController
Definition: run.py:1