Skip to content
This repository was archived by the owner on Feb 25, 2025. It is now read-only.

Commit 4e078f7

Browse files
committed
added test that passes before this change, and fails after it
1 parent c160f5c commit 4e078f7

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

shell/platform/darwin/ios/framework/Source/FlutterEngineTest.mm

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -218,4 +218,25 @@ - (void)testDeallocNotification {
218218
[center removeObserver:observer];
219219
}
220220

221+
- (void)testSetHandlerAfterRun {
222+
FlutterEngine* engine = [[FlutterEngine alloc] initWithName:@"foobar"];
223+
NSObject<FlutterPluginRegistrar>* registrar = [engine registrarForPlugin:@"foo"];
224+
XCTestExpectation* gotMessage = [self expectationWithDescription:@"gotMessage"];
225+
fml::AutoResetWaitableEvent latch;
226+
[engine run];
227+
flutter::Shell& shell = engine.shell;
228+
engine.shell.GetTaskRunners().GetUITaskRunner()->PostTask([&latch, &shell] {
229+
flutter::Engine::Delegate& delegate = shell;
230+
auto message = std::make_unique<flutter::PlatformMessage>("foo", nullptr);
231+
delegate.OnEngineHandlePlatformMessage(std::move(message));
232+
latch.Signal();
233+
});
234+
latch.Wait();
235+
[registrar.messenger setMessageHandlerOnChannel:@"foo"
236+
binaryMessageHandler:^(NSData* message, FlutterBinaryReply reply) {
237+
[gotMessage fulfill];
238+
}];
239+
[self waitForExpectationsWithTimeout:1 handler:nil];
240+
}
241+
221242
@end

shell/platform/darwin/ios/framework/Source/FlutterEngine_Test.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// Use of this source code is governed by a BSD-style license that can be
33
// found in the LICENSE file.
44

5+
#import "flutter/shell/common/shell.h"
56
#import "flutter/shell/platform/darwin/ios/framework/Headers/FlutterEngine.h"
67
#import "flutter/shell/platform/darwin/ios/rendering_api_selection.h"
78

@@ -15,6 +16,7 @@ class ThreadHost;
1516

1617
// Category to add test-only visibility.
1718
@interface FlutterEngine (Test) <FlutterBinaryMessenger>
19+
- (flutter::Shell&)shell;
1820
- (void)setBinaryMessenger:(FlutterBinaryMessengerRelay*)binaryMessenger;
1921
- (flutter::IOSRenderingAPI)platformViewsRenderingAPI;
2022
- (void)waitForFirstFrame:(NSTimeInterval)timeout callback:(void (^)(BOOL didTimeout))callback;

0 commit comments

Comments
 (0)