5 #import <OCMock/OCMock.h>
6 #import <XCTest/XCTest.h>
17 @property(nonatomic, readwrite) UITouchPhase phase;
35 - (void)setUpKeyboardAnimationVsyncClient:
37 - (void)startKeyBoardAnimation:(NSTimeInterval)duration;
38 - (void)triggerTouchRateCorrectionIfNeeded:(NSSet*)touches;
47 - (void)testSetupKeyboardAnimationVsyncClientWillCreateNewVsyncClientForFlutterViewController {
48 id bundleMock = OCMPartialMock([NSBundle mainBundle]);
49 OCMStub([bundleMock objectForInfoDictionaryKey:
@"CADisableMinimumFrameDurationOnPhone"])
52 double maxFrameRate = 120;
53 [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
60 [viewController setUpKeyboardAnimationVsyncClient:callback];
62 CADisplayLink* link = [viewController.keyboardAnimationVSyncClient getDisplayLink];
63 XCTAssertNotNil(link);
64 if (@available(iOS 15.0, *)) {
65 XCTAssertEqual(link.preferredFrameRateRange.maximum, maxFrameRate);
66 XCTAssertEqual(link.preferredFrameRateRange.preferred, maxFrameRate);
67 XCTAssertEqual(link.preferredFrameRateRange.minimum, maxFrameRate / 2);
69 XCTAssertEqual(link.preferredFramesPerSecond, maxFrameRate);
74 testCreateTouchRateCorrectionVSyncClientWillCreateVsyncClientWhenRefreshRateIsLargerThan60HZ {
76 double maxFrameRate = 120;
77 [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
82 [viewController createTouchRateCorrectionVSyncClientIfNeeded];
86 - (void)testCreateTouchRateCorrectionVSyncClientWillNotCreateNewVSyncClientWhenClientAlreadyExists {
88 double maxFrameRate = 120;
89 [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
95 [viewController createTouchRateCorrectionVSyncClientIfNeeded];
97 XCTAssertNotNil(clientBefore);
99 [viewController createTouchRateCorrectionVSyncClientIfNeeded];
101 XCTAssertNotNil(clientAfter);
103 XCTAssertTrue(clientBefore == clientAfter);
106 - (void)testCreateTouchRateCorrectionVSyncClientWillNotCreateVsyncClientWhenRefreshRateIs60HZ {
108 double maxFrameRate = 60;
109 [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
114 [viewController createTouchRateCorrectionVSyncClientIfNeeded];
118 - (void)testTriggerTouchRateCorrectionVSyncClientCorrectly {
120 double maxFrameRate = 120;
121 [[[mockDisplayLinkManager stub] andReturnValue:@(maxFrameRate)] displayRefreshRate];
126 [viewController loadView];
127 [viewController viewDidLoad];
130 CADisplayLink* link = [client getDisplayLink];
132 UITouch* fakeTouchBegan = [[[UITouch alloc] init] autorelease];
133 fakeTouchBegan.phase = UITouchPhaseBegan;
135 UITouch* fakeTouchMove = [[[UITouch alloc] init] autorelease];
136 fakeTouchMove.phase = UITouchPhaseMoved;
138 UITouch* fakeTouchEnd = [[[UITouch alloc] init] autorelease];
139 fakeTouchEnd.phase = UITouchPhaseEnded;
141 UITouch* fakeTouchCancelled = [[[UITouch alloc] init] autorelease];
142 fakeTouchCancelled.phase = UITouchPhaseCancelled;
145 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchBegan, nil]
147 XCTAssertFalse(link.isPaused);
150 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchEnd, nil]
152 XCTAssertTrue(link.isPaused);
155 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchMove, nil]
157 XCTAssertFalse(link.isPaused);
160 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc] initWithObjects:fakeTouchCancelled, nil]
162 XCTAssertTrue(link.isPaused);
165 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc]
166 initWithObjects:fakeTouchBegan, fakeTouchEnd, nil]
168 XCTAssertFalse(link.isPaused);
171 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc]
172 initWithObjects:fakeTouchEnd, fakeTouchCancelled, nil]
174 XCTAssertTrue(link.isPaused);
177 triggerTouchRateCorrectionIfNeeded:[[[NSSet alloc]
178 initWithObjects:fakeTouchMove, fakeTouchEnd, nil]
180 XCTAssertFalse(link.isPaused);
183 - (void)testFlutterViewControllerStartKeyboardAnimationWillCreateVsyncClientCorrectly {
189 [viewController startKeyBoardAnimation:0.25];
194 testSetupKeyboardAnimationVsyncClientWillNotCreateNewVsyncClientWhenKeyboardAnimationCallbackIsNil {
199 [viewController setUpKeyboardAnimationVsyncClient:nil];