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 Original line Diff line number Diff line
@@ -451,6 +451,11 @@ public class LauncherModel extends BroadcastReceiver
     * @return true if the page could be bound synchronously.
     * @return true if the page could be bound synchronously.
     */
     */
    public boolean startLoader(int synchronousBindPage) {
    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
        // Enable queue before starting loader. It will get disabled in Launcher#finishBindingItems
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING);
        InstallShortcutReceiver.enableInstallQueue(InstallShortcutReceiver.FLAG_LOADER_RUNNING);
        synchronized (mLock) {
        synchronized (mLock) {
+21 −12
Original line number Original line Diff line number Diff line
@@ -47,6 +47,7 @@ import androidx.test.uiautomator.Until;
import com.android.launcher3.Launcher;
import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppState;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherAppWidgetProviderInfo;
import com.android.launcher3.LauncherModel;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherSettings;
import com.android.launcher3.LauncherState;
import com.android.launcher3.LauncherState;
import com.android.launcher3.MainThreadExecutor;
import com.android.launcher3.MainThreadExecutor;
@@ -133,7 +134,8 @@ public abstract class AbstractLauncherUiTest {
                    try {
                    try {
                        // Create launcher activity if necessary and bring it to the front.
                        // Create launcher activity if necessary and bring it to the front.
                        mDevice.pressHome();
                        mDevice.pressHome();
                        waitForLauncherCondition(launcher -> launcher != null);
                        waitForLauncherCondition("Launcher activity wasn't created",
                                launcher -> launcher != null);


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


    protected void lockRotation(boolean naturalOrientation) throws RemoteException {
    protected void lockRotation(boolean naturalOrientation) throws RemoteException {
@@ -320,8 +322,7 @@ public abstract class AbstractLauncherUiTest {
        } catch (Throwable t) {
        } catch (Throwable t) {
            throw new IllegalArgumentException(t);
            throw new IllegalArgumentException(t);
        }
        }
        waitForLauncherCondition(launcher ->
        waitForModelLoaded();
                LauncherAppState.getInstance(mTargetContext).getModel().isModelLoaded());
        if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
        if (com.android.launcher3.Utilities.IS_RUNNING_IN_TEST_HARNESS
                && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
                && com.android.launcher3.Utilities.IS_DEBUG_DEVICE) {
            android.util.Log.d("b/117332845",
            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.
     * 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
    // 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.
    // the results of that gesture because the wait can hide flakeness.
    protected boolean waitForState(LauncherState state) {
    protected void waitForState(String message, LauncherState state) {
        return waitForLauncherCondition(launcher -> launcher.getStateManager().getState() == state);
        waitForLauncherCondition(message,
                launcher -> launcher.getStateManager().getState() == state);
    }
    }


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


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


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


        // Open all apps and wait for load complete.
        // Open all apps and wait for load complete.
        final UiObject2 appsContainer = openAllApps();
        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.
        // Drag icon to homescreen.
        UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString()));
        UiObject2 icon = scrollAndFind(appsContainer, By.text(settingsApp.getLabel().toString()));
+1 −2
Original line number Original line Diff line number Diff line
@@ -47,8 +47,7 @@ public class ShortcutsLaunchTest extends AbstractLauncherUiTest {


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


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


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


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