Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit 0c7fd04a authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Removing verifying internal Launcher state from tests

I’ve never seen a useful failure from these checks, and now I’m seeing a false positive error. That error is fixable by reworking the code, but I think the value of these checks is not worth the effort.

Bug: 322823209
Test: presubmit
Flag: N/A
Change-Id: If675dad254fb82a2a842ef3f9054936f38de1cff
parent 0b32b7a9
Loading
Loading
Loading
Loading
+0 −38
Original line number Diff line number Diff line
@@ -25,8 +25,6 @@ import androidx.test.uiautomator.Until;

import com.android.launcher3.Launcher;
import com.android.launcher3.tapl.LaunchedAppState;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.quickstep.views.RecentsView;

@@ -55,31 +53,6 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
        }
    }

    @Override
    protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType,
            boolean isResumed, boolean isStarted) {
        if (ENABLE_SHELL_TRANSITIONS || !isInLiveTileMode(launcher, expectedContainerType)) {
            super.checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);
        } else {
            assertTrue("[Live Tile] hasBeenResumed() == isStarted(), hasBeenResumed(): "
                            + isResumed, isResumed != isStarted);
        }
    }

    @Override
    protected void checkLauncherStateInOverview(Launcher launcher,
            ContainerType expectedContainerType, boolean isStarted, boolean isResumed) {
        if (ENABLE_SHELL_TRANSITIONS || !isInLiveTileMode(launcher, expectedContainerType)) {
            super.checkLauncherStateInOverview(launcher, expectedContainerType, isStarted,
                    isResumed);
        } else {
            assertTrue(
                    "[Live Tile] Launcher is not started or has been resumed in state: "
                            + expectedContainerType,
                    isStarted && !isResumed);
        }
    }

    protected void assertTestActivityIsRunning(int activityNumber, String message) {
        assertTrue(message, mDevice.wait(
                Until.hasObject(By.pkg(getAppPackageName()).text("TestActivity" + activityNumber)),
@@ -94,15 +67,4 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
                isInLaunchedApp(launcher)));
        return launchedAppState;
    }

    private boolean isInLiveTileMode(Launcher launcher,
            LauncherInstrumentation.ContainerType expectedContainerType) {
        if (expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) {
            return false;
        }

        RecentsView recentsView = launcher.getOverviewPanel();
        return recentsView.getSizeStrategy().isInLiveTileMode()
                && recentsView.getRunningTaskViewId() != -1;
    }
}
+0 −93
Original line number Diff line number Diff line
@@ -55,14 +55,11 @@ import androidx.test.uiautomator.Until;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.Utilities;
import com.android.launcher3.statemanager.StateManager;
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.tapl.HomeAppIcon;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.LauncherInstrumentation.ContainerType;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.launcher3.testing.shared.TestProtocol;
import com.android.launcher3.util.LooperExecutor;
import com.android.launcher3.util.SimpleBroadcastReceiver;
import com.android.launcher3.util.TestUtil;
@@ -204,10 +201,6 @@ public abstract class AbstractLauncherUiTest {
            mLauncher.setSystemHealthSupplier(startTime -> TestCommandReceiver.callCommand(
                            TestCommandReceiver.GET_SYSTEM_HEALTH_MESSAGE, startTime.toString())
                    .getString("result"));
            mLauncher.setOnSettledStateAction(
                    containerType -> executeOnLauncher(
                            launcher ->
                                    checkLauncherIntegrity(launcher, containerType)));
        }
        mLauncher.enableDebugTracing();
        // Avoid double-reporting of Launcher crashes.
