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

Commit a34a9a0a authored by Pat Manning's avatar Pat Manning
Browse files

Add screenshot test for edit state drop targets.

see: go/tapl-run-on-hold-event

Bug: 241386128
Test: HomeScreenImageTest.java
Change-Id: I5d6421c8da7d06a9eb77da249957c64d413524f1
parent c5b3b75f
Loading
Loading
Loading
Loading
+18 −2
Original line number Diff line number Diff line
@@ -18,8 +18,6 @@ package com.android.launcher3.ui;

import static androidx.test.InstrumentationRegistry.getInstrumentation;

import android.platform.test.annotations.IwTest;

import static com.google.common.truth.Truth.assertThat;

import static org.junit.Assert.assertEquals;
@@ -31,6 +29,7 @@ import static org.junit.Assume.assumeTrue;

import android.content.Intent;
import android.graphics.Point;
import android.platform.test.annotations.IwTest;

import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;
@@ -435,6 +434,23 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
        waitForState("Launcher internal state didn't switch to Home", () -> LauncherState.NORMAL);
    }

    @Test
    @PortraitLandscape
    public void testDragAndCancelAppIcon() {
        final HomeAppIcon homeAppIcon = createShortcutInCenterIfNotExist(GMAIL_APP_NAME);
        Point positionBeforeDrag =
                mLauncher.getWorkspace().getWorkspaceIconsPositions().get(GMAIL_APP_NAME);
        assertNotNull("App not found in Workspace before dragging.", positionBeforeDrag);

        mLauncher.getWorkspace().dragAndCancelAppIcon(homeAppIcon);

        Point positionAfterDrag =
                mLauncher.getWorkspace().getWorkspaceIconsPositions().get(GMAIL_APP_NAME);
        assertNotNull("App not found in Workspace after dragging.", positionAfterDrag);
        assertEquals("App not returned to same position in Workspace after drag & cancel",
                positionBeforeDrag, positionAfterDrag);
    }

    @Test
    @PortraitLandscape
    public void testDeleteFromWorkspace() throws Exception {
+25 −0
Original line number Diff line number Diff line
@@ -138,6 +138,15 @@ public final class LauncherInstrumentation {
        OUTSIDE_WITH_KEYCODE,
    }

    /**
     * Represents a point in the code at which a callback can run.
     */
    public enum CALLBACK_RUN_POINT {
        CALLBACK_HOLD_BEFORE_DROP
    }

    private Consumer<CALLBACK_RUN_POINT> mCallbackAtRunPoint = null;

    // Base class for launcher containers.
    abstract static class VisibleContainer {
        protected final LauncherInstrumentation mLauncher;
@@ -1935,4 +1944,20 @@ public final class LauncherInstrumentation {
                    LauncherInstrumentation.GestureScope.INSIDE);
        }
    }

    /**
     * Sets the consumer to run callbacks at all run-points.
     */
    public void setRunPointCallback(Consumer<CALLBACK_RUN_POINT> callback) {
        mCallbackAtRunPoint = callback;
    }

    /**
     * Runs the callback at the specified point if it exists.
     */
    void runCallbackIfActive(CALLBACK_RUN_POINT runPoint) {
        if (mCallbackAtRunPoint != null) {
            mCallbackAtRunPoint.accept(runPoint);
        }
    }
}
+27 −0
Original line number Diff line number Diff line
@@ -18,6 +18,7 @@ package com.android.launcher3.tapl;

import static android.view.accessibility.AccessibilityEvent.TYPE_VIEW_SCROLLED;

import static com.android.launcher3.tapl.LauncherInstrumentation.CALLBACK_RUN_POINT.CALLBACK_HOLD_BEFORE_DROP;
import static com.android.launcher3.testing.shared.TestProtocol.ALL_APPS_STATE_ORDINAL;
import static com.android.launcher3.testing.shared.TestProtocol.NORMAL_STATE_ORDINAL;

@@ -301,6 +302,31 @@ public final class Workspace extends Home {
                targetId).getVisibleCenter();
    }

    /**
     * Drag the appIcon from the workspace and cancel by dragging icon to corner of screen where no
     * drop point exists.
     *
     * @param homeAppIcon to be dragged.
     */
    @NonNull
    public Workspace dragAndCancelAppIcon(HomeAppIcon homeAppIcon) {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                     "dragging app icon across workspace")) {
            dragIconToWorkspace(
                    mLauncher,
                    homeAppIcon,
                    () -> new Point(0, 0),
                    () -> mLauncher.expectEvent(TestProtocol.SEQUENCE_MAIN, LONG_CLICK_EVENT),
                    null);

            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
                    "dragged the app across workspace")) {
                return new Workspace(mLauncher);
            }
        }
    }

    /**
     * Delete the appIcon from the workspace.
     *
@@ -493,6 +519,7 @@ public final class Workspace extends Home {
            launcher.movePointer(dragStart, targetDest, DEFAULT_DRAG_STEPS, isDecelerating,
                    downTime, SystemClock.uptimeMillis(), false,
                    LauncherInstrumentation.GestureScope.INSIDE);
            launcher.runCallbackIfActive(CALLBACK_HOLD_BEFORE_DROP);
            dropDraggedIcon(launcher, targetDest, downTime, expectDropEvents);
        }
    }