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

Commit cd791c5c authored by Alex Chau's avatar Alex Chau
Browse files

Wait for taskbar to become visible after closing launcher in tests

- Taskbar takes some time to appear after closing launcher and launching test app

Bug: 193653850
Test: StartLauncherViaGestureTests
Change-Id: I714e35ee855660ac28bb214386f48ddbea0e834c
parent be0b0700
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -67,6 +67,7 @@ import androidx.annotation.BinderThread;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.annotation.UiThread;
import androidx.annotation.VisibleForTesting;
import androidx.annotation.WorkerThread;

import com.android.launcher3.BaseDraggingActivity;
@@ -301,17 +302,26 @@ public class TouchInteractionService extends Service implements PluginListener<O

    private static boolean sConnected = false;
    private static boolean sIsInitialized = false;
    private static TouchInteractionService sInstance;
    private RotationTouchHelper mRotationTouchHelper;

    public static boolean isConnected() {
        return sConnected;
    }


    public static boolean isInitialized() {
        return sIsInitialized;
    }

    @VisibleForTesting
    @Nullable
    public static TaskbarManager getTaskbarManagerForTesting() {
        if (sInstance == null) {
            return null;
        }
        return sInstance.mTaskbarManager;
    }

    private final AbsSwipeUpHandler.Factory mLauncherSwipeHandlerFactory =
            this::createLauncherSwipeHandler;
    private final AbsSwipeUpHandler.Factory mFallbackSwipeHandlerFactory =
@@ -355,6 +365,7 @@ public class TouchInteractionService extends Service implements PluginListener<O
        mDeviceState.runOnUserUnlocked(mTaskbarManager::onUserUnlocked);
        ProtoTracer.INSTANCE.get(this).add(this);
        sConnected = true;
        sInstance = this;
    }

    private void disposeEventHandlers() {
@@ -512,6 +523,7 @@ public class TouchInteractionService extends Service implements PluginListener<O

        mTaskbarManager.destroy();
        sConnected = false;
        sInstance = null;
        super.onDestroy();
    }

+37 −3
Original line number Diff line number Diff line
@@ -25,7 +25,12 @@ import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.Launcher;
import com.android.launcher3.taskbar.TaskbarActivityContext;
import com.android.launcher3.taskbar.TaskbarDragLayer;
import com.android.launcher3.taskbar.TaskbarManager;
import com.android.launcher3.taskbar.TaskbarView;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.launcher3.ui.TestViewHelpers;
import com.android.launcher3.util.RaceConditionReproducer;
import com.android.quickstep.NavigationModeSwitchRule.Mode;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
@@ -85,7 +90,7 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {
    public void testStressPressHome() {
        for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
            // Destroy Launcher activity.
            closeLauncherActivity();
            destroyLauncherActivityAndWaitForTaskbarVisible();

            // The test action.
            mLauncher.pressHome();
@@ -97,12 +102,41 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {
    public void testStressSwipeToOverview() {
        for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
            // Destroy Launcher activity.
            closeLauncherActivity();
            destroyLauncherActivityAndWaitForTaskbarVisible();

            // The test action.
            mLauncher.getBackground().switchToOverview();
        }
        closeLauncherActivity();
        destroyLauncherActivityAndWaitForTaskbarVisible();
        mLauncher.pressHome();
    }

    private void destroyLauncherActivityAndWaitForTaskbarVisible() {
        closeLauncherActivity();

        // After Launcher is destroyed, calculator app started in setup() will be launched, wait for
        // taskbar to settle before further interaction if it's a tablet.
        if (!mLauncher.isTablet()) {
            return;
        }

        waitForLauncherCondition(
                "Taskbar not yet visible", launcher -> {
                    TaskbarManager taskbarManager =
                            TouchInteractionService.getTaskbarManagerForTesting();
                    if (taskbarManager == null) {
                        return false;
                    }

                    TaskbarActivityContext taskbarActivityContext =
                            taskbarManager.getCurrentActivityContext();
                    if (taskbarActivityContext == null) {
                        return false;
                    }

                    TaskbarDragLayer taskbarDragLayer = taskbarActivityContext.getDragLayer();
                    return TestViewHelpers.findChildView(taskbarDragLayer,
                            view -> view instanceof TaskbarView && view.isVisibleToUser()) != null;
                }, DEFAULT_UI_TIMEOUT);
    }
}
+0 −4
Original line number Diff line number Diff line
@@ -746,7 +746,6 @@ public final class LauncherInstrumentation {
                    dumpViewHierarchy();
                    action = "swiping up to home";

                    final boolean launcherIsVisible = isLauncherVisible();
                    swipeToState(
                            displaySize.x / 2, displaySize.y - 1,
                            displaySize.x / 2, 0,
@@ -754,9 +753,6 @@ public final class LauncherInstrumentation {
                            launcherWasVisible
                                    ? GestureScope.INSIDE_TO_OUTSIDE
                                    : GestureScope.OUTSIDE_WITH_PILFER);
                    // b/193653850: launcherWasVisible is a flaky indicator.
                    log("launcherWasVisible: " + launcherWasVisible + ", launcherIsVisible: "
                            + launcherIsVisible);
                }
            } else {
                log("Hierarchy before clicking home:");