From b18ac9a01a6e5ef7f8b61a6be2a0702bb7102ce8 Mon Sep 17 00:00:00 2001 From: vadimt Date: Thu, 13 Oct 2022 14:25:55 -0700 Subject: [PATCH] Making Launcher TAPL check orientation only when the expected orientation is set by the test This makes life simpler for tests that don't care about orientation Bug: 245576832 Test: presubmit Change-Id: I3c247826c6cac0e20c93a2fad9b81775fd2ebaa8 --- .../tapl/LauncherInstrumentation.java | 23 +++++++++++-------- 1 file changed, 14 insertions(+), 9 deletions(-) diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 98a48c0549..46787347d2 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -48,7 +48,6 @@ import android.text.TextUtils; import android.util.Log; import android.view.InputDevice; import android.view.MotionEvent; -import android.view.Surface; import android.view.ViewConfiguration; import android.view.WindowManager; import android.view.accessibility.AccessibilityEvent; @@ -180,7 +179,7 @@ public final class LauncherInstrumentation { private final UiDevice mDevice; private final Instrumentation mInstrumentation; - private int mExpectedRotation = Surface.ROTATION_0; + private Integer mExpectedRotation = null; private boolean mExpectedRotationCheckEnabled = true; private final Uri mTestProviderUri; private final Deque mDiagnosticContext = new LinkedList<>(); @@ -194,6 +193,7 @@ public final class LauncherInstrumentation { private boolean mCheckEventsForSuccessfulGestures = false; private Runnable mOnLauncherCrashed; + private static Pattern getTouchEventPattern(String prefix, String action) { // The pattern includes checks that we don't get a multi-touch events or other surprises. return Pattern.compile( @@ -298,8 +298,8 @@ public final class LauncherInstrumentation { final String testSuffix = ".test"; return testPackage.endsWith(testSuffix) && testPackage.length() > testSuffix.length() - && testPackage.substring(0, testPackage.length() - testSuffix.length()) - .equals(targetPackage); + && testPackage.substring(0, testPackage.length() - testSuffix.length()) + .equals(targetPackage); } public void enableCheckEventsForSuccessfulGestures() { @@ -686,15 +686,20 @@ public final class LauncherInstrumentation { * Whether to ignore verifying the task bar visibility during instrumenting. * * @param ignoreTaskbarVisibility {@code true} will ignore the instrumentation implicitly - * verifying the task bar visibility with - * {@link VisibleContainer#verifyActiveContainer}. - * {@code false} otherwise. + * verifying the task bar visibility with + * {@link VisibleContainer#verifyActiveContainer}. + * {@code false} otherwise. */ public void setIgnoreTaskbarVisibility(boolean ignoreTaskbarVisibility) { mIgnoreTaskbarVisibility = ignoreTaskbarVisibility; } - public void setExpectedRotation(int expectedRotation) { + /** + * Sets expected rotation. + * TAPL periodically checks that Launcher didn't suddenly change the rotation to unexpected one. + * Null parameter disables checks. The initial state is "no checks". + */ + public void setExpectedRotation(Integer expectedRotation) { mExpectedRotation = expectedRotation; } @@ -735,7 +740,7 @@ public final class LauncherInstrumentation { private UiObject2 verifyContainerType(ContainerType containerType) { waitForLauncherInitialized(); - if (mExpectedRotationCheckEnabled) { + if (mExpectedRotationCheckEnabled && mExpectedRotation != null) { assertEquals("Unexpected display rotation", mExpectedRotation, mDevice.getDisplayRotation()); }