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

Commit 802a2894 authored by Vadim Tryshev's avatar Vadim Tryshev
Browse files

Add support for testing in portrait mode

Bug: 110103162
Test: TaplTests
Change-Id: I7f633405c04984ea8f04acdc6dd4ad21019d3409
parent e583a064
Loading
Loading
Loading
Loading
+0 −11
Original line number Diff line number Diff line
@@ -867,17 +867,6 @@ public class Launcher extends BaseDraggingActivity implements LauncherExterns,
        }
    }

    public boolean hasSettings() {
        if (mLauncherCallbacks != null) {
            return mLauncherCallbacks.hasSettings();
        } else {
            // On O and above we there is always some setting present settings (add icon to
            // home screen or icon badging). On earlier APIs we will have the allow rotation
            // setting, on devices with a locked orientation,
            return Utilities.ATLEAST_OREO || !getResources().getBoolean(R.bool.allow_rotation);
        }
    }

    public boolean isInState(LauncherState state) {
        return mStateManager.getState() == state;
    }
+8 −1
Original line number Diff line number Diff line
@@ -56,7 +56,7 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
    private final Activity mActivity;
    private final SharedPreferences mPrefs;

    private final boolean mIgnoreAutoRotateSettings;
    private boolean mIgnoreAutoRotateSettings;
    private boolean mAutoRotateEnabled;

    /**
@@ -110,6 +110,13 @@ public class RotationHelper implements OnSharedPreferenceChangeListener {
        }
    }

    // Used by tests only.
    public void forceAllowRotationForTesting(boolean allowRotation) {
        mIgnoreAutoRotateSettings =
                allowRotation || mActivity.getResources().getBoolean(R.bool.allow_rotation);
        notifyChange();
    }

    public void initialize() {
        if (!mInitialized) {
            mInitialized = true;
+8 −11
Original line number Diff line number Diff line
@@ -52,7 +52,6 @@ import com.android.launcher3.compat.LauncherAppsCompat;
import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.testcomponent.AppWidgetNoConfig;
import com.android.launcher3.testcomponent.AppWidgetWithConfig;
import com.android.launcher3.util.Condition;
import com.android.launcher3.util.Wait;
import com.android.launcher3.util.rule.LauncherActivityRule;

@@ -79,20 +78,23 @@ public abstract class AbstractLauncherUiTest {
    public static final long DEFAULT_WORKER_TIMEOUT_SECS = 5;

    protected MainThreadExecutor mMainThreadExecutor = new MainThreadExecutor();
    protected UiDevice mDevice;
    protected LauncherInstrumentation mLauncher;
    protected final UiDevice mDevice;
    protected final LauncherInstrumentation mLauncher;
    protected Context mTargetContext;
    protected String mTargetPackage;

    private static final String TAG = "AbstractLauncherUiTest";

    protected AbstractLauncherUiTest() {
        mDevice = UiDevice.getInstance(getInstrumentation());
        mLauncher = new LauncherInstrumentation(getInstrumentation());
    }

    @Rule
    public LauncherActivityRule mActivityMonitor = new LauncherActivityRule();

    @Before
    public void setUp() throws Exception {
        mDevice = UiDevice.getInstance(getInstrumentation());
        mLauncher = new LauncherInstrumentation(getInstrumentation());
        mTargetContext = InstrumentationRegistry.getTargetContext();
        mTargetPackage = mTargetContext.getPackageName();
        mDevice.executeShellCommand("settings put global heads_up_notifications_enabled 0");
@@ -285,12 +287,7 @@ public abstract class AbstractLauncherUiTest {
    // flakiness.
    protected boolean waitForLauncherCondition(
            Function<Launcher, Boolean> condition, long timeout) {
        return Wait.atMost(new Condition() {
            @Override
            public boolean isTrue() {
                return getFromLauncher(condition);
            }
        }, timeout);
        return Wait.atMost(() -> getFromLauncher(condition), timeout);
    }

    /**
+24 −2
Original line number Diff line number Diff line
@@ -25,6 +25,7 @@ import android.os.Bundle;
import android.os.Parcelable;
import android.provider.Settings;
import android.util.Log;
import android.view.Surface;
import android.view.accessibility.AccessibilityEvent;

import androidx.annotation.NonNull;
@@ -92,6 +93,7 @@ public final class LauncherInstrumentation {
    private final boolean mSwipeUpEnabled;
    private Boolean mSwipeUpEnabledOverride = null;
    private final Instrumentation mInstrumentation;
    private int mExpectedRotation = Surface.ROTATION_0;

    /**
     * Constructs the root of TAPL hierarchy. You get all other objects from it.
@@ -109,7 +111,7 @@ public final class LauncherInstrumentation {
        assertTrue("Device must run in a test harness", ActivityManager.isRunningInTestHarness());
    }

    // Used only by tests.
    // Used only by TaplTests.
    public void overrideSwipeUpEnabled(Boolean swipeUpEnabledOverride) {
        mSwipeUpEnabledOverride = swipeUpEnabledOverride;
    }
@@ -144,14 +146,30 @@ public final class LauncherInstrumentation {
        fail(message + ". " + "Actual: " + actual);
    }

    static public void assertEquals(String message, int expected, int actual) {
        if (expected != actual) {
            fail(message + " expected: " + expected + " but was: " + actual);
        }
    }

    static void assertNotEquals(String message, int unexpected, int actual) {
        if (unexpected == actual) {
            failEquals(message, actual);
        }
    }

    public void setExpectedRotation(int expectedRotation) {
        mExpectedRotation = expectedRotation;
    }

    private UiObject2 verifyContainerType(ContainerType containerType) {
        assertEquals("Unexpected display rotation",
                mExpectedRotation, mDevice.getDisplayRotation());
        assertTrue("Presence of recents button doesn't match isSwipeUpEnabled()",
                isSwipeUpEnabled() ==
                        (mDevice.findObject(By.res(SYSTEMUI_PACKAGE, "recent_apps")) == null));
        log("verifyContainerType: " + containerType);

        switch (containerType) {
            case WORKSPACE: {
                waitUntilGone(APPS_RES_ID);
@@ -172,7 +190,11 @@ public final class LauncherInstrumentation {
                return waitForLauncherObject(APPS_RES_ID);
            }
            case OVERVIEW: {
                if (mDevice.isNaturalOrientation()) {
                    waitForLauncherObject(APPS_RES_ID);
                } else {
                    waitUntilGone(APPS_RES_ID);
                }
                waitUntilGone(WORKSPACE_RES_ID);
                waitUntilGone(WIDGETS_RES_ID);
                return waitForLauncherObject(OVERVIEW_RES_ID);