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

Commit bfef402e authored by Tracy Zhou's avatar Tracy Zhou
Browse files

Add quick switch to trackpad gesture tests

Bug: 23895346
Test: presubmit
Change-Id: I85f3e010757595763f58ea81a13671fe49604b76
parent d33fc050
Loading
Loading
Loading
Loading
+21 −0
Original line number Diff line number Diff line
@@ -16,11 +16,17 @@

package com.android.quickstep;

import static com.android.launcher3.ui.TaplTestsLauncher3.getAppPackageName;

import static org.junit.Assert.assertTrue;

import android.os.SystemProperties;

import androidx.test.uiautomator.By;
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;
@@ -76,6 +82,21 @@ public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
        }
    }

    protected void assertTestActivityIsRunning(int activityNumber, String message) {
        assertTrue(message, mDevice.wait(
                Until.hasObject(By.pkg(getAppPackageName()).text("TestActivity" + activityNumber)),
                DEFAULT_UI_TIMEOUT));
    }

    protected LaunchedAppState getAndAssertLaunchedApp() {
        final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
        executeOnLauncher(launcher -> assertTrue(
                "Launcher activity is the top activity; expecting another activity to be the top "
                        + "one",
                isInLaunchedApp(launcher)));
        return launchedAppState;
    }

    private boolean isInLiveTileMode(Launcher launcher,
            LauncherInstrumentation.ContainerType expectedContainerType) {
        if (expectedContainerType != LauncherInstrumentation.ContainerType.OVERVIEW) {
+13 −29
Original line number Diff line number Diff line
@@ -241,16 +241,6 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
                isInState(() -> LauncherState.OVERVIEW));
    }

    private LaunchedAppState getAndAssertLaunchedApp() {
        final LaunchedAppState launchedAppState = mLauncher.getLaunchedAppState();
        assertNotNull("Launcher.getLaunchedApp() returned null", launchedAppState);
        executeOnLauncher(launcher -> assertTrue(
                "Launcher activity is the top activity; expecting another activity to be the top "
                        + "one",
                isInLaunchedApp(launcher)));
        return launchedAppState;
    }

    private void quickSwitchToPreviousAppAndAssert(boolean toRight) {
        final LaunchedAppState launchedAppState = getAndAssertLaunchedApp();
        if (toRight) {
@@ -292,22 +282,22 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
        startTestActivity(4);

        quickSwitchToPreviousAppAndAssert(true /* toRight */);
        assertTrue("The first app we should have quick switched to is not running",
                isTestActivityRunning(3));
        assertTestActivityIsRunning(3,
                "The first app we should have quick switched to is not running");

        quickSwitchToPreviousAppAndAssert(true /* toRight */);
        if (mLauncher.getNavigationModel() == NavigationModel.THREE_BUTTON) {
            // 3-button mode toggles between 2 apps, rather than going back further.
            assertTrue("Second quick switch should have returned to the first app.",
                    isTestActivityRunning(4));
            assertTestActivityIsRunning(4,
                    "Second quick switch should have returned to the first app.");
        } else {
            assertTrue("The second app we should have quick switched to is not running",
                    isTestActivityRunning(2));
            assertTestActivityIsRunning(2,
                    "The second app we should have quick switched to is not running");
        }

        quickSwitchToPreviousAppAndAssert(false /* toRight */);
        assertTrue("The 2nd app we should have quick switched to is not running",
                isTestActivityRunning(3));
        assertTestActivityIsRunning(3,
                "The 2nd app we should have quick switched to is not running");

        final LaunchedAppState launchedAppState = getAndAssertLaunchedApp();
        launchedAppState.switchToOverview();
@@ -331,9 +321,9 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
        // Quick-switch to the test app with swiping to right.
        quickSwitchToPreviousAppAndAssert(true /* toRight */);

        assertTrue("The first app we should have quick switched to is not running",
                isTestActivityRunning(2));

        assertTestActivityIsRunning(2,
                "The first app we should have quick switched to is not running");
        // Expect task bar visible when the launched app was the test activity.
        launchedAppState = getAndAssertLaunchedApp();

        Log.e(FLAKY_QUICK_SWITCH_TO_PREVIOUS_APP,
@@ -347,12 +337,6 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
        }
    }

    private boolean isTestActivityRunning(int activityNumber) {
        return mDevice.wait(Until.hasObject(By.pkg(getAppPackageName())
                        .text("TestActivity" + activityNumber)),
                DEFAULT_UI_TIMEOUT);
    }

    @Test
    @NavigationModeSwitch
    @PortraitLandscape
@@ -360,8 +344,8 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
    public void testQuickSwitchFromHome() throws Exception {
        startTestActivity(2);
        mLauncher.goHome().quickSwitchToPreviousApp();
        assertTrue("The most recent task is not running after quick switching from home",
                isTestActivityRunning(2));
        assertTestActivityIsRunning(2,
                "The most recent task is not running after quick switching from home");
        getAndAssertLaunchedApp();
    }

+17 −0
Original line number Diff line number Diff line
@@ -19,6 +19,7 @@ package com.android.quickstep;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.ZERO_BUTTON;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assume.assumeFalse;
import static org.junit.Assume.assumeTrue;

@@ -30,6 +31,7 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.config.FeatureFlags;
import com.android.launcher3.tapl.LauncherInstrumentation.TrackpadGestureType;
import com.android.launcher3.tapl.Workspace;
import com.android.launcher3.ui.PortraitLandscapeRunner.PortraitLandscape;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
@@ -112,4 +114,19 @@ public class TaplTestsTrackpad extends AbstractQuickStepTest {
        assertNotNull("switchToAllApps() returned null",
                mLauncher.getWorkspace().switchToAllApps());
    }

    @Test
    @NavigationModeSwitch
    @PortraitLandscape
    public void testQuickSwitchFromHome() throws Exception {
        assumeTrue(mLauncher.isTablet());

        startTestActivity(2);
        Workspace workspace = mLauncher.goHome();
        mLauncher.setTrackpadGestureType(TrackpadGestureType.FOUR_FINGER);
        workspace.quickSwitchToPreviousApp();
        assertTestActivityIsRunning(2,
                "The most recent task is not running after quick switching from home");
        getAndAssertLaunchedApp();
    }
}
+61 −66
Original line number Diff line number Diff line
@@ -240,8 +240,8 @@ public abstract class Background extends LauncherInstrumentation.VisibleContaine
                     "want to quick switch to the previous app")) {
            verifyActiveContainer();
            final boolean launcherWasVisible = mLauncher.isLauncherVisible();
            switch (mLauncher.getNavigationModel()) {
                case ZERO_BUTTON: {
            if (mLauncher.getNavigationModel() == NavigationModel.ZERO_BUTTON
                    || mLauncher.getTrackpadGestureType() == TrackpadGestureType.FOUR_FINGER) {
                final int startX;
                final int startY;
                final int endX;
@@ -270,10 +270,7 @@ public abstract class Background extends LauncherInstrumentation.VisibleContaine
                                startX, startY, endX, endY, 20, false, gestureScope),
                        event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
                        () -> "Quick switch gesture didn't change window state", "swiping");
                    break;
                }

                case THREE_BUTTON:
            } else {
                // Double press the recents button.
                UiObject2 recentsButton = mLauncher.waitForNavigationUiObject("recent_apps");
                if (mLauncher.isTablet()) {
@@ -306,10 +303,8 @@ public abstract class Background extends LauncherInstrumentation.VisibleContaine
                        event -> event.getEventType() == TYPE_WINDOW_STATE_CHANGED,
                        () -> "Pressing recents button didn't change window state",
                        "clicking Recents button for the second time");
                    break;
            }
            mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, TASK_START_EVENT);
            return;
        }
    }