@@ -642,86 +635,6 @@ public abstract class AbstractLauncherUiTest {
        return launcher.getAppsView().getActiveRecyclerView().computeVerticalScrollOffset();
    }

    private void checkLauncherIntegrity(
            Launcher launcher, ContainerType expectedContainerType) {
        if (launcher != null) {
            final StateManager<LauncherState> stateManager = launcher.getStateManager();
            final LauncherState stableState = stateManager.getCurrentStableState();

            assertTrue("Stable state != state: " + stableState.getClass().getSimpleName() + ", "
                            + stateManager.getState().getClass().getSimpleName(),
                    stableState == stateManager.getState());

            final boolean isResumed = launcher.hasBeenResumed();
            final boolean isStarted = launcher.isStarted();
            checkLauncherState(launcher, expectedContainerType, isResumed, isStarted);

            final int ordinal = stableState.ordinal;

            switch (expectedContainerType) {
                case WORKSPACE:
                case WIDGETS: {
                    assertTrue(
                            "Launcher is not resumed in state: " + expectedContainerType,
                            isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal),
                            ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
                case HOME_ALL_APPS: {
                    assertTrue(
                            "Launcher is not resumed in state: " + expectedContainerType,
                            isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal),
                            ordinal == TestProtocol.ALL_APPS_STATE_ORDINAL);
                    break;
                }
                case OVERVIEW: {
                    verifyOverviewState(launcher, expectedContainerType, isStarted, isResumed,
                            ordinal, TestProtocol.OVERVIEW_STATE_ORDINAL);
                    break;
                }
                case SPLIT_SCREEN_SELECT: {
                    verifyOverviewState(launcher, expectedContainerType, isStarted, isResumed,
                            ordinal, TestProtocol.OVERVIEW_SPLIT_SELECT_ORDINAL);
                    break;
                }
                case TASKBAR_ALL_APPS:
                case LAUNCHED_APP: {
                    assertTrue("Launcher is resumed in state: " + expectedContainerType,
                            !isResumed);
                    assertTrue(TestProtocol.stateOrdinalToString(ordinal),
                            ordinal == TestProtocol.NORMAL_STATE_ORDINAL);
                    break;
                }
                default:
                    throw new IllegalArgumentException(
                            "Illegal container: " + expectedContainerType);
            }
        } else {
            assertTrue(
                    "Container type is not LAUNCHED_APP, TASKBAR_ALL_APPS "
                            + "or FALLBACK_OVERVIEW: " + expectedContainerType,
                    expectedContainerType == ContainerType.LAUNCHED_APP
                            || expectedContainerType == ContainerType.TASKBAR_ALL_APPS
                            || expectedContainerType == ContainerType.FALLBACK_OVERVIEW);
        }
    }

    protected void checkLauncherState(Launcher launcher, ContainerType expectedContainerType,
            boolean isResumed, boolean isStarted) {
        assertTrue("hasBeenResumed() != isStarted(), hasBeenResumed(): " + isResumed,
                isResumed == isStarted);
        assertTrue("hasBeenResumed() != isUserActive(), hasBeenResumed(): " + isResumed,
                isResumed == launcher.isUserActive());
    }

    protected void checkLauncherStateInOverview(Launcher launcher,
            ContainerType expectedContainerType, boolean isStarted, boolean isResumed) {
        assertTrue("Launcher is not resumed in state: " + expectedContainerType,
                isResumed);
    }

    protected void onLauncherActivityClose(Launcher launcher) {
    }

@@ -750,10 +663,4 @@ public abstract class AbstractLauncherUiTest {
        }
        return homeAppIcon;
    }

    private void verifyOverviewState(Launcher launcher, ContainerType expectedContainerType,
            boolean isStarted, boolean isResumed, int ordinal, int expectedOrdinal) {
        checkLauncherStateInOverview(launcher, expectedContainerType, isStarted, isResumed);
        assertEquals(TestProtocol.stateOrdinalToString(ordinal), ordinal, expectedOrdinal);
    }
}
+0 −9
Original line number Diff line number Diff line
@@ -94,7 +94,6 @@ import java.util.List;
import java.util.Optional;
import java.util.concurrent.TimeoutException;
import java.util.function.BooleanSupplier;
import java.util.function.Consumer;
import java.util.function.Function;
import java.util.function.Supplier;
import java.util.regex.Pattern;
@@ -200,8 +199,6 @@ public final class LauncherInstrumentation {

    private boolean mIgnoreTaskbarVisibility = false;

    private Consumer<ContainerType> mOnSettledStateAction;

    private LogEventChecker mEventChecker;

    // UI anomaly checker provided by the test.
@@ -655,10 +652,6 @@ public final class LauncherInstrumentation {
        this.mSystemHealthSupplier = supplier;
    }

    public void setOnSettledStateAction(Consumer<ContainerType> onSettledStateAction) {
        mOnSettledStateAction = onSettledStateAction;
    }

    public void onTestStart() {
        mTestStartTime = System.currentTimeMillis();
    }
@@ -869,8 +862,6 @@ public final class LauncherInstrumentation {

        final UiObject2 container = verifyVisibleObjects(containerType);

        if (mOnSettledStateAction != null) mOnSettledStateAction.accept(containerType);

        return container;
    }