1010#import " flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
1111#import " flutter/shell/platform/darwin/common/framework/Headers/FlutterMacros.h"
1212#import " flutter/shell/platform/darwin/ios/framework/Headers/FlutterViewController.h"
13+ #import " flutter/shell/platform/darwin/ios/framework/Source/FlutterEmbedderKeyResponder.h"
1314#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterFakeKeyEvents.h"
1415#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterTextInputPlugin.h"
1516#import " flutter/shell/platform/darwin/ios/framework/Source/FlutterViewController_Internal.h"
@@ -116,6 +117,15 @@ - (UIAccessibilityContrast)accessibilityContrast;
116117@end
117118#endif
118119
120+ @interface FlutterKeyboardManager (Tests)
121+ @property (nonatomic , retain , readonly )
122+ NSMutableArray <id<FlutterKeyPrimaryResponder>>* primaryResponders;
123+ @end
124+
125+ @interface FlutterEmbedderKeyResponder (Tests)
126+ @property (nonatomic , copy , readonly ) FlutterSendKeyEvent sendEvent;
127+ @end
128+
119129@interface FlutterViewController (Tests)
120130- (void )surfaceUpdated : (BOOL )appeared ;
121131- (void )performOrientationUpdate : (UIInterfaceOrientationMask)new_preferences ;
@@ -130,6 +140,7 @@ - (void)keyboardWillChangeFrame:(NSNotification*)notification;
130140- (void )startKeyBoardAnimation : (NSTimeInterval )duration ;
131141- (void )ensureViewportMetricsIsCorrect ;
132142- (void )invalidateDisplayLink ;
143+ - (void )addInternalPlugins ;
133144@end
134145
135146@interface FlutterViewControllerTest : XCTestCase
@@ -392,6 +403,24 @@ - (void)testViewDidLoadDoesInvokeEngineWhenIsTheViewController {
392403 OCMVerify ([mockEngine attachView ]);
393404}
394405
406+ - (void )testInternalPluginsWeakPtrNotCrash {
407+ FlutterSendKeyEvent sendEvent;
408+ @autoreleasepool {
409+ FlutterViewController* vc = [[FlutterViewController alloc ] initWithProject: nil
410+ nibName: nil
411+ bundle: nil ];
412+ [vc addInternalPlugins ];
413+ FlutterKeyboardManager* keyboardManager = vc.keyboardManager ;
414+ FlutterEmbedderKeyResponder* keyPrimaryResponder = (FlutterEmbedderKeyResponder*)
415+ [(NSArray <id <FlutterKeyPrimaryResponder>>*)keyboardManager.primaryResponders firstObject ];
416+ sendEvent = [keyPrimaryResponder sendEvent ];
417+ }
418+
419+ if (sendEvent) {
420+ sendEvent ({}, nil , nil );
421+ }
422+ }
423+
395424- (void )testBinaryMessenger {
396425 FlutterViewController* vc = [[FlutterViewController alloc ] initWithEngine: self .mockEngine
397426 nibName: nil
0 commit comments