Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit a5f98c9e authored by Harry Cutts's avatar Harry Cutts
Browse files

GestureConverterTest: split tests for clearing after gesture ends

GestureConverter doesn't use its stored array of fake fingers
(mFakeFingerCoords) when making move gestures, so using move gestures to
check for the GESTURE_* axes being cleared won't reveal failures. We
still need to use move gestures to check that the classification is
reset properly, though (as any other gestures will have their own
classifications).

Bug: 283093437
Test: atest inputflinger_tests:GestureConverterTest
Change-Id: I1349dc72f4c3fe0a7da5d9f1e06affd0dc45da49
parent fd45037f
Loading
Loading
Loading
Loading
+84 −19
Original line number Diff line number Diff line
@@ -332,7 +332,7 @@ TEST_F(GestureConverterTest, Scroll_Rotated) {
                      WithToolType(ToolType::FINGER)));
}

TEST_F(GestureConverterTest, Scroll_ClearsClassificationAndOffsetsAfterGesture) {
TEST_F(GestureConverterTest, Scroll_ClearsClassificationAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

@@ -349,12 +349,34 @@ TEST_F(GestureConverterTest, Scroll_ClearsClassificationAndOffsetsAfterGesture)
    Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
    ASSERT_EQ(1u, args.size());
    ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
                AllOf(WithMotionClassification(MotionClassification::NONE),
                      WithGestureScrollDistance(0, 0, EPSILON)));
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
                WithMotionClassification(MotionClassification::NONE));
}

TEST_F(GestureConverterTest, Scroll_ClearsScrollDistanceAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

    Gesture startGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -10);
    std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);

    Gesture continueGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 0, -5);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, continueGesture);

    Gesture flingGesture(kGestureFling, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, 1, 1,
                         GESTURES_FLING_START);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, flingGesture);

    // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
    // need to use another gesture type, like pinch.
    Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
                         GESTURES_ZOOM_START);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
    ASSERT_FALSE(args.empty());
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureScrollDistance(0, 0, EPSILON));
}

TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAndOffsetsAfterGesture) {
TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

@@ -369,9 +391,28 @@ TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsClassificationAndOffsetsAfte
                        /*dy=*/10);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
    ASSERT_EQ(1u, args.size());
    ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
                AllOf(WithMotionClassification(MotionClassification::NONE),
                      WithGestureOffset(0, 0, EPSILON)));
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
                WithMotionClassification(MotionClassification::NONE));
}

TEST_F(GestureConverterTest, ThreeFingerSwipe_ClearsOffsetsAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

    Gesture startGesture(kGestureSwipe, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/5,
                         /*dy=*/5);
    std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);

    Gesture liftGesture(kGestureSwipeLift, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, liftGesture);

    // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
    // need to use another gesture type, like pinch.
    Gesture pinchGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
                         GESTURES_ZOOM_START);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, pinchGesture);
    ASSERT_FALSE(args.empty());
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGestureOffset(0, 0, EPSILON));
}

TEST_F(GestureConverterTest, ThreeFingerSwipe_Vertical) {
@@ -761,7 +802,7 @@ TEST_F(GestureConverterTest, Pinch_Outwards) {
                      WithToolType(ToolType::FINGER)));
}

TEST_F(GestureConverterTest, Pinch_ClearsClassificationAndScaleFactorAfterGesture) {
TEST_F(GestureConverterTest, Pinch_ClearsClassificationAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

@@ -780,9 +821,33 @@ TEST_F(GestureConverterTest, Pinch_ClearsClassificationAndScaleFactorAfterGestur
    Gesture moveGesture(kGestureMove, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, -5, 10);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, moveGesture);
    ASSERT_EQ(1u, args.size());
    ASSERT_THAT(std::get<NotifyMotionArgs>(args.front()),
                AllOf(WithMotionClassification(MotionClassification::NONE),
                      WithGesturePinchScaleFactor(0, EPSILON)));
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()),
                WithMotionClassification(MotionClassification::NONE));
}

TEST_F(GestureConverterTest, Pinch_ClearsScaleFactorAfterGesture) {
    InputDeviceContext deviceContext(*mDevice, EVENTHUB_ID);
    GestureConverter converter(*mReader->getContext(), deviceContext, DEVICE_ID);

    Gesture startGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
                         GESTURES_ZOOM_START);
    std::list<NotifyArgs> args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, startGesture);

    Gesture updateGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME,
                          /*dz=*/1.2, GESTURES_ZOOM_UPDATE);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, updateGesture);

    Gesture endGesture(kGesturePinch, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dz=*/1,
                       GESTURES_ZOOM_END);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, endGesture);

    // Move gestures don't use the fake finger array, so to test that gesture axes are cleared we
    // need to use another gesture type, like scroll.
    Gesture scrollGesture(kGestureScroll, ARBITRARY_GESTURE_TIME, ARBITRARY_GESTURE_TIME, /*dx=*/1,
                          /*dy=*/0);
    args = converter.handleGesture(ARBITRARY_TIME, READ_TIME, scrollGesture);
    ASSERT_FALSE(args.empty());
    EXPECT_THAT(std::get<NotifyMotionArgs>(args.front()), WithGesturePinchScaleFactor(0, EPSILON));
}

TEST_F(GestureConverterTest, ResetWithButtonPressed) {