Loading tests/multivalentTests/tapl/com/android/launcher3/tapl/Folder.java +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.launcher3.tapl; import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; Loading Loading @@ -58,4 +60,7 @@ public class Folder { return mLauncher.getWorkspace(); } } Rect getDropLocationBounds() { return mLauncher.getVisibleBounds(mContainer); } } tests/multivalentTests/tapl/com/android/launcher3/tapl/FolderIcon.java +2 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import com.android.launcher3.testing.shared.TestProtocol; /** * Folder Icon, an app folder in workspace. */ public class FolderIcon implements FolderDragTarget { public class FolderIcon implements IconDragTarget { protected final UiObject2 mObject; protected final LauncherInstrumentation mLauncher; Loading Loading @@ -60,7 +60,7 @@ public class FolderIcon implements FolderDragTarget { /** This method requires public access, however should not be called in tests. */ @Override public FolderIcon getTargetFolder(Rect bounds) { public FolderIcon getTargetIcon(Rect bounds) { return this; } } tests/multivalentTests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +25 −5 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ import java.util.function.Supplier; /** * App icon on the workspace or all apps. */ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, WorkspaceDragSource { public abstract class HomeAppIcon extends AppIcon implements IconDragTarget, WorkspaceDragSource { private final String mAppName; Loading @@ -42,7 +42,7 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W * @param target the destination icon. */ @NonNull public FolderIcon dragToIcon(FolderDragTarget target) { public FolderIcon dragToIcon(IconDragTarget target) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer("want to drag icon")) { final Rect dropBounds = target.getDropLocationBounds(); Loading @@ -51,13 +51,33 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W () -> { final Rect bounds = target.getDropLocationBounds(); return new Point(bounds.centerX(), bounds.centerY()); }); FolderIcon result = target.getTargetFolder(dropBounds); }, false); FolderIcon result = target.getTargetIcon(dropBounds); mLauncher.assertTrue("Can't find the target folder.", result != null); return result; } } /** * Drag the AppIcon to the given position of a folder icon, and then inside that folder. * * @param target the destination folder. */ @NonNull public Folder dragToFolder(IconDragTarget target) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer("want to drag icon")) { Workspace.dragIconToWorkspace( mLauncher, this, () -> { final Rect bounds = target.getDropLocationBounds(); return new Point(bounds.centerX(), bounds.centerY()); }, /* isDraggingToFolder */ true); } return new Folder(mLauncher); } /** This method requires public access, however should not be called in tests. */ @Override public Rect getDropLocationBounds() { Loading @@ -66,7 +86,7 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W /** This method requires public access, however should not be called in tests. */ @Override public FolderIcon getTargetFolder(Rect bounds) { public FolderIcon getTargetIcon(Rect bounds) { for (FolderIcon folderIcon : mLauncher.getWorkspace().getFolderIcons()) { final Rect folderIconBounds = folderIcon.getDropLocationBounds(); if (bounds.contains(folderIconBounds.centerX(), folderIconBounds.centerY())) { Loading tests/multivalentTests/tapl/com/android/launcher3/tapl/FolderDragTarget.java→tests/multivalentTests/tapl/com/android/launcher3/tapl/IconDragTarget.java +2 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ package com.android.launcher3.tapl; import android.graphics.Rect; public interface FolderDragTarget { public interface IconDragTarget { /** This method requires public access, however should not be called in tests. */ Rect getDropLocationBounds(); /** This method requires public access, however should not be called in tests. */ FolderIcon getTargetFolder(Rect bounds); FolderIcon getTargetIcon(Rect bounds); } tests/multivalentTests/tapl/com/android/launcher3/tapl/Workspace.java +39 −9 Original line number Diff line number Diff line Loading @@ -551,7 +551,8 @@ public final class Workspace extends Home { * This function expects the launchable is inside the workspace and there is no drop event. */ static void dragIconToWorkspace( LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> destSupplier) { LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> destSupplier, boolean isDraggingToFolder) { dragIconToWorkspace( launcher, launchable, Loading @@ -559,7 +560,8 @@ public final class Workspace extends Home { /* isDecelerating= */ false, () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), /* expectDropEvents= */ null, /* startsActivity = */ false); /* startsActivity = */ false, isDraggingToFolder); } static void dragIconToWorkspace( Loading @@ -570,7 +572,8 @@ public final class Workspace extends Home { @Nullable Runnable expectDropEvents, boolean startsActivity) { dragIconToWorkspace(launcher, launchable, dest, /* isDecelerating */ true, expectLongClickEvents, expectDropEvents, startsActivity); expectLongClickEvents, expectDropEvents, startsActivity, /* isDraggingToFolder */ false); } static void dragIconToWorkspace( Loading @@ -580,7 +583,8 @@ public final class Workspace extends Home { boolean isDecelerating, Runnable expectLongClickEvents, @Nullable Runnable expectDropEvents, boolean startsActivity) { boolean startsActivity, boolean isDraggingToFolder) { try (LauncherInstrumentation.Closable ignored = launcher.addContextLayer( "want to drag icon to workspace")) { final long downTime = SystemClock.uptimeMillis(); Loading @@ -607,11 +611,27 @@ public final class Workspace extends Home { dragStart = screenEdge; } // targetDest.x is now between 0 and displayX so we found the target page, // we just have to put move the icon to the destination and drop it launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, // targetDest.x is now between 0 and displayX so we found the target page. // If not a folder, we just have to put move the icon to the destination and drop it. // If it's a folder we want to drag to the folder icon and then drag to the center of // that folder when it opens. if (isDraggingToFolder) { Point finalDragStart = dragStart; Point finalTargetDest = targetDest; Folder folder = executeAndWaitForFolderOpen(launcher, () -> launcher.movePointer( finalDragStart, finalTargetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER)); Rect dropBounds = folder.getDropLocationBounds(); dragStart = targetDest; targetDest = new Point(dropBounds.centerX(), dropBounds.centerY()); } launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents, startsActivity); } } Loading Loading @@ -696,6 +716,16 @@ public final class Workspace extends Home { () -> "Page scroll didn't happen", "Scrolling page"); } private static Folder executeAndWaitForFolderOpen(LauncherInstrumentation launcher, Runnable command) { launcher.executeAndWaitForEvent(command, event -> TestProtocol.FOLDER_OPENED_MESSAGE.equals( event.getClassName().toString()), () -> "Fail to open folder.", "open folder"); return new Folder(launcher); } static void dragIconToHotseat( LauncherInstrumentation launcher, Launchable launchable, Loading Loading
tests/multivalentTests/tapl/com/android/launcher3/tapl/Folder.java +5 −0 Original line number Diff line number Diff line Loading @@ -16,6 +16,8 @@ package com.android.launcher3.tapl; import android.graphics.Rect; import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; Loading Loading @@ -58,4 +60,7 @@ public class Folder { return mLauncher.getWorkspace(); } } Rect getDropLocationBounds() { return mLauncher.getVisibleBounds(mContainer); } }
tests/multivalentTests/tapl/com/android/launcher3/tapl/FolderIcon.java +2 −2 Original line number Diff line number Diff line Loading @@ -26,7 +26,7 @@ import com.android.launcher3.testing.shared.TestProtocol; /** * Folder Icon, an app folder in workspace. */ public class FolderIcon implements FolderDragTarget { public class FolderIcon implements IconDragTarget { protected final UiObject2 mObject; protected final LauncherInstrumentation mLauncher; Loading Loading @@ -60,7 +60,7 @@ public class FolderIcon implements FolderDragTarget { /** This method requires public access, however should not be called in tests. */ @Override public FolderIcon getTargetFolder(Rect bounds) { public FolderIcon getTargetIcon(Rect bounds) { return this; } }
tests/multivalentTests/tapl/com/android/launcher3/tapl/HomeAppIcon.java +25 −5 Original line number Diff line number Diff line Loading @@ -27,7 +27,7 @@ import java.util.function.Supplier; /** * App icon on the workspace or all apps. */ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, WorkspaceDragSource { public abstract class HomeAppIcon extends AppIcon implements IconDragTarget, WorkspaceDragSource { private final String mAppName; Loading @@ -42,7 +42,7 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W * @param target the destination icon. */ @NonNull public FolderIcon dragToIcon(FolderDragTarget target) { public FolderIcon dragToIcon(IconDragTarget target) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer("want to drag icon")) { final Rect dropBounds = target.getDropLocationBounds(); Loading @@ -51,13 +51,33 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W () -> { final Rect bounds = target.getDropLocationBounds(); return new Point(bounds.centerX(), bounds.centerY()); }); FolderIcon result = target.getTargetFolder(dropBounds); }, false); FolderIcon result = target.getTargetIcon(dropBounds); mLauncher.assertTrue("Can't find the target folder.", result != null); return result; } } /** * Drag the AppIcon to the given position of a folder icon, and then inside that folder. * * @param target the destination folder. */ @NonNull public Folder dragToFolder(IconDragTarget target) { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer("want to drag icon")) { Workspace.dragIconToWorkspace( mLauncher, this, () -> { final Rect bounds = target.getDropLocationBounds(); return new Point(bounds.centerX(), bounds.centerY()); }, /* isDraggingToFolder */ true); } return new Folder(mLauncher); } /** This method requires public access, however should not be called in tests. */ @Override public Rect getDropLocationBounds() { Loading @@ -66,7 +86,7 @@ public abstract class HomeAppIcon extends AppIcon implements FolderDragTarget, W /** This method requires public access, however should not be called in tests. */ @Override public FolderIcon getTargetFolder(Rect bounds) { public FolderIcon getTargetIcon(Rect bounds) { for (FolderIcon folderIcon : mLauncher.getWorkspace().getFolderIcons()) { final Rect folderIconBounds = folderIcon.getDropLocationBounds(); if (bounds.contains(folderIconBounds.centerX(), folderIconBounds.centerY())) { Loading
tests/multivalentTests/tapl/com/android/launcher3/tapl/FolderDragTarget.java→tests/multivalentTests/tapl/com/android/launcher3/tapl/IconDragTarget.java +2 −2 Original line number Diff line number Diff line Loading @@ -18,11 +18,11 @@ package com.android.launcher3.tapl; import android.graphics.Rect; public interface FolderDragTarget { public interface IconDragTarget { /** This method requires public access, however should not be called in tests. */ Rect getDropLocationBounds(); /** This method requires public access, however should not be called in tests. */ FolderIcon getTargetFolder(Rect bounds); FolderIcon getTargetIcon(Rect bounds); }
tests/multivalentTests/tapl/com/android/launcher3/tapl/Workspace.java +39 −9 Original line number Diff line number Diff line Loading @@ -551,7 +551,8 @@ public final class Workspace extends Home { * This function expects the launchable is inside the workspace and there is no drop event. */ static void dragIconToWorkspace( LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> destSupplier) { LauncherInstrumentation launcher, Launchable launchable, Supplier<Point> destSupplier, boolean isDraggingToFolder) { dragIconToWorkspace( launcher, launchable, Loading @@ -559,7 +560,8 @@ public final class Workspace extends Home { /* isDecelerating= */ false, () -> launcher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT), /* expectDropEvents= */ null, /* startsActivity = */ false); /* startsActivity = */ false, isDraggingToFolder); } static void dragIconToWorkspace( Loading @@ -570,7 +572,8 @@ public final class Workspace extends Home { @Nullable Runnable expectDropEvents, boolean startsActivity) { dragIconToWorkspace(launcher, launchable, dest, /* isDecelerating */ true, expectLongClickEvents, expectDropEvents, startsActivity); expectLongClickEvents, expectDropEvents, startsActivity, /* isDraggingToFolder */ false); } static void dragIconToWorkspace( Loading @@ -580,7 +583,8 @@ public final class Workspace extends Home { boolean isDecelerating, Runnable expectLongClickEvents, @Nullable Runnable expectDropEvents, boolean startsActivity) { boolean startsActivity, boolean isDraggingToFolder) { try (LauncherInstrumentation.Closable ignored = launcher.addContextLayer( "want to drag icon to workspace")) { final long downTime = SystemClock.uptimeMillis(); Loading @@ -607,11 +611,27 @@ public final class Workspace extends Home { dragStart = screenEdge; } // targetDest.x is now between 0 and displayX so we found the target page, // we just have to put move the icon to the destination and drop it launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, // targetDest.x is now between 0 and displayX so we found the target page. // If not a folder, we just have to put move the icon to the destination and drop it. // If it's a folder we want to drag to the folder icon and then drag to the center of // that folder when it opens. if (isDraggingToFolder) { Point finalDragStart = dragStart; Point finalTargetDest = targetDest; Folder folder = executeAndWaitForFolderOpen(launcher, () -> launcher.movePointer( finalDragStart, finalTargetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER)); Rect dropBounds = folder.getDropLocationBounds(); dragStart = targetDest; targetDest = new Point(dropBounds.centerX(), dropBounds.centerY()); } launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating, downTime, SystemClock.uptimeMillis(), false, LauncherInstrumentation.GestureScope.DONT_EXPECT_PILFER); dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents, startsActivity); } } Loading Loading @@ -696,6 +716,16 @@ public final class Workspace extends Home { () -> "Page scroll didn't happen", "Scrolling page"); } private static Folder executeAndWaitForFolderOpen(LauncherInstrumentation launcher, Runnable command) { launcher.executeAndWaitForEvent(command, event -> TestProtocol.FOLDER_OPENED_MESSAGE.equals( event.getClassName().toString()), () -> "Fail to open folder.", "open folder"); return new Folder(launcher); } static void dragIconToHotseat( LauncherInstrumentation launcher, Launchable launchable, Loading