From 4b3cc96ac2afbc416d0416c3ecca30eef1e7fe82 Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Wed, 6 Dec 2023 18:46:14 -0800 Subject: [PATCH] Waiting for Launcher stop when dropping a widget that starts an activity This will help to ensure that Launcher state has settled before continuing the test. Bug: 313926097 Flag: N/A Test: presubmit Change-Id: I810c3bd1da2839a482422396536acd664f3e4b82 --- .../android/launcher3/tapl/Launchable.java | 6 +- .../tapl/LauncherInstrumentation.java | 8 +++ .../android/launcher3/tapl/OverviewTask.java | 5 +- .../launcher3/tapl/OverviewTaskMenu.java | 7 +-- .../com/android/launcher3/tapl/Workspace.java | 57 ++++++++++++------- .../launcher3/tapl/WorkspaceDragSource.java | 3 +- 6 files changed, 52 insertions(+), 34 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/Launchable.java b/tests/tapl/com/android/launcher3/tapl/Launchable.java index 2512175e6c..fe927b3fd0 100644 --- a/tests/tapl/com/android/launcher3/tapl/Launchable.java +++ b/tests/tapl/com/android/launcher3/tapl/Launchable.java @@ -65,11 +65,9 @@ public abstract class Launchable { + mLauncher.getVisibleBounds(mObject)); if (launcherStopsAfterLaunch()) { - mLauncher.executeAndWaitForLauncherEvent( + mLauncher.executeAndWaitForLauncherStop( () -> mLauncher.clickLauncherObject(mObject), - event -> TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE - .equals(event.getClassName().toString()), - () -> "Launcher activity didn't stop", "clicking the launchable"); + "clicking the launchable"); } else { mLauncher.clickLauncherObject(mObject); } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index cbf1952ebb..c8c45466a2 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -973,6 +973,14 @@ public final class LauncherInstrumentation { } } + void executeAndWaitForLauncherStop(Runnable command, String actionName) { + executeAndWaitForLauncherEvent( + () -> command.run(), + event -> TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE + .equals(event.getClassName().toString()), + () -> "Launcher activity didn't stop", actionName); + } + /** * Get the resource ID of visible floating view. */ diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java index 068482e7a1..f383e99584 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTask.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTask.java @@ -201,11 +201,8 @@ public final class OverviewTask { public LaunchedAppState open() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) { verifyActiveContainer(); - mLauncher.executeAndWaitForLauncherEvent( + mLauncher.executeAndWaitForLauncherStop( () -> mLauncher.clickLauncherObject(mTask), - event -> TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE - .equals(event.getClassName().toString()), - () -> "Launcher activity didn't stop", "clicking an overview task"); if (mOverview.getContainerType() == LauncherInstrumentation.ContainerType.SPLIT_SCREEN_SELECT) { diff --git a/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java b/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java index 4a0131b0ff..3d2914d754 100644 --- a/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java +++ b/tests/tapl/com/android/launcher3/tapl/OverviewTaskMenu.java @@ -20,8 +20,6 @@ import androidx.annotation.NonNull; import androidx.test.uiautomator.By; import androidx.test.uiautomator.UiObject2; -import com.android.launcher3.testing.shared.TestProtocol; - /** Represents the menu of an overview task. */ public class OverviewTaskMenu { @@ -61,12 +59,9 @@ public class OverviewTaskMenu { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "before tapping the app info menu item")) { - mLauncher.executeAndWaitForLauncherEvent( + mLauncher.executeAndWaitForLauncherStop( () -> mLauncher.clickLauncherObject( mLauncher.findObjectInContainer(mMenu, By.text("App info"))), - event -> TestProtocol.LAUNCHER_ACTIVITY_STOPPED_MESSAGE - .equals(event.getClassName().toString()), - () -> "Launcher activity didn't stop", "tapped app info menu item"); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 2a2a83f33f..f8fa00c365 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -335,7 +335,8 @@ public final class Workspace extends Home { homeAppIcon, () -> new Point(0, 0), () -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), - null); + null, + /* startsActivity = */ false); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( "dragged the app across workspace")) { @@ -359,7 +360,8 @@ public final class Workspace extends Home { homeAppIcon, () -> getDropPointFromDropTargetBar(mLauncher, DELETE_TARGET_TEXT_ID), () -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), - /* expectDropEvents= */ null); + /* expectDropEvents= */ null, + /* startsActivity = */ false); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( "dragged the app to the drop bar")) { @@ -368,7 +370,6 @@ public final class Workspace extends Home { } } - /** * Uninstall the appIcon by dragging it to the 'uninstall' drop point of the drop_target_bar. * @@ -390,7 +391,8 @@ public final class Workspace extends Home { homeAppIcon, () -> getDropPointFromDropTargetBar(launcher, UNINSTALL_TARGET_TEXT_ID), expectLongClickEvents, - /* expectDropEvents= */null); + /* expectDropEvents= */null, + /* startsActivity = */ false); launcher.waitUntilLauncherObjectGone(DROP_BAR_RES_ID); @@ -464,14 +466,25 @@ public final class Workspace extends Home { o -> new FolderIcon(mLauncher, o)).collect(Collectors.toList()); } + private static void sendUp(LauncherInstrumentation launcher, Point dest, + long downTime) { + launcher.sendPointer( + downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, dest, + LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); + } + private static void dropDraggedIcon(LauncherInstrumentation launcher, Point dest, long downTime, - @Nullable Runnable expectedEvents) { - launcher.runToState( - () -> launcher.sendPointer( - downTime, SystemClock.uptimeMillis(), MotionEvent.ACTION_UP, dest, - LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER), - NORMAL_STATE_ORDINAL, - "sending UP event"); + @Nullable Runnable expectedEvents, boolean startsActivity) { + if (startsActivity) { + launcher.executeAndWaitForLauncherStop( + () -> sendUp(launcher, dest, downTime), + "sending UP event"); + } else { + launcher.runToState( + () -> sendUp(launcher, dest, downTime), + NORMAL_STATE_ORDINAL, + "sending UP event"); + } if (expectedEvents != null) { expectedEvents.run(); } @@ -488,7 +501,8 @@ public final class Workspace extends Home { LauncherInstrumentation.EVENT_START); } dragIconToWorkspace( - launcher, launchable, dest, expectLongClickEvents, expectDropEvents); + launcher, launchable, dest, expectLongClickEvents, expectDropEvents, + startsActivity); } static void dragIconToWorkspaceCellPosition(LauncherInstrumentation launcher, @@ -517,7 +531,8 @@ public final class Workspace extends Home { destSupplier, /* isDecelerating= */ false, () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), - /* expectDropEvents= */ null); + /* expectDropEvents= */ null, + /* startsActivity = */ false); } static void dragIconToWorkspace( @@ -525,9 +540,10 @@ public final class Workspace extends Home { Launchable launchable, Supplier dest, Runnable expectLongClickEvents, - @Nullable Runnable expectDropEvents) { + @Nullable Runnable expectDropEvents, + boolean startsActivity) { dragIconToWorkspace(launcher, launchable, dest, /* isDecelerating */ true, - expectLongClickEvents, expectDropEvents); + expectLongClickEvents, expectDropEvents, startsActivity); } static void dragIconToWorkspace( @@ -536,7 +552,8 @@ public final class Workspace extends Home { Supplier dest, boolean isDecelerating, Runnable expectLongClickEvents, - @Nullable Runnable expectDropEvents) { + @Nullable Runnable expectDropEvents, + boolean startsActivity) { try (LauncherInstrumentation.Closable ignored = launcher.addContextLayer( "want to drag icon to workspace")) { final long downTime = SystemClock.uptimeMillis(); @@ -568,7 +585,7 @@ public final class Workspace extends Home { launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); - dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents); + dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents, startsActivity); } } @@ -601,7 +618,8 @@ public final class Workspace extends Home { launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); - dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents); + dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents, + /* startsActivity = */ false); } } @@ -667,7 +685,8 @@ public final class Workspace extends Home { launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, true, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); - dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents); + dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents, + /* startsActivity = */ false); } /** diff --git a/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java b/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java index 5a4d562474..e5a2a2ef6c 100644 --- a/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java +++ b/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java @@ -81,7 +81,8 @@ interface WorkspaceDragSource { launchable, dest, launchable::addExpectedEventsForLongClick, - /*expectDropEvents= */ null); + /*expectDropEvents= */ null, + /* startsActivity = */ false); try (LauncherInstrumentation.Closable ignore = launcher.addContextLayer("dragged")) { WorkspaceAppIcon appIcon =