5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
8 #include "flutter/fml/platform/darwin/message_loop_darwin.h"
9 #import "flutter/lib/ui/window/platform_configuration.h"
10 #include "flutter/lib/ui/window/pointer_data.h"
11 #include "flutter/lib/ui/window/pointer_data_packet.h"
12 #import "flutter/lib/ui/window/viewport_metrics.h"
30 #import "flutter/shell/platform/embedder/embedder.h"
31 #import "flutter/testing/ios/IosUnitTests/App/AppDelegate.h"
32 #import "flutter/third_party/spring_animation/spring_animation.h"
41 - (void)setUpKeyboardAnimationVsyncClient:
45 @property(nonatomic, weak) id<FlutterKeyboardInsetManagerDelegate>
delegate;
48 - (void)handleKeyboardNotification:(NSNotification*)notification;
49 - (BOOL)isKeyboardNotificationForDifferentView:(NSNotification*)notification;
50 - (CGFloat)calculateKeyboardInset:(CGRect)keyboardFrame
51 keyboardMode:(FlutterKeyboardMode)keyboardMode;
52 - (BOOL)shouldIgnoreKeyboardNotification:(NSNotification*)notification;
53 - (FlutterKeyboardMode)calculateKeyboardAttachMode:(NSNotification*)notification;
54 - (CGFloat)calculateMultitaskingAdjustment:(CGRect)screenRect keyboardFrame:(CGRect)keyboardFrame;
55 - (void)startKeyBoardAnimation:(NSTimeInterval)duration;
59 - (void)setUpKeyboardSpringAnimationIfNeeded:(CAAnimation*)keyboardAnimation;
70 @property(nonatomic, assign) CGFloat targetViewInsetBottom;
71 @property(nonatomic, assign) BOOL isKeyboardInOrTransitioningFromBackground;
72 @property(nonatomic, strong) FlutterVSyncClient* keyboardAnimationVSyncClient;
73 @property(nonatomic, assign) BOOL didCallEnsureViewportMetricsIsCorrect;
74 @property(nonatomic, assign) BOOL didCallInvalidateKeyboardAnimationVSyncClient;
76 - (instancetype)initWithDelegate:(
id<FlutterKeyboardInsetManagerDelegate>)delegate;
80 __weak id<FlutterKeyboardInsetManagerDelegate> _delegate;
83 - (instancetype)initWithDelegate:(
id<FlutterKeyboardInsetManagerDelegate>)delegate {
91 - (void)setDelegate:(
id<FlutterKeyboardInsetManagerDelegate>)delegate {
95 - (id<FlutterKeyboardInsetManagerDelegate>)delegate {
99 - (void)startKeyBoardAnimation:(NSTimeInterval)duration {
102 - (void)handleKeyboardNotification:(NSNotification*)notification {
106 self.keyboardAnimationVSyncClient = nil;
112 - (void)setUpKeyboardSpringAnimationIfNeeded:(CAAnimation*)keyboardAnimation {
115 - (BOOL)shouldIgnoreKeyboardNotification:(NSNotification*)notification {
119 - (FlutterKeyboardMode)calculateKeyboardAttachMode:(NSNotification*)notification {
120 return FlutterKeyboardModeHidden;
123 - (void)ensureViewportMetricsIsCorrect {
124 self.didCallEnsureViewportMetricsIsCorrect = YES;
127 - (void)invalidateKeyboardAnimationVSyncClient {
128 self.didCallInvalidateKeyboardAnimationVSyncClient = YES;
131 - (void)hideKeyboardImmediately {
132 [
self ensureViewportMetricsIsCorrect];
133 [
self invalidateKeyboardAnimationVSyncClient];
136 - (SpringAnimation*)keyboardSpringAnimation {
140 - (UIView*)keyboardAnimationView {
160 - (instancetype)init {
161 if (
self = [super init]) {
162 fml::MessageLoop::EnsureInitializedForCurrentThread();
164 initWithTaskRunner:fml::MessageLoop::GetCurrent().GetTaskRunner()];
170 return self.mockTaskRunner;
173 - (void)updateViewportMetricsWithInset:(CGFloat)inset {
174 self.currentInset = inset;
176 self.updateViewportMetricsBlock(inset);
180 - (CGFloat)physicalViewInsetBottom {
181 return self.currentInset;
185 return self.mockView;
189 return self.mockEngine;
192 - (UIScreen*)flutterScreenIfViewLoaded {
193 return self.mockScreen;
196 - (BOOL)isPadInSlideOverOrStageManagerMode {
197 return self.mockIsPadInSlideOverOrStageManagerMode;
200 - (CGRect)convertViewRectToScreen:(CGRect)rect {
201 return self.mockConvertedViewRect;
224 @property(nonatomic, assign) BOOL didCallNotifyLowMemory;
229 - (void)sendKeyEvent:(const FlutterKeyEvent&)event
230 callback:(nullable FlutterKeyEventCallback)callback
231 userData:(nullable
void*)userData;
234 - (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint;
246 - (void)notifyLowMemory {
247 _didCallNotifyLowMemory = YES;
250 - (instancetype)init {
251 if (
self = [super init]) {
252 fml::MessageLoop::EnsureInitializedForCurrentThread();
254 initWithTaskRunner:fml::MessageLoop::GetCurrent().GetTaskRunner()];
260 return _uiTaskRunner;
263 - (BOOL)runWithEntrypoint:(nullable NSString*)entrypoint {
271 - (void)sendKeyEvent:(const FlutterKeyEvent&)event
272 callback:(FlutterKeyEventCallback)callback
273 userData:(
void*)userData API_AVAILABLE(ios(9.0)) {
274 if (callback == nil) {
280 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode,
282 callback(
true, userData);
288 - (BOOL)createShell:(NSString*)entrypoint
289 libraryURI:(NSString*)libraryURI
290 initialRoute:(NSString*)initialRoute;
291 - (void)dispatchPointerDataPacket:(std::unique_ptr<
flutter::PointerDataPacket>)packet;
292 - (void)updateViewportMetrics:(
flutter::ViewportMetrics)viewportMetrics;
324 @property(nonatomic, retain, readonly)
344 - (void)surfaceUpdated:(BOOL)appeared;
345 - (void)performOrientationUpdate:(UIInterfaceOrientationMask)new_preferences;
346 - (void)handlePressEvent:(FlutterUIPressProxy*)press
347 nextAction:(
void (^)())next API_AVAILABLE(ios(13.4));
348 - (void)discreteScrollEvent:(UIPanGestureRecognizer*)recognizer;
352 - (void)onUserSettingsChanged:(NSNotification*)notification;
353 - (void)applicationWillTerminate:(NSNotification*)notification;
354 - (void)goToApplicationLifecycle:(nonnull NSString*)state;
357 - (
flutter::PointerData)generatePointerDataForFake;
358 - (void)dispatchTouches:(NSSet*)touches
359 pointerDataChangeOverride:(
flutter::PointerData::Change*)changeOverride
360 event:(UIEvent*)event;
362 initialRoute:(nullable NSString*)initialRoute;
363 - (void)applicationBecameActive:(NSNotification*)notification;
364 - (void)applicationWillResignActive:(NSNotification*)notification;
365 - (void)applicationWillTerminate:(NSNotification*)notification;
366 - (void)applicationDidEnterBackground:(NSNotification*)notification;
367 - (void)applicationWillEnterForeground:(NSNotification*)notification;
368 - (void)sceneBecameActive:(NSNotification*)notification API_AVAILABLE(ios(13.0));
369 - (void)sceneWillResignActive:(NSNotification*)notification API_AVAILABLE(ios(13.0));
370 - (void)sceneWillDisconnect:(NSNotification*)notification API_AVAILABLE(ios(13.0));
371 - (void)sceneDidEnterBackground:(NSNotification*)notification API_AVAILABLE(ios(13.0));
372 - (void)sceneWillEnterForeground:(NSNotification*)notification API_AVAILABLE(ios(13.0));
373 - (void)onAccessibilityStatusChanged:(NSNotification*)notification;
378 @property(nonatomic, strong)
id mockTextInputPlugin;
379 @property(nonatomic, strong)
id messageSent;
380 - (void)sendMessage:(
id _Nullable)message reply:(
FlutterReply _Nullable)callback;
383 @interface UITouch ()
385 @property(nonatomic, readwrite) UITouchPhase phase;
391 - (const std::vector<flutter::PointerData>&)capturedPointerData;
395 std::vector<flutter::PointerData> _capturedPointerData;
398 - (void)dispatchPointerDataPacket:(std::unique_ptr<
flutter::PointerDataPacket>)packet {
399 for (
size_t i = 0; i < packet->GetLength(); i++) {
400 _capturedPointerData.push_back(packet->GetPointerData(i));
404 - (const std::vector<flutter::PointerData>&)capturedPointerData {
405 return _capturedPointerData;
416 self.messageSent = nil;
422 [
self.mockEngine stopMocking];
423 self.mockEngine = nil;
424 self.mockTextInputPlugin = nil;
425 self.messageSent = nil;
428 - (id)setUpMockScreen {
429 UIScreen*
mockScreen = OCMClassMock([UIScreen
class]);
431 CGRect screenBounds = CGRectMake(0, 0, 1170, 2532);
432 OCMStub([
mockScreen bounds]).andReturn(screenBounds);
433 CGFloat screenScale = 1;
434 OCMStub([
mockScreen scale]).andReturn(screenScale);
440 screen:(UIScreen*)screen
441 viewFrame:(CGRect)viewFrame
442 convertedFrame:(CGRect)convertedFrame {
443 OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
444 UIView* view = [[UIView alloc] initWithFrame:viewFrame];
445 UIWindow* window = [[UIWindow alloc] initWithFrame:viewFrame];
446 [window addSubview:view];
448 OCMStub([viewControllerMock viewIfLoaded]).andReturn(view);
449 OCMStub([viewControllerMock view]).andReturn(view);
461 - (void)testEngineAllowHeadlessExecutionIsSettableViaKeyValueCoding {
468 [viewController setValue:@YES forKey:@"engineAllowHeadlessExecution"];
474 - (void)testImplicitEngineTakesAllowHeadlessExecutionFromViewController {
487 - (void)testStartKeyboardAnimationWillInvokeSetupKeyboardSpringAnimationIfNeeded {
494 OCMStub([viewControllerMock
isViewLoaded]).andReturn(YES);
495 __unused UIView* dummyView = [viewControllerMock view];
497 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
499 engine.viewController = viewControllerMock;
501 FlutterKeyboardInsetManager* manager =
502 (FlutterKeyboardInsetManager*)
viewController.keyboardInsetManager;
504 id viewClassMock = OCMClassMock([UIView
class]);
505 OCMStub([viewClassMock animateWithDuration:0.25 animations:[OCMArg any] completion:[OCMArg any]])
506 .andDo(^(NSInvocation* invocation) {
509 __unsafe_unretained void (^animations)(void);
510 [invocation getArgument:&animations atIndex:3];
514 __unsafe_unretained void (^completion)(BOOL finished);
515 [invocation getArgument:&completion atIndex:4];
524 manager.targetViewInsetBottom = 320;
525 manager.keyboardSpringAnimation = [[SpringAnimation alloc] initWithStiffness:100
531 XCTAssertNotNil(manager.keyboardSpringAnimation);
533 [manager startKeyBoardAnimation:0.25];
535 XCTAssertNil(manager.keyboardSpringAnimation);
536 [viewClassMock stopMocking];
539 - (void)testSetupKeyboardSpringAnimationIfNeeded {
544 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
545 UIScreen* screen = [
self setUpMockScreen];
546 CGRect viewFrame = screen.bounds;
547 [
self setUpMockView:viewControllerMock
550 convertedFrame:viewFrame];
553 [viewController.keyboardInsetManager setUpKeyboardSpringAnimationIfNeeded:nil];
554 SpringAnimation* keyboardSpringAnimation =
556 XCTAssertTrue(keyboardSpringAnimation == nil);
559 CABasicAnimation* nonSpringAnimation = [CABasicAnimation animation];
560 nonSpringAnimation.duration = 1.0;
561 nonSpringAnimation.fromValue = [NSNumber numberWithFloat:0.0];
562 nonSpringAnimation.toValue = [NSNumber numberWithFloat:1.0];
563 nonSpringAnimation.keyPath =
@"position";
564 [viewController.keyboardInsetManager setUpKeyboardSpringAnimationIfNeeded:nonSpringAnimation];
565 keyboardSpringAnimation =
viewController.keyboardInsetManager.keyboardSpringAnimation;
567 XCTAssertTrue(keyboardSpringAnimation == nil);
570 CASpringAnimation* springAnimation = [CASpringAnimation animation];
571 springAnimation.mass = 1.0;
572 springAnimation.stiffness = 100.0;
573 springAnimation.damping = 10.0;
574 springAnimation.keyPath =
@"position";
575 springAnimation.fromValue = [NSValue valueWithCGPoint:CGPointMake(0, 0)];
576 springAnimation.toValue = [NSValue valueWithCGPoint:CGPointMake(100, 100)];
577 [viewController.keyboardInsetManager setUpKeyboardSpringAnimationIfNeeded:springAnimation];
578 keyboardSpringAnimation =
viewController.keyboardInsetManager.keyboardSpringAnimation;
579 XCTAssertTrue(keyboardSpringAnimation != nil);
589 - (void)testKeyboardAnimationIsShowingAndCompounding {
590 UIScreen* screen = [
self setUpMockScreen];
591 CGFloat screenWidth = screen.bounds.size.width;
592 CGFloat screenHeight = screen.bounds.size.height;
593 CGRect viewFrame = screen.bounds;
598 delegate.
mockView = [[UIView alloc] init];
608 FlutterKeyboardInsetManager* manager =
609 [[FlutterKeyboardInsetManager alloc] initWithDelegate:delegate
610 displayLinkManager:FlutterDisplayLinkManager.shared];
615 CGRect initialShowKeyboardBeginFrame = CGRectMake(0, screenHeight, screenWidth, 250);
616 CGRect initialShowKeyboardEndFrame = CGRectMake(0, screenHeight - 250, screenWidth, 500);
617 NSNotification* fakeNotification = [NSNotification
618 notificationWithName:UIKeyboardWillChangeFrameNotification
621 @"UIKeyboardFrameBeginUserInfoKey" : @(initialShowKeyboardBeginFrame),
622 @"UIKeyboardFrameEndUserInfoKey" : @(initialShowKeyboardEndFrame),
623 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
624 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
626 manager.targetViewInsetBottom = 0;
627 [manager handleKeyboardNotification:fakeNotification];
628 BOOL isShowingAnimation1 = manager.keyboardAnimationIsShowing;
629 XCTAssertTrue(isShowingAnimation1);
632 CGRect compoundingShowKeyboardBeginFrame = CGRectMake(0, screenHeight - 250, screenWidth, 250);
633 CGRect compoundingShowKeyboardEndFrame = CGRectMake(0, screenHeight - 500, screenWidth, 500);
634 fakeNotification = [NSNotification
635 notificationWithName:UIKeyboardWillChangeFrameNotification
638 @"UIKeyboardFrameBeginUserInfoKey" : @(compoundingShowKeyboardBeginFrame),
639 @"UIKeyboardFrameEndUserInfoKey" : @(compoundingShowKeyboardEndFrame),
640 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
641 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
644 [manager handleKeyboardNotification:fakeNotification];
645 BOOL isShowingAnimation2 = manager.keyboardAnimationIsShowing;
646 XCTAssertTrue(isShowingAnimation2);
647 XCTAssertTrue(isShowingAnimation1 == isShowingAnimation2);
650 CGRect initialHideKeyboardBeginFrame = CGRectMake(0, screenHeight - 500, screenWidth, 250);
651 CGRect initialHideKeyboardEndFrame = CGRectMake(0, screenHeight - 250, screenWidth, 500);
652 fakeNotification = [NSNotification
653 notificationWithName:UIKeyboardWillChangeFrameNotification
656 @"UIKeyboardFrameBeginUserInfoKey" : @(initialHideKeyboardBeginFrame),
657 @"UIKeyboardFrameEndUserInfoKey" : @(initialHideKeyboardEndFrame),
658 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
659 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
662 [manager handleKeyboardNotification:fakeNotification];
663 BOOL isShowingAnimation3 = manager.keyboardAnimationIsShowing;
664 XCTAssertFalse(isShowingAnimation3);
665 XCTAssertTrue(isShowingAnimation2 != isShowingAnimation3);
668 CGRect compoundingHideKeyboardBeginFrame = CGRectMake(0, screenHeight - 250, screenWidth, 250);
669 CGRect compoundingHideKeyboardEndFrame = CGRectMake(0, screenHeight, screenWidth, 500);
670 fakeNotification = [NSNotification
671 notificationWithName:UIKeyboardWillChangeFrameNotification
674 @"UIKeyboardFrameBeginUserInfoKey" : @(compoundingHideKeyboardBeginFrame),
675 @"UIKeyboardFrameEndUserInfoKey" : @(compoundingHideKeyboardEndFrame),
676 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
677 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
680 [manager handleKeyboardNotification:fakeNotification];
681 BOOL isShowingAnimation4 = manager.keyboardAnimationIsShowing;
682 XCTAssertFalse(isShowingAnimation4);
683 XCTAssertTrue(isShowingAnimation3 == isShowingAnimation4);
685 [manager invalidate];
688 - (void)testShouldIgnoreKeyboardNotification {
697 FlutterKeyboardInsetManager* managerMock = [[FlutterKeyboardInsetManager alloc]
698 initWithDelegate:(id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock
699 displayLinkManager:FlutterDisplayLinkManager.shared];
702 UIScreen* screen = [
self setUpMockScreen];
703 CGRect viewFrame = screen.bounds;
704 [
self setUpMockView:viewControllerMock
707 convertedFrame:viewFrame];
709 CGFloat screenWidth = screen.bounds.size.width;
710 CGFloat screenHeight = screen.bounds.size.height;
711 CGRect emptyKeyboard = CGRectZero;
712 CGRect zeroHeightKeyboard = CGRectMake(0, 0, screenWidth, 0);
713 CGRect validKeyboardEndFrame = CGRectMake(0, screenHeight - 320, screenWidth, 320);
717 NSNotification* notification =
718 [NSNotification notificationWithName:UIKeyboardWillHideNotification
721 @"UIKeyboardFrameEndUserInfoKey" : @(validKeyboardEndFrame),
722 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
723 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
726 BOOL shouldIgnore = [managerMock shouldIgnoreKeyboardNotification:notification];
727 XCTAssertTrue(shouldIgnore == NO);
731 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
734 @"UIKeyboardFrameEndUserInfoKey" : @(emptyKeyboard),
735 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
736 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
738 shouldIgnore = [managerMock shouldIgnoreKeyboardNotification:notification];
739 XCTAssertTrue(shouldIgnore == YES);
744 [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
747 @"UIKeyboardFrameEndUserInfoKey" : @(zeroHeightKeyboard),
748 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
749 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
751 shouldIgnore = [managerMock shouldIgnoreKeyboardNotification:notification];
752 XCTAssertTrue(shouldIgnore == NO);
757 [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
760 @"UIKeyboardFrameEndUserInfoKey" : @(validKeyboardEndFrame),
761 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
762 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
764 shouldIgnore = [managerMock shouldIgnoreKeyboardNotification:notification];
765 XCTAssertTrue(shouldIgnore == YES);
770 [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
773 @"UIKeyboardFrameEndUserInfoKey" : @(validKeyboardEndFrame),
774 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
775 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
777 shouldIgnore = [managerMock shouldIgnoreKeyboardNotification:notification];
778 XCTAssertTrue(shouldIgnore == NO);
780 [(id)viewControllerMock stopMocking];
783 - (void)testKeyboardAnimationWillNotCrashWhenEngineDestroyed {
789 [viewController.keyboardInsetManager
790 setUpKeyboardAnimationVsyncClient:^(NSTimeInterval targetTime){
795 - (void)testKeyboardAnimationFirstVsyncCallbackCalculatesSafeInset {
802 OCMStub([viewControllerMock
isViewLoaded]).andReturn(YES);
803 __unused UIView* dummyView = [viewControllerMock view];
805 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
807 engine.viewController = viewControllerMock;
809 XCTestExpectation* expectation = [
self expectationWithDescription:@"metrics updated"];
811 __block CGFloat capturedInset = -1.0;
812 __block BOOL fulfilled = NO;
813 OCMStub([viewControllerMock updateViewportMetricsWithInset:0])
814 .ignoringNonObjectArgs()
815 .andDo(^(NSInvocation* invocation) {
816 [invocation getArgument:&capturedInset atIndex:2];
821 [viewController.keyboardInsetManager invalidateKeyboardAnimationVSyncClient];
822 [expectation fulfill];
827 CASpringAnimation* springAnimation = [CASpringAnimation animation];
828 springAnimation.mass = 1.0;
829 springAnimation.stiffness = 100.0;
830 springAnimation.damping = 10.0;
831 springAnimation.keyPath =
@"position";
833 viewController.keyboardInsetManager.targetViewInsetBottom = 300.0;
836 [viewController.keyboardInsetManager startKeyBoardAnimation:0.25];
837 [viewController.keyboardInsetManager setUpKeyboardSpringAnimationIfNeeded:springAnimation];
840 FlutterVSyncClient* client =
viewController.keyboardInsetManager.keyboardAnimationVSyncClient;
841 [client onDisplayLink:client.displayLink];
844 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
847 XCTAssertFalse(isnan(capturedInset));
848 XCTAssertFalse(isinf(capturedInset));
849 XCTAssertGreaterThanOrEqual(capturedInset, 0.0);
850 XCTAssertLessThan(capturedInset, 300.0);
853 - (void)testKeyboardAnimationCallbackIsDeliveredAsynchronously {
862 id mockCADisplayLink = OCMClassMock([CADisplayLink
class]);
864 ClassMethod([mockCADisplayLink displayLinkWithTarget:[OCMArg any]
865 selector:sel_registerName(
"onDisplayLink:")]));
867 XCTestExpectation* expectation = [
self expectationWithDescription:@"keyboard animation callback"];
868 __block BOOL callbackExecuted = NO;
869 [viewController.keyboardInsetManager
870 setUpKeyboardAnimationVsyncClient:^(NSTimeInterval targetTime) {
871 callbackExecuted = YES;
872 [expectation fulfill];
875 FlutterVSyncClient* client =
viewController.keyboardInsetManager.keyboardAnimationVSyncClient;
876 [client onDisplayLink:client.displayLink];
880 XCTAssertFalse(callbackExecuted);
883 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
884 XCTAssertTrue(callbackExecuted);
885 [mockCADisplayLink stopMocking];
888 - (void)testCalculateKeyboardAttachMode {
894 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
895 UIScreen* screen = [
self setUpMockScreen];
896 CGRect viewFrame = screen.bounds;
897 [
self setUpMockView:viewControllerMock
900 convertedFrame:viewFrame];
902 CGFloat screenWidth = screen.bounds.size.width;
903 CGFloat screenHeight = screen.bounds.size.height;
906 CGRect keyboardFrame = CGRectZero;
907 NSNotification* notification =
908 [NSNotification notificationWithName:UIKeyboardWillHideNotification
911 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
912 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
913 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
915 FlutterKeyboardMode keyboardMode =
916 [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
917 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
920 keyboardFrame = CGRectZero;
921 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
924 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
925 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
926 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
928 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
929 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
932 keyboardFrame = CGRectMake(0, 0, screenWidth, 0);
933 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
936 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
937 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
938 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
940 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
941 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
944 keyboardFrame = CGRectMake(0, 0, 320, 320);
945 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
948 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
949 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
950 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
952 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
953 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
956 keyboardFrame = CGRectMake(0, 0, screenWidth, 320);
957 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
960 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
961 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
962 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
964 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
965 XCTAssertTrue(keyboardMode == FlutterKeyboardModeFloating);
968 keyboardFrame = CGRectMake(0, screenHeight - 320, screenWidth, 320);
969 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
972 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
973 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
974 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
976 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
977 XCTAssertTrue(keyboardMode == FlutterKeyboardModeDocked);
980 CGFloat longDecimalHeight = 320.666666666666666;
981 keyboardFrame = CGRectMake(0, screenHeight - longDecimalHeight, screenWidth, longDecimalHeight);
982 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
985 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
986 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
987 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
989 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
990 XCTAssertTrue(keyboardMode == FlutterKeyboardModeDocked);
993 keyboardFrame = CGRectMake(0, screenHeight - .0000001, screenWidth, longDecimalHeight);
994 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
997 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
998 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
999 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
1001 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
1002 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
1005 keyboardFrame = CGRectMake(0, screenHeight, screenWidth, 320);
1006 notification = [NSNotification notificationWithName:UIKeyboardWillChangeFrameNotification
1009 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
1010 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
1011 @"UIKeyboardIsLocalUserInfoKey" : @(YES)
1013 keyboardMode = [viewController.keyboardInsetManager calculateKeyboardAttachMode:notification];
1014 XCTAssertTrue(keyboardMode == FlutterKeyboardModeHidden);
1017 - (void)testCalculateMultitaskingAdjustment {
1018 UIScreen* screen = [UIScreen mainScreen];
1019 CGFloat screenWidth = screen.bounds.size.width;
1020 CGFloat screenHeight = screen.bounds.size.height;
1021 CGRect screenRect = screen.bounds;
1022 CGRect convertedViewFrame = CGRectMake(0, 0, 320, screenHeight - 20);
1023 CGRect keyboardFrame = CGRectMake(20, screenHeight - 320, screenWidth, 300);
1032 FlutterKeyboardInsetManager* manager =
1033 [[FlutterKeyboardInsetManager alloc] initWithDelegate:delegate
1034 displayLinkManager:FlutterDisplayLinkManager.shared];
1036 CGFloat adjustment = [manager calculateMultitaskingAdjustment:screenRect
1037 keyboardFrame:keyboardFrame];
1038 XCTAssertTrue(adjustment == 20);
1041 - (void)testCalculateKeyboardInset {
1042 UIScreen* screen = [UIScreen mainScreen];
1043 CGFloat screenWidth = screen.bounds.size.width;
1044 CGFloat screenHeight = screen.bounds.size.height;
1045 CGRect convertedViewFrame = CGRectMake(0, 0, 320, screenHeight - 20);
1046 CGRect keyboardFrame = CGRectMake(20, screenHeight - 320, screenWidth, 300);
1054 FlutterKeyboardInsetManager* manager =
1055 [[FlutterKeyboardInsetManager alloc] initWithDelegate:delegate
1056 displayLinkManager:FlutterDisplayLinkManager.shared];
1058 CGFloat inset = [manager calculateKeyboardInset:keyboardFrame
1059 keyboardMode:FlutterKeyboardModeDocked];
1060 XCTAssertTrue(inset == 300 * screen.scale);
1063 - (void)testHandleKeyboardNotification {
1064 UIScreen* screen = [
self setUpMockScreen];
1065 CGFloat screenWidth = screen.bounds.size.width;
1066 CGFloat screenHeight = screen.bounds.size.height;
1067 CGRect keyboardFrame = CGRectMake(0, screenHeight - 320, screenWidth, 320);
1068 CGRect viewFrame = screen.bounds;
1070 NSNotification* notification = [NSNotification
1071 notificationWithName:UIKeyboardWillShowNotification
1074 @"UIKeyboardFrameEndUserInfoKey" : [NSValue valueWithCGRect:keyboardFrame],
1075 @"UIKeyboardAnimationDurationUserInfoKey" : @0.25,
1076 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
1085 delegate.
mockView = [[UIView alloc] init];
1092 FlutterKeyboardInsetManager* manager =
1093 [[FlutterKeyboardInsetManager alloc] initWithDelegate:delegate
1094 displayLinkManager:FlutterDisplayLinkManager.shared];
1095 manager.targetViewInsetBottom = 0;
1097 [manager handleKeyboardNotification:notification];
1100 XCTAssertTrue(manager.targetViewInsetBottom == 320 * screen.scale);
1103 XCTAssertNotNil(manager.keyboardAnimationVSyncClient);
1105 [manager invalidate];
1108 - (void)testEnsureBottomInsetIsZeroWhenKeyboardDismissed {
1117 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
1119 engine.viewController = viewControllerMock;
1121 CGRect keyboardFrame = CGRectZero;
1123 NSNotification* fakeNotification =
1124 [NSNotification notificationWithName:UIKeyboardWillHideNotification
1127 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
1128 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.25),
1129 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
1133 [viewController.keyboardInsetManager handleKeyboardNotification:fakeNotification];
1134 XCTAssertTrue(
viewController.keyboardInsetManager.targetViewInsetBottom == 0);
1137 - (void)testStopKeyBoardAnimationWhenReceivedWillHideNotificationAfterWillShowNotification {
1147 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
1149 engine.viewController = viewControllerMock;
1150 OCMStub([viewControllerMock
isViewLoaded]).andReturn(YES);
1151 __unused UIView* dummyView2 = [viewControllerMock view];
1153 UIScreen* screen = [
self setUpMockScreen];
1154 OCMStub([screen scale]).andReturn(1.0);
1155 OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
1156 CGRect viewFrame = screen.bounds;
1157 [
self setUpMockView:viewControllerMock
1160 convertedFrame:viewFrame];
1163 CGFloat screenWidth = screen.bounds.size.width;
1164 CGFloat screenHeight = screen.bounds.size.height;
1165 CGRect keyboardFrame = CGRectMake(0, screenHeight - 320, screenWidth, 320);
1169 NSNotification* fakeShowNotification =
1170 [NSNotification notificationWithName:UIKeyboardWillShowNotification
1173 UIKeyboardFrameEndUserInfoKey : @(keyboardFrame),
1174 UIKeyboardAnimationDurationUserInfoKey : @0.25,
1175 UIKeyboardIsLocalUserInfoKey : @(isLocal)
1177 [viewController.keyboardInsetManager handleKeyboardNotification:fakeShowNotification];
1178 XCTAssertEqual(
viewController.keyboardInsetManager.targetViewInsetBottom, 320 * screen.scale);
1181 NSNotification* fakeHideNotification =
1182 [NSNotification notificationWithName:UIKeyboardWillHideNotification
1185 @"UIKeyboardFrameEndUserInfoKey" : @(keyboardFrame),
1186 @"UIKeyboardAnimationDurationUserInfoKey" : @(0.0),
1187 @"UIKeyboardIsLocalUserInfoKey" : @(isLocal)
1189 [viewController.keyboardInsetManager handleKeyboardNotification:fakeHideNotification];
1190 XCTAssertEqual(
viewController.keyboardInsetManager.targetViewInsetBottom, 0);
1193 XCTAssertNil([
viewController.keyboardInsetManager keyboardAnimationView]);
1194 XCTAssertNil([
viewController.keyboardInsetManager keyboardSpringAnimation]);
1197 - (void)testEnsureViewportMetricsWillInvokeAndDisplayLinkWillInvalidateInViewDidDisappear {
1205 (id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock;
1208 initWithDelegate:(id<FlutterKeyboardInsetManagerDelegate>)viewControllerMock];
1211 [viewControllerMock viewDidDisappear:YES];
1217 - (void)testViewDidDisappearDoesntPauseEngineWhenNotTheViewController {
1225 id viewControllerMock = OCMPartialMock(viewControllerA);
1226 OCMStub([viewControllerMock surfaceUpdated:NO]);
1228 [viewControllerA viewDidDisappear:NO];
1229 OCMReject([lifecycleChannel sendMessage:
@"AppLifecycleState.paused"]);
1230 OCMReject([viewControllerMock surfaceUpdated:[OCMArg any]]);
1233 - (void)testAppWillTerminateViewDidDestroyTheEngine {
1235 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1240 OCMStub([viewControllerMock goToApplicationLifecycle:
@"AppLifecycleState.detached"]);
1242 [viewController applicationWillTerminate:nil];
1243 OCMVerify([viewControllerMock goToApplicationLifecycle:
@"AppLifecycleState.detached"]);
1247 - (void)testViewDidDisappearDoesPauseEngineWhenIsTheViewController {
1258 OCMStub([viewControllerMock surfaceUpdated:NO]);
1259 [viewController viewDidDisappear:NO];
1260 OCMVerify([lifecycleChannel sendMessage:
@"AppLifecycleState.paused"]);
1261 OCMVerify([viewControllerMock surfaceUpdated:NO]);
1263 XCTAssertNil(weakViewController);
1267 testEngineConfigSyncMethodWillExecuteWhenViewControllerInEngineIsCurrentViewControllerInViewWillAppear {
1269 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1273 [viewController viewWillAppear:YES];
1278 testEngineConfigSyncMethodWillNotExecuteWhenViewControllerInEngineIsNotCurrentViewControllerInViewWillAppear {
1280 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1290 [viewControllerA viewWillAppear:YES];
1291 OCMVerify(never(), [viewControllerA onUserSettingsChanged:nil]);
1295 testEngineConfigSyncMethodWillExecuteWhenViewControllerInEngineIsCurrentViewControllerInViewDidAppear {
1297 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1301 [viewController viewDidAppear:YES];
1306 testEngineConfigSyncMethodWillNotExecuteWhenViewControllerInEngineIsNotCurrentViewControllerInViewDidAppear {
1308 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1318 [viewControllerA viewDidAppear:YES];
1319 OCMVerify(never(), [viewControllerA onUserSettingsChanged:nil]);
1323 testEngineConfigSyncMethodWillExecuteWhenViewControllerInEngineIsCurrentViewControllerInViewWillDisappear {
1331 [viewController viewWillDisappear:NO];
1332 OCMVerify([lifecycleChannel sendMessage:
@"AppLifecycleState.inactive"]);
1336 testEngineConfigSyncMethodWillNotExecuteWhenViewControllerInEngineIsNotCurrentViewControllerInViewWillDisappear {
1347 [viewControllerA viewDidDisappear:NO];
1348 OCMReject([lifecycleChannel sendMessage:
@"AppLifecycleState.inactive"]);
1351 - (void)testUpdateViewportMetricsIfNeeded_DoesntInvokeEngineWhenNotTheViewController {
1353 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1362 [viewControllerA updateViewportMetricsIfNeeded];
1363 flutter::ViewportMetrics viewportMetrics;
1364 OCMVerify(never(), [
mockEngine updateViewportMetrics:viewportMetrics]);
1367 - (void)testUpdateViewportMetricsIfNeeded_DoesInvokeEngineWhenIsTheViewController {
1369 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1374 flutter::ViewportMetrics viewportMetrics;
1375 OCMExpect([
mockEngine updateViewportMetrics:viewportMetrics]).ignoringNonObjectArgs();
1376 [viewController updateViewportMetricsIfNeeded];
1380 - (void)testUpdatedViewportMetricsDoesResizeFlutterViewWhenAutoResizable {
1382 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1387 id mockVC = OCMPartialMock(realVC);
1390 OCMExpect([mockVC updateAutoResizeConstraints]);
1392 [mockVC setAutoResizable:YES];
1394 [mockVC viewDidLayoutSubviews];
1396 OCMVerifyAll(mockVC);
1399 - (void)testUpdatedViewportMetricsDoesNotResizeFlutterViewWhenNotAutoResizable {
1401 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1406 id mockVC = OCMPartialMock(realVC);
1409 OCMReject([mockVC updateAutoResizeConstraints]);
1411 [mockVC setAutoResizable:NO];
1413 [mockVC viewDidLayoutSubviews];
1415 OCMVerifyAll(mockVC);
1418 - (void)testViewDidLayoutSubviewsUpdatesEngineDisplays {
1420 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1428 [viewController viewDidLayoutSubviews];
1432 - (void)testViewDidLayoutSubviewsDoesNotUpdateEngineDisplaysWhenNotEngineViewController {
1434 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1441 [viewController viewDidLayoutSubviews];
1445 - (void)testUpdateViewportMetricsIfNeeded_DoesNotInvokeEngineWhenShouldBeIgnoredDuringRotation {
1447 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1452 UIScreen* screen = [
self setUpMockScreen];
1453 OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
1456 id mockCoordinator = OCMProtocolMock(
@protocol(UIViewControllerTransitionCoordinator));
1457 OCMStub([mockCoordinator transitionDuration]).andReturn(0.5);
1460 [viewController viewWillTransitionToSize:CGSizeZero withTransitionCoordinator:mockCoordinator];
1462 [viewController updateViewportMetricsIfNeeded];
1464 OCMVerify(never(), [
mockEngine updateViewportMetrics:flutter::ViewportMetrics()]);
1467 - (void)testViewWillTransitionToSize_DoesDelayEngineCallIfNonZeroDuration {
1469 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1474 UIScreen* screen = [
self setUpMockScreen];
1475 OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
1479 NSTimeInterval transitionDuration = 0.5;
1480 id mockCoordinator = OCMProtocolMock(
@protocol(UIViewControllerTransitionCoordinator));
1481 OCMStub([mockCoordinator transitionDuration]).andReturn(transitionDuration);
1483 flutter::ViewportMetrics viewportMetrics;
1484 OCMExpect([
mockEngine updateViewportMetrics:viewportMetrics]).ignoringNonObjectArgs();
1486 [viewController viewWillTransitionToSize:CGSizeZero withTransitionCoordinator:mockCoordinator];
1488 [viewController updateViewportMetricsIfNeeded];
1489 OCMVerify(never(), [
mockEngine updateViewportMetrics:flutter::ViewportMetrics()]);
1493 XCTWaiterResult result = [XCTWaiter
1494 waitForExpectations:@[ [
self expectationWithDescription:@"Waiting for rotation duration"] ]
1495 timeout:transitionDuration];
1496 XCTAssertEqual(result, XCTWaiterResultTimedOut);
1501 - (void)testViewWillTransitionToSize_DoesNotDelayEngineCallIfZeroDuration {
1503 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1508 UIScreen* screen = [
self setUpMockScreen];
1509 OCMStub([viewControllerMock flutterScreenIfViewLoaded]).andReturn(screen);
1513 id mockCoordinator = OCMProtocolMock(
@protocol(UIViewControllerTransitionCoordinator));
1514 OCMStub([mockCoordinator transitionDuration]).andReturn(0);
1516 flutter::ViewportMetrics viewportMetrics;
1517 OCMExpect([
mockEngine updateViewportMetrics:viewportMetrics]).ignoringNonObjectArgs();
1520 [viewController viewWillTransitionToSize:CGSizeZero withTransitionCoordinator:mockCoordinator];
1521 [viewController updateViewportMetricsIfNeeded];
1526 - (void)testViewDidLoadDoesntInvokeEngineWhenNotTheViewController {
1528 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1537 UIView* view = viewControllerA.view;
1538 XCTAssertNotNil(view);
1542 - (void)testViewDidLoadDoesInvokeEngineWhenIsTheViewController {
1544 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1551 XCTAssertNotNil(view);
1552 OCMVerify(times(1), [
mockEngine attachView]);
1555 - (void)testViewDidLoadDoesntInvokeEngineAttachViewWhenEngineNeedsLaunch {
1557 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1563 [viewController sharedSetupWithProject:nil initialRoute:nil];
1566 XCTAssertNotNil(view);
1570 - (void)testSplashScreenViewRemoveNotCrash {
1575 [flutterViewController setSplashScreenView:[[UIView alloc] init]];
1576 [flutterViewController setSplashScreenView:nil];
1579 - (void)testInternalPluginsWeakPtrNotCrash {
1585 [vc addInternalPlugins];
1588 [(NSArray<id<FlutterKeyPrimaryResponder>>*)keyboardManager.primaryResponders firstObject];
1589 sendEvent = [keyPrimaryResponder sendEvent];
1593 sendEvent({}, nil, nil);
1598 - (void)testInternalPluginsInvokeInViewDidLoad {
1600 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1608 XCTAssertNotNil(view);
1609 [viewController viewDidLoad];
1613 - (void)testBinaryMessenger {
1617 XCTAssertNotNil(vc);
1619 OCMStub([
self.
mockEngine binaryMessenger]).andReturn(messenger);
1621 OCMVerify([
self.
mockEngine binaryMessenger]);
1624 - (void)testViewControllerIsReleased {
1626 __weak UIView* weakView;
1635 [viewController loadView];
1636 [viewController viewDidLoad];
1640 XCTAssertNil(weakViewController);
1641 XCTAssertNil(weakView);
1644 #pragma mark - Platform Brightness
1646 - (void)testItReportsLightPlatformBrightnessByDefault {
1649 OCMStub([
self.
mockEngine settingsChannel]).andReturn(settingsChannel);
1656 [vc traitCollectionDidChange:nil];
1659 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1660 return [message[@"platformBrightness"] isEqualToString:@"light"];
1664 [settingsChannel stopMocking];
1667 - (void)testItReportsPlatformBrightnessWhenViewWillAppear {
1671 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1672 OCMStub([
mockEngine settingsChannel]).andReturn(settingsChannel);
1678 [vc viewWillAppear:false];
1681 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1682 return [message[@"platformBrightness"] isEqualToString:@"light"];
1686 [settingsChannel stopMocking];
1689 - (void)testItReportsDarkPlatformBrightnessWhenTraitCollectionRequestsIt {
1692 OCMStub([
self.
mockEngine settingsChannel]).andReturn(settingsChannel);
1693 id mockTraitCollection =
1694 [
self fakeTraitCollectionWithUserInterfaceStyle:UIUserInterfaceStyleDark];
1703 OCMStub([partialMockVC traitCollection]).andReturn(mockTraitCollection);
1706 [partialMockVC traitCollectionDidChange:nil];
1709 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1710 return [message[@"platformBrightness"] isEqualToString:@"dark"];
1714 [partialMockVC stopMocking];
1715 [settingsChannel stopMocking];
1716 [mockTraitCollection stopMocking];
1721 - (UITraitCollection*)fakeTraitCollectionWithUserInterfaceStyle:(UIUserInterfaceStyle)style {
1722 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
1723 OCMStub([mockTraitCollection userInterfaceStyle]).andReturn(style);
1724 return mockTraitCollection;
1727 - (void)testTraitCollectionDidChangeCallsResetIntrinsicContentSizeWhenAutoResizable {
1730 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1735 id partialMockVC = OCMPartialMock(realVC);
1737 id mockFlutterView = OCMClassMock([
FlutterView class]);
1738 OCMStub([partialMockVC flutterView]).andReturn(mockFlutterView);
1741 OCMStub([partialMockVC isAutoResizable]).andReturn(YES);
1744 OCMExpect([mockFlutterView resetIntrinsicContentSize]);
1747 [partialMockVC traitCollectionDidChange:nil];
1750 OCMVerifyAll(mockFlutterView);
1753 [partialMockVC stopMocking];
1754 [mockFlutterView stopMocking];
1757 #pragma mark - Platform Contrast
1759 - (void)testItReportsNormalPlatformContrastByDefault {
1762 OCMStub([
self.
mockEngine settingsChannel]).andReturn(settingsChannel);
1769 [vc traitCollectionDidChange:nil];
1772 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1773 return [message[@"platformContrast"] isEqualToString:@"normal"];
1777 [settingsChannel stopMocking];
1780 - (void)testItReportsPlatformContrastWhenViewWillAppear {
1782 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1786 OCMStub([
mockEngine settingsChannel]).andReturn(settingsChannel);
1792 [vc viewWillAppear:false];
1795 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1796 return [message[@"platformContrast"] isEqualToString:@"normal"];
1800 [settingsChannel stopMocking];
1803 - (void)testItReportsHighContrastWhenTraitCollectionRequestsIt {
1806 OCMStub([
self.
mockEngine settingsChannel]).andReturn(settingsChannel);
1808 id mockTraitCollection = [
self fakeTraitCollectionWithContrast:UIAccessibilityContrastHigh];
1817 OCMStub([partialMockVC traitCollection]).andReturn(mockTraitCollection);
1820 [partialMockVC traitCollectionDidChange:mockTraitCollection];
1823 OCMVerify([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1824 return [message[@"platformContrast"] isEqualToString:@"high"];
1828 [partialMockVC stopMocking];
1829 [settingsChannel stopMocking];
1830 [mockTraitCollection stopMocking];
1833 - (void)testItReportsAlwaysUsed24HourFormat {
1836 OCMStub([
self.
mockEngine settingsChannel]).andReturn(settingsChannel);
1842 OCMStub([mockHourFormat isAlwaysUse24HourFormat]).andReturn(YES);
1843 OCMExpect([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1844 return [message[@"alwaysUse24HourFormat"] isEqual:@(YES)];
1846 [vc onUserSettingsChanged:nil];
1847 [mockHourFormat stopMocking];
1851 OCMStub([mockHourFormat isAlwaysUse24HourFormat]).andReturn(NO);
1852 OCMExpect([settingsChannel sendMessage:[OCMArg checkWithBlock:^BOOL(
id message) {
1853 return [message[@"alwaysUse24HourFormat"] isEqual:@(NO)];
1855 [vc onUserSettingsChanged:nil];
1856 [mockHourFormat stopMocking];
1859 [settingsChannel stopMocking];
1862 - (void)testOnAccessibilityStatusChangedCallsEnableSemanticsWithFlags {
1865 id mockAccessibilityFeatures = OCMClassMock([FlutterAccessibilityFeatures
class]);
1866 OCMStub([mockAccessibilityFeatures flags]).andReturn(333);
1868 OCMStub([mockViewController accessibilityFeatures]).andReturn(mockAccessibilityFeatures);
1870 [mockViewController onAccessibilityStatusChanged:nil];
1871 OCMVerify([
self.
mockEngine enableSemantics:[OCMArg any] withFlags:333]);
1874 - (void)testHandleAccessibilityNotifications {
1878 __block NSUInteger callsCount = 0;
1879 OCMStub([mockViewController onAccessibilityStatusChanged:[OCMArg isNotNil]])
1880 .andDo(^(NSInvocation* invocation) {
1884 FlutterAccessibilityFeatures* accessibilityFeatures = [[FlutterAccessibilityFeatures alloc] init];
1885 NSArray<NSString*>* accessibilityNotification = [accessibilityFeatures observedNotificationNames];
1887 for (NSUInteger i = 0; i < [accessibilityNotification count]; i++) {
1888 NSString* notificationName = [accessibilityNotification objectAtIndex:i];
1889 [[NSNotificationCenter defaultCenter] postNotificationName:notificationName object:nil];
1890 XCTAssertEqual(callsCount, i + 1);
1894 - (void)testAccessibilityPerformEscapePopsRoute {
1896 [mockEngine createShell:@"" libraryURI:@"" initialRoute:nil];
1898 OCMStub([
mockEngine navigationChannel]).andReturn(mockNavigationChannel);
1905 OCMVerify([mockNavigationChannel invokeMethod:
@"popRoute" arguments:nil]);
1907 [mockNavigationChannel stopMocking];
1910 - (void)testPerformOrientationUpdateForcesOrientationChange {
1911 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
1912 currentOrientation:UIInterfaceOrientationLandscapeLeft
1913 didChangeOrientation:YES
1914 resultingOrientation:UIInterfaceOrientationPortrait];
1916 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
1917 currentOrientation:UIInterfaceOrientationLandscapeRight
1918 didChangeOrientation:YES
1919 resultingOrientation:UIInterfaceOrientationPortrait];
1921 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
1922 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1923 didChangeOrientation:YES
1924 resultingOrientation:UIInterfaceOrientationPortrait];
1926 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
1927 currentOrientation:UIInterfaceOrientationLandscapeLeft
1928 didChangeOrientation:YES
1929 resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
1931 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
1932 currentOrientation:UIInterfaceOrientationLandscapeRight
1933 didChangeOrientation:YES
1934 resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
1936 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
1937 currentOrientation:UIInterfaceOrientationPortrait
1938 didChangeOrientation:YES
1939 resultingOrientation:UIInterfaceOrientationPortraitUpsideDown];
1941 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
1942 currentOrientation:UIInterfaceOrientationPortrait
1943 didChangeOrientation:YES
1944 resultingOrientation:UIInterfaceOrientationLandscapeLeft];
1946 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
1947 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1948 didChangeOrientation:YES
1949 resultingOrientation:UIInterfaceOrientationLandscapeLeft];
1951 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
1952 currentOrientation:UIInterfaceOrientationPortrait
1953 didChangeOrientation:YES
1954 resultingOrientation:UIInterfaceOrientationLandscapeLeft];
1956 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
1957 currentOrientation:UIInterfaceOrientationLandscapeRight
1958 didChangeOrientation:YES
1959 resultingOrientation:UIInterfaceOrientationLandscapeLeft];
1961 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
1962 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1963 didChangeOrientation:YES
1964 resultingOrientation:UIInterfaceOrientationLandscapeLeft];
1966 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
1967 currentOrientation:UIInterfaceOrientationPortrait
1968 didChangeOrientation:YES
1969 resultingOrientation:UIInterfaceOrientationLandscapeRight];
1971 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
1972 currentOrientation:UIInterfaceOrientationLandscapeLeft
1973 didChangeOrientation:YES
1974 resultingOrientation:UIInterfaceOrientationLandscapeRight];
1976 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
1977 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1978 didChangeOrientation:YES
1979 resultingOrientation:UIInterfaceOrientationLandscapeRight];
1981 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
1982 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1983 didChangeOrientation:YES
1984 resultingOrientation:UIInterfaceOrientationPortrait];
1987 - (void)testPerformOrientationUpdateDoesNotForceOrientationChange {
1988 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
1989 currentOrientation:UIInterfaceOrientationPortrait
1990 didChangeOrientation:NO
1991 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
1993 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
1994 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
1995 didChangeOrientation:NO
1996 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
1998 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
1999 currentOrientation:UIInterfaceOrientationLandscapeLeft
2000 didChangeOrientation:NO
2001 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2003 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAll
2004 currentOrientation:UIInterfaceOrientationLandscapeRight
2005 didChangeOrientation:NO
2006 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2008 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
2009 currentOrientation:UIInterfaceOrientationPortrait
2010 didChangeOrientation:NO
2011 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2013 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
2014 currentOrientation:UIInterfaceOrientationLandscapeLeft
2015 didChangeOrientation:NO
2016 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2018 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskAllButUpsideDown
2019 currentOrientation:UIInterfaceOrientationLandscapeRight
2020 didChangeOrientation:NO
2021 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2023 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortrait
2024 currentOrientation:UIInterfaceOrientationPortrait
2025 didChangeOrientation:NO
2026 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2028 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskPortraitUpsideDown
2029 currentOrientation:UIInterfaceOrientationPortraitUpsideDown
2030 didChangeOrientation:NO
2031 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2033 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
2034 currentOrientation:UIInterfaceOrientationLandscapeLeft
2035 didChangeOrientation:NO
2036 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2038 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscape
2039 currentOrientation:UIInterfaceOrientationLandscapeRight
2040 didChangeOrientation:NO
2041 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2043 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeLeft
2044 currentOrientation:UIInterfaceOrientationLandscapeLeft
2045 didChangeOrientation:NO
2046 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2048 [
self orientationTestWithOrientationUpdate:UIInterfaceOrientationMaskLandscapeRight
2049 currentOrientation:UIInterfaceOrientationLandscapeRight
2050 didChangeOrientation:NO
2051 resultingOrientation:static_cast<UIInterfaceOrientation>(0)];
2056 - (void)orientationTestWithOrientationUpdate:(UIInterfaceOrientationMask)mask
2057 currentOrientation:(UIInterfaceOrientation)currentOrientation
2058 didChangeOrientation:(BOOL)didChange
2059 resultingOrientation:(UIInterfaceOrientation)resultingOrientation {
2060 id mockApplication = OCMClassMock([UIApplication
class]);
2064 __block __weak
id weakPreferences;
2070 if (@available(iOS 16.0, *)) {
2071 mockWindowScene = OCMClassMock([UIWindowScene
class]);
2072 mockVC = OCMPartialMock(realVC);
2073 OCMStub([mockVC flutterWindowSceneIfViewLoaded]).andReturn(mockWindowScene);
2074 if (realVC.supportedInterfaceOrientations == mask) {
2075 OCMReject([mockWindowScene requestGeometryUpdateWithPreferences:[OCMArg any]
2076 errorHandler:[OCMArg any]]);
2080 OCMExpect([mockWindowScene
2081 requestGeometryUpdateWithPreferences:[OCMArg checkWithBlock:^BOOL(
2082 UIWindowSceneGeometryPreferencesIOS*
2084 weakPreferences = preferences;
2085 return preferences.interfaceOrientations == mask;
2087 errorHandler:[OCMArg any]]);
2089 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
2090 OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockWindowScene]);
2092 deviceMock = OCMPartialMock([UIDevice currentDevice]);
2094 OCMReject([deviceMock setValue:[OCMArg any] forKey:
@"orientation"]);
2096 OCMExpect([deviceMock setValue:@(resultingOrientation) forKey:
@"orientation"]);
2098 mockWindowScene = OCMClassMock([UIWindowScene
class]);
2099 mockVC = OCMPartialMock(realVC);
2100 OCMStub([mockVC flutterWindowSceneIfViewLoaded]).andReturn(mockWindowScene);
2101 OCMStub(((UIWindowScene*)mockWindowScene).interfaceOrientation).andReturn(currentOrientation);
2104 [realVC performOrientationUpdate:mask];
2105 if (@available(iOS 16.0, *)) {
2106 OCMVerifyAll(mockWindowScene);
2108 OCMVerifyAll(deviceMock);
2111 [mockWindowScene stopMocking];
2112 [deviceMock stopMocking];
2113 [mockApplication stopMocking];
2114 XCTAssertNil(weakPreferences);
2119 - (UITraitCollection*)fakeTraitCollectionWithContrast:(UIAccessibilityContrast)contrast {
2120 id mockTraitCollection = OCMClassMock([UITraitCollection
class]);
2121 OCMStub([mockTraitCollection accessibilityContrast]).andReturn(contrast);
2122 return mockTraitCollection;
2125 - (void)testWillDeallocNotification {
2126 XCTestExpectation* expectation =
2127 [[XCTestExpectation alloc] initWithDescription:@"notification called"];
2134 [NSNotificationCenter.defaultCenter addObserverForName:FlutterViewControllerWillDealloc
2136 queue:[NSOperationQueue mainQueue]
2137 usingBlock:^(NSNotification* _Nonnull note) {
2138 [expectation fulfill];
2140 XCTAssertNotNil(realVC);
2143 [
self waitForExpectations:@[ expectation ] timeout:1.0];
2146 - (void)testReleasesKeyboardManagerOnDealloc {
2151 [viewController addInternalPlugins];
2153 XCTAssertNotNil(weakKeyboardManager);
2154 [viewController deregisterNotifications];
2158 XCTAssertNil(weakKeyboardManager);
2161 - (void)testDoesntLoadViewInInit {
2164 [engine createShell:@"" libraryURI:@"" initialRoute:nil];
2168 XCTAssertFalse([realVC
isViewLoaded],
@"shouldn't have loaded since it hasn't been shown");
2169 engine.viewController = nil;
2172 - (void)testHideOverlay {
2175 [engine createShell:@"" libraryURI:@"" initialRoute:nil];
2179 XCTAssertFalse(realVC.prefersHomeIndicatorAutoHidden,
@"");
2180 [NSNotificationCenter.defaultCenter postNotificationName:FlutterViewControllerHideHomeIndicator
2182 XCTAssertTrue(realVC.prefersHomeIndicatorAutoHidden,
@"");
2183 engine.viewController = nil;
2186 - (void)testNotifyLowMemory {
2192 OCMStub([viewControllerMock surfaceUpdated:NO]);
2193 [viewController beginAppearanceTransition:NO animated:NO];
2194 [viewController endAppearanceTransition];
2195 XCTAssertTrue(
mockEngine.didCallNotifyLowMemory);
2198 - (void)sendMessage:(
id _Nullable)message reply:(
FlutterReply _Nullable)callback {
2199 NSMutableDictionary* replyMessage = [@{
2204 self.messageSent = message;
2205 CFRunLoopPerformBlock(CFRunLoopGetCurrent(), fml::MessageLoopDarwin::kMessageLoopCFRunLoopMode,
2207 callback(replyMessage);
2212 if (@available(iOS 13.4, *)) {
2220 .andCall(
self,
@selector(sendMessage:reply:));
2222 mockEngine.textInputPlugin =
self.mockTextInputPlugin;
2230 [vc addInternalPlugins];
2232 [vc handlePressEvent:keyUpEvent(UIKeyboardHIDUsageKeyboardA, UIKeyModifierShift, 123.0)
2237 XCTAssert([
self.
messageSent[
@"keymap"] isEqualToString:
@"ios"]);
2238 XCTAssert([
self.
messageSent[
@"type"] isEqualToString:
@"keyup"]);
2239 XCTAssert([
self.
messageSent[
@"keyCode"] isEqualToNumber:[NSNumber numberWithInt:4]]);
2240 XCTAssert([
self.
messageSent[
@"modifiers"] isEqualToNumber:[NSNumber numberWithInt:0]]);
2241 XCTAssert([
self.
messageSent[
@"characters"] isEqualToString:
@""]);
2242 XCTAssert([
self.
messageSent[
@"charactersIgnoringModifiers"] isEqualToString:
@""]);
2243 [vc deregisterNotifications];
2247 if (@available(iOS 13.4, *)) {
2256 .andCall(
self,
@selector(sendMessage:reply:));
2258 mockEngine.textInputPlugin =
self.mockTextInputPlugin;
2265 [vc addInternalPlugins];
2267 [vc handlePressEvent:keyDownEvent(UIKeyboardHIDUsageKeyboardA, UIKeyModifierShift, 123.0f, "A",
2273 XCTAssert([
self.
messageSent[
@"keymap"] isEqualToString:
@"ios"]);
2274 XCTAssert([
self.
messageSent[
@"type"] isEqualToString:
@"keydown"]);
2275 XCTAssert([
self.
messageSent[
@"keyCode"] isEqualToNumber:[NSNumber numberWithInt:4]]);
2276 XCTAssert([
self.
messageSent[
@"modifiers"] isEqualToNumber:[NSNumber numberWithInt:0]]);
2277 XCTAssert([
self.
messageSent[
@"characters"] isEqualToString:
@"A"]);
2278 XCTAssert([
self.
messageSent[
@"charactersIgnoringModifiers"] isEqualToString:
@"a"]);
2279 [vc deregisterNotifications];
2284 if (@available(iOS 13.4, *)) {
2290 OCMStub([keyEventChannel sendMessage:[OCMArg any] reply:[OCMArg any]])
2291 .andCall(
self,
@selector(sendMessage:reply:));
2293 OCMStub([
self.
mockEngine keyEventChannel]).andReturn(keyEventChannel);
2301 [vc addInternalPlugins];
2303 [vc handlePressEvent:keyEventWithPhase(UIPressPhaseStationary, UIKeyboardHIDUsageKeyboardA,
2304 UIKeyModifierShift, 123.0)
2307 [vc handlePressEvent:keyEventWithPhase(UIPressPhaseCancelled, UIKeyboardHIDUsageKeyboardA,
2308 UIKeyModifierShift, 123.0)
2311 [vc handlePressEvent:keyEventWithPhase(UIPressPhaseChanged, UIKeyboardHIDUsageKeyboardA,
2312 UIKeyModifierShift, 123.0)
2317 OCMVerify(never(), [keyEventChannel sendMessage:[OCMArg any]]);
2318 [vc deregisterNotifications];
2322 if (@available(iOS 13.4, *)) {
2331 XCTAssertNotNil(vc);
2332 UIView* view = vc.view;
2333 XCTAssertNotNil(view);
2334 NSArray* gestureRecognizers = view.gestureRecognizers;
2335 XCTAssertNotNil(gestureRecognizers);
2338 for (
id gesture in gestureRecognizers) {
2339 if ([gesture isKindOfClass:[UIPanGestureRecognizer
class]]) {
2344 XCTAssertTrue(found);
2348 if (@available(iOS 13.4, *)) {
2357 XCTAssertNotNil(vc);
2359 id mockPanGestureRecognizer = OCMClassMock([UIPanGestureRecognizer
class]);
2360 XCTAssertNotNil(mockPanGestureRecognizer);
2362 [vc discreteScrollEvent:mockPanGestureRecognizer];
2365 [[mockPanGestureRecognizer verify] locationInView:[OCMArg any]];
2366 [[[
self.mockEngine verify] ignoringNonObjectArgs]
2367 dispatchPointerDataPacket:std::make_unique<flutter::PointerDataPacket>(0)];
2375 - (void)testStylusTouchFieldsSurviveConversion {
2384 XCTAssertNotNil(vc);
2387 const CGFloat altitudeAngle = M_PI / 6;
2388 const CGFloat azimuthAngle = M_PI / 4;
2389 const CGFloat force = 0.75;
2390 const CGFloat maximumPossibleForce = 4.0;
2391 const CGFloat majorRadius = 20.0;
2392 const CGFloat majorRadiusTolerance = 3.0;
2394 id fakeTouch = OCMPartialMock([[UITouch alloc] init]);
2395 [fakeTouch setPhase:UITouchPhaseBegan];
2396 OCMStub([fakeTouch force]).andReturn(force);
2397 OCMStub([fakeTouch maximumPossibleForce]).andReturn(maximumPossibleForce);
2398 OCMStub([fakeTouch majorRadius]).andReturn(majorRadius);
2399 OCMStub([fakeTouch majorRadiusTolerance]).andReturn(majorRadiusTolerance);
2400 OCMStub([fakeTouch altitudeAngle]).andReturn(altitudeAngle);
2401 OCMStub([fakeTouch azimuthAngleInView:[OCMArg any]]).andReturn(azimuthAngle);
2403 [vc dispatchTouches:[NSSet setWithObject:fakeTouch] pointerDataChangeOverride:nullptr event:nil];
2406 XCTAssertEqual(captured.size(), 1u);
2407 const flutter::PointerData& data = captured[0];
2409 const double tolerance = 1e-6;
2412 XCTAssertEqualWithAccuracy(data.pressure, force, tolerance);
2413 XCTAssertEqualWithAccuracy(data.pressure_max, maximumPossibleForce, tolerance);
2414 XCTAssertEqualWithAccuracy(data.pressure_min, 0.0, tolerance);
2417 XCTAssertEqualWithAccuracy(data.radius_major, majorRadius, tolerance);
2418 XCTAssertEqualWithAccuracy(data.radius_min, majorRadius - majorRadiusTolerance, tolerance);
2419 XCTAssertEqualWithAccuracy(data.radius_max, majorRadius + majorRadiusTolerance, tolerance);
2423 XCTAssertEqualWithAccuracy(data.tilt, M_PI_2 - altitudeAngle, tolerance);
2427 XCTAssertEqualWithAccuracy(data.orientation, azimuthAngle - M_PI_2, tolerance);
2434 - (void)testStylusTiltEndpoints {
2442 id flatTouch = OCMPartialMock([[UITouch alloc] init]);
2443 [flatTouch setPhase:UITouchPhaseBegan];
2444 OCMStub([flatTouch altitudeAngle]).andReturn(0.0);
2445 OCMStub([flatTouch azimuthAngleInView:[OCMArg any]]).andReturn(M_PI_2);
2447 [vc dispatchTouches:[NSSet setWithObject:flatTouch] pointerDataChangeOverride:nullptr event:nil];
2449 id perpendicularTouch = OCMPartialMock([[UITouch alloc] init]);
2450 [perpendicularTouch setPhase:UITouchPhaseBegan];
2451 OCMStub([perpendicularTouch altitudeAngle]).andReturn(M_PI_2);
2452 OCMStub([perpendicularTouch azimuthAngleInView:[OCMArg any]]).andReturn(0.0);
2454 [vc dispatchTouches:[NSSet setWithObject:perpendicularTouch]
2455 pointerDataChangeOverride:nullptr
2458 const double tolerance = 1e-6;
2460 XCTAssertEqual(captured.size(), 2u);
2463 XCTAssertEqualWithAccuracy(captured[0].tilt, M_PI_2, tolerance);
2465 XCTAssertEqualWithAccuracy(captured[0].orientation, 0.0, tolerance);
2468 XCTAssertEqualWithAccuracy(captured[1].tilt, 0.0, tolerance);
2470 XCTAssertEqualWithAccuracy(captured[1].orientation, -M_PI_2, tolerance);
2473 - (void)testFakeEventTimeStamp {
2477 XCTAssertNotNil(vc);
2479 flutter::PointerData pointer_data = [vc generatePointerDataForFake];
2480 int64_t current_micros = [[NSProcessInfo processInfo] systemUptime] * 1000 * 1000;
2481 int64_t interval_micros = current_micros - pointer_data.time_stamp;
2482 const int64_t tolerance_millis = 2;
2483 XCTAssertTrue(interval_micros / 1000 < tolerance_millis,
2484 @"PointerData.time_stamp should be equal to NSProcessInfo.systemUptime");
2487 - (void)testSplashScreenViewCanSetNil {
2490 [flutterViewController setSplashScreenView:nil];
2493 - (void)testLifeCycleNotificationApplicationBecameActive {
2498 NSNotification* sceneNotification =
2499 [NSNotification notificationWithName:UISceneDidActivateNotification object:nil userInfo:nil];
2500 NSNotification* applicationNotification =
2501 [NSNotification notificationWithName:UIApplicationDidBecomeActiveNotification
2504 id mockVC = OCMPartialMock(flutterViewController);
2505 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2506 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2507 OCMReject([mockVC sceneBecameActive:[OCMArg any]]);
2508 OCMVerify([mockVC applicationBecameActive:[OCMArg any]]);
2510 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2511 XCTestExpectation* timeoutApplicationLifeCycle =
2512 [
self expectationWithDescription:@"timeoutApplicationLifeCycle"];
2513 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
2514 dispatch_get_main_queue(), ^{
2515 [timeoutApplicationLifeCycle fulfill];
2516 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.resumed"]);
2517 [flutterViewController deregisterNotifications];
2519 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
2522 - (void)testLifeCycleNotificationSceneBecameActive {
2523 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2524 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2525 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2531 NSNotification* sceneNotification =
2532 [NSNotification notificationWithName:UISceneDidActivateNotification object:nil userInfo:nil];
2533 NSNotification* applicationNotification =
2534 [NSNotification notificationWithName:UIApplicationDidBecomeActiveNotification
2537 id mockVC = OCMPartialMock(flutterViewController);
2538 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2539 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2540 OCMVerify([mockVC sceneBecameActive:[OCMArg any]]);
2541 OCMReject([mockVC applicationBecameActive:[OCMArg any]]);
2543 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2544 XCTestExpectation* timeoutApplicationLifeCycle =
2545 [
self expectationWithDescription:@"timeoutApplicationLifeCycle"];
2546 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
2547 dispatch_get_main_queue(), ^{
2548 [timeoutApplicationLifeCycle fulfill];
2549 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.resumed"]);
2550 [flutterViewController deregisterNotifications];
2552 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
2553 [mockBundle stopMocking];
2559 - (void)testSurfaceCreatedWhenApplicationBecomesActiveAfterLayoutWhileInactive {
2567 UIWindowScene* windowScene =
2568 (UIWindowScene*)UIApplication.sharedApplication.connectedScenes.anyObject;
2569 XCTAssertNotNil(windowScene,
@"The host app must have a connected scene for test");
2570 UIWindow* window = [[UIWindow alloc] initWithWindowScene:windowScene];
2571 [window addSubview:flutterViewController.view];
2572 flutterViewController.view.bounds = CGRectMake(0, 0, 100, 100);
2574 __block UIApplicationState applicationState = UIApplicationStateInactive;
2575 id mockApplication = OCMClassMock([UIApplication
class]);
2576 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
2577 OCMStub([mockApplication applicationState]).andDo(^(NSInvocation* invocation) {
2578 [invocation setReturnValue:&applicationState];
2580 id mockVC = OCMPartialMock(flutterViewController);
2583 [flutterViewController viewDidLayoutSubviews];
2584 applicationState = UIApplicationStateActive;
2585 [NSNotificationCenter.defaultCenter postNotificationName:UIApplicationDidBecomeActiveNotification
2587 OCMVerify([mockVC surfaceUpdated:YES]);
2589 [NSObject cancelPreviousPerformRequestsWithTarget:flutterViewController];
2590 [flutterViewController deregisterNotifications];
2591 [mockApplication stopMocking];
2596 - (void)testSurfaceNotCreatedWhenLayoutRunsWhileApplicationStateIsBackground {
2604 UIWindowScene* windowScene =
2605 (UIWindowScene*)UIApplication.sharedApplication.connectedScenes.anyObject;
2606 XCTAssertNotNil(windowScene,
@"The host app must have a connected scene for test");
2607 UIWindow* window = [[UIWindow alloc] initWithWindowScene:windowScene];
2608 [window addSubview:flutterViewController.view];
2609 flutterViewController.view.bounds = CGRectMake(0, 0, 100, 100);
2611 id mockApplication = OCMClassMock([UIApplication
class]);
2612 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
2613 OCMStub([mockApplication applicationState]).andReturn(UIApplicationStateBackground);
2614 id mockVC = OCMPartialMock(flutterViewController);
2616 [flutterViewController viewDidLayoutSubviews];
2617 OCMVerify(never(), [mockVC surfaceUpdated:YES]);
2619 [flutterViewController deregisterNotifications];
2620 [mockApplication stopMocking];
2626 - (void)testSurfaceCreatedOnWillEnterForegroundWhileApplicationStateIsBackground {
2634 UIWindowScene* windowScene =
2635 (UIWindowScene*)UIApplication.sharedApplication.connectedScenes.anyObject;
2636 XCTAssertNotNil(windowScene,
@"The host app must have a connected scene for test");
2637 UIWindow* window = [[UIWindow alloc] initWithWindowScene:windowScene];
2638 [window addSubview:flutterViewController.view];
2639 flutterViewController.view.bounds = CGRectMake(0, 0, 100, 100);
2641 __block UIApplicationState applicationState = UIApplicationStateActive;
2642 id mockApplication = OCMClassMock([UIApplication
class]);
2643 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
2644 OCMStub([mockApplication applicationState]).andDo(^(NSInvocation* invocation) {
2645 [invocation setReturnValue:&applicationState];
2647 id mockVC = OCMPartialMock(flutterViewController);
2650 [flutterViewController viewDidLayoutSubviews];
2651 OCMVerify(times(1), [mockVC surfaceUpdated:YES]);
2654 applicationState = UIApplicationStateBackground;
2655 [NSNotificationCenter.defaultCenter
2656 postNotificationName:UIApplicationDidEnterBackgroundNotification
2658 OCMVerify([mockVC surfaceUpdated:NO]);
2661 [NSNotificationCenter.defaultCenter
2662 postNotificationName:UIApplicationWillEnterForegroundNotification
2664 OCMVerify(times(2), [mockVC surfaceUpdated:YES]);
2666 [NSObject cancelPreviousPerformRequestsWithTarget:flutterViewController];
2667 [flutterViewController deregisterNotifications];
2668 [mockApplication stopMocking];
2671 - (void)testLifeCycleNotificationApplicationWillResignActive {
2676 NSNotification* sceneNotification =
2677 [NSNotification notificationWithName:UISceneWillDeactivateNotification
2680 NSNotification* applicationNotification =
2681 [NSNotification notificationWithName:UIApplicationWillResignActiveNotification
2684 id mockVC = OCMPartialMock(flutterViewController);
2685 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2686 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2687 OCMReject([mockVC sceneWillResignActive:[OCMArg any]]);
2688 OCMVerify([mockVC applicationWillResignActive:[OCMArg any]]);
2689 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.inactive"]);
2690 [flutterViewController deregisterNotifications];
2693 - (void)testLifeCycleNotificationSceneWillResignActive {
2694 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2695 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2696 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2702 NSNotification* sceneNotification =
2703 [NSNotification notificationWithName:UISceneWillDeactivateNotification
2706 NSNotification* applicationNotification =
2707 [NSNotification notificationWithName:UIApplicationWillResignActiveNotification
2710 id mockVC = OCMPartialMock(flutterViewController);
2711 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2712 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2713 OCMVerify([mockVC sceneWillResignActive:[OCMArg any]]);
2714 OCMReject([mockVC applicationWillResignActive:[OCMArg any]]);
2715 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.inactive"]);
2716 [flutterViewController deregisterNotifications];
2717 [mockBundle stopMocking];
2720 - (void)testLifeCycleNotificationApplicationWillTerminate {
2725 NSNotification* sceneNotification =
2726 [NSNotification notificationWithName:UISceneDidDisconnectNotification
2729 NSNotification* applicationNotification =
2730 [NSNotification notificationWithName:UIApplicationWillTerminateNotification
2733 id mockVC = OCMPartialMock(flutterViewController);
2736 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2737 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2738 OCMReject([mockVC sceneWillDisconnect:[OCMArg any]]);
2739 OCMVerify([mockVC applicationWillTerminate:[OCMArg any]]);
2740 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.detached"]);
2742 [flutterViewController deregisterNotifications];
2745 - (void)testLifeCycleNotificationSceneWillTerminate {
2746 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2747 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2748 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2754 NSNotification* sceneNotification =
2755 [NSNotification notificationWithName:UISceneDidDisconnectNotification
2758 NSNotification* applicationNotification =
2759 [NSNotification notificationWithName:UIApplicationWillTerminateNotification
2762 id mockVC = OCMPartialMock(flutterViewController);
2765 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2766 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2767 OCMVerify([mockVC sceneWillDisconnect:[OCMArg any]]);
2768 OCMReject([mockVC applicationWillTerminate:[OCMArg any]]);
2769 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.detached"]);
2771 [flutterViewController deregisterNotifications];
2772 [mockBundle stopMocking];
2775 - (void)testLifeCycleNotificationApplicationDidEnterBackground {
2780 NSNotification* sceneNotification =
2781 [NSNotification notificationWithName:UISceneDidEnterBackgroundNotification
2784 NSNotification* applicationNotification =
2785 [NSNotification notificationWithName:UIApplicationDidEnterBackgroundNotification
2788 id mockVC = OCMPartialMock(flutterViewController);
2789 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2790 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2791 OCMReject([mockVC sceneDidEnterBackground:[OCMArg any]]);
2792 OCMVerify([mockVC applicationDidEnterBackground:[OCMArg any]]);
2794 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2795 OCMVerify([mockVC surfaceUpdated:NO]);
2796 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.paused"]);
2797 [flutterViewController deregisterNotifications];
2800 - (void)testLifeCycleNotificationSceneDidEnterBackground {
2801 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2802 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2803 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2809 NSNotification* sceneNotification =
2810 [NSNotification notificationWithName:UISceneDidEnterBackgroundNotification
2813 NSNotification* applicationNotification =
2814 [NSNotification notificationWithName:UIApplicationDidEnterBackgroundNotification
2817 id mockVC = OCMPartialMock(flutterViewController);
2818 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2819 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2820 OCMVerify([mockVC sceneDidEnterBackground:[OCMArg any]]);
2821 OCMReject([mockVC applicationDidEnterBackground:[OCMArg any]]);
2823 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2824 OCMVerify([mockVC surfaceUpdated:NO]);
2825 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.paused"]);
2826 [flutterViewController deregisterNotifications];
2827 [mockBundle stopMocking];
2840 testLifeCycleNotificationSceneDidEnterBackgroundIgnoresOtherScenes
API_AVAILABLE(ios(13.0)) {
2841 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2842 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2843 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2849 id mockVC = OCMPartialMock(flutterViewController);
2852 id flutterWindowScene = OCMClassMock([UIWindowScene
class]);
2853 OCMStub([mockVC flutterWindowSceneIfViewLoaded]).andReturn(flutterWindowScene);
2856 id auxiliaryScene = OCMClassMock([UIWindowScene
class]);
2860 NSNotification* auxiliarySceneNotification =
2861 [NSNotification notificationWithName:UISceneDidEnterBackgroundNotification
2862 object:auxiliaryScene
2864 [NSNotificationCenter.defaultCenter postNotification:auxiliarySceneNotification];
2865 OCMVerify(never(), [mockVC surfaceUpdated:[OCMArg any]]);
2866 OCMVerify(never(), [mockVC goToApplicationLifecycle:
@"AppLifecycleState.paused"]);
2868 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2872 NSNotification* flutterSceneNotification =
2873 [NSNotification notificationWithName:UISceneDidEnterBackgroundNotification
2874 object:flutterWindowScene
2876 [NSNotificationCenter.defaultCenter postNotification:flutterSceneNotification];
2877 OCMVerify([mockVC surfaceUpdated:NO]);
2878 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.paused"]);
2880 flutterViewController.keyboardInsetManager.isKeyboardInOrTransitioningFromBackground);
2882 [flutterViewController deregisterNotifications];
2883 [mockBundle stopMocking];
2886 - (void)testLifeCycleNotificationApplicationWillEnterForeground {
2893 UIWindowScene* windowScene =
2894 (UIWindowScene*)UIApplication.sharedApplication.connectedScenes.anyObject;
2895 XCTAssertNotNil(windowScene,
@"The host app must have a connected scene for test");
2896 UIWindow* window = [[UIWindow alloc] initWithWindowScene:windowScene];
2897 [window addSubview:flutterViewController.view];
2898 flutterViewController.view.bounds = CGRectMake(0, 0, 100, 100);
2899 [flutterViewController viewDidLayoutSubviews];
2900 NSNotification* sceneNotification =
2901 [NSNotification notificationWithName:UISceneWillEnterForegroundNotification
2904 NSNotification* applicationNotification =
2905 [NSNotification notificationWithName:UIApplicationWillEnterForegroundNotification
2908 id mockVC = OCMPartialMock(flutterViewController);
2909 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2910 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2911 OCMReject([mockVC sceneWillEnterForeground:[OCMArg any]]);
2912 OCMVerify([mockVC applicationWillEnterForeground:[OCMArg any]]);
2913 OCMVerify([mockVC surfaceUpdated:YES]);
2914 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.inactive"]);
2915 [flutterViewController deregisterNotifications];
2918 - (void)testLifeCycleNotificationSceneWillEnterForeground {
2919 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
2920 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
2921 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
2929 UIWindowScene* windowScene =
2930 (UIWindowScene*)UIApplication.sharedApplication.connectedScenes.anyObject;
2931 XCTAssertNotNil(windowScene,
@"The host app must have a connected scene for test");
2932 UIWindow* window = [[UIWindow alloc] initWithWindowScene:windowScene];
2933 [window addSubview:flutterViewController.view];
2934 flutterViewController.view.bounds = CGRectMake(0, 0, 100, 100);
2935 [flutterViewController viewDidLayoutSubviews];
2936 NSNotification* sceneNotification =
2937 [NSNotification notificationWithName:UISceneWillEnterForegroundNotification
2940 NSNotification* applicationNotification =
2941 [NSNotification notificationWithName:UIApplicationWillEnterForegroundNotification
2944 id mockVC = OCMPartialMock(flutterViewController);
2945 [NSNotificationCenter.defaultCenter postNotification:sceneNotification];
2946 [NSNotificationCenter.defaultCenter postNotification:applicationNotification];
2947 OCMVerify([mockVC sceneWillEnterForeground:[OCMArg any]]);
2948 OCMReject([mockVC applicationWillEnterForeground:[OCMArg any]]);
2949 OCMVerify([mockVC surfaceUpdated:YES]);
2950 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.inactive"]);
2951 [flutterViewController deregisterNotifications];
2952 [mockBundle stopMocking];
2955 - (void)testLifeCycleNotificationCancelledInvalidResumed {
2960 NSNotification* applicationDidBecomeActiveNotification =
2961 [NSNotification notificationWithName:UIApplicationDidBecomeActiveNotification
2964 NSNotification* applicationWillResignActiveNotification =
2965 [NSNotification notificationWithName:UIApplicationWillResignActiveNotification
2968 id mockVC = OCMPartialMock(flutterViewController);
2969 [NSNotificationCenter.defaultCenter postNotification:applicationDidBecomeActiveNotification];
2970 [NSNotificationCenter.defaultCenter postNotification:applicationWillResignActiveNotification];
2971 OCMVerify([mockVC goToApplicationLifecycle:
@"AppLifecycleState.inactive"]);
2973 XCTestExpectation* timeoutApplicationLifeCycle =
2974 [
self expectationWithDescription:@"timeoutApplicationLifeCycle"];
2975 dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(1 * NSEC_PER_SEC)),
2976 dispatch_get_main_queue(), ^{
2977 OCMReject([mockVC goToApplicationLifecycle:
@"AppLifecycleState.resumed"]);
2978 [timeoutApplicationLifeCycle fulfill];
2979 [flutterViewController deregisterNotifications];
2981 [
self waitForExpectationsWithTimeout:5.0 handler:nil];
2984 - (void)testSetupKeyboardAnimationVsyncClientWillCreateNewVsyncClientForFlutterViewController {
2985 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
2986 OCMStub([bundleMock objectForInfoDictionaryKey:
@"CADisableMinimumFrameDurationOnPhone"])
2988 id mockDisplayLinkManager = OCMPartialMock([FlutterDisplayLinkManager shared]);
2989 [
self addTeardownBlock:^{
2990 [mockDisplayLinkManager stopMocking];
2992 double maxFrameRate = 120;
2993 (void)[[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
3001 [viewController.keyboardInsetManager setUpKeyboardAnimationVsyncClient:callback];
3002 XCTAssertNotNil(
viewController.keyboardInsetManager.keyboardAnimationVSyncClient);
3003 CADisplayLink* link =
3004 viewController.keyboardInsetManager.keyboardAnimationVSyncClient.displayLink;
3005 XCTAssertNotNil(link);
3006 CADisplayLink* linkMock = OCMPartialMock(link);
3007 if (@available(iOS 15.0, *)) {
3008 CAFrameRateRange range = CAFrameRateRangeMake(maxFrameRate / 2, maxFrameRate, maxFrameRate);
3009 NSValue* rangeValue = [NSValue valueWithBytes:&range objCType:@encode(CAFrameRateRange)];
3010 [[[(id)linkMock stub] andReturnValue:rangeValue] preferredFrameRateRange];
3012 XCTAssertEqual(linkMock.preferredFrameRateRange.maximum, maxFrameRate);
3013 XCTAssertEqual(linkMock.preferredFrameRateRange.preferred, maxFrameRate);
3014 XCTAssertEqual(linkMock.preferredFrameRateRange.minimum, maxFrameRate / 2);
3016 [[[(id)linkMock stub] andReturnValue:@(maxFrameRate)] preferredFramesPerSecond];
3017 XCTAssertEqual(linkMock.preferredFramesPerSecond, maxFrameRate);
3021 - (void)testFlutterViewControllerStartKeyboardAnimationWillCreateVsyncClientCorrectly {
3022 id mockDisplayLink = OCMClassMock([CADisplayLink
class]);
3023 OCMStub(ClassMethod([mockDisplayLink displayLinkWithTarget:[OCMArg any]
3024 selector:sel_registerName(
"onDisplayLink:")]))
3025 .andReturn(mockDisplayLink);
3032 FlutterKeyboardInsetManager* manager =
3033 [[FlutterKeyboardInsetManager alloc] initWithDelegate:delegate
3034 displayLinkManager:FlutterDisplayLinkManager.shared];
3035 manager.targetViewInsetBottom = 100;
3036 [manager startKeyBoardAnimation:0.25];
3038 XCTAssertNotNil(manager.keyboardAnimationVSyncClient);
3039 fml::MessageLoop::GetCurrent().RunExpiredTasksNow();
3040 [manager invalidate];
3041 [mockDisplayLink stopMocking];
3045 testSetupKeyboardAnimationVsyncClientWillNotCreateNewVsyncClientWhenKeyboardAnimationCallbackIsNil {
3051 [viewController.keyboardInsetManager setUpKeyboardAnimationVsyncClient:nil];
3052 XCTAssertNil(
viewController.keyboardInsetManager.keyboardAnimationVSyncClient);
3055 - (void)testSupportsShowingSystemContextMenuForIOS16AndAbove {
3061 BOOL supportsShowingSystemContextMenu = [viewController supportsShowingSystemContextMenu];
3062 if (@available(iOS 16.0, *)) {
3063 XCTAssertTrue(supportsShowingSystemContextMenu);
3065 XCTAssertFalse(supportsShowingSystemContextMenu);
3069 - (void)testStatePropertiesWhenApplicationStateIsActive {
3075 id mockApplication = OCMClassMock([UIApplication
class]);
3076 OCMStub([mockApplication applicationState]).andReturn(UIApplicationStateActive);
3077 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3083 - (void)testStatePropertiesWhenApplicationStateIsBackground {
3089 id mockApplication = OCMClassMock([UIApplication
class]);
3090 OCMStub([mockApplication applicationState]).andReturn(UIApplicationStateBackground);
3091 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3097 - (void)testStatePropertiesWhenApplicationStateIsInactive {
3103 id mockApplication = OCMClassMock([UIApplication
class]);
3104 OCMStub([mockApplication applicationState]).andReturn(UIApplicationStateInactive);
3105 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3111 - (void)testStatePropertiesWhenSceneStateIsActive {
3112 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
3113 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
3114 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
3122 OCMStub([mockVC activationState]).andReturn(UISceneActivationStateForegroundActive);
3127 [mockBundle stopMocking];
3128 [mockVC stopMocking];
3131 - (void)testStatePropertiesWhenSceneStateIsBackground {
3132 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
3133 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
3134 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
3142 OCMStub([mockVC activationState]).andReturn(UISceneActivationStateBackground);
3147 [mockBundle stopMocking];
3148 [mockVC stopMocking];
3151 - (void)testStatePropertiesWhenSceneStateIsInactive {
3152 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
3153 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
3154 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
3162 OCMStub([mockVC activationState]).andReturn(UISceneActivationStateForegroundInactive);
3167 [mockBundle stopMocking];
3168 [mockVC stopMocking];
3171 - (void)testStatePropertiesWhenSceneStateIsUnattached {
3172 id mockBundle = OCMPartialMock([NSBundle mainBundle]);
3173 OCMStub([mockBundle objectForInfoDictionaryKey:
@"NSExtension"]).andReturn(@{
3174 @"NSExtensionPointIdentifier" :
@"com.apple.share-services"
3182 OCMStub([mockVC activationState]).andReturn(UISceneActivationStateUnattached);
3187 [mockBundle stopMocking];
3188 [mockVC stopMocking];
3191 - (void)testPerformImplicitEngineCallbacks {
3193 id appDelegate = [[UIApplication sharedApplication] delegate];
3194 [appDelegate setMockLaunchEngine:self.mockEngine];
3195 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Flutter" bundle:nil];
3196 XCTAssertTrue([appDelegate respondsToSelector:
@selector(setPluginRegistrant:)]);
3197 [appDelegate setPluginRegistrant:mockRegistrant];
3200 [appDelegate setPluginRegistrant:nil];
3202 OCMVerify([
self.
mockEngine performImplicitEngineCallback]);
3203 [appDelegate setMockLaunchEngine:nil];
3206 - (void)testPerformImplicitEngineCallbacksUsesAppLaunchEventFallbacks {
3212 OCMStub([
mockEngine performImplicitEngineCallback]).andReturn(YES);
3213 OCMStub([viewControllerMock awokenFromNib]).andReturn(YES);
3215 id mockApplication = OCMClassMock([UIApplication
class]);
3216 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3218 OCMStub([mockApplication delegate]).andReturn(mockApplicationDelegate);
3219 OCMStub([mockApplicationDelegate takeLaunchEngine]).andReturn(
mockEngine);
3221 id mockScene = OCMClassMock([UIScene
class]);
3222 id mockSceneDelegate = OCMProtocolMock(
@protocol(UISceneDelegate));
3223 OCMStub([mockScene delegate]).andReturn(mockSceneDelegate);
3224 OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockScene]);
3228 OCMStub([mockApplicationDelegate lifeCycleDelegate]).andReturn(mockLifecycleDelegate);
3230 [viewControllerMock sharedSetupWithProject:nil initialRoute:nil];
3231 OCMVerify([mockLifecycleDelegate sceneFallbackWillFinishLaunchingApplication:mockApplication]);
3232 OCMVerify([mockLifecycleDelegate sceneFallbackDidFinishLaunchingApplication:mockApplication]);
3235 - (void)testPerformImplicitEngineCallbacksNoAppLaunchEventFallbacksWhenNoStoryboard {
3241 OCMStub([
mockEngine performImplicitEngineCallback]).andReturn(YES);
3242 OCMStub([viewControllerMock awokenFromNib]).andReturn(NO);
3244 id mockApplication = OCMClassMock([UIApplication
class]);
3245 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3247 OCMStub([mockApplication delegate]).andReturn(mockApplicationDelegate);
3248 OCMStub([mockApplicationDelegate takeLaunchEngine]).andReturn(
mockEngine);
3250 id mockScene = OCMClassMock([UIScene
class]);
3251 id mockSceneDelegate = OCMProtocolMock(
@protocol(UISceneDelegate));
3252 OCMStub([mockScene delegate]).andReturn(mockSceneDelegate);
3253 OCMStub([mockApplication connectedScenes]).andReturn([NSSet setWithObject:mockScene]);
3257 OCMStub([mockApplicationDelegate lifeCycleDelegate]).andReturn(mockLifecycleDelegate);
3259 [viewControllerMock sharedSetupWithProject:nil initialRoute:nil];
3260 OCMReject([mockLifecycleDelegate sceneFallbackWillFinishLaunchingApplication:mockApplication]);
3261 OCMReject([mockLifecycleDelegate sceneFallbackDidFinishLaunchingApplication:mockApplication]);
3264 - (void)testPerformImplicitEngineCallbacksNoAppLaunchEventFallbacksWhenNoScenes {
3270 OCMStub([
mockEngine performImplicitEngineCallback]).andReturn(YES);
3271 OCMStub([viewControllerMock awokenFromNib]).andReturn(YES);
3273 id mockApplication = OCMClassMock([UIApplication
class]);
3274 OCMStub([mockApplication sharedApplication]).andReturn(mockApplication);
3276 OCMStub([mockApplication delegate]).andReturn(mockApplicationDelegate);
3277 OCMStub([mockApplicationDelegate takeLaunchEngine]).andReturn(
mockEngine);
3281 OCMStub([mockApplicationDelegate lifeCycleDelegate]).andReturn(mockLifecycleDelegate);
3283 [viewControllerMock sharedSetupWithProject:nil initialRoute:nil];
3284 OCMReject([mockLifecycleDelegate sceneFallbackWillFinishLaunchingApplication:mockApplication]);
3285 OCMReject([mockLifecycleDelegate sceneFallbackDidFinishLaunchingApplication:mockApplication]);
3288 - (void)testGrabLaunchEngine {
3289 id appDelegate = [[UIApplication sharedApplication] delegate];
3290 XCTAssertTrue([appDelegate respondsToSelector:
@selector(setMockLaunchEngine:)]);
3291 [appDelegate setMockLaunchEngine:self.mockEngine];
3292 UIStoryboard* storyboard = [UIStoryboard storyboardWithName:@"Flutter" bundle:nil];
3293 XCTAssertTrue(storyboard);
3299 [appDelegate setMockLaunchEngine:nil];
3302 - (void)testDoesntGrabLaunchEngine {
3303 id appDelegate = [[UIApplication sharedApplication] delegate];
3304 XCTAssertTrue([appDelegate respondsToSelector:
@selector(setMockLaunchEngine:)]);
3305 [appDelegate setMockLaunchEngine:self.mockEngine];
3307 XCTAssertNotNil(flutterViewController.
engine);
3308 XCTAssertNotEqual(flutterViewController.
engine,
self.mockEngine);
3309 [appDelegate setMockLaunchEngine:nil];
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterReply)(id _Nullable reply)
void(^ FlutterSendKeyEvent)(const FlutterKeyEvent &, _Nullable FlutterKeyEventCallback, void *_Nullable)
UITextSmartQuotesType smartQuotesType API_AVAILABLE(ios(11.0))
FlutterViewController * viewController
FlutterTextInputPlugin * textInputPlugin
void(^ FlutterKeyboardAnimationCallback)(NSTimeInterval targetTime)
NSNotificationName const FlutterViewControllerWillDealloc
FlutterSendKeyEvent sendEvent
void hideKeyboardImmediately()
UIView * keyboardAnimationView()
BOOL keyboardAnimationIsShowing
BOOL isKeyboardInOrTransitioningFromBackground
void ensureViewportMetricsIsCorrect()
SpringAnimation * keyboardSpringAnimation()
CGFloat targetViewInsetBottom
void invalidateKeyboardAnimationVSyncClient()
id< FlutterKeyboardInsetManagerDelegate > delegate
FlutterVSyncClient * keyboardAnimationVSyncClient
NSMutableArray< id< FlutterKeyPrimaryResponder > > * primaryResponders
BOOL keyboardAnimationIsShowing
void addInternalPlugins()
void updateAutoResizeConstraints()
double targetViewInsetBottom
FlutterVSyncClient * touchRateCorrectionVSyncClient
void checkAndUpdateAutoResizeConstraints()
void updateViewportMetricsIfNeeded()
FlutterVSyncClient * keyboardAnimationVSyncClient
FlutterEngine * mockLaunchEngine
BOOL didCallInvalidateKeyboardAnimationVSyncClient
BOOL didCallEnsureViewportMetricsIsCorrect
BOOL allowHeadlessExecution
FlutterBasicMessageChannel * keyEventChannel
FlutterBasicMessageChannel * lifecycleChannel
FlutterViewController * viewController
BOOL runWithEntrypoint:(nullable NSString *NS_SWIFT_UI_ACTOR)
BOOL runWithEntrypoint:(nullable NSString *entrypoint)
FlutterBasicMessageChannel * lifecycleChannel
FlutterBasicMessageChannel * keyEventChannel
FlutterFMLTaskRunner * uiTaskRunner
A view controller that allows headless execution in the engine it creates.
BOOL engineAllowHeadlessExecution
NSObject< FlutterBinaryMessenger > * binaryMessenger
A FlutterEngine that saves received PointerDatas instead of forwarding to the shell.
const std::vector< flutter::PointerData > & capturedPointerData()
BOOL mockIsPadInSlideOverOrStageManagerMode
FlutterFMLTaskRunner * mockTaskRunner
FlutterEngine * mockEngine
CGRect mockConvertedViewRect
void(^ updateViewportMetricsBlock)(CGFloat inset)