From d936273b1f762146330fd0b2f48081a1033eabb4 Mon Sep 17 00:00:00 2001 From: Alex Chau Date: Mon, 20 Jun 2022 22:05:46 +0100 Subject: [PATCH] Add test to dismiss AllApps bottom sheet - http://docs/document/d/1ITZDMchoMndfa0nMuOTXbhKhK2aMDz0AT9dgusgxEro Bug: 236360930 Test: TaplTestsLauncher3.testAllAppsDeadzoneForTablet Test: TaplTestsNexus.testSearchDeadzoneForTablet Change-Id: I62adb1d6ef237f9bca3812b8cdce9e5a8383158f --- .../launcher3/ui/TaplTestsLauncher3.java | 12 ++++++++++ .../com/android/launcher3/tapl/Folder.java | 19 ++-------------- .../android/launcher3/tapl/HomeAllApps.java | 20 +++++++++++++++++ .../tapl/LauncherInstrumentation.java | 22 +++++++++++++++++++ .../launcher3/tapl/SearchResultFromQsb.java | 20 +++++++++++++++++ 5 files changed, 76 insertions(+), 17 deletions(-) diff --git a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java index 0f29abc3d2..8fa456083e 100644 --- a/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java +++ b/tests/src/com/android/launcher3/ui/TaplTestsLauncher3.java @@ -25,6 +25,7 @@ import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertTrue; +import static org.junit.Assume.assumeTrue; import android.content.Intent; import android.graphics.Point; @@ -190,6 +191,17 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest { isInState(() -> LauncherState.ALL_APPS)); } + @Test + @PortraitLandscape + public void testAllAppsDeadzoneForTablet() throws Exception { + assumeTrue(mLauncher.isTablet()); + + mLauncher.getWorkspace().switchToAllApps().dismissByTappingOutsideForTablet( + true /* tapRight */); + mLauncher.getWorkspace().switchToAllApps().dismissByTappingOutsideForTablet( + false /* tapRight */); + } + @Test @ScreenRecord // b/202433017 public void testWorkspace() throws Exception { diff --git a/tests/tapl/com/android/launcher3/tapl/Folder.java b/tests/tapl/com/android/launcher3/tapl/Folder.java index 26f0a8b26d..1352cc07c1 100644 --- a/tests/tapl/com/android/launcher3/tapl/Folder.java +++ b/tests/tapl/com/android/launcher3/tapl/Folder.java @@ -16,11 +16,6 @@ package com.android.launcher3.tapl; -import android.graphics.Point; -import android.graphics.Rect; -import android.os.SystemClock; -import android.view.MotionEvent; - import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; @@ -50,25 +45,15 @@ public class Folder { } } - private void touchOutsideFolder() { - Rect containerBounds = mLauncher.getVisibleBounds(this.mContainer); - final long downTime = SystemClock.uptimeMillis(); - Point containerLeftTopCorner = new Point(containerBounds.left - 1, containerBounds.top - 1); - mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, - containerLeftTopCorner, LauncherInstrumentation.GestureScope.INSIDE); - mLauncher.sendPointer(downTime, downTime, MotionEvent.ACTION_UP, - containerLeftTopCorner, LauncherInstrumentation.GestureScope.INSIDE); - } - /** - * CLose opened folder if possible. It throws assertion error if the folder is already closed. + * Close opened folder if possible. It throws assertion error if the folder is already closed. */ public Workspace close() { try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); LauncherInstrumentation.Closable c = mLauncher.addContextLayer( "Want to close opened folder")) { mLauncher.waitForLauncherObject(FOLDER_CONTENT_RES_ID); - touchOutsideFolder(); + mLauncher.touchOutsideContainer(this.mContainer, false /* tapRight */); mLauncher.waitUntilLauncherObjectGone(FOLDER_CONTENT_RES_ID); return mLauncher.getWorkspace(); } diff --git a/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java b/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java index c275f3b320..7123de44a9 100644 --- a/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java +++ b/tests/tapl/com/android/launcher3/tapl/HomeAllApps.java @@ -19,6 +19,7 @@ import androidx.annotation.NonNull; import androidx.test.uiautomator.UiObject2; public class HomeAllApps extends AllApps { + private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; HomeAllApps(LauncherInstrumentation launcher) { super(launcher); @@ -45,4 +46,23 @@ public class HomeAllApps extends AllApps { protected boolean hasSearchBox() { return true; } + + /** + * Taps outside bottom sheet to dismiss and return to workspace. Available on tablets only. + * @param tapRight Tap on the right of bottom sheet if true, or left otherwise. + */ + public Workspace dismissByTappingOutsideForTablet(boolean tapRight) { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to tap outside AllApps bottom sheet on the " + + (tapRight ? "right" : "left"))) { + final UiObject2 allAppsBottomSheet = + mLauncher.waitForLauncherObject(BOTTOM_SHEET_RES_ID); + mLauncher.touchOutsideContainer(allAppsBottomSheet, tapRight); + try (LauncherInstrumentation.Closable tapped = mLauncher.addContextLayer( + "tapped outside AllApps bottom sheet")) { + return mLauncher.getWorkspace(); + } + } + } } diff --git a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java index 99cab848a6..ae7c46a647 100644 --- a/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java +++ b/tests/tapl/com/android/launcher3/tapl/LauncherInstrumentation.java @@ -1831,4 +1831,26 @@ public final class LauncherInstrumentation { return ResourceUtils.getBoolByName( "config_supportsRoundedCornersOnWindows", resources, false); } + + /** + * Taps outside container to dismiss. + * @param container container to be dismissed + * @param tapRight tap on the right of the container if true, or left otherwise + */ + void touchOutsideContainer(UiObject2 container, boolean tapRight) { + try (LauncherInstrumentation.Closable c = addContextLayer( + "want to tap outside container on the " + (tapRight ? "right" : "left"))) { + Rect containerBounds = getVisibleBounds(container); + final long downTime = SystemClock.uptimeMillis(); + final Point tapTarget = new Point( + tapRight + ? (containerBounds.right + getRealDisplaySize().x) / 2 + : containerBounds.left / 2, + containerBounds.top + 1); + sendPointer(downTime, downTime, MotionEvent.ACTION_DOWN, tapTarget, + LauncherInstrumentation.GestureScope.INSIDE); + sendPointer(downTime, downTime, MotionEvent.ACTION_UP, tapTarget, + LauncherInstrumentation.GestureScope.INSIDE); + } + } } diff --git a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java index 82652c7f27..ddeeac225a 100644 --- a/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java +++ b/tests/tapl/com/android/launcher3/tapl/SearchResultFromQsb.java @@ -26,6 +26,7 @@ import androidx.test.uiautomator.UiObject2; public class SearchResultFromQsb { // The input resource id in the search box. private static final String INPUT_RES = "input"; + private static final String BOTTOM_SHEET_RES_ID = "bottom_sheet_background"; private final LauncherInstrumentation mLauncher; SearchResultFromQsb(LauncherInstrumentation launcher) { @@ -47,4 +48,23 @@ public class SearchResultFromQsb { UiObject2 icon = mLauncher.waitForLauncherObject(By.clazz(TextView.class).text(appName)); return new AllAppsAppIcon(mLauncher, icon); } + + /** + * Taps outside bottom sheet to dismiss and return to workspace. Available on tablets only. + * @param tapRight Tap on the right of bottom sheet if true, or left otherwise. + */ + public Workspace dismissByTappingOutsideForTablet(boolean tapRight) { + try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck(); + LauncherInstrumentation.Closable c = mLauncher.addContextLayer( + "want to tap outside AllApps bottom sheet on the " + + (tapRight ? "right" : "left"))) { + final UiObject2 allAppsBottomSheet = + mLauncher.waitForLauncherObject(BOTTOM_SHEET_RES_ID); + mLauncher.touchOutsideContainer(allAppsBottomSheet, tapRight); + try (LauncherInstrumentation.Closable tapped = mLauncher.addContextLayer( + "tapped outside AllApps bottom sheet")) { + return mLauncher.getWorkspace(); + } + } + } }