Donate to e Foundation | Murena handsets with /e/OS | Own a part of Murena! Learn more

Commit f52a13e4 authored by Alex Chau's avatar Alex Chau Committed by Android (Google) Code Review
Browse files

Merge "Add test to dismiss AllApps bottom sheet" into tm-qpr-dev

parents 7cbe51c2 d936273b
Loading
Loading
Loading
Loading
+12 −0
Original line number Diff line number Diff line
@@ -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;
@@ -191,6 +192,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 {
+2 −17
Original line number Diff line number Diff line
@@ -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();
        }
+20 −0
Original line number Diff line number Diff line
@@ -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();
            }
        }
    }
}
+22 −0
Original line number Diff line number Diff line
@@ -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);
        }
    }
}
+20 −0
Original line number Diff line number Diff line
@@ -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();
            }
        }
    }
}