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

Commit 14c6c8ce authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Improving tests to fix testBindNormalWidget_withoutConfig, and beyond

1. Make waitXXX methods fail if the condition diesn’t turn true.
2. Waiting for loading to complete in tearDown instead of reloading the
 model
3. Avoiding waiting for load-complete where loading didn’t start
4. Disabling last test in AddConfigWidgetTest
5. Waiting for loading to complete inside setupAndVerifyContents(), not
 outside
6. Unifying how we wait for loader to complete
7. Adding more logging

Bug: 117332845
Test: running all Nexus tests
Change-Id: I3070e1ac2b9161179cc3e0800b0cd8162807389a
parent 02e900c3
Loading
Loading
Loading
Loading
+5 −0
Original line number Diff line number Diff line
@@ -451,6 +451,11 @@ public class LauncherModel extends BroadcastReceiver
     * @return true if the page could be bound synchronously.
     */
    public boolean startLoader(int synchronousBindPage) {
        if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
                && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
            android.util.Log.d("b/117332845",
                    android.util.Log.getStackTraceString(new Throwable()));
        }
        // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING);
        synchronized (mLock) {
+21 −12
Original line number Diff line number Diff line
@@ -47,6 +47,7 @@ import androidx.test.uiautomator.Until;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherState;
import com.android.launcher3.MainThreadExecutor;
@@ -133,7 +134,8 @@ public abstract class AbstractLauncherUiTest {
                    try {
                        // Create launcher activity if necessary and bring it to the front.
                        mDevice.pressHome();
                        waitForLauncherCondition(launcher -> launcher != null);
                        waitForLauncherCondition("Launcher activity wasn't created",
                                launcher -> launcher != null);

                        executeOnLauncher(launcher ->
                                launcher.getRotationHelper().forceAllowRotationForTesting(true));
@@ -170,7 +172,7 @@ public abstract class AbstractLauncherUiTest {
    @After
    public void tearDown() throws Exception {
        // Limits UI tests affecting tests running after them.
        resetLoaderState();
        waitForModelLoaded();
    }

    protected void lockRotation(boolean naturalOrientation) throws RemoteException {
@@ -320,8 +322,7 @@ public abstract class AbstractLauncherUiTest {
        } catch (Throwable t) {
            throw new IllegalArgumentException(t);
        }
        waitForLauncherCondition(launcher ->
                LauncherAppState.getInstance(mTargetContext).getModel().isModelLoaded());
        waitForModelLoaded();
        if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
                && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
            android.util.Log.d("b/117332845",
@@ -329,6 +330,13 @@ public abstract class AbstractLauncherUiTest {
        }
    }

    protected void waitForModelLoaded() {
        waitForLauncherCondition("Launcher model didn't load", launcher -> {
            final LauncherModel model = LauncherAppState.getInstance(mTargetContext).getModel();
            return model.getCallback() == null || model.isModelLoaded();
        });
    }

    /**
     * Runs the callback on the UI thread and returns the result.
     */
@@ -354,22 +362,23 @@ public abstract class AbstractLauncherUiTest {

    // Cannot be used in TaplTests between a Tapl call injecting a gesture and a tapl call expecting
    // the results of that gesture because the wait can hide flakeness.
    protected boolean waitForState(LauncherState state) {
        return waitForLauncherCondition(launcher -> launcher.getStateManager().getState() == state);
    protected void waitForState(String message, LauncherState state) {
        waitForLauncherCondition(message,
                launcher -> launcher.getStateManager().getState() == state);
    }

    // Cannot be used in TaplTests after injecting any gesture using Tapl because this can hide
    // flakiness.
    protected boolean waitForLauncherCondition(Function<Launcher, Boolean> condition) {
        return waitForLauncherCondition(condition, DEFAULT_ACTIVITY_TIMEOUT);
    protected void waitForLauncherCondition(String message, Function<Launcher, Boolean> condition) {
        waitForLauncherCondition(message, condition, DEFAULT_ACTIVITY_TIMEOUT);
    }

    // Cannot be used in TaplTests after injecting any gesture using Tapl because this can hide
    // flakiness.
    protected boolean waitForLauncherCondition(
            Function<Launcher, Boolean> condition, long timeout) {
        if (!TestHelpers.isInLauncherProcess()) return true;
        return Wait.atMost(() -> getFromLauncher(condition), timeout);
    protected void waitForLauncherCondition(
            String message, Function<Launcher, Boolean> condition, long timeout) {
        if (!TestHelpers.isInLauncherProcess()) return;
        Wait.atMost(message, () -> getFromLauncher(condition), timeout);
    }

    /**
+1 −1
Original line number Diff line number Diff line
@@ -46,7 +46,7 @@ public class AllAppsIconToHomeTest extends AbstractLauncherUiTest {

        // Open all apps and wait for load complete.
        final UiObject2 appsContainer = openAllApps();
        assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT));
        Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT);

        // Drag icon to homescreen.
        UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString()));
+1 −2
Original line number Diff line number Diff line
@@ -47,8 +47,7 @@ public class ShortcutsLaunchTest extends AbstractLauncherUiTest {

        // Open all apps and wait for load complete
        final UiObject2 appsContainer = openAllApps();
        assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2),
                DEFAULT_UI_TIMEOUT));
        Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT);

        // Find settings app and verify shortcuts appear when long pressed
        UiObject2 icon = scrollAndFind(appsContainer, By.text(testApp.getLabel().toString()));
+1 −2
Original line number Diff line number Diff line
@@ -49,8 +49,7 @@ public class ShortcutsToHomeTest extends AbstractLauncherUiTest {

        // Open all apps and wait for load complete.
        final UiObject2 appsContainer = openAllApps();
        assertTrue(Wait.atMost(Condition.minChildCount(appsContainer, 2),
                DEFAULT_UI_TIMEOUT));
        Wait.atMost(null, Condition.minChildCount(appsContainer, 2), DEFAULT_UI_TIMEOUT);

        // Find the app and long press it to show shortcuts.
        UiObject2 icon = scrollAndFind(appsContainer, By.text(testApp.getLabel().toString()));
Loading