743 OCMStub([engineMock renderer]).andReturn(renderer_);
744 __block
bool called =
false;
745 __block FlutterPointerEvent last_event;
747 .andDo((^(NSInvocation* invocation) {
748 FlutterPointerEvent* event;
749 [invocation getArgument:&event atIndex:2];
757 [viewController loadView];
761 CGEventRef cgEventStart = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
762 CGEventSetType(cgEventStart, kCGEventScrollWheel);
763 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventScrollPhase, kCGScrollPhaseBegan);
764 CGEventSetIntegerValueField(cgEventStart, kCGScrollWheelEventIsContinuous, 1);
767 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventStart]];
769 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
770 EXPECT_EQ(last_event.phase, kPanZoomStart);
771 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
772 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
775 CGEventRef cgEventUpdate = CGEventCreateCopy(cgEventStart);
776 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventScrollPhase, kCGScrollPhaseChanged);
777 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis2, 1);
778 CGEventSetIntegerValueField(cgEventUpdate, kCGScrollWheelEventDeltaAxis1, 2);
781 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
783 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
784 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
785 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
786 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
787 EXPECT_EQ(last_event.pan_x, 8 * viewController.flutterView.layer.contentsScale);
788 EXPECT_EQ(last_event.pan_y, 16 * viewController.flutterView.layer.contentsScale);
792 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
794 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
795 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
796 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
797 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
798 EXPECT_EQ(last_event.pan_x, 16 * viewController.flutterView.layer.contentsScale);
799 EXPECT_EQ(last_event.pan_y, 32 * viewController.flutterView.layer.contentsScale);
802 CGEventRef cgEventEnd = CGEventCreateCopy(cgEventStart);
803 CGEventSetIntegerValueField(cgEventEnd, kCGScrollWheelEventScrollPhase, kCGScrollPhaseEnded);
806 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventEnd]];
808 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
809 EXPECT_EQ(last_event.phase, kPanZoomEnd);
810 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
811 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
814 CGEventRef cgEventMomentumStart = CGEventCreateCopy(cgEventStart);
815 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventScrollPhase, 0);
816 CGEventSetIntegerValueField(cgEventMomentumStart, kCGScrollWheelEventMomentumPhase,
817 kCGMomentumScrollPhaseBegin);
820 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumStart]];
821 EXPECT_FALSE(called);
824 CGEventRef cgEventMomentumUpdate = CGEventCreateCopy(cgEventStart);
825 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventScrollPhase, 0);
826 CGEventSetIntegerValueField(cgEventMomentumUpdate, kCGScrollWheelEventMomentumPhase,
827 kCGMomentumScrollPhaseContinue);
830 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumUpdate]];
831 EXPECT_FALSE(called);
834 id touchMock = OCMClassMock([NSTouch
class]);
835 NSSet* touchSet = [NSSet setWithObject:touchMock];
836 id touchEventMock1 = OCMClassMock([NSEvent
class]);
837 OCMStub([touchEventMock1 allTouches]).andReturn(touchSet);
838 CGPoint touchLocation = {0, 0};
839 OCMStub([touchEventMock1 locationInWindow]).andReturn(touchLocation);
840 OCMStub([(NSEvent*)touchEventMock1 timestamp]).andReturn(0.150);
844 [viewController touchesBeganWithEvent:touchEventMock1];
845 EXPECT_FALSE(called);
848 id touchEventMock2 = OCMClassMock([NSEvent
class]);
849 OCMStub([touchEventMock2 allTouches]).andReturn(touchSet);
850 OCMStub([touchEventMock2 locationInWindow]).andReturn(touchLocation);
851 OCMStub([(NSEvent*)touchEventMock2 timestamp]).andReturn(0.005);
855 [viewController touchesBeganWithEvent:touchEventMock2];
857 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScrollInertiaCancel);
858 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
861 CGEventRef cgEventMomentumEnd = CGEventCreateCopy(cgEventStart);
862 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventScrollPhase, 0);
863 CGEventSetIntegerValueField(cgEventMomentumEnd, kCGScrollWheelEventMomentumPhase,
864 kCGMomentumScrollPhaseEnd);
867 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMomentumEnd]];
868 EXPECT_FALSE(called);
871 CGEventRef cgEventMayBegin = CGEventCreateCopy(cgEventStart);
872 CGEventSetIntegerValueField(cgEventMayBegin, kCGScrollWheelEventScrollPhase,
873 kCGScrollPhaseMayBegin);
876 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventMayBegin]];
878 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
879 EXPECT_EQ(last_event.phase, kPanZoomStart);
880 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
881 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
884 CGEventRef cgEventCancel = CGEventCreateCopy(cgEventStart);
885 CGEventSetIntegerValueField(cgEventCancel, kCGScrollWheelEventScrollPhase,
886 kCGScrollPhaseCancelled);
889 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventCancel]];
891 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
892 EXPECT_EQ(last_event.phase, kPanZoomEnd);
893 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
894 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
897 CGEventRef cgEventDiscrete = CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
898 CGEventSetType(cgEventDiscrete, kCGEventScrollWheel);
899 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventIsContinuous, 0);
900 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis2, 1);
901 CGEventSetIntegerValueField(cgEventDiscrete, kCGScrollWheelEventDeltaAxis1, 2);
904 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscrete]];
906 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
908 EXPECT_EQ(last_event.scroll_delta_x, -40 * viewController.flutterView.layer.contentsScale);
909 EXPECT_EQ(last_event.scroll_delta_y, -80 * viewController.flutterView.layer.contentsScale);
913 CGEventRef cgEventDiscreteShift =
914 CGEventCreateScrollWheelEvent(NULL, kCGScrollEventUnitPixel, 1, 0);
915 CGEventSetType(cgEventDiscreteShift, kCGEventScrollWheel);
917 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventIsContinuous, 0);
918 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis2,
920 CGEventSetIntegerValueField(cgEventDiscreteShift, kCGScrollWheelEventDeltaAxis1,
924 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventDiscreteShift]];
926 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
928 EXPECT_FLOAT_EQ(last_event.scroll_delta_x, 0.0 * viewController.flutterView.layer.contentsScale);
929 EXPECT_FLOAT_EQ(last_event.scroll_delta_y,
930 -80.0 * viewController.flutterView.layer.contentsScale);
935 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
936 NSEventPhaseBegan, 1, 0)];
938 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
939 EXPECT_EQ(last_event.phase, kPanZoomStart);
940 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
941 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
945 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
946 NSEventPhaseChanged, 1, 0)];
948 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
949 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
950 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
951 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
952 EXPECT_EQ(last_event.pan_x, 0);
953 EXPECT_EQ(last_event.pan_y, 0);
954 EXPECT_EQ(last_event.scale, 2);
956 EXPECT_EQ(last_event.rotation, 0);
960 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
961 NSEventPhaseChanged, 1, 0)];
963 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
964 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
965 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
966 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
967 EXPECT_EQ(last_event.pan_x, 0);
968 EXPECT_EQ(last_event.pan_y, 0);
969 EXPECT_EQ(last_event.scale, 4);
971 EXPECT_EQ(last_event.rotation, 0);
975 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
976 NSEventPhaseEnded, 0, 0)];
978 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
979 EXPECT_EQ(last_event.phase, kPanZoomEnd);
980 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
981 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
986 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
987 NSEventPhaseBegan, 1, 0)];
989 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
990 EXPECT_EQ(last_event.phase, kPanZoomStart);
991 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
992 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
996 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
997 NSEventTypeRotate, NSEventPhaseChanged, 0, -180)];
999 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1000 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
1001 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
1002 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1003 EXPECT_EQ(last_event.pan_x, 0);
1004 EXPECT_EQ(last_event.pan_y, 0);
1005 EXPECT_EQ(last_event.scale, 1);
1006 EXPECT_EQ(last_event.rotation, M_PI);
1010 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
1011 NSEventTypeRotate, NSEventPhaseChanged, 0, -360)];
1012 EXPECT_TRUE(called);
1013 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1014 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
1015 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
1016 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1017 EXPECT_EQ(last_event.pan_x, 0);
1018 EXPECT_EQ(last_event.pan_y, 0);
1019 EXPECT_EQ(last_event.scale, 1);
1020 EXPECT_EQ(last_event.rotation, 3 * M_PI);
1024 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1025 NSEventPhaseEnded, 0, 0)];
1026 EXPECT_TRUE(called);
1027 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1028 EXPECT_EQ(last_event.phase, kPanZoomEnd);
1029 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
1030 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1034 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1035 NSEventPhaseCancelled, 0, 0)];
1036 EXPECT_FALSE(called);