From 55d828b6f56b1718e3f86b2b03fbd7a57c6e5c42 Mon Sep 17 00:00:00 2001 From: Luca Zuccarini Date: Wed, 23 Nov 2022 14:37:31 +0000 Subject: [PATCH] Add Tapl support for swiping from All Apps to Workspace. This mirrors the way we swipe from Workspace to All Apps, with minor differences for selecting the start position of the swipe motion. Bug: 260218332 Test: included Change-Id: I9fe2284b1c920ebed87a6bab3dfc9c8c29aa2d5d --- .../launcher3/ui/TaplTestsLauncher3.java | 9 ++++ .../com/android/launcher3/tapl/AllApps.java | 2 +- .../android/launcher3/tapl/HomeAllApps.java | 42 +++++++++++++++++++ 3 files changed, 52 insertions(+), 1 deletion(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 50e099068f..e1a2c1bf4d 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -193,6 +193,15 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { isInState(() -> LauncherState.ALL_APPS)); } + @Test + @PortraitLandscape + public void testAllAppsSwitchToWorkspace() { + assertNotNull("switchToWorkspace() returned null", + mLauncher.getWorkspace().switchToAllApps().switchToWorkspace()); + assertTrue("Launcher internal state is not Workspace", + isInState(() -> LauncherState.NORMAL)); + } + @Test @PortraitLandscape public void testAllAppsDeadzoneForTablet() throws Exception { diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java index b0cf20f796..6f6428ad78 100644 --- a/tests/tapl/com/android/launcher3/tapl/AllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java @@ -244,7 +244,7 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer { return mLauncher.waitForObjectInContainer(allAppsContainer, "apps_list_view"); } - private UiObject2 getSearchBox(UiObject2 allAppsContainer) { + protected UiObject2 getSearchBox(UiObject2 allAppsContainer) { return mLauncher.waitForObjectInContainer(allAppsContainer, "search_container_all_apps"); } diff --git a/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java b/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java index 9a4c6d4dce..50b03aa7df 100644 --- a/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java @@ -15,11 +15,17 @@ */ package com.android.launcher3.tapl; +import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL; + +import android.graphics.Rect; + import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; import com.android.launcher3.testing.shared.TestProtocol; +import java.util.Objects; + public class HomeAllApps extends AllApps { private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; @@ -27,6 +33,42 @@ public class HomeAllApps extends AllApps { super(launcher); } + /** + * Swipes down to Workspace. + * + * @return the Workspace object. + */ + @NonNull + public Workspace switchToWorkspace() { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = + mLauncher.addContextLayer("want to switch from all apps to workspace")) { + UiObject2 allAppsContainer = verifyActiveContainer(); + + final Rect searchBoxBounds = Objects.requireNonNull( + mLauncher.getVisibleBounds(getSearchBox(allAppsContainer))); + final int startX = searchBoxBounds.centerX(); + final int startY = searchBoxBounds.bottom; + final int endY = mLauncher.getDevice().getDisplayHeight(); + LauncherInstrumentation.log( + "switchToWorkspace: startY = " + startY + ", endY = " + endY + + ", slop = " + mLauncher.getTouchSlop()); + + mLauncher.swipeToState( + startX, + startY, + startX, + endY, + 12 /* steps */, + NORMAL_STATE_ORDINAL, LauncherInstrumentation.GestureScope.INSIDE); + + try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer( + "swiped to workspace")) { + return mLauncher.getWorkspace(); + } + } + } + @Override protected LauncherInstrumentation.ContainerType getContainerType() { return LauncherInstrumentation.ContainerType.HOME_ALL_APPS;