From 599e95bddedf7b6efe42692d48bfe23faec5ec32 Mon Sep 17 00:00:00 2001 From: Sunny Goyal Date: Tue, 24 Sep 2019 13:58:32 -0700 Subject: [PATCH] Fixing some tests > Adding retry to fallback recents tests > Fixing provider test after provider name change > Fixing AllApps icon detection when there is no more scroll available Bug: 141390432 Bug: 141523101 Bug: 141517004 Bug: 141524555 Bug: 141522764 Change-Id: I425638d20c053206134835dabde819f16160f035 --- .../quickstep/FallbackRecentsTest.java | 20 ++++++++++++++----- .../ui/DefaultLayoutProviderTest.java | 4 ++-- .../com/android/launcher3/tapl/AllApps.java | 15 ++++++++------ 3 files changed, 26 insertions(+), 13 deletions(-) diff --git a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java index 986f845985..3697230ee5 100644 --- a/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java +++ b/quickstep/tests/src/com/android/quickstep/FallbackRecentsTest.java @@ -53,6 +53,7 @@ import com.android.launcher3.tapl.LauncherInstrumentation; import com.android.launcher3.tapl.OverviewTask; import com.android.launcher3.tapl.TestHelpers; import com.android.launcher3.testcomponent.TestCommandReceiver; +import com.android.launcher3.util.Wait; import com.android.launcher3.util.rule.FailureWatcher; import com.android.launcher3.util.rule.SimpleActivityRule; import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch; @@ -147,16 +148,25 @@ public class FallbackRecentsTest { mLauncher.getBackground().switchToOverview(); } - protected void executeOnRecents(Consumer f) throws Exception { + protected void executeOnRecents(Consumer f) { getFromRecents(r -> { f.accept(r); - return null; + return true; }); } - protected T getFromRecents(Function f) throws Exception { + protected T getFromRecents(Function f) { if (!TestHelpers.isInLauncherProcess()) return null; - return MAIN_EXECUTOR.submit(() -> f.apply(mActivityMonitor.getActivity())).get(); + Object[] result = new Object[1]; + Wait.atMost("Failed to get from recents", () -> MAIN_EXECUTOR.submit(() -> { + RecentsActivity activity = mActivityMonitor.getActivity(); + if (activity == null) { + return false; + } + result[0] = f.apply(activity); + return true; + }).get(), DEFAULT_UI_TIMEOUT); + return (T) result[0]; } private BaseOverview pressHomeAndGoToOverview() { @@ -166,7 +176,7 @@ public class FallbackRecentsTest { @NavigationModeSwitch @Test - public void testOverview() throws Exception { + public void testOverview() { startAppFast(getAppPackageName()); startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR)); startTestActivity(2); diff --git a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java index a76b4a4886..3d4e17bf5c 100644 --- a/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java +++ b/tests/src/com/android/launcher3/ui/DefaultLayoutProviderTest.java @@ -30,7 +30,7 @@ import androidx.test.filters.MediumTest; import androidx.test.runner.AndroidJUnit4; import com.android.launcher3.LauncherAppWidgetProviderInfo; -import com.android.launcher3.testcomponent.TestCommandReceiver; +import com.android.launcher3.testcomponent.TestCommandProvider; import com.android.launcher3.util.LauncherLayoutBuilder; import com.android.launcher3.util.rule.ShellCommandRule; @@ -63,7 +63,7 @@ public class DefaultLayoutProviderTest extends AbstractLauncherUiTest { PackageManager pm = mTargetContext.getPackageManager(); ProviderInfo pi = pm.getProviderInfo(new ComponentName(mContext, - TestCommandReceiver.class), 0); + TestCommandProvider.class), 0); mAuthority = pi.authority; } diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index 0359ff7e92..7754b5e52b 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -54,7 +54,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { } private boolean hasClickableIcon(UiObject2 allAppsContainer, UiObject2 appListRecycler, - BySelector appIconSelector, int bottomOffset) { + BySelector appIconSelector, int displayBottom) { final UiObject2 icon = appListRecycler.findObject(appIconSelector); if (icon == null) { LauncherInstrumentation.log("hasClickableIcon: icon not visible"); @@ -66,7 +66,7 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { LauncherInstrumentation.log("hasClickableIcon: icon center is under search box"); return false; } - if (iconBounds.bottom > bottomOffset) { + if (iconBounds.bottom > displayBottom) { LauncherInstrumentation.log("hasClickableIcon: icon center bellow bottom offset"); return false; } @@ -97,7 +97,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { int bottomGestureMargin = ResourceUtils.getNavbarSize( ResourceUtils.NAVBAR_BOTTOM_GESTURE_SIZE, mLauncher.getResources()) + 1; - int bottomOffset = mLauncher.getDevice().getDisplayHeight() - bottomGestureMargin; + int deviceHeight = mLauncher.getDevice().getDisplayHeight(); + int displayBottom = deviceHeight - bottomGestureMargin; allAppsContainer.setGestureMargins( 0, getSearchBox(allAppsContainer).getVisibleBounds().bottom + 1, @@ -105,13 +106,13 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { bottomGestureMargin); final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher); if (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, - bottomOffset)) { + displayBottom)) { scrollBackToBeginning(); int attempts = 0; int scroll = getAllAppsScroll(); try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) { while (!hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, - bottomOffset)) { + displayBottom)) { mLauncher.scroll(allAppsContainer, Direction.DOWN, 0.8f, null, 50); final int newScroll = getAllAppsScroll(); if (newScroll == scroll) break; @@ -126,9 +127,11 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer { verifyActiveContainer(); } + // Ignore bottom offset selection here as there might not be any scroll more scroll + // region available. mLauncher.assertTrue("Unable to scroll to a clickable icon: " + appName, hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector, - bottomOffset)); + deviceHeight)); final UiObject2 appIcon = mLauncher.waitForObjectInContainer(appListRecycler, appIconSelector);