diff options
author | Thales Lima <tsuharesu@google.com> | 2023-05-23 18:32:34 +0000 |
---|---|---|
committer | Android (Google) Code Review <android-gerrit@google.com> | 2023-05-23 18:32:34 +0000 |
commit | ac206e1daf2a67075bba8958e993e2662f60c129 (patch) | |
tree | 57ad40aa173c9b6bfc72f63b5ad713f03605eeef /tests | |
parent | 64c83470752cc603e7dbe71e1794c7591696749f (diff) | |
parent | 1f10e53ba2e9b416fe1f905498cc3095055fb98e (diff) | |
download | Launcher3-ac206e1daf2a67075bba8958e993e2662f60c129.tar.gz |
Merge "Create TAPL test for taskbar in overview" into udc-dev
Diffstat (limited to 'tests')
4 files changed, 146 insertions, 20 deletions
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 @@ -72,6 +72,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. */ public void dismissAllTasks() { @@ -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); + } + } } |