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
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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.
|
||||
*/
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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(
|
||||
|
||||
@@ -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<Point> 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<Point> 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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -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 =
|
||||
|
||||
Reference in New Issue
Block a user