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

Commit 09b91447 authored by Vadim Tryshev's avatar Vadim Tryshev Committed by Android (Google) Code Review
Browse files

Merge "Preparing QuickstepOnOff for running in 3 navigation modes" into ub-launcher3-master

parents ae775276 c5b06f4c
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -27,5 +27,5 @@ import org.junit.rules.TestRule;
public abstract class AbstractQuickStepTest extends AbstractLauncherUiTest {
    @Rule
    public TestRule mQuickstepOnOffExecutor =
            new QuickStepOnOffRule(mMainThreadExecutor, mLauncher);
            new NavigationModeSwitchRule(mLauncher);
}
+13 −14
Original line number Diff line number Diff line
@@ -17,26 +17,31 @@ package com.android.quickstep;

import static android.content.pm.PackageManager.MATCH_DISABLED_COMPONENTS;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import static com.android.launcher3.tapl.LauncherInstrumentation.WAIT_TIME_MS;
import static com.android.launcher3.tapl.TestHelpers.getHomeIntentInPackage;
import static com.android.launcher3.tapl.TestHelpers.getLauncherInMyProcess;
import static com.android.launcher3.util.rule.ShellCommandRule.disableHeadsUpNotification;
import static com.android.launcher3.util.rule.ShellCommandRule.getLauncherCommand;
import static com.android.quickstep.QuickStepOnOffRule.Mode.OFF;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON;

import static org.junit.Assert.assertTrue;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import android.app.Instrumentation;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;

import com.android.launcher3.MainThreadExecutor;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.Until;

import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.testcomponent.TestCommandReceiver;
import com.android.quickstep.QuickStepOnOffRule.QuickstepOnOff;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;

import org.junit.Rule;
import org.junit.Test;
@@ -44,12 +49,6 @@ import org.junit.rules.TestRule;
import org.junit.runner.RunWith;
import org.junit.runners.model.Statement;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.UiDevice;
import androidx.test.uiautomator.Until;

@LargeTest
@RunWith(AndroidJUnit4.class)
/**
@@ -72,7 +71,7 @@ public class FallbackRecentsTest {
        mDevice = UiDevice.getInstance(instrumentation);
        mLauncher = new LauncherInstrumentation(instrumentation);

        mQuickstepOnOffExecutor = new QuickStepOnOffRule(new MainThreadExecutor(), mLauncher);
        mQuickstepOnOffExecutor = new NavigationModeSwitchRule(mLauncher);
        mOtherLauncherActivity = context.getPackageManager().queryIntentActivities(
                getHomeIntentInPackage(context),
                MATCH_DISABLED_COMPONENTS).get(0).activityInfo;
@@ -94,7 +93,7 @@ public class FallbackRecentsTest {
        };
    }

    @QuickstepOnOff(mode = OFF)
    @NavigationModeSwitch(mode = THREE_BUTTON)
    @Test
    public void goToOverviewFromHome() {
        mDevice.pressHome();
@@ -104,7 +103,7 @@ public class FallbackRecentsTest {
        mLauncher.getBackground().switchToOverview();
    }

    @QuickstepOnOff(mode = OFF)
    @NavigationModeSwitch(mode = THREE_BUTTON)
    @Test
    public void goToOverviewFromApp() {
        startAppFast("com.android.settings");
+44 −32
Original line number Diff line number Diff line
@@ -18,9 +18,9 @@ package com.android.quickstep;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import static com.android.quickstep.QuickStepOnOffRule.Mode.BOTH;
import static com.android.quickstep.QuickStepOnOffRule.Mode.OFF;
import static com.android.quickstep.QuickStepOnOffRule.Mode.ON;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.ALL;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.THREE_BUTTON;
import static com.android.quickstep.NavigationModeSwitchRule.Mode.TWO_BUTTON;
import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_2BUTTON_OVERLAY;
import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_3BUTTON_OVERLAY;
import static com.android.systemui.shared.system.QuickStepContract.NAV_BAR_MODE_GESTURAL_OVERLAY;
@@ -34,49 +34,46 @@ import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.TestHelpers;
import com.android.systemui.shared.system.QuickStepContract;

import org.junit.Assert;
import org.junit.rules.TestRule;
import org.junit.runner.Description;
import org.junit.runners.model.Statement;

import java.io.IOException;
import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.Executor;

/**
 * Test rule that allows executing a test with Quickstep on and then Quickstep off.
 * The test should be annotated with @QuickstepOnOff.
 */
