6#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterViewController.h"
7#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewController_Internal.h"
9#import <OCMock/OCMock.h>
11#import "flutter/shell/platform/darwin/common/framework/Headers/FlutterBinaryMessenger.h"
12#import "flutter/shell/platform/darwin/macos/framework/Headers/FlutterEngine.h"
13#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterDartProject_Internal.h"
14#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngineTestUtils.h"
15#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterEngine_Internal.h"
16#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterRenderer.h"
17#import "flutter/shell/platform/darwin/macos/framework/Source/FlutterViewControllerTestUtils.h"
18#include "flutter/shell/platform/embedder/test_utils/key_codes.g.h"
19#include "flutter/testing/autoreleasepool_test.h"
20#include "flutter/testing/testing.h"
22#pragma mark - Test Helper Classes
53- (instancetype)initWithResponder:(NSResponder*)responder {
60- (void)keyDown:(NSEvent*)event {
61 [_responder keyDown:event];
64- (void)keyUp:(NSEvent*)event {
65 [_responder keyUp:event];
68- (
BOOL)performKeyEquivalent:(NSEvent*)event {
69 return [_responder performKeyEquivalent:event];
72- (void)flagsChanged:(NSEvent*)event {
73 [_responder flagsChanged:event];
81@property(nonatomic, assign)
BOOL mouseDownCalled;
82@property(nonatomic, assign)
BOOL mouseUpCalled;
86- (void)mouseDown:(NSEvent*)event {
87 self.mouseDownCalled = YES;
90- (void)mouseUp:(NSEvent*)event {
91 self.mouseUpCalled = YES;
96- (bool)testKeyEventsAreSentToFramework:(
id)mockEngine;
97- (bool)testKeyEventsArePropagatedIfNotHandled:(
id)mockEngine;
98- (bool)testKeyEventsAreNotPropagatedIfHandled:(
id)mockEngine;
99- (bool)testCtrlTabKeyEventIsPropagated:(
id)mockEngine;
100- (bool)testKeyEquivalentIsPassedToTextInputPlugin:(
id)mockEngine;
101- (bool)testFlagsChangedEventsArePropagatedIfNotHandled:(
id)mockEngine;
102- (bool)testKeyboardIsRestartedOnEngineRestart:(
id)mockEngine;
103- (bool)testTrackpadGesturesAreSentToFramework:(
id)mockEngine;
104- (bool)mouseAndGestureEventsAreHandledSeparately:(
id)engineMock;
105- (bool)testMouseDownUpEventsSentToNextResponder:(
id)mockEngine;
106- (bool)testModifierKeysAreSynthesizedOnMouseMove:(
id)mockEngine;
107- (bool)testViewWillAppearCalledMultipleTimes:(
id)mockEngine;
108- (bool)testFlutterViewIsConfigured:(
id)mockEngine;
115 userData:(nullable
void*)userData;
118#pragma mark - Static helper functions
126id MockGestureEvent(NSEventType
type, NSEventPhase phase,
double magnification,
double rotation) {
127 id event = [OCMockObject mockForClass:[NSEvent class]];
128 NSPoint locationInWindow = NSMakePoint(0, 0);
131 NSTimeInterval timestamp = 1;
132 NSUInteger modifierFlags = 0;
133 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(type)] type];
134 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(phase)] phase];
135 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(locationInWindow)] locationInWindow];
136 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaX)] deltaX];
137 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(deltaY)] deltaY];
138 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(timestamp)] timestamp];
139 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(modifierFlags)] modifierFlags];
140 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(magnification)] magnification];
141 [(NSEvent*)[[event stub] andReturnValue:OCMOCK_VALUE(rotation)] rotation];
149 initWithAssetsPath:fixtures
150 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
151 return [[
FlutterEngine alloc] initWithName:@"test" project:project allowHeadlessExecution:true];
154NSResponder* mockResponder() {
155 NSResponder* mock = OCMStrictClassMock([NSResponder
class]);
156 OCMStub([mock keyDown:[OCMArg
any]]).andDo(nil);
157 OCMStub([mock keyUp:[OCMArg
any]]).andDo(nil);
158 OCMStub([mock flagsChanged:[OCMArg
any]]).andDo(nil);
162NSEvent* CreateMouseEvent(NSEventModifierFlags modifierFlags) {
163 return [NSEvent mouseEventWithType:NSEventTypeMouseMoved
165 modifierFlags:modifierFlags
176#pragma mark - gtest tests
185 [viewControllerMock loadView];
186 auto subViews = [viewControllerMock.view subviews];
188 EXPECT_EQ([subViews
count], 1u);
189 EXPECT_EQ(subViews[0], viewControllerMock.flutterView);
191 NSTextField* textField = [[NSTextField alloc] initWithFrame:NSMakeRect(0, 0, 1, 1)];
192 [viewControllerMock.view addSubview:textField];
194 subViews = [viewControllerMock.view subviews];
195 EXPECT_EQ([subViews
count], 2u);
197 auto accessibilityChildren = viewControllerMock.
view.accessibilityChildren;
199 EXPECT_EQ([accessibilityChildren
count], 1u);
200 EXPECT_EQ(accessibilityChildren[0], viewControllerMock.flutterView);
205 [viewControllerMock loadView];
206 EXPECT_EQ([viewControllerMock.flutterView acceptsFirstMouse:nil], YES);
214 [viewController loadView];
216 NSWindow*
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
217 styleMask:NSBorderlessWindowMask
218 backing:NSBackingStoreBuffered
221 NSView* dummyView = [[NSView alloc] initWithFrame:CGRectZero];
222 [viewController.view addSubview:dummyView];
224 [dummyView addSubview:viewController.textInputPlugin];
229 [viewController onAccessibilityStatusChanged:NO];
237 initWithAssetsPath:fixtures
238 ICUDataPath:[fixtures stringByAppendingString:@"/icudtl.dat"]];
245 id mockEngine = GetMockEngine();
250 id mockEngine = GetMockEngine();
256 id mockEngine = GetMockEngine();
262 id mockEngine = GetMockEngine();
267 id mockEngine = GetMockEngine();
269 testKeyEquivalentIsPassedToTextInputPlugin:mockEngine]);
273 id mockEngine = GetMockEngine();
275 testFlagsChangedEventsArePropagatedIfNotHandled:mockEngine]);
279 id mockEngine = GetMockEngine();
285 id mockEngine = GetMockEngine();
291 id mockEngine = GetMockEngine();
297 id mockEngine = GetMockEngine();
303 id mockEngine = GetMockEngine();
309 id mockEngine = GetMockEngine();
315 id mockEngine = GetMockEngine();
333#pragma mark - FlutterViewControllerTestObjC
337- (bool)testKeyEventsAreSentToFramework:(
id)engineMock {
340 [engineMock binaryMessenger])
341 .andReturn(binaryMessengerMock);
342 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
346 @selector(respondFalseForSendEvent:
callback:userData:));
350 NSDictionary* expectedEvent = @{
351 @"keymap" :
@"macos",
352 @"type" :
@"keydown",
354 @"modifiers" : @(538968064),
355 @"characters" :
@".",
356 @"charactersIgnoringModifiers" :
@".",
359 CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 65,
TRUE);
360 NSEvent*
event = [NSEvent eventWithCGEvent:cgEvent];
362 [viewController
keyDown:event];
365 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
367 binaryReply:[OCMArg
any]]);
375- (bool)testCtrlTabKeyEventIsPropagated:(
id)engineMock {
376 __block
bool called =
false;
378 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
381 .andDo((^(NSInvocation* invocation) {
383 [invocation getArgument:&event atIndex:2];
391 NSEvent*
event = [NSEvent keyEventWithType:NSEventTypeKeyDown
393 modifierFlags:0x40101
398 charactersIgnoringModifiers:@""
401 const uint64_t kPhysicalKeyTab = 0x7002b;
405 NSWindow*
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
406 styleMask:NSBorderlessWindowMask
407 backing:NSBackingStoreBuffered
410 [window makeFirstResponder:viewController.flutterView];
411 [viewController.view performKeyEquivalent:event];
415 EXPECT_EQ(last_event.physical, kPhysicalKeyTab);
419- (bool)testKeyEquivalentIsPassedToTextInputPlugin:(
id)engineMock {
420 __block
bool called =
false;
422 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
425 .andDo((^(NSInvocation* invocation) {
427 [invocation getArgument:&event atIndex:2];
435 NSEvent*
event = [NSEvent keyEventWithType:NSEventTypeKeyDown
437 modifierFlags:0x40101
442 charactersIgnoringModifiers:@""
445 const uint64_t kPhysicalKeyTab = 0x7002b;
449 NSWindow*
window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, 800, 600)
450 styleMask:NSBorderlessWindowMask
451 backing:NSBackingStoreBuffered
455 [viewController.view addSubview:viewController.textInputPlugin];
459 [window makeFirstResponder:viewController.textInputPlugin];
461 [viewController.view performKeyEquivalent:event];
465 EXPECT_EQ(last_event.physical, kPhysicalKeyTab);
469- (bool)testKeyEventsArePropagatedIfNotHandled:(
id)engineMock {
472 [engineMock binaryMessenger])
473 .andReturn(binaryMessengerMock);
474 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
478 @selector(respondFalseForSendEvent:
callback:userData:));
482 id responderMock = flutter::testing::mockResponder();
485 NSDictionary* expectedEvent = @{
486 @"keymap" :
@"macos",
487 @"type" :
@"keydown",
489 @"modifiers" : @(538968064),
490 @"characters" :
@".",
491 @"charactersIgnoringModifiers" :
@".",
494 CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 65,
TRUE);
495 NSEvent*
event = [NSEvent eventWithCGEvent:cgEvent];
497 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
499 binaryReply:[OCMArg
any]])
500 .andDo((^(NSInvocation* invocation) {
502 [invocation getArgument:&handler atIndex:4];
503 NSDictionary* reply = @{
504 @"handled" : @(
false),
507 handler(encodedReply);
510 [viewController
keyDown:event];
513 [responderMock keyDown:[OCMArg
any]]);
515 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
517 binaryReply:[OCMArg
any]]);
524- (bool)testFlutterViewIsConfigured:(
id)engineMock {
526 OCMStub([engineMock
renderer]).andReturn(renderer_);
543- (bool)testFlagsChangedEventsArePropagatedIfNotHandled:(
id)engineMock {
546 [engineMock binaryMessenger])
547 .andReturn(binaryMessengerMock);
548 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
552 @selector(respondFalseForSendEvent:
callback:userData:));
556 id responderMock = flutter::testing::mockResponder();
559 NSDictionary* expectedEvent = @{
560 @"keymap" :
@"macos",
561 @"type" :
@"keydown",
563 @"modifiers" : @(537001986),
566 CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 56,
TRUE);
567 CGEventSetType(cgEvent, kCGEventFlagsChanged);
568 NSEvent*
event = [NSEvent eventWithCGEvent:cgEvent];
570 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
572 binaryReply:[OCMArg
any]])
573 .andDo((^(NSInvocation* invocation) {
575 [invocation getArgument:&handler atIndex:4];
576 NSDictionary* reply = @{
577 @"handled" : @(
false),
580 handler(encodedReply);
586 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
588 binaryReply:[OCMArg
any]]);
589 }
@catch (NSException*
e) {
590 NSLog(
@"%@",
e.reason);
596- (bool)testKeyEventsAreNotPropagatedIfHandled:(
id)engineMock {
599 [engineMock binaryMessenger])
600 .andReturn(binaryMessengerMock);
601 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
605 @selector(respondFalseForSendEvent:
callback:userData:));
609 id responderMock = flutter::testing::mockResponder();
612 NSDictionary* expectedEvent = @{
613 @"keymap" :
@"macos",
614 @"type" :
@"keydown",
616 @"modifiers" : @(538968064),
617 @"characters" :
@".",
618 @"charactersIgnoringModifiers" :
@".",
621 CGEventRef cgEvent = CGEventCreateKeyboardEvent(NULL, 65,
TRUE);
622 NSEvent*
event = [NSEvent eventWithCGEvent:cgEvent];
624 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
626 binaryReply:[OCMArg
any]])
627 .andDo((^(NSInvocation* invocation) {
629 [invocation getArgument:&handler atIndex:4];
630 NSDictionary* reply = @{
631 @"handled" : @(
true),
634 handler(encodedReply);
637 [viewController
keyDown:event];
640 never(), [responderMock keyDown:[OCMArg
any]]);
642 [binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
644 binaryReply:[OCMArg
any]]);
651- (bool)testKeyboardIsRestartedOnEngineRestart:(
id)engineMock {
654 [engineMock binaryMessenger])
655 .andReturn(binaryMessengerMock);
656 __block
bool called =
false;
658 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
661 .andDo((^(NSInvocation* invocation) {
663 [invocation getArgument:&event atIndex:2];
672 NSEvent* keyADown = [NSEvent keyEventWithType:NSEventTypeKeyDown
679 charactersIgnoringModifiers:@"a"
689 [viewController
keyDown:keyADown];
697 [viewController
keyDown:keyADown];
706 userData:(nullable
void*)userData {
712- (bool)testTrackpadGesturesAreSentToFramework:(
id)engineMock {
715 OCMStub([engineMock
renderer]).andReturn(renderer_);
716 __block
bool called =
false;
719 .andDo((^(NSInvocation* invocation) {
721 [invocation getArgument:&event atIndex:2];
733 CGEventRef cgEventStart = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
734 CGEventSetType(cgEventStart, kCGEventScrollWheel);
735 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventScrollPhase, kCGScrollPhaseBegan);
736 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventIsContinuous, 1);
739 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventStart]];
747 CGEventRef cgEventUpdate = CGEventCreateCopy(cgEventStart);
748 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventScrollPhase, kCGScrollPhaseChanged);
749 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis2, 1);
750 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis1, 2);
753 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
764 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
774 CGEventRef cgEventEnd = CGEventCreateCopy(cgEventStart);
775 CGEventSetIntegerValueField(cgEventEnd, kCGScrollWheelEventScrollPhase, kCGScrollPhaseEnded);
778 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventEnd]];
786 CGEventRef cgEventMomentumStart = CGEventCreateCopy(cgEventStart);
787 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventScrollPhase, 0);
788 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventMomentumPhase,
789 kCGMomentumScrollPhaseBegin);
792 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumStart]];
793 EXPECT_FALSE(called);
796 CGEventRef cgEventMomentumUpdate = CGEventCreateCopy(cgEventStart);
797 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventScrollPhase, 0);
798 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventMomentumPhase,
799 kCGMomentumScrollPhaseContinue);
802 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumUpdate]];
803 EXPECT_FALSE(called);
806 id touchMock = OCMClassMock([NSTouch
class]);
807 NSSet* touchSet = [NSSet setWithObject:touchMock];
808 id touchEventMock1 = OCMClassMock([NSEvent
class]);
809 OCMStub([touchEventMock1 allTouches]).andReturn(touchSet);
810 CGPoint touchLocation = {0, 0};
811 OCMStub([touchEventMock1 locationInWindow]).andReturn(touchLocation);
812 OCMStub([(NSEvent*)touchEventMock1 timestamp]).andReturn(0.150);
817 EXPECT_FALSE(called);
820 id touchEventMock2 = OCMClassMock([NSEvent
class]);
821 OCMStub([touchEventMock2 allTouches]).andReturn(touchSet);
822 OCMStub([touchEventMock2 locationInWindow]).andReturn(touchLocation);
823 OCMStub([(NSEvent*)touchEventMock2 timestamp]).andReturn(0.005);
833 CGEventRef cgEventMomentumEnd = CGEventCreateCopy(cgEventStart);
834 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventScrollPhase, 0);
835 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventMomentumPhase,
836 kCGMomentumScrollPhaseEnd);
839 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumEnd]];
840 EXPECT_FALSE(called);
843 CGEventRef cgEventMayBegin = CGEventCreateCopy(cgEventStart);
844 CGEventSetIntegerValueField(cgEventMayBegin, kCGScrollWheelEventScrollPhase,
845 kCGScrollPhaseMayBegin);
848 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventMayBegin]];
856 CGEventRef cgEventCancel = CGEventCreateCopy(cgEventStart);
857 CGEventSetIntegerValueField(cgEventCancel, kCGScrollWheelEventScrollPhase,
858 kCGScrollPhaseCancelled);
861 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventCancel]];
869 CGEventRef cgEventDiscrete = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
870 CGEventSetType(cgEventDiscrete, kCGEventScrollWheel);
871 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventIsContinuous, 0);
872 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis2, 1);
873 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis1, 2);
876 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscrete]];
885 CGEventRef cgEventDiscreteShift =
886 CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
887 CGEventSetType(cgEventDiscreteShift, kCGEventScrollWheel);
889 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventIsContinuous, 0);
890 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis2,
892 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis1,
896 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscreteShift]];
901 EXPECT_FLOAT_EQ(last_event.scroll_delta_y,
907 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
908 NSEventPhaseBegan, 1, 0)];
917 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
918 NSEventPhaseChanged, 1, 0)];
924 EXPECT_EQ(last_event.pan_x, 0);
925 EXPECT_EQ(last_event.pan_y, 0);
926 EXPECT_EQ(last_event.scale, 2);
928 EXPECT_EQ(last_event.rotation, 0);
932 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
933 NSEventPhaseChanged, 1, 0)];
939 EXPECT_EQ(last_event.pan_x, 0);
940 EXPECT_EQ(last_event.pan_y, 0);
941 EXPECT_EQ(last_event.scale, 4);
943 EXPECT_EQ(last_event.rotation, 0);
947 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
948 NSEventPhaseEnded, 0, 0)];
958 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
959 NSEventPhaseBegan, 1, 0)];
968 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
969 NSEventTypeRotate, NSEventPhaseChanged, 0, -180)];
975 EXPECT_EQ(last_event.pan_x, 0);
976 EXPECT_EQ(last_event.pan_y, 0);
977 EXPECT_EQ(last_event.scale, 1);
978 EXPECT_EQ(last_event.rotation,
M_PI);
982 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
983 NSEventTypeRotate, NSEventPhaseChanged, 0, -360)];
989 EXPECT_EQ(last_event.pan_x, 0);
990 EXPECT_EQ(last_event.pan_y, 0);
991 EXPECT_EQ(last_event.scale, 1);
992 EXPECT_EQ(last_event.rotation, 3 *
M_PI);
996 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
997 NSEventPhaseEnded, 0, 0)];
1006 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1007 NSEventPhaseCancelled, 0, 0)];
1008 EXPECT_FALSE(called);
1014- (bool)mouseAndGestureEventsAreHandledSeparately:(
id)engineMock {
1022 CGEventRef cgEventStart = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
1023 CGEventSetType(cgEventStart, kCGEventScrollWheel);
1024 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventScrollPhase, kCGScrollPhaseBegan);
1025 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventIsContinuous, 1);
1026 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventStart]];
1027 CFRelease(cgEventStart);
1029 CGEventRef cgEventUpdate = CGEventCreateCopy(cgEventStart);
1030 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventScrollPhase, kCGScrollPhaseChanged);
1031 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis2, 1);
1032 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis1, 2);
1033 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
1034 CFRelease(cgEventUpdate);
1036 NSEvent* mouseEvent = flutter::testing::CreateMouseEvent(0x00);
1041 CGEventRef cgEventEnd = CGEventCreateCopy(cgEventStart);
1042 CGEventSetIntegerValueField(cgEventEnd, kCGScrollWheelEventScrollPhase, kCGScrollPhaseEnded);
1043 [viewController
scrollWheel:[NSEvent eventWithCGEvent:cgEventEnd]];
1044 CFRelease(cgEventEnd);
1049- (bool)testViewWillAppearCalledMultipleTimes:(
id)engineMock {
1062 [
key isEqualToString:
@"Contents/Frameworks/App.framework/Resources/flutter_assets/test.png"]);
1072 @"Contents/Frameworks/App.framework/Resources/flutter_assets/packages/test/test.png"]);
1085- (bool)testMouseDownUpEventsSentToNextResponder:(
id)engineMock {
1090 Method mouseDown = class_getInstanceMethod([NSResponder
class],
@selector(mouseDown:));
1091 Method mouseUp = class_getInstanceMethod([NSResponder
class],
@selector(mouseUp:));
1093 IMP origMouseDown = method_setImplementation(mouseDown, noopImp);
1094 IMP origMouseUp = method_setImplementation(mouseUp, noopImp);
1104 NSEvent* mouseEvent = flutter::testing::CreateMouseEvent(0x00);
1105 [view mouseDown:mouseEvent];
1110 [view mouseUp:mouseEvent];
1115 method_setImplementation(mouseDown, origMouseDown);
1116 method_setImplementation(mouseUp, origMouseUp);
1121- (bool)testModifierKeysAreSynthesizedOnMouseMove:(
id)engineMock {
1124 [engineMock binaryMessenger])
1125 .andReturn(binaryMessengerMock);
1129 OCMStub([engineMock
renderer]).andReturn(renderer_);
1132 __block NSMutableArray<KeyEventWrapper*>* events = [NSMutableArray array];
1133 OCMStub([[engineMock ignoringNonObjectArgs] sendKeyEvent:
FlutterKeyEvent {}
1136 .andDo((^(NSInvocation* invocation) {
1138 [invocation getArgument:&event atIndex:2];
1142 __block NSMutableArray<NSDictionary*>* channelEvents = [NSMutableArray array];
1143 OCMStub([binaryMessengerMock sendOnChannel:
@"flutter/keyevent"
1145 binaryReply:[OCMArg
any]])
1146 .andDo((^(NSInvocation* invocation) {
1148 [invocation getArgument:&data atIndex:3];
1150 [channelEvents addObject:event];
1160 NSEvent* mouseEvent = flutter::testing::CreateMouseEvent(0x00);
1162 EXPECT_EQ([events
count], 0u);
1167 NSDictionary* channelEvent;
1168 NSNumber* logicalKey;
1169 NSNumber* physicalKey;
1170 NSEventModifierFlags
flag = [flutter::keyCodeToModifierFlag[keyCode] unsignedLongValue];
1174 flag |= NSEventModifierFlagShift;
1177 flag |= NSEventModifierFlagControl;
1180 flag |= NSEventModifierFlagOption;
1183 flag |= NSEventModifierFlagCommand;
1187 NSEvent* mouseEvent = flutter::testing::CreateMouseEvent(
flag);
1189 EXPECT_EQ([events
count], 1u);
1190 event = events[0].data;
1191 logicalKey = [flutter::keyCodeToLogicalKey objectForKey:keyCode];
1192 physicalKey = [flutter::keyCodeToPhysicalKey objectForKey:keyCode];
1194 EXPECT_EQ(
event->logical, logicalKey.unsignedLongLongValue);
1195 EXPECT_EQ(
event->physical, physicalKey.unsignedLongLongValue);
1196 EXPECT_EQ(
event->synthesized,
true);
1198 channelEvent = channelEvents[0];
1199 EXPECT_TRUE([channelEvent[
@"type"] isEqual:
@"keydown"]);
1200 EXPECT_TRUE([channelEvent[
@"keyCode"] isEqual:keyCode]);
1204 mouseEvent = flutter::testing::CreateMouseEvent(0x00);
1206 EXPECT_EQ([events
count], 2u);
1207 event = events[1].data;
1208 logicalKey = [flutter::keyCodeToLogicalKey objectForKey:keyCode];
1209 physicalKey = [flutter::keyCodeToPhysicalKey objectForKey:keyCode];
1211 EXPECT_EQ(
event->logical, logicalKey.unsignedLongLongValue);
1212 EXPECT_EQ(
event->physical, physicalKey.unsignedLongLongValue);
1213 EXPECT_EQ(
event->synthesized,
true);
1215 channelEvent = channelEvents[1];
1216 EXPECT_TRUE([channelEvent[
@"type"] isEqual:
@"keyup"]);
1217 EXPECT_TRUE([channelEvent[
@"keyCode"] isEqual:keyCode]);
1218 EXPECT_TRUE([channelEvent[
@"modifiers"] isEqual:@(0)]);
1220 [events removeAllObjects];
1221 [channelEvents removeAllObjects];
1233 OCMStub([engineMock
renderer]).andReturn(renderer_);
1241 [engineMock shutDownEngine];
1244 EXPECT_EQ(weakController, nil);
NS_ASSUME_NONNULL_BEGIN typedef void(^ FlutterBinaryReply)(NSData *_Nullable reply)
FlutterView * view() const
@ kPanZoomUpdate
The pan/zoom updated.
@ kPanZoomStart
A pan/zoom started on this pointer.
@ kPanZoomEnd
The pan/zoom ended.
@ kFlutterPointerSignalKindScrollInertiaCancel
@ kFlutterPointerSignalKindScroll
@ kFlutterPointerSignalKindNone
void(* FlutterKeyEventCallback)(bool, void *)
@ kFlutterKeyEventTypeDown
@ kFlutterPointerDeviceKindTrackpad
FlutterSemanticsFlag flag
FlKeyEvent uint64_t FlKeyResponderAsyncCallback callback
instancetype sharedInstance()
bool testLookupKeyAssetsWithPackage()
bool testViewControllerIsReleased()
static void SwizzledNoop(id self, SEL _cmd)
bool testLookupKeyAssets()
void mouseExited:(NSEvent *event)
void mouseMoved:(NSEvent *event)
void onPreEngineRestart()
void scrollWheel:(NSEvent *event)
void mouseEntered:(NSEvent *event)
FlutterTextInputPlugin * textInputPlugin
void keyDown:(NSEvent *event)
FlutterMouseTrackingMode mouseTrackingMode
FlutterView * flutterView
NSString * lookupKeyForAsset:(NSString *asset)
void touchesBeganWithEvent:(NSEvent *event)
void flagsChanged:(NSEvent *event)
NSString * lookupKeyForAsset:fromPackage:(NSString *asset,[fromPackage] NSString *package)
FlutterViewController * viewController
constexpr uint64_t kPhysicalKeyA
const char * GetFixturesPath()
Returns the directory containing the test fixture for the target if this target has fixtures configur...
id CreateMockViewController()
id CreateMockFlutterEngine(NSString *pasteboardString)
TEST_F(FlutterViewControllerTest, testViewControllerIsReleased)
const NSDictionary * keyCodeToModifierFlag
@ kModifierFlagControlLeft
@ kModifierFlagControlRight
@ kModifierFlagShiftRight
SIT bool any(const Vec< 1, T > &x)
NSResponder * nextResponder
#define EXPECT_TRUE(handle)