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

Commit dc6d7e1e authored by Tracy Zhou's avatar Tracy Zhou Committed by Android (Google) Code Review
Browse files

Merge "Add pressBack test to TaplTestsTrackpad" into udc-qpr-dev

parents a1bcd4b1 c9968e6c
Loading
Loading
Loading
Loading
+33 −0
Original line number Original line Diff line number Diff line
@@ -16,12 +16,19 @@


package com.android.quickstep;
package com.android.quickstep;


import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;
import static org.junit.Assume.assumeTrue;


import android.app.Instrumentation;

import androidx.test.filters.LargeTest;
import androidx.test.filters.LargeTest;
import androidx.test.platform.app.InstrumentationRegistry;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.runner.AndroidJUnit4;


import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.ui.TaplTestsLauncher3;
@@ -36,6 +43,9 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
@RunWith(AndroidJUnit4.class)
public class TaplTestsTrackpad extends AbstractQuickStepTest {
public class TaplTestsTrackpad extends AbstractQuickStepTest {


    private static final String READ_DEVICE_CONFIG_PERMISSION =
            "android.permission.READ_DEVICE_CONFIG";

    @Before
    @Before
    public void setUp() throws Exception {
    public void setUp() throws Exception {
        super.setUp();
        super.setUp();
@@ -58,6 +68,29 @@ public class TaplTestsTrackpad extends AbstractQuickStepTest {
        mLauncher.goHome();
        mLauncher.goHome();
    }
    }


    @Test
    @PortraitLandscape
    // TODO(b/291944684): Support back in 3-button mode. It requires triggering the logic to enable
    //  trackpad gesture back in SysUI. Normally it's triggered by the attachment of a trackpad. We
    //  need to figure out a way to emulate that in the test, or bypass the logic altogether.
    @NavigationModeSwitch(mode = ZERO_BUTTON)
    public void pressBack() throws Exception {
        assumeTrue(mLauncher.isTablet());
        assumeFalse(FeatureFlags.ENABLE_BACK_SWIPE_LAUNCHER_ANIMATION.get());
        Instrumentation instrumentation = InstrumentationRegistry.getInstrumentation();

        try {
            instrumentation.getUiAutomation().adoptShellPermissionIdentity(
                    READ_DEVICE_CONFIG_PERMISSION);
            mLauncher.setTrackpadGestureType(TrackpadGestureType.THREE_FINGER);

            startTestActivity(2);
            mLauncher.pressBack();
        } finally {
            instrumentation.getUiAutomation().dropShellPermissionIdentity();
        }
    }

    @Test
    @Test
    @PortraitLandscape
    @PortraitLandscape
    @NavigationModeSwitch
    @NavigationModeSwitch
+35 −22
Original line number Original line Diff line number Diff line
@@ -99,15 +99,17 @@ public final class LauncherInstrumentation {
    private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 15;
    private static final int ZERO_BUTTON_STEPS_FROM_BACKGROUND_TO_HOME = 15;
    private static final int GESTURE_STEP_MS = 16;
    private static final int GESTURE_STEP_MS = 16;


    static final Pattern EVENT_TOUCH_DOWN = getTouchEventPattern("ACTION_DOWN");
    static final Pattern EVENT_TOUCH_DOWN = getTouchEventPatternWithPointerCount("ACTION_DOWN");
    static final Pattern EVENT_TOUCH_UP = getTouchEventPattern("ACTION_UP");
    static final Pattern EVENT_TOUCH_UP = getTouchEventPatternWithPointerCount("ACTION_UP");
    private static final Pattern EVENT_TOUCH_CANCEL = getTouchEventPattern("ACTION_CANCEL");
    private static final Pattern EVENT_TOUCH_CANCEL = getTouchEventPatternWithPointerCount(
            "ACTION_CANCEL");
    static final Pattern EVENT_PILFER_POINTERS = Pattern.compile("pilferPointers");
    static final Pattern EVENT_PILFER_POINTERS = Pattern.compile("pilferPointers");
    static final Pattern EVENT_START = Pattern.compile("start:");
    static final Pattern EVENT_START = Pattern.compile("start:");


    static final Pattern EVENT_TOUCH_DOWN_TIS = getTouchEventPatternTIS("ACTION_DOWN");
    static final Pattern EVENT_TOUCH_DOWN_TIS = getTouchEventPatternTIS("ACTION_DOWN");
    static final Pattern EVENT_TOUCH_UP_TIS = getTouchEventPatternTIS("ACTION_UP");
    static final Pattern EVENT_TOUCH_UP_TIS = getTouchEventPatternTIS("ACTION_UP");
    static final Pattern EVENT_TOUCH_CANCEL_TIS = getTouchEventPatternTIS("ACTION_CANCEL");
    static final Pattern EVENT_TOUCH_CANCEL_TIS = getTouchEventPattern(
            "TouchInteractionService.onInputEvent", "ACTION_CANCEL");
    static final Pattern EVENT_HOVER_ENTER_TIS = getTouchEventPatternTIS("ACTION_HOVER_ENTER");
    static final Pattern EVENT_HOVER_ENTER_TIS = getTouchEventPatternTIS("ACTION_HOVER_ENTER");
    static final Pattern EVENT_HOVER_EXIT_TIS = getTouchEventPatternTIS("ACTION_HOVER_EXIT");
    static final Pattern EVENT_HOVER_EXIT_TIS = getTouchEventPatternTIS("ACTION_HOVER_EXIT");
    static final Pattern EVENT_BUTTON_PRESS_TIS = getTouchEventPatternTIS("ACTION_BUTTON_PRESS");
    static final Pattern EVENT_BUTTON_PRESS_TIS = getTouchEventPatternTIS("ACTION_BUTTON_PRESS");
@@ -212,30 +214,35 @@ public final class LauncherInstrumentation {
    private int mPointerCount = 0;
    private int mPointerCount = 0;


    private static Pattern getTouchEventPattern(String prefix, String action) {
    private static Pattern getTouchEventPattern(String prefix, String action) {
        return getTouchEventPattern(prefix, action, 1);
        return Pattern.compile(
                prefix + ": MotionEvent.*?action=" + action + ".*?id\\[0\\]=0"
                        + ".*?toolType\\[0\\]=TOOL_TYPE_FINGER.*?buttonState=0.*?");
    }
    }


    private static Pattern getTouchEventPattern(String prefix, String action, int pointerCount) {
    private static Pattern getTouchEventPatternWithPointerCount(String prefix, String action,
            int pointerCount) {
        return Pattern.compile(
        return Pattern.compile(
                prefix + ": MotionEvent.*?action=" + action + ".*?id\\[0\\]=0"
                prefix + ": MotionEvent.*?action=" + action + ".*?id\\[0\\]=0"
                        + ".*?toolType\\[0\\]=TOOL_TYPE_FINGER.*?buttonState=0.*?pointerCount="
                        + ".*?toolType\\[0\\]=TOOL_TYPE_FINGER.*?buttonState=0.*?pointerCount="
                        + pointerCount);
                        + pointerCount);
    }
    }


    private static Pattern getTouchEventPattern(String action) {
    private static Pattern getTouchEventPatternWithPointerCount(String action) {
        return getTouchEventPattern("Touch event", action);
        return getTouchEventPatternWithPointerCount("Touch event", action, 1);
    }
    }


    private static Pattern getTouchEventPattern(String action, int pointerCount) {
    private static Pattern getTouchEventPatternWithPointerCount(String action, int pointerCount) {
        return getTouchEventPattern("Touch event", action, pointerCount);
        return getTouchEventPatternWithPointerCount("Touch event", action, pointerCount);
    }
    }


    private static Pattern getTouchEventPatternTIS(String action) {
    private static Pattern getTouchEventPatternTIS(String action) {
        return getTouchEventPattern("TouchInteractionService.onInputEvent", action);
        return getTouchEventPatternWithPointerCount("TouchInteractionService.onInputEvent", action,
                1);
    }
    }


    private static Pattern getTouchEventPatternTIS(String action, int pointerCount) {
    private static Pattern getTouchEventPatternTIS(String action, int pointerCount) {
        return getTouchEventPattern("TouchInteractionService.onInputEvent", action, pointerCount);
        return getTouchEventPatternWithPointerCount("TouchInteractionService.onInputEvent", action,
                pointerCount);
    }
    }


    private static Pattern getKeyEventPattern(String action, String keyCode) {
    private static Pattern getKeyEventPattern(String action, String keyCode) {
@@ -1814,11 +1821,14 @@ public final class LauncherInstrumentation {
                        && gestureScope != GestureScope.OUTSIDE_WITHOUT_PILFER
                        && gestureScope != GestureScope.OUTSIDE_WITHOUT_PILFER
                        && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE
                        && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE
                        && (!isTrackpadGesture || isTwoFingerTrackpadGesture)) {
                        && (!isTrackpadGesture || isTwoFingerTrackpadGesture)) {
                    expectEvent(TestProtocol.SEQUENCE_MAIN,
                    expectEvent(TestProtocol.SEQUENCE_MAIN, getTouchEventPatternWithPointerCount(
                            getTouchEventPattern("ACTION_POINTER_DOWN", mPointerCount));
                            "ACTION_POINTER_DOWN", mPointerCount));
                }
                }
                if (hasTIS && (isTrackpadGestureEnabled()
                        || getNavigationModel() != NavigationModel.THREE_BUTTON)) {
                    expectEvent(TestProtocol.SEQUENCE_TIS, getTouchEventPatternTIS(
                    expectEvent(TestProtocol.SEQUENCE_TIS, getTouchEventPatternTIS(
                            "ACTION_POINTER_DOWN", mPointerCount));
                            "ACTION_POINTER_DOWN", mPointerCount));
                }
                pointerCount = mPointerCount;
                pointerCount = mPointerCount;
                break;
                break;
            case MotionEvent.ACTION_POINTER_UP:
            case MotionEvent.ACTION_POINTER_UP:
@@ -1826,15 +1836,18 @@ public final class LauncherInstrumentation {
                        && gestureScope != GestureScope.OUTSIDE_WITHOUT_PILFER
                        && gestureScope != GestureScope.OUTSIDE_WITHOUT_PILFER
                        && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE
                        && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE
                        && (!isTrackpadGesture || isTwoFingerTrackpadGesture)) {
                        && (!isTrackpadGesture || isTwoFingerTrackpadGesture)) {
                    expectEvent(TestProtocol.SEQUENCE_MAIN,
                    expectEvent(TestProtocol.SEQUENCE_MAIN, getTouchEventPatternWithPointerCount(
                            getTouchEventPattern("ACTION_POINTER_UP", mPointerCount));
                            "ACTION_POINTER_UP", mPointerCount));
                }
                }
                // When the gesture is handled outside, it's cancelled within launcher.
                // When the gesture is handled outside, it's cancelled within launcher.
                if (hasTIS && (isTrackpadGestureEnabled()
                        || getNavigationModel() != NavigationModel.THREE_BUTTON)) {
                    if (gestureScope != GestureScope.INSIDE_TO_OUTSIDE_WITH_KEYCODE
                    if (gestureScope != GestureScope.INSIDE_TO_OUTSIDE_WITH_KEYCODE
                            && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE) {
                            && gestureScope != GestureScope.OUTSIDE_WITH_KEYCODE) {
                        expectEvent(TestProtocol.SEQUENCE_TIS, getTouchEventPatternTIS(
                        expectEvent(TestProtocol.SEQUENCE_TIS, getTouchEventPatternTIS(
                                "ACTION_POINTER_UP", mPointerCount));
                                "ACTION_POINTER_UP", mPointerCount));
                    }
                    }
                }
                mPointerCount--;
                mPointerCount--;
                break;
                break;
            case MotionEvent.ACTION_BUTTON_PRESS:
            case MotionEvent.ACTION_BUTTON_PRESS: