From 0ad6d9bceee0ba94d678651cdf679a944ed4f7ca Mon Sep 17 00:00:00 2001 From: Vadim Tryshev Date: Thu, 30 Nov 2023 16:03:25 -0800 Subject: [PATCH] Waiting for Launcher to stop after quick-starting test apps Bug: 313926097 Flag: N/A Test: presubmit Change-Id: I795571ec191b01929bb871fd021d8653449bb608 --- .../launcher3/testing/TestInformationHandler.java | 9 +++++++++ .../android/launcher3/testing/shared/TestProtocol.java | 2 ++ .../com/android/launcher3/ui/AbstractLauncherUiTest.java | 6 ++++++ .../android/launcher3/tapl/LauncherInstrumentation.java | 6 ++++++ 4 files changed, 23 insertions(+) diff --git a/src/com/android/launcher3/testing/TestInformationHandler.java b/src/com/android/launcher3/testing/TestInformationHandler.java index 0438e575c6..1b1d347d81 100644 --- a/src/com/android/launcher3/testing/TestInformationHandler.java +++ b/src/com/android/launcher3/testing/TestInformationHandler.java @@ -104,6 +104,15 @@ public class TestInformationHandler implements ResourceBasedOverride { return getUIProperty(Bundle::putBoolean, t -> isLauncherInitialized(), () -> true); } + case TestProtocol.REQUEST_IS_LAUNCHER_LAUNCHER_ACTIVITY_STARTED: { + final Bundle bundle = getLauncherUIProperty(Bundle::putBoolean, l -> l.isStarted()); + if (bundle != null) return bundle; + + // If Launcher activity wasn't created, it's not started. + response.putBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD, false); + return response; + } + case TestProtocol.REQUEST_FREEZE_APP_LIST: return getLauncherUIProperty(Bundle::putBoolean, l -> { l.getAppsView().getAppsStore().enableDeferUpdates(DEFER_UPDATES_TEST); diff --git a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java index ffe8ce1f13..a55e6822a5 100644 --- a/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java +++ b/tests/shared/com/android/launcher3/testing/shared/TestProtocol.java @@ -86,6 +86,8 @@ public final class TestProtocol { public static final String REQUEST_ICON_HEIGHT = "icon-height"; public static final String REQUEST_IS_LAUNCHER_INITIALIZED = "is-launcher-initialized"; + public static final String REQUEST_IS_LAUNCHER_LAUNCHER_ACTIVITY_STARTED = + "is-launcher-activity-started"; public static final String REQUEST_FREEZE_APP_LIST = "freeze-app-list"; public static final String REQUEST_UNFREEZE_APP_LIST = "unfreeze-app-list"; public static final String REQUEST_ENABLE_MANUAL_TASKBAR_STASHING = "enable-taskbar-stashing"; diff --git a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java index 5f536c7d9a..8ad224913c 100644 --- a/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java +++ b/tests/src/com/android/launcher3/ui/AbstractLauncherUiTest.java @@ -590,6 +590,12 @@ public abstract class AbstractLauncherUiTest { getInstrumentation().getTargetContext().startActivity(intent); assertTrue("App didn't start: " + selector, TestHelpers.wait(Until.hasObject(selector), DEFAULT_UI_TIMEOUT)); + + // Wait for the Launcher to stop. + final LauncherInstrumentation launcherInstrumentation = new LauncherInstrumentation(); + Wait.atMost("Launcher activity didn't stop", + () -> !launcherInstrumentation.isLauncherActivityStarted(), + DEFAULT_ACTIVITY_TIMEOUT, launcherInstrumentation); } public static ActivityInfo resolveSystemAppInfo(String category) { diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 51e1ae0fc4..7568b7d920 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -946,6 +946,12 @@ public final class LauncherInstrumentation { fail("Launcher didn't initialize"); } + public boolean isLauncherActivityStarted() { + return getTestInfo( + TestProtocol.REQUEST_IS_LAUNCHER_LAUNCHER_ACTIVITY_STARTED). + getBoolean(TestProtocol.TEST_INFO_RESPONSE_FIELD); + } + Parcelable executeAndWaitForLauncherEvent(Runnable command, UiAutomation.AccessibilityEventFilter eventFilter, Supplier message, String actionName) {