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

Commit 1f10e53b authored by Thales Lima's avatar Thales Lima
Browse files

Create TAPL test for taskbar in overview

Fix: 269985301
Test: TaplTestsQuickstep
Flag: none
Change-Id: Iea0311bcba54882f7f2cf5d35cd98a538ae85855
parent d282d595
Loading
Loading
Loading
Loading
+49 −0
Original line number Original line Diff line number Diff line
@@ -425,6 +425,55 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
                        0, getTaskCount(launcher)));
                        0, getTaskCount(launcher)));
    }
    }


    @Test
    @PortraitLandscape
    public void testOverviewDeadzones() throws Exception {
        startTestAppsWithCheck();

        Overview overview = mLauncher.goHome().switchToOverview();
        assertTrue("Launcher internal state should be Overview",
                isInState(() -> LauncherState.OVERVIEW));
        executeOnLauncher(
                launcher -> assertTrue("Should have at least 3 tasks",
                        getTaskCount(launcher) >= 3));

        // It should not dismiss overview when tapping between tasks
        overview.touchBetweenTasks();
        overview = mLauncher.getOverview();
        assertTrue("Launcher internal state should be Overview",
                isInState(() -> LauncherState.OVERVIEW));

        // Dismiss when tapping to the right of the focused task
        overview.touchOutsideFirstTask();
        assertTrue("Launcher internal state should be Home",
                isInState(() -> LauncherState.NORMAL));
    }

    @Test
    @PortraitLandscape
    public void testTaskbarDeadzonesForTablet() throws Exception {
        assumeTrue(mLauncher.isTablet());

        startTestAppsWithCheck();

        Overview overview = mLauncher.goHome().switchToOverview();
        assertTrue("Launcher internal state should be Overview",
                isInState(() -> LauncherState.OVERVIEW));
        executeOnLauncher(
                launcher -> assertTrue("Should have at least 3 tasks",
                        getTaskCount(launcher) >= 3));

        // On persistent taskbar, it should not dismiss when tapping the taskbar
        overview.touchTaskbarBottomCorner(/* tapRight= */ false);
        assertTrue("Launcher internal state should be Overview",
                isInState(() -> LauncherState.OVERVIEW));

        // On persistent taskbar, it should not dismiss when tapping the taskbar
        overview.touchTaskbarBottomCorner(/* tapRight= */ true);
        assertTrue("Launcher internal state should be Overview",
                isInState(() -> LauncherState.OVERVIEW));
    }

    @Test
    @Test
    @ScreenRecord // b/242163205
    @ScreenRecord // b/242163205
    public void testDisableRotationCheckForPhone() throws Exception {
    public void testDisableRotationCheckForPhone() throws Exception {
+86 −14
Original line number Original line Diff line number Diff line
@@ -71,6 +71,44 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
        }
        }
    }
    }


    /**
     * Flings backward (right) and waits the fling's end.
     */
    public void flingBackward() {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            flingBackwardImpl();
        }
    }

    private void flingBackwardImpl() {
        try (LauncherInstrumentation.Closable c =
                     mLauncher.addContextLayer("want to fling backward in overview")) {
            LauncherInstrumentation.log("Overview.flingBackward before fling");
            final UiObject2 overview = verifyActiveContainer();
            final int rightMargin =
                    mLauncher.getTargetInsets().right + mLauncher.getEdgeSensitivityWidth();
            mLauncher.scroll(
                    overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false);
            try (LauncherInstrumentation.Closable c2 =
                         mLauncher.addContextLayer("flung backwards")) {
                verifyActiveContainer();
                verifyActionsViewVisibility();
            }
        }
    }

    private OverviewTask flingToFirstTask() {
        OverviewTask currentTask = getCurrentTask();

        while (mLauncher.getRealDisplaySize().x - currentTask.getUiObject().getVisibleBounds().right
                <= mLauncher.getOverviewPageSpacing()) {
            flingBackwardImpl();
            currentTask = getCurrentTask();
        }

        return currentTask;
    }

    /**
    /**
     * Dismissed all tasks by scrolling to Clear-all button and pressing it.
     * Dismissed all tasks by scrolling to Clear-all button and pressing it.
     */
     */
