From 1f10e53ba2e9b416fe1f905498cc3095055fb98e Mon Sep 17 00:00:00 2001 From: Thales Lima Date: Wed, 3 May 2023 18:34:36 +0100 Subject: [PATCH] Create TAPL test for taskbar in overview Fix: 269985301 Test: TaplTestsQuickstep Flag: none Change-Id: Iea0311bcba54882f7f2cf5d35cd98a538ae85855 --- .../android/quickstep/TaplTestsQuickstep.java | 49 +++++++++ .../android/launcher3/tapl/BaseOverview.java | 100 +++++++++++++++--- .../tapl/LauncherInstrumentation.java | 32 ++++-- .../android/launcher3/tapl/OverviewTask.java | 4 + .../com/android/launcher3/tapl/Taskbar.java | 30 ++++++ 5 files changed, 195 insertions(+), 20 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java index c39d095068..00b72b1692 100644 --- a/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java +++ b/quickstep/tests/src/com/android/quickstep/TaplTestsQuickstep.java @@ -425,6 +425,55 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest { 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 @ScreenRecord // b/242163205 public void testDisableRotationCheckForPhone() throws Exception { diff --git a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java index afeb8d782b..2c3c02827d 100644 --- a/tests/tapl/com/android/launcher3/tapl/BaseOverview.java +++ b/tests/tapl/com/android/launcher3/tapl/BaseOverview.java @@ -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. */ @@ -94,23 +132,57 @@ 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(); - 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(); + 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= */ 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(); } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 80fded5872..2adfc98e6d 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -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 tapRight tap on the right of the container if true, or left otherwise */ 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( "want to tap outside container on the " + (tapRight ? "right" : "left"))) { Rect containerBounds = getVisibleBounds(container); + + int x; + if (halfwayToEdge) { + x = tapRight + ? (containerBounds.right + getRealDisplaySize().x) / 2 + : containerBounds.left / 2; + } 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( - tapRight - ? (containerBounds.right + getRealDisplaySize().x) / 2 - : containerBounds.left / 2, - containerBounds.top + 1); + final Point tapTarget = new Point(x, y); sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget, LauncherInstrumentation.GestureScope.INSIDE); sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget, diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index 90f3d13a5d..39b93b4b59 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -71,6 +71,10 @@ public final class OverviewTask { return mTask.getVisibleBounds().exactCenterX(); } + UiObject2 getUiObject() { + return mTask; + } + /** * Dismisses the task by swiping up. */ diff --git a/tests/tapl/com/android/launcher3/tapl/Taskbar.java b/tests/tapl/com/android/launcher3/tapl/Taskbar.java index 6ca7f4bf79..051630e185 100644 --- a/tests/tapl/com/android/launcher3/tapl/Taskbar.java +++ b/tests/tapl/com/android/launcher3/tapl/Taskbar.java @@ -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 android.graphics.Point; +import android.graphics.Rect; import android.os.SystemClock; import android.text.TextUtils; import android.view.MotionEvent; @@ -122,4 +123,33 @@ public final class Taskbar { // Look for an icon with no 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); + } + } }