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
This commit is contained in:
Sunny Goyal 2019-09-24 13:58:32 -07:00
parent a4deb15c30
commit 599e95bdde
3 changed files with 26 additions and 13 deletions

View File

@ -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<RecentsActivity> f) throws Exception {
protected void executeOnRecents(Consumer<RecentsActivity> f) {
getFromRecents(r -> {
f.accept(r);
return null;
return true;
});
}
protected <T> T getFromRecents(Function<RecentsActivity, T> f) throws Exception {
protected <T> T getFromRecents(Function<RecentsActivity, T> 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);

View File

@ -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;
}

View File

@ -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);