From 25b36f7716b62252d899ae26177a06ba8779c6bc Mon Sep 17 00:00:00 2001 From: Nicolo' Mazzucato Date: Mon, 23 May 2022 15:00:45 +0000 Subject: [PATCH] Fix flakiness in getIconPosition test After uninstalling the app, it was disappearing after some time. For this reason, tryGetWorkspaceAppIcon was still returning it after the uninstall. Fixes: 232009313 Test: atest TaplTestsLauncher3 Change-Id: I62e3a8f9a481e9786a136b6c00051c1025ab5b32 --- .../launcher3/ui/TaplTestsLauncher3.java | 28 +++++++++---------- .../com/android/launcher3/tapl/Workspace.java | 14 ++++++++++ 2 files changed, 27 insertions(+), 15 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 8a97c6ba5b..c93be8bbcb 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -53,7 +53,6 @@ import com.android.launcher3.widget.picker.WidgetsFullSheet; import com.android.launcher3.widget.picker.WidgetsRecyclerView; import org.junit.Before; -import org.junit.Rule; import org.junit.Test; import org.junit.runner.RunWith; @@ -199,8 +198,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { // Test that ensureWorkspaceIsScrollable adds a page by dragging an icon there. executeOnLauncher(launcher -> assertFalse("Initial workspace state is scrollable", isWorkspaceScrollable(launcher))); - assertNull("Chrome app was found on empty workspace", - workspace.tryGetWorkspaceAppIcon("Chrome")); + workspace.verifyWorkspaceAppIconIsGone( + "Chrome app was found on empty workspace", "Chrome"); workspace.ensureWorkspaceIsScrollable(); @@ -388,10 +387,10 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { folder.getAppIcon(GMAIL_APP_NAME); Workspace workspace = folder.close(); - assertNull(STORE_APP_NAME + " should be moved to a folder.", - workspace.tryGetWorkspaceAppIcon(STORE_APP_NAME)); - assertNull(GMAIL_APP_NAME + " should be moved to a folder.", - workspace.tryGetWorkspaceAppIcon(GMAIL_APP_NAME)); + workspace.verifyWorkspaceAppIconIsGone(STORE_APP_NAME + " should be moved to a folder.", + STORE_APP_NAME); + workspace.verifyWorkspaceAppIconIsGone(GMAIL_APP_NAME + " should be moved to a folder.", + GMAIL_APP_NAME); final HomeAppIcon mapIcon = createShortcutInCenterIfNotExist(MAPS_APP_NAME); folderIcon = mapIcon.dragToIcon(folderIcon); @@ -399,8 +398,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { folder.getAppIcon(MAPS_APP_NAME); workspace = folder.close(); - assertNull(MAPS_APP_NAME + " should be moved to a folder.", - workspace.tryGetWorkspaceAppIcon(MAPS_APP_NAME)); + workspace.verifyWorkspaceAppIconIsGone(MAPS_APP_NAME + " should be moved to a folder.", + MAPS_APP_NAME); } @Test @@ -424,8 +423,9 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { for (String appName : new String[]{"Gmail", "Play Store", APP_NAME}) { final HomeAppIcon homeAppIcon = createShortcutInCenterIfNotExist(appName); Workspace workspace = mLauncher.getWorkspace().deleteAppIcon(homeAppIcon); - assertNull(appName + " app was found after being deleted from workspace", - workspace.tryGetWorkspaceAppIcon(appName)); + workspace.verifyWorkspaceAppIconIsGone( + appName + " app was found after being deleted from workspace", + appName); } } @@ -509,10 +509,8 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { .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)); + mLauncher.getWorkspace().verifyWorkspaceAppIconIsGone( + DUMMY_APP_NAME + " was expected to disappear after uninstall.", DUMMY_APP_NAME); Map finalPositions = mLauncher.getWorkspace().getWorkspaceIconsPositions(); diff --git a/tests/tapl/com/android/launcher3/tapl/Workspace.java b/tests/tapl/com/android/launcher3/tapl/Workspace.java index eb7f05bd1e..e91974024e 100644 --- a/tests/tapl/com/android/launcher3/tapl/Workspace.java +++ b/tests/tapl/com/android/launcher3/tapl/Workspace.java @@ -140,6 +140,20 @@ public final class Workspace extends Home { } } + /** + * Waits for an app icon to be gone (e.g. after uninstall). Fails if it remains. + * + * @param errorMessage error message thrown then the icon doesn't disappear. + * @param appName app that should be gone. + */ + public void verifyWorkspaceAppIconIsGone(String errorMessage, String appName) { + final UiObject2 workspace = verifyActiveContainer(); + assertTrue(errorMessage, + workspace.wait( + Until.gone(AppIcon.getAppIconSelector(appName, mLauncher)), + LauncherInstrumentation.WAIT_TIME_MS)); + } + /** * Returns an icon for the app; fails if the icon doesn't exist.