Started allowing setting message handlers to nil for dead engines (flutter/engine#18428)

This commit is contained in:
gaaclarke
2020-05-15 14:11:10 -07:00
committed by GitHub
parent 57b3bcb8c5
commit b93fa363d3
2 changed files with 14 additions and 3 deletions

View File

@@ -677,9 +677,12 @@ static constexpr int kNumProfilerSamplesPerSec = 5;
- (void)setMessageHandlerOnChannel:(NSString*)channel
binaryMessageHandler:(FlutterBinaryMessageHandler)handler {
NSParameterAssert(channel);
NSAssert(_shell && _shell->IsSetup(),
@"Setting a message handler before the FlutterEngine has been run.");
self.iosPlatformView->GetPlatformMessageRouter().SetMessageHandler(channel.UTF8String, handler);
if (_shell && _shell->IsSetup()) {
self.iosPlatformView->GetPlatformMessageRouter().SetMessageHandler(channel.UTF8String, handler);
} else {
NSAssert(!handler, @"Setting a message handler before the FlutterEngine has been run.");
// Setting a handler to nil for a not setup channel is a noop.
}
}
#pragma mark - FlutterTextureRegistry

View File

@@ -47,6 +47,14 @@ FLUTTER_ASSERT_ARC
}]);
}
- (void)testNilSetMessageHandlerBeforeRun {
id project = OCMClassMock([FlutterDartProject class]);
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar" project:project];
XCTAssertNotNil(engine);
XCTAssertNoThrow([engine.binaryMessenger setMessageHandlerOnChannel:@"foo"
binaryMessageHandler:nil]);
}
- (void)testNotifyPluginOfDealloc {
id plugin = OCMProtocolMock(@protocol(FlutterPlugin));
OCMStub([plugin detachFromEngineForRegistrar:[OCMArg any]]);