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
diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
index 50e0990..e1a2c1b 100644
--- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
+++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java
@@ -195,6 +195,15 @@
 
     @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 {
         assumeTrue(mLauncher.isTablet());
 
diff --git a/tests/tapl/com/android/launcher3/tapl/AllApps.java b/tests/tapl/com/android/launcher3/tapl/AllApps.java
index b0cf20f..6f6428a 100644
--- a/tests/tapl/com/android/launcher3/tapl/AllApps.java
+++ b/tests/tapl/com/android/launcher3/tapl/AllApps.java
@@ -244,7 +244,7 @@
         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 9a4c6d4..50b03aa 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 @@
         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;