@@ -94,24 +132,58 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
    }
    }


    /**
    /**
     * Flings backward (right) and waits the fling's end.
     * Touch to the right of current task. This should dismiss overview and go back to Workspace.
     */
     */
    public void flingBackward() {
    public Workspace touchOutsideFirstTask() {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
             LauncherInstrumentation.Closable c =
             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                     mLauncher.addContextLayer("want to fling backward in overview")) {
                     "touching outside the focused task")) {
            LauncherInstrumentation.log("Overview.flingBackward before fling");

            final UiObject2 overview = verifyActiveContainer();
            if (getTaskCount() < 2) {
            final int rightMargin =
                throw new IllegalStateException(
                    mLauncher.getTargetInsets().right + mLauncher.getEdgeSensitivityWidth();
                        "Need to have at least 2 tasks");
            mLauncher.scroll(
            }
                    overview, Direction.RIGHT, new Rect(0, 0, rightMargin + 1, 0), 20, false);

            try (LauncherInstrumentation.Closable c2 =
            OverviewTask currentTask = flingToFirstTask();
                         mLauncher.addContextLayer("flung backwards")) {

                verifyActiveContainer();
            mLauncher.touchOutsideContainer(currentTask.getUiObject(),
                verifyActionsViewVisibility();
                    /* tapRight= */ true,
                    /* halfwayToEdge= */ false);

            return new Workspace(mLauncher);
        }
        }
    }
    }

    /**
     * Touch between two tasks
     */
    public void touchBetweenTasks() {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                     "touching outside the focused task")) {
            if (getTaskCount() < 2) {
                throw new IllegalStateException(
                        "Need to have at least 2 tasks");
            }

            OverviewTask currentTask = flingToFirstTask();

            mLauncher.touchOutsideContainer(currentTask.getUiObject(),
                    /* tapRight= */ false,
                    /* halfwayToEdge= */ false);
        }
    }

    /**
     * Touch either on the right or the left corner of the screen, 1 pixel from the bottom and
     * from the sides.
     */
    public void touchTaskbarBottomCorner(boolean tapRight) {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            Taskbar taskbar = new Taskbar(mLauncher);
            taskbar.touchBottomCorner(tapRight);
            verifyActiveContainer();
        }
    }
    }


    /**
    /**
+26 −6
Original line number Original line Diff line number Diff line
@@ -2014,21 +2014,41 @@ public final class LauncherInstrumentation {
    }
    }


    /**
    /**
     * Taps outside container to dismiss.
     * Taps outside container to dismiss, centered vertically and halfway to the edge of the screen.
     *
     *
     * @param container container to be dismissed
     * @param container container to be dismissed
     * @param tapRight  tap on the right of the container if true, or left otherwise
     * @param tapRight  tap on the right of the container if true, or left otherwise
     */
     */
    void touchOutsideContainer(UiObject2 container, boolean tapRight) {
    void touchOutsideContainer(UiObject2 container, boolean tapRight) {
        touchOutsideContainer(container, tapRight, true);
    }

    /**
     * Taps outside the container, to the right or left, and centered vertically.
     *
     * @param tapRight      if true touches to the right of the container, otherwise touches on left
     * @param halfwayToEdge if true touches halfway to the screen edge, if false touches 1 px from
     *                      container
     */
    void touchOutsideContainer(UiObject2 container, boolean tapRight, boolean halfwayToEdge) {
        try (LauncherInstrumentation.Closable c = addContextLayer(
        try (LauncherInstrumentation.Closable c = addContextLayer(
                "want to tap outside container on the " + (tapRight ? "right" : "left"))) {
                "want to tap outside container on the " + (tapRight ? "right" : "left"))) {
            Rect containerBounds = getVisibleBounds(container);
            Rect containerBounds = getVisibleBounds(container);
            final long downTime = SystemClock.uptimeMillis();

            final Point tapTarget = new Point(
            int x;
                    tapRight
            if (halfwayToEdge) {
                x = tapRight
                        ? (containerBounds.right + getRealDisplaySize().x) / 2
                        ? (containerBounds.right + getRealDisplaySize().x) / 2
                            : containerBounds.left / 2,
                        : containerBounds.left / 2;
                    containerBounds.top + 1);
            } else {
                x = tapRight
                        ? containerBounds.right + 1
                        : containerBounds.left - 1;
            }
            int y = containerBounds.top + containerBounds.height() / 2;

            final long downTime = SystemClock.uptimeMillis();
            final Point tapTarget = new Point(x, y);
            sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget,
            sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget,
                    LauncherInstrumentation.GestureScope.INSIDE);
                    LauncherInstrumentation.GestureScope.INSIDE);
            sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget,
            sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget,
+4 −0
Original line number Original line Diff line number Diff line
@@ -71,6 +71,10 @@ public final class OverviewTask {
        return mTask.getVisibleBounds().exactCenterX();
        return mTask.getVisibleBounds().exactCenterX();
    }
    }


    UiObject2 getUiObject() {
        return mTask;
    }

    /**
    /**
     * Dismisses the task by swiping up.
     * Dismisses the task by swiping up.
     */
     */
+30 −0
Original line number Original line Diff line number Diff line
@@ -20,6 +20,7 @@ import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_DISABLE_
import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING;
import static com.android.launcher3.testing.shared.TestProtocol.REQUEST_ENABLE_MANUAL_TASKBAR_STASHING;


import android.graphics.Point;
import android.graphics.Point;
import android.graphics.Rect;
import android.os.SystemClock;
import android.os.SystemClock;
import android.text.TextUtils;
import android.text.TextUtils;
import android.view.MotionEvent;
import android.view.MotionEvent;
@@ -122,4 +123,33 @@ public final class Taskbar {
        // Look for an icon with no text
        // Look for an icon with no text
        return By.clazz(TextView.class).text("");
        return By.clazz(TextView.class).text("");
    }
    }

    private Rect getVisibleBounds() {
        return mLauncher.waitForSystemLauncherObject(TASKBAR_RES_ID).getVisibleBounds();
    }

    /**
     * Touch either on the right or the left corner of the screen, 1 pixel from the bottom and
     * from the sides.
     */
    void touchBottomCorner(boolean tapRight) {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to tap bottom corner on the " + (tapRight ? "right" : "left"))) {
            final long downTime = SystemClock.uptimeMillis();
            final Point tapTarget = new Point(
                    tapRight
                            ?
                            getVisibleBounds().right
                                    - mLauncher.getTargetInsets().right
                                    - 1
                            : getVisibleBounds().left
                                    + 1,
                    mLauncher.getRealDisplaySize().y - 1);

            mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget,
                    LauncherInstrumentation.GestureScope.INSIDE);
            mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget,
                    LauncherInstrumentation.GestureScope.INSIDE);
        }
    }
}
}