From 802a28946c43f4f3e4d314838d019fdf6573f2fa Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Fri, 21 Sep 2018 14:31:21 -0700 Subject: [PATCH] Add support for testing in portrait mode Bug: 110103162 Test: TaplTests Change-Id: I7f633405c04984ea8f04acdc6dd4ad21019d3409 --- src/com/android/launcher3/Launcher.java | 11 -------- .../launcher3/states/RotationHelper.java | 9 ++++++- .../launcher3/ui/AbstractLauncherUiTest.java | 19 ++++++-------- .../tapl/LauncherInstrumentation.java | 26 +++++++++++++++++-- 4 files changed, 40 insertions(+), 25 deletions(-) diff --git a/src/com/android/launcher3/Launcher.java b/src/com/android/launcher3/Launcher.java index 55074f8134..151c76183c 100644 --- a/src/com/android/launcher3/Launcher.java +++ b/src/com/android/launcher3/Launcher.java @@ -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; } diff --git a/src/com/android/launcher3/states/RotationHelper.java b/src/com/android/launcher3/states/RotationHelper.java index e8664458d5..9c4a4eaa4b 100644 --- a/src/com/android/launcher3/states/RotationHelper.java +++ b/src/com/android/launcher3/states/RotationHelper.java @@ -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; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 5a3d36d6d2..ba7d9c5237 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -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 condition, long timeout) { - return Wait.atMost(new Condition() { - @Override - public boolean isTrue() { - return getFromLauncher(condition); - } - }, timeout); + return Wait.atMost(() -> getFromLauncher(condition), timeout); } /** diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 9e4a61530b..7885e3cce4 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -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: { - waitForLauncherObject(APPS_RES_ID); + 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);