public class QuickStepOnOffRule implements TestRule {
public class NavigationModeSwitchRule implements TestRule {

    static final String TAG = "QuickStepOnOffRule";

    public enum Mode {
        ON, OFF, BOTH
        THREE_BUTTON, TWO_BUTTON, ZERO_BUTTON, ALL
    }

    // Annotation for tests that need to be run with quickstep enabled and disabled.
    @Retention(RetentionPolicy.RUNTIME)
    @Target(ElementType.METHOD)
    public @interface QuickstepOnOff {
        Mode mode() default BOTH;
    public @interface NavigationModeSwitch {
        Mode mode() default ALL;
    }

    private final Executor mMainThreadExecutor;
    private final LauncherInstrumentation mLauncher;

    public QuickStepOnOffRule(Executor mainThreadExecutor, LauncherInstrumentation launcher) {
    public NavigationModeSwitchRule(LauncherInstrumentation launcher) {
        mLauncher = launcher;
        this.mMainThreadExecutor = mainThreadExecutor;
    }

    @Override
    public Statement apply(Statement base, Description description) {
        if (TestHelpers.isInLauncherProcess() &&
                description.getAnnotation(QuickstepOnOff.class) != null) {
            Mode mode = description.getAnnotation(QuickstepOnOff.class).mode();
                description.getAnnotation(NavigationModeSwitch.class) != null) {
            Mode mode = description.getAnnotation(NavigationModeSwitch.class).mode();
            return new Statement() {
                @Override
                public void evaluate() throws Throwable {
@@ -86,15 +83,20 @@ public class QuickStepOnOffRule implements TestRule {
                            : QuickStepContract.isSwipeUpMode(context)
                                    ? NAV_BAR_MODE_2BUTTON_OVERLAY
                                    : NAV_BAR_MODE_3BUTTON_OVERLAY;
                    final LauncherInstrumentation.NavigationModel originalMode =
                            mLauncher.getNavigationModel();
                    try {
                        if (mode == ON || mode == BOTH) {
                            evaluateWithQuickstepOn();
//                        if (mode == ZERO_BUTTON || mode == ALL) {
//                            evaluateWithZeroButtons();
//                        }
                        if (mode == TWO_BUTTON || mode == ALL) {
                            evaluateWithTwoButtons();
                        }
                        if (mode == OFF || mode == BOTH) {
                            evaluateWithQuickstepOff();
                        if (mode == THREE_BUTTON || mode == ALL) {
                            evaluateWithThreeButtons();
                        }
                    } finally {
                        setActiveOverlay(prevOverlayPkg);
                        setActiveOverlay(prevOverlayPkg, originalMode);
                    }
                }

@@ -102,17 +104,26 @@ public class QuickStepOnOffRule implements TestRule {
                    base.evaluate();
                }

                private void evaluateWithQuickstepOff() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY);
                private void evaluateWithThreeButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_3BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.THREE_BUTTON);
                    evaluateWithoutChangingSetting(base);
                }

                private void evaluateWithQuickstepOn() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY);
                private void evaluateWithTwoButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_2BUTTON_OVERLAY,
                            LauncherInstrumentation.NavigationModel.TWO_BUTTON);
                    base.evaluate();
                }

                private void setActiveOverlay(String overlayPackage) {
                private void evaluateWithZeroButtons() throws Throwable {
                    setActiveOverlay(NAV_BAR_MODE_GESTURAL_OVERLAY,
                            LauncherInstrumentation.NavigationModel.ZERO_BUTTON);
                    base.evaluate();
                }

                private void setActiveOverlay(String overlayPackage,
                        LauncherInstrumentation.NavigationModel expectedMode) throws Exception {
                    setOverlayPackageEnabled(NAV_BAR_MODE_3BUTTON_OVERLAY,
                            overlayPackage == NAV_BAR_MODE_3BUTTON_OVERLAY);
                    setOverlayPackageEnabled(NAV_BAR_MODE_2BUTTON_OVERLAY,
@@ -120,18 +131,19 @@ public class QuickStepOnOffRule implements TestRule {
                    setOverlayPackageEnabled(NAV_BAR_MODE_GESTURAL_OVERLAY,
                            overlayPackage == NAV_BAR_MODE_GESTURAL_OVERLAY);

                    // TODO: Wait until nav bar mode has applied
                    for (int i = 0; i != 100; ++i) {
                        if (mLauncher.getNavigationModel() == expectedMode) return;
                        Thread.sleep(100);
                    }
                    Assert.fail("Couldn't switch to " + overlayPackage);
                }

                private void setOverlayPackageEnabled(String overlayPackage, boolean enable) {
                private void setOverlayPackageEnabled(String overlayPackage, boolean enable)
                        throws Exception {
                    Log.d(TAG, "setOverlayPackageEnabled: " + overlayPackage + " " + enable);
                    final String action = enable ? "enable" : "disable";
                    try {
                    UiDevice.getInstance(getInstrumentation()).executeShellCommand(
                            "cmd overlay " + action + " " + overlayPackage);
                    } catch (IOException e) {
                        e.printStackTrace();
                    }
                }
            };
        } else {
+6 −6
Original line number Diff line number Diff line
@@ -26,8 +26,8 @@ import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.Launcher;
import com.android.launcher3.util.RaceConditionReproducer;
import com.android.quickstep.QuickStepOnOffRule.Mode;
import com.android.quickstep.QuickStepOnOffRule.QuickstepOnOff;
import com.android.quickstep.NavigationModeSwitchRule.Mode;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;

import org.junit.Before;
import org.junit.Ignore;
@@ -62,7 +62,7 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {

    @Test
    @Ignore // Ignoring until gestural navigation event sequence settles
    @QuickstepOnOff(mode = Mode.ON)
    @NavigationModeSwitch(mode = Mode.TWO_BUTTON)
    public void testPressHome() {
        runTest(enterEvt(Launcher.ON_CREATE_EVT),
                exitEvt(Launcher.ON_CREATE_EVT),
@@ -77,14 +77,14 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {

    @Test
    @Ignore // Ignoring until gestural navigation event sequence settles
    @QuickstepOnOff(mode = Mode.ON)
    @NavigationModeSwitch(mode = Mode.TWO_BUTTON)
    public void testSwipeToOverview() {
        closeLauncherActivity();
        mLauncher.getBackground().switchToOverview();
    }

    @Test
    @QuickstepOnOff
    @NavigationModeSwitch
    public void testStressPressHome() {
        for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
            // Destroy Launcher activity.
@@ -96,7 +96,7 @@ public class StartLauncherViaGestureTests extends AbstractQuickStepTest {
    }

    @Test
    @QuickstepOnOff
    @NavigationModeSwitch
    public void testStressSwipeToOverview() {
        for (int i = 0; i < STRESS_REPEAT_COUNT; ++i) {
            // Destroy Launcher activity.
+4 −4
Original line number Diff line number Diff line
@@ -37,7 +37,7 @@ import com.android.launcher3.tapl.Overview;
import com.android.launcher3.tapl.OverviewTask;
import com.android.launcher3.tapl.TestHelpers;
import com.android.launcher3.ui.TaplTestsLauncher3;
import com.android.quickstep.QuickStepOnOffRule.QuickstepOnOff;
import com.android.quickstep.NavigationModeSwitchRule.NavigationModeSwitch;
import com.android.quickstep.views.RecentsView;

import org.junit.Before;
@@ -79,7 +79,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
    }

    @Test
    @QuickstepOnOff
    @NavigationModeSwitch
    @PortraitLandscape
    public void testWorkspaceSwitchToAllApps() {
        assertNotNull("switchToAllApps() returned null",
@@ -198,7 +198,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
    }

    @Test
    @QuickstepOnOff
    @NavigationModeSwitch
    @PortraitLandscape
    public void testSwitchToOverview() throws Exception {
        assertNotNull("Workspace.switchToOverview() returned null",
@@ -208,7 +208,7 @@ public class TaplTestsQuickstep extends AbstractQuickStepTest {
    }

    @Test
    @QuickstepOnOff
    @NavigationModeSwitch
    @PortraitLandscape
    public void testBackground() throws Exception {
        startAppFast(resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR));
Loading