715 OCMStub([engineMock renderer]).andReturn(renderer_);
716 __block
bool called =
false;
717 __block FlutterPointerEvent last_event;
718 OCMStub([[engineMock ignoringNonObjectArgs] sendPointerEvent:FlutterPointerEvent{}])
719 .andDo((^(NSInvocation* invocation) {
720 FlutterPointerEvent* event;
721 [invocation getArgument:&event atIndex:2];
729 [viewController loadView];
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]];
741 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
742 EXPECT_EQ(last_event.phase, kPanZoomStart);
743 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
744 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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]];
755 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
756 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
757 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
758 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
759 EXPECT_EQ(last_event.pan_x, 8 * viewController.flutterView.layer.contentsScale);
760 EXPECT_EQ(last_event.pan_y, 16 * viewController.flutterView.layer.contentsScale);
764 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventUpdate]];
766 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
767 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
768 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
769 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
770 EXPECT_EQ(last_event.pan_x, 16 * viewController.flutterView.layer.contentsScale);
771 EXPECT_EQ(last_event.pan_y, 32 * viewController.flutterView.layer.contentsScale);
774 CGEventRef cgEventEnd = CGEventCreateCopy(cgEventStart);
775 CGEventSetIntegerValueField(cgEventEnd, kCGScrollWheelEventScrollPhase, kCGScrollPhaseEnded);
778 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventEnd]];
780 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
781 EXPECT_EQ(last_event.phase, kPanZoomEnd);
782 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
783 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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);
816 [viewController touchesBeganWithEvent:touchEventMock1];
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);
827 [viewController touchesBeganWithEvent:touchEventMock2];
829 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScrollInertiaCancel);
830 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
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]];
850 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
851 EXPECT_EQ(last_event.phase, kPanZoomStart);
852 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
853 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
856 CGEventRef cgEventCancel = CGEventCreateCopy(cgEventStart);
857 CGEventSetIntegerValueField(cgEventCancel, kCGScrollWheelEventScrollPhase,
858 kCGScrollPhaseCancelled);
861 [viewController scrollWheel:[NSEvent eventWithCGEvent:cgEventCancel]];
863 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
864 EXPECT_EQ(last_event.phase, kPanZoomEnd);
865 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
866 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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]];
878 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
880 EXPECT_EQ(last_event.scroll_delta_x, -40 * viewController.flutterView.layer.contentsScale);
881 EXPECT_EQ(last_event.scroll_delta_y, -80 * viewController.flutterView.layer.contentsScale);
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]];
898 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindScroll);
900 EXPECT_FLOAT_EQ(last_event.scroll_delta_x, 0.0 * viewController.flutterView.layer.contentsScale);
901 EXPECT_FLOAT_EQ(last_event.scroll_delta_y,
902 -80.0 * viewController.flutterView.layer.contentsScale);
907 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
908 NSEventPhaseBegan, 1, 0)];
910 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
911 EXPECT_EQ(last_event.phase, kPanZoomStart);
912 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
913 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
917 [viewController magnifyWithEvent:flutter::testing::MockGestureEvent(NSEventTypeMagnify,
918 NSEventPhaseChanged, 1, 0)];
920 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
921 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
922 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
923 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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)];
935 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
936 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
937 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
938 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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)];
950 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
951 EXPECT_EQ(last_event.phase, kPanZoomEnd);
952 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
953 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
958 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
959 NSEventPhaseBegan, 1, 0)];
961 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
962 EXPECT_EQ(last_event.phase, kPanZoomStart);
963 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
964 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
968 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(
969 NSEventTypeRotate, NSEventPhaseChanged, 0, -180)];
971 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
972 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
973 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
974 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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)];
985 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
986 EXPECT_EQ(last_event.phase, kPanZoomUpdate);
987 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
988 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
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)];
999 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1000 EXPECT_EQ(last_event.phase, kPanZoomEnd);
1001 EXPECT_EQ(last_event.device_kind, kFlutterPointerDeviceKindTrackpad);
1002 EXPECT_EQ(last_event.signal_kind, kFlutterPointerSignalKindNone);
1006 [viewController rotateWithEvent:flutter::testing::MockGestureEvent(NSEventTypeRotate,
1007 NSEventPhaseCancelled, 0, 0)];
1008 EXPECT_FALSE(called);