@@ -48,6 +48,7 @@ const auto TOUCHPAD_PALM_REJECTION_V2 =
4848using testing::AllOf;
4949using testing::Each;
5050using testing::ElementsAre;
51+ using testing::IsEmpty;
5152using testing::VariantWith;
5253
5354class GestureConverterTest : public testing ::Test {
@@ -849,6 +850,107 @@ TEST_F(GestureConverterTest, FourFingerSwipe_Horizontal) {
849850 WithDisplayId (ui::LogicalDisplayId::DEFAULT)))));
850851}
851852
853+ TEST_F (GestureConverterTest, DisablingSystemGestures_IgnoresMultiFingerSwipe) {
854+ InputDeviceContext deviceContext (*mDevice , EVENTHUB_ID);
855+ GestureConverter converter (*mReader ->getContext (), deviceContext, DEVICE_ID);
856+ converter.setDisplayId (ui::LogicalDisplayId::DEFAULT);
857+
858+ std::list<NotifyArgs> args = converter.setEnableSystemGestures (ARBITRARY_TIME, false );
859+ ASSERT_THAT (args, IsEmpty ());
860+
861+ Gesture startGesture (kGestureSwipe , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx=*/ 0 ,
862+ /* dy=*/ 10 );
863+ Gesture continueGesture (kGestureSwipe , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx=*/ 0 ,
864+ /* dy=*/ 5 );
865+ Gesture liftGesture (kGestureSwipeLift , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
866+
867+ args += converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
868+ args += converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
869+ args += converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
870+ ASSERT_THAT (args, IsEmpty ());
871+
872+ args = converter.setEnableSystemGestures (ARBITRARY_TIME, true );
873+ ASSERT_THAT (args, IsEmpty ());
874+
875+ args = converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
876+ ASSERT_THAT (args,
877+ ElementsAre (VariantWith<NotifyMotionArgs>(
878+ WithMotionAction (AMOTION_EVENT_ACTION_DOWN)),
879+ VariantWith<NotifyMotionArgs>(WithMotionAction (
880+ AMOTION_EVENT_ACTION_POINTER_DOWN |
881+ 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
882+ VariantWith<NotifyMotionArgs>(WithMotionAction (
883+ AMOTION_EVENT_ACTION_POINTER_DOWN |
884+ 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT)),
885+ VariantWith<NotifyMotionArgs>(
886+ WithMotionAction (AMOTION_EVENT_ACTION_MOVE))));
887+ ASSERT_THAT (args,
888+ Each (VariantWith<NotifyMotionArgs>(
889+ WithMotionClassification (MotionClassification::MULTI_FINGER_SWIPE))));
890+ }
891+
892+ TEST_F (GestureConverterTest, DisablingSystemGestures_EndsOngoingMultiFingerSwipe) {
893+ InputDeviceContext deviceContext (*mDevice , EVENTHUB_ID);
894+ GestureConverter converter (*mReader ->getContext (), deviceContext, DEVICE_ID);
895+ converter.setDisplayId (ui::LogicalDisplayId::DEFAULT);
896+
897+ Gesture startGesture (kGestureSwipe , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx=*/ 0 ,
898+ /* dy=*/ 10 );
899+ std::list<NotifyArgs> args;
900+ args = converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, startGesture);
901+ ASSERT_FALSE (args.empty ());
902+
903+ // Disabling system gestures should end the swipe early.
904+ args = converter.setEnableSystemGestures (ARBITRARY_TIME, false );
905+ ASSERT_THAT (args,
906+ ElementsAre (VariantWith<NotifyMotionArgs>(
907+ AllOf (WithMotionAction (
908+ AMOTION_EVENT_ACTION_POINTER_UP |
909+ 2 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
910+ WithGestureOffset (0 , 0 , EPSILON),
911+ WithMotionClassification (
912+ MotionClassification::MULTI_FINGER_SWIPE),
913+ WithPointerCount (3u ))),
914+ VariantWith<NotifyMotionArgs>(
915+ AllOf (WithMotionAction (
916+ AMOTION_EVENT_ACTION_POINTER_UP |
917+ 1 << AMOTION_EVENT_ACTION_POINTER_INDEX_SHIFT),
918+ WithGestureOffset (0 , 0 , EPSILON),
919+ WithMotionClassification (
920+ MotionClassification::MULTI_FINGER_SWIPE),
921+ WithPointerCount (2u ))),
922+ VariantWith<NotifyMotionArgs>(
923+ AllOf (WithMotionAction (AMOTION_EVENT_ACTION_UP),
924+ WithGestureOffset (0 , 0 , EPSILON),
925+ WithMotionClassification (
926+ MotionClassification::MULTI_FINGER_SWIPE),
927+ WithPointerCount (1u ))),
928+ VariantWith<NotifyMotionArgs>(
929+ AllOf (WithMotionAction (AMOTION_EVENT_ACTION_HOVER_ENTER),
930+ WithMotionClassification (MotionClassification::NONE)))));
931+ ASSERT_THAT (args,
932+ Each (VariantWith<NotifyMotionArgs>(
933+ AllOf (WithToolType (ToolType::FINGER),
934+ WithDisplayId (ui::LogicalDisplayId::DEFAULT)))));
935+
936+ // Further movement in the same swipe should be ignored.
937+ Gesture continueGesture (kGestureSwipe , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /* dx=*/ 0 ,
938+ /* dy=*/ 5 );
939+ args = converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, continueGesture);
940+ ASSERT_THAT (args, IsEmpty ());
941+ Gesture liftGesture (kGestureSwipeLift , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
942+ args = converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, liftGesture);
943+ ASSERT_THAT (args, IsEmpty ());
944+
945+ // But single-finger pointer motion should be reported.
946+ Gesture moveGesture (kGestureMove , ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5 , 10 );
947+ args = converter.handleGesture (ARBITRARY_TIME, READ_TIME, ARBITRARY_TIME, moveGesture);
948+ ASSERT_THAT (args,
949+ ElementsAre (VariantWith<NotifyMotionArgs>(
950+ AllOf (WithMotionAction (AMOTION_EVENT_ACTION_HOVER_MOVE),
951+ WithRelativeMotion (-5 , 10 ), WithButtonState (0 )))));
952+ }
953+
852954TEST_F (GestureConverterTest, Pinch_Inwards) {
853955 input_flags::enable_touchpad_no_focus_change (true );
854956
0 commit comments