diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 3c6aff4799..366b868ee8 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -18,8 +18,6 @@ package com.android.launcher3.ui; import static androidx.test.InstrumentationRegistry.getInstrumentation; -import android.platform.test.annotations.IwTest; - import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; @@ -31,6 +29,7 @@ import static org.junit.Assume.assumeTrue; import android.content.Intent; import android.graphics.Point; +import android.platform.test.annotations.IwTest; import androidx.test.filters.LargeTest; import androidx.test.runner.AndroidJUnit4; @@ -435,6 +434,23 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL); } + @Test + @PortraitLandscape + public void testDragAndCancelAppIcon() { + final HomeAppIcon homeAppIcon = createShortcutInCenterIfNotExist(GMAIL_APP_NAME); + Point positionBeforeDrag = + mLauncher.getWorkspace().getWorkspaceIconsPositions().get(GMAIL_APP_NAME); + assertNotNull("App not found in Workspace before dragging.", positionBeforeDrag); + + mLauncher.getWorkspace().dragAndCancelAppIcon(homeAppIcon); + + Point positionAfterDrag = + mLauncher.getWorkspace().getWorkspaceIconsPositions().get(GMAIL_APP_NAME); + assertNotNull("App not found in Workspace after dragging.", positionAfterDrag); + assertEquals("App not returned to same position in Workspace after drag & cancel", + positionBeforeDrag, positionAfterDrag); + } + @Test @PortraitLandscape public void testDeleteFromWorkspace() throws Exception { diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 98a48c0549..d4400046fb 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -138,6 +138,15 @@ public final class LauncherInstrumentation { OUTSIDE_WITH_KEYCODE, } + /** + * Represents a point in the code at which a callback can run. + */ + public enum CALLBACK_RUN_POINT { + CALLBACK_HOLD_BEFORE_DROP + } + + private Consumer mCallbackAtRunPoint = null; + // Base class for launcher containers. abstract static class VisibleContainer { protected final LauncherInstrumentation mLauncher; @@ -1963,4 +1972,20 @@ public final class LauncherInstrumentation { LauncherInstrumentation.GestureScope.INSIDE); } } + + /** + * Sets the consumer to run callbacks at all run-points. + */ + public void setRunPointCallback(Consumer callback) { + mCallbackAtRunPoint = callback; + } + + /** + * Runs the callback at the specified point if it exists. + */ + void runCallbackIfActive(CALLBACK_RUN_POINT runPoint) { + if (mCallbackAtRunPoint != null) { + mCallbackAtRunPoint.accept(runPoint); + } + } } diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index 2c9fdb357e..425a90a988 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -18,6 +18,7 @@ package com.android.launcher3.tapl; import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_SCROLLED; +import static com.android.launcher3.tapl.LauncherInstrumentation.CALLBACK_RUN_POINT.CALLBACK_HOLD_BEFORE_DROP; import static com.android.launcher3.testing.shared.TestProtocol.ALL_APPS_STATE_ORDINAL; import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL; @@ -301,6 +302,31 @@ public final class Workspace extends Home { targetId).getVisibleCenter(); } + /** + * Drag the appIcon from the workspace and cancel by dragging icon to corner of screen where no + * drop point exists. + * + * @param homeAppIcon to be dragged. + */ + @NonNull + public Workspace dragAndCancelAppIcon(HomeAppIcon homeAppIcon) { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "dragging app icon across workspace")) { + dragIconToWorkspace( + mLauncher, + homeAppIcon, + () -> new Point(0, 0), + () -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), + null); + + try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( + "dragged the app across workspace")) { + return new Workspace(mLauncher); + } + } + } + /** * Delete the appIcon from the workspace. * @@ -493,6 +519,7 @@ public final class Workspace extends Home { launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.INSIDE); + launcher.runCallbackIfActive(CALLBACK_HOLD_BEFORE_DROP); dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents); } }