Loading tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -613,6 +613,10 @@ public abstract class AbstractLauncherUiTest { return createShortcutIfNotExist(name, dimension.x / 2, dimension.y / 2); } protected HomeAppIcon createShortcutIfNotExist(String name, Point cellPosition) { return createShortcutIfNotExist(name, cellPosition.x, cellPosition.y); } protected HomeAppIcon createShortcutIfNotExist(String name, int cellX, int cellY) { HomeAppIcon homeAppIcon = mLauncher.getWorkspace().tryGetWorkspaceAppIcon(name); if (homeAppIcon == null) { Loading tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +50 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.launcher3.ui; import static androidx.test.InstrumentationRegistry.getInstrumentation; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading Loading @@ -54,11 +56,16 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.io.IOException; import java.util.Map; @LargeTest @RunWith(AndroidJUnit4.class) public class TaplTestsLauncher3 extends AbstractLauncherUiTest { private static final String APP_NAME = "LauncherTestApp"; private static final String DUMMY_APP_NAME = "Aardwolf"; private static final String MAPS_APP_NAME = "Maps"; private static final String STORE_APP_NAME = "Play Store"; @Before public void setUp() throws Exception { Loading Loading @@ -462,15 +469,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { @Test @PortraitLandscape public void testDragAppIconToWorkspaceCell() throws Exception { final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions(); Point[] targets = { new Point(0, 1), new Point(0, dimensions.y - 2), new Point(dimensions.x - 1, 1), new Point(dimensions.x - 1, dimensions.y - 2), new Point(dimensions.x / 2, dimensions.y / 2) }; Point[] targets = getCornersAndCenterPositions(); for (Point target : targets) { final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps(); Loading @@ -491,6 +490,48 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } @Test public void getIconsPosition_afterIconRemoved_notContained() throws IOException { Point[] gridPositions = getCornersAndCenterPositions(); createShortcutIfNotExist(STORE_APP_NAME, gridPositions[0]); createShortcutIfNotExist(MAPS_APP_NAME, gridPositions[1]); TestUtil.installDummyApp(); try { createShortcutIfNotExist(DUMMY_APP_NAME, gridPositions[2]); Map<String, Point> initialPositions = mLauncher.getWorkspace().getWorkspaceIconsPositions(); assertThat(initialPositions.keySet()) .containsAtLeast(DUMMY_APP_NAME, MAPS_APP_NAME, STORE_APP_NAME); mLauncher.getWorkspace().getWorkspaceAppIcon(DUMMY_APP_NAME).uninstall(); assertNull( DUMMY_APP_NAME + " app was found after being uninstalled", mLauncher.getWorkspace().tryGetWorkspaceAppIcon(DUMMY_APP_NAME)); Map<String, Point> finalPositions = mLauncher.getWorkspace().getWorkspaceIconsPositions(); assertThat(finalPositions).doesNotContainKey(DUMMY_APP_NAME); } finally { TestUtil.uninstallDummyApp(); } } /** * @return List of workspace grid coordinates. Those are not pixels. See {@link * Workspace#getIconGridDimensions()} */ private Point[] getCornersAndCenterPositions() { final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions(); return new Point[] { new Point(0, 1), new Point(0, dimensions.y - 2), new Point(dimensions.x - 1, 1), new Point(dimensions.x - 1, dimensions.y - 2), new Point(dimensions.x / 2, dimensions.y / 2) }; } public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } Loading tests/tapl/com/android/launcher3/tapl/Workspace.java +16 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.testing.WorkspaceCellCenterRequest; import java.util.List; import java.util.Map; import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; Loading Loading @@ -222,6 +223,21 @@ public final class Workspace extends Home { mHotseat, AppIcon.getAppIconSelector(appName, mLauncher))); } /** * @return map of text -> center of the view. In case of icons with the same name, the one with * lower x coordinate is selected. */ public Map<String, Point> getWorkspaceIconsPositions() { final UiObject2 workspace = verifyActiveContainer(); List<UiObject2> workspaceIcons = mLauncher.waitForObjectsInContainer(workspace, AppIcon.getAnyAppIconSelector()); return workspaceIcons.stream() .collect( Collectors.toMap( /* keyMapper= */ UiObject2::getText, /* valueMapper= */ UiObject2::getVisibleCenter, /* mergeFunction= */ (p1, p2) -> p1.x < p2.x ? p1 : p2)); } /* * Get the center point of the delete/uninstall icon in the drop target bar. */ Loading Loading
tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +4 −0 Original line number Diff line number Diff line Loading @@ -613,6 +613,10 @@ public abstract class AbstractLauncherUiTest { return createShortcutIfNotExist(name, dimension.x / 2, dimension.y / 2); } protected HomeAppIcon createShortcutIfNotExist(String name, Point cellPosition) { return createShortcutIfNotExist(name, cellPosition.x, cellPosition.y); } protected HomeAppIcon createShortcutIfNotExist(String name, int cellX, int cellY) { HomeAppIcon homeAppIcon = mLauncher.getWorkspace().tryGetWorkspaceAppIcon(name); if (homeAppIcon == null) { Loading
tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +50 −9 Original line number Diff line number Diff line Loading @@ -18,6 +18,8 @@ package com.android.launcher3.ui; import static androidx.test.InstrumentationRegistry.getInstrumentation; import static com.google.common.truth.Truth.assertThat; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; Loading Loading @@ -54,11 +56,16 @@ import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import java.io.IOException; import java.util.Map; @LargeTest @RunWith(AndroidJUnit4.class) public class TaplTestsLauncher3 extends AbstractLauncherUiTest { private static final String APP_NAME = "LauncherTestApp"; private static final String DUMMY_APP_NAME = "Aardwolf"; private static final String MAPS_APP_NAME = "Maps"; private static final String STORE_APP_NAME = "Play Store"; @Before public void setUp() throws Exception { Loading Loading @@ -462,15 +469,7 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { @Test @PortraitLandscape public void testDragAppIconToWorkspaceCell() throws Exception { final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions(); Point[] targets = { new Point(0, 1), new Point(0, dimensions.y - 2), new Point(dimensions.x - 1, 1), new Point(dimensions.x - 1, dimensions.y - 2), new Point(dimensions.x / 2, dimensions.y / 2) }; Point[] targets = getCornersAndCenterPositions(); for (Point target : targets) { final HomeAllApps allApps = mLauncher.getWorkspace().switchToAllApps(); Loading @@ -491,6 +490,48 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { } } @Test public void getIconsPosition_afterIconRemoved_notContained() throws IOException { Point[] gridPositions = getCornersAndCenterPositions(); createShortcutIfNotExist(STORE_APP_NAME, gridPositions[0]); createShortcutIfNotExist(MAPS_APP_NAME, gridPositions[1]); TestUtil.installDummyApp(); try { createShortcutIfNotExist(DUMMY_APP_NAME, gridPositions[2]); Map<String, Point> initialPositions = mLauncher.getWorkspace().getWorkspaceIconsPositions(); assertThat(initialPositions.keySet()) .containsAtLeast(DUMMY_APP_NAME, MAPS_APP_NAME, STORE_APP_NAME); mLauncher.getWorkspace().getWorkspaceAppIcon(DUMMY_APP_NAME).uninstall(); assertNull( DUMMY_APP_NAME + " app was found after being uninstalled", mLauncher.getWorkspace().tryGetWorkspaceAppIcon(DUMMY_APP_NAME)); Map<String, Point> finalPositions = mLauncher.getWorkspace().getWorkspaceIconsPositions(); assertThat(finalPositions).doesNotContainKey(DUMMY_APP_NAME); } finally { TestUtil.uninstallDummyApp(); } } /** * @return List of workspace grid coordinates. Those are not pixels. See {@link * Workspace#getIconGridDimensions()} */ private Point[] getCornersAndCenterPositions() { final Point dimensions = mLauncher.getWorkspace().getIconGridDimensions(); return new Point[] { new Point(0, 1), new Point(0, dimensions.y - 2), new Point(dimensions.x - 1, 1), new Point(dimensions.x - 1, dimensions.y - 2), new Point(dimensions.x / 2, dimensions.y / 2) }; } public static String getAppPackageName() { return getInstrumentation().getContext().getPackageName(); } Loading
tests/tapl/com/android/launcher3/tapl/Workspace.java +16 −0 Original line number Diff line number Diff line Loading @@ -43,6 +43,7 @@ import com.android.launcher3.testing.TestProtocol; import com.android.launcher3.testing.WorkspaceCellCenterRequest; import java.util.List; import java.util.Map; import java.util.function.Supplier; import java.util.regex.Pattern; import java.util.stream.Collectors; Loading Loading @@ -222,6 +223,21 @@ public final class Workspace extends Home { mHotseat, AppIcon.getAppIconSelector(appName, mLauncher))); } /** * @return map of text -> center of the view. In case of icons with the same name, the one with * lower x coordinate is selected. */ public Map<String, Point> getWorkspaceIconsPositions() { final UiObject2 workspace = verifyActiveContainer(); List<UiObject2> workspaceIcons = mLauncher.waitForObjectsInContainer(workspace, AppIcon.getAnyAppIconSelector()); return workspaceIcons.stream() .collect( Collectors.toMap( /* keyMapper= */ UiObject2::getText, /* valueMapper= */ UiObject2::getVisibleCenter, /* mergeFunction= */ (p1, p2) -> p1.x < p2.x ? p1 : p2)); } /* * Get the center point of the delete/uninstall icon in the drop target bar. */ Loading