From d2e978c54f3384bb5e29135fa5f0abe0d19f7770 Mon Sep 17 00:00:00 2001 From: Nataniel Borges Date: Tue, 12 Jul 2022 15:59:04 +0000 Subject: [PATCH] Allow disabling orientation changes check on TAPL This is necessary when a command intentionally changes the device orientation. For example, when triggering `goHome` from an app that is in landscape mode, without enabling launcher rotation Bug: 238757607 Test: testDisableRotationCheck Change-Id: Ia00d85d3263b6524b4806f54f729a0749684b92a --- .../android/launcher3/ui/TaplTestsLauncher3.java | 16 ++++++++++++++++ .../launcher3/tapl/LauncherInstrumentation.java | 11 +++++++++-- 2 files changed, 25 insertions(+), 2 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 03bf4af3de..c3839977cb 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -431,6 +431,22 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL); } + @Test + public void testDisableRotationCheck() throws Exception { + try { + mLauncher.setExpectedRotationCheckEnabled(false); + mLauncher.setEnableRotation(false); + final AllApps allApps = mLauncher.getWorkspace().switchToAllApps(); + final AppIcon app = allApps.getAppIcon("TestActivity7"); + mLauncher.getDevice().setOrientationLeft(); + mLauncher.goHome(); + } finally { + mLauncher.setExpectedRotationCheckEnabled(true); + mLauncher.setEnableRotation(true); + mLauncher.getDevice().setOrientationNatural(); + } + } + @Test @PortraitLandscape public void testDeleteFromWorkspace() throws Exception { diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 5f920972ca..0d0905a2eb 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -178,6 +178,7 @@ public final class LauncherInstrumentation { private final UiDevice mDevice; private final Instrumentation mInstrumentation; private int mExpectedRotation = Surface.ROTATION_0; + private boolean mExpectedRotationCheckEnabled = true; private final Uri mTestProviderUri; private final Deque mDiagnosticContext = new LinkedList<>(); private Function mSystemHealthSupplier; @@ -667,6 +668,10 @@ public final class LauncherInstrumentation { mExpectedRotation = expectedRotation; } + public void setExpectedRotationCheckEnabled(boolean expectedRotationCheckEnabled) { + mExpectedRotationCheckEnabled = expectedRotationCheckEnabled; + } + public String getNavigationModeMismatchError(boolean waitForCorrectState) { final int waitTime = waitForCorrectState ? WAIT_TIME_MS : 0; final NavigationModel navigationModel = getNavigationModel(); @@ -700,8 +705,10 @@ public final class LauncherInstrumentation { private UiObject2 verifyContainerType(ContainerType containerType) { waitForLauncherInitialized(); - assertEquals("Unexpected display rotation", - mExpectedRotation, mDevice.getDisplayRotation()); + if (mExpectedRotationCheckEnabled) { + assertEquals("Unexpected display rotation", + mExpectedRotation, mDevice.getDisplayRotation()); + } final String error = getNavigationModeMismatchError(true); assertTrue(error, error == null);