From 9a8964b122261b4cdda61928a6f9e023231a8997 Mon Sep 17 00:00:00 2001 From: Ling WO Date: Wed, 4 May 2022 14:37:04 -0700 Subject: [PATCH] Cherrypick needed for merge conflict with ag/18875278 Support move to a specific location on workspace for all workspaceDragSource, so other workspaceDragSource such as HomeAppIconMenuItem can be moved to a fixed location during testing to avoid ui-diff flakiess Design doc: https://docs.google.com/document/d/1tZWbfsv86O6UAKtHJrDBGecu-x3ac51qmWvARDg057M Test: atest Bug: 216189838 Change-Id: Ia6ef7338beb257d0313be17a53a9fc59ae39fdb6 (cherry picked from commit fe8fb4d1379eecbfd68dc8538a2af891353f59d1) --- .../launcher3/ui/TaplTestsLauncher3.java | 19 ++++++++++ .../android/launcher3/tapl/HomeAppIcon.java | 34 ----------------- .../com/android/launcher3/tapl/Workspace.java | 7 ++-- .../launcher3/tapl/WorkspaceDragSource.java | 38 ++++++++++++++++++- 4 files changed, 60 insertions(+), 38 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index e00b5693bc..0f29abc3d2 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -521,6 +521,25 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } + @Test + @PortraitLandscape + public void testDragShortcutToWorkspaceCell() throws Exception { + Point[] targets = getCornersAndCenterPositions(); + + for (Point target : targets) { + final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps(); + allApps.freeze(); + try { + allApps.getAppIcon(APP_NAME) + .openDeepShortcutMenu() + .getMenuItem(0) + .dragToWorkspace(target.x, target.y); + } finally { + allApps.unfreeze(); + } + } + } + /** * @return List of workspace grid coordinates. Those are not pixels. See {@link * Workspace#getIconGridDimensions()} diff --git a/tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java b/tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java index 71d8ba9a41..75465046d5 100644 --- a/tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +++ b/tests/tapl/com/android/launcher3/tapl/HomeAppIcon.java @@ -22,8 +22,6 @@ import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; -import java.util.function.Supplier; - /** * App icon on the workspace or all apps. */ @@ -102,38 +100,6 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W } } - /** - * Drag an object to the given cell in workspace. The target cell must be empty. - * - * @param cellX zero based column number, starting from the left of the screen. - * @param cellY zero based row number, starting from the top of the screen. - */ - public HomeAppIcon dragToWorkspace(int cellX, int cellY) { - try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); - LauncherInstrumentation.Closable c = mLauncher.addContextLayer( - String.format("want to drag the icon to cell(%d, %d)", cellX, cellY)) - ) { - final Supplier dest = () -> Workspace.getCellCenter(mLauncher, cellX, cellY); - Workspace.dragIconToWorkspace( - mLauncher, - /* launchable= */ this, - dest, - () -> addExpectedEventsForLongClick(), - /*expectDropEvents= */ null); - try (LauncherInstrumentation.Closable ignore = mLauncher.addContextLayer("dragged")) { - WorkspaceAppIcon appIcon = - (WorkspaceAppIcon) mLauncher.getWorkspace().getWorkspaceAppIcon(mAppName); - mLauncher.assertTrue( - String.format( - "The %s icon should be in the cell (%d, %d).", mAppName, cellX, - cellY), - appIcon.isInCell(cellX, cellY)); - return appIcon; - } - } - } - - /** This method requires public access, however should not be called in tests. */ @Override public Launchable getLaunchable() { diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index e91974024e..42ba18c36d 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -228,10 +228,11 @@ public final class Workspace extends Home { private void dragIcon(UiObject2 workspace, HomeAppIcon homeAppIcon, int pageDelta) { int pageWidth = mLauncher.getDevice().getDisplayWidth() / pagesPerScreen(); int targetX = (pageWidth / 2) + pageWidth * pageDelta; + int targetY = mLauncher.getVisibleBounds(workspace).centerY(); dragIconToWorkspace( mLauncher, homeAppIcon, - new Point(targetX, mLauncher.getVisibleBounds(workspace).centerY()), + () -> new Point(targetX, targetY), false, false, () -> mLauncher.expectEvent( @@ -386,7 +387,7 @@ public final class Workspace extends Home { } static void dragIconToWorkspace(LauncherInstrumentation launcher, Launchable launchable, - Point dest, boolean startsActivity, boolean isWidgetShortcut, + Supplier dest, boolean startsActivity, boolean isWidgetShortcut, Runnable expectLongClickEvents) { Runnable expectDropEvents = null; if (startsActivity || isWidgetShortcut) { @@ -394,7 +395,7 @@ public final class Workspace extends Home { LauncherInstrumentation.EVENT_START); } dragIconToWorkspace( - launcher, launchable, () -> dest, expectLongClickEvents, expectDropEvents); + launcher, launchable, dest, expectLongClickEvents, expectDropEvents); } /** diff --git a/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java b/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java index d8d4420005..021cc98c23 100644 --- a/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java +++ b/tests/tapl/com/android/launcher3/tapl/WorkspaceDragSource.java @@ -17,6 +17,8 @@ package com.android.launcher3.tapl; import android.graphics.Point; +import java.util.function.Supplier; + /** Launchable that can serve as a source for dragging and dropping to the workspace. */ interface WorkspaceDragSource { @@ -36,7 +38,7 @@ interface WorkspaceDragSource { Workspace.dragIconToWorkspace( launcher, launchable, - new Point( + () -> new Point( launchableCenter.x >= width ? launchableCenter.x - width / 2 : launchableCenter.x + width / 2, @@ -47,6 +49,40 @@ interface WorkspaceDragSource { } } + /** + * Drag an object to the given cell in workspace. The target cell must be empty. + * + * @param cellX zero based column number, starting from the left of the screen. + * @param cellY zero based row number, starting from the top of the screen. * + */ + default HomeAppIcon dragToWorkspace(int cellX, int cellY) { + Launchable launchable = getLaunchable(); + final String iconName = launchable.getObject().getText(); + LauncherInstrumentation launcher = launchable.mLauncher; + try (LauncherInstrumentation.Closable e = launcher.eventsCheck(); + LauncherInstrumentation.Closable c = launcher.addContextLayer( + String.format("want to drag the icon to cell(%d, %d)", cellX, cellY))) { + final Supplier dest = () -> Workspace.getCellCenter(launcher, cellX, cellY); + Workspace.dragIconToWorkspace( + launcher, + launchable, + dest, + launchable::addExpectedEventsForLongClick, + /*expectDropEvents= */ null); + + try (LauncherInstrumentation.Closable ignore = launcher.addContextLayer("dragged")) { + WorkspaceAppIcon appIcon = + (WorkspaceAppIcon) launcher.getWorkspace().getWorkspaceAppIcon(iconName); + launcher.assertTrue( + String.format( + "The %s icon should be in the cell (%d, %d).", iconName, cellX, + cellY), + appIcon.isInCell(cellX, cellY)); + return appIcon; + } + } + } + /** This method requires public access, however should not be called in tests. */ Launchable getLaunchable(); }