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

Commit 4397d8d5 authored by vadimt's avatar vadimt
Browse files

Improving TAPL diagnostics

Bug: 128531133
Change-Id: If81861afccb665e2dc2293f2704d99818b3297c8
parent 6d862386
Loading
Loading
Loading
Loading
+65 −42
Original line number Diff line number Diff line
@@ -60,30 +60,39 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
     */
    @NonNull
    public AppIcon getAppIcon(String appName) {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to get app icon on all apps")) {
            final UiObject2 allAppsContainer = verifyActiveContainer();
            final BySelector appIconSelector = AppIcon.getAppIconSelector(appName, mLauncher);
            if (!hasClickableIcon(allAppsContainer, appIconSelector)) {
                scrollBackToBeginning();
                int attempts = 0;
                try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled")) {
                    while (!hasClickableIcon(allAppsContainer, appIconSelector) &&
                            allAppsContainer.scroll(Direction.DOWN, 0.8f)) {
                LauncherInstrumentation.assertTrue(
                        mLauncher.assertTrue(
                                "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
                                ++attempts <= MAX_SCROLL_ATTEMPTS);
                        verifyActiveContainer();
                    }
                }
                verifyActiveContainer();
            }

        final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer, appIconSelector);
            final UiObject2 appIcon = mLauncher.getObjectInContainer(allAppsContainer,
                    appIconSelector);
            ensureIconVisible(appIcon, allAppsContainer);
            return new AppIcon(mLauncher, appIcon);
        }
    }

    private void scrollBackToBeginning() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to scroll back in all apps")) {
            final UiObject2 allAppsContainer = verifyActiveContainer();
            final UiObject2 searchBox =
                mLauncher.waitForObjectInContainer(allAppsContainer, "search_container_all_apps");
                    mLauncher.waitForObjectInContainer(allAppsContainer,
                            "search_container_all_apps");

            int attempts = 0;
            allAppsContainer.setGestureMargins(0, searchBox.getVisibleBounds().bottom + 1, 0, 5);
@@ -91,17 +100,20 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
            for (int scroll = getScroll(allAppsContainer);
                    scroll != 0;
                    scroll = getScroll(allAppsContainer)) {
            LauncherInstrumentation.assertTrue("Negative scroll position", scroll > 0);
                mLauncher.assertTrue("Negative scroll position", scroll > 0);

            LauncherInstrumentation.assertTrue(
                mLauncher.assertTrue(
                        "Exceeded max scroll attempts: " + MAX_SCROLL_ATTEMPTS,
                        ++attempts <= MAX_SCROLL_ATTEMPTS);

                allAppsContainer.scroll(Direction.UP, 1);
            }

            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("scrolled up")) {
                verifyActiveContainer();
            }
        }
    }

    private int getScroll(UiObject2 allAppsContainer) {
        return mLauncher.getAnswerFromLauncher(allAppsContainer, TestProtocol.GET_SCROLL_MESSAGE).
@@ -115,30 +127,41 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
            // to reveal the app icon to have the MIN_INTERACT_SIZE
            final float pct = Math.max(((float) (MIN_INTERACT_SIZE - appHeight)) / mHeight, 0.2f);
            allAppsContainer.scroll(Direction.DOWN, pct);
            try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                    "scrolled an icon in all apps to make it visible - and then")) {
                mLauncher.waitForIdle();
                verifyActiveContainer();
            }
        }
    }

    /**
     * Flings forward (down) and waits the fling's end.
     */
    public void flingForward() {
        try(LauncherInstrumentation.Closable c =
                    mLauncher.addContextLayer("want to fling forward in all apps")) {
            final UiObject2 allAppsContainer = verifyActiveContainer();
            // Start the gesture in the center to avoid starting at elements near the top.
            allAppsContainer.setGestureMargins(0, 0, 0, mHeight / 2);
        allAppsContainer.fling(Direction.DOWN, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            allAppsContainer.fling(Direction.DOWN,
                    (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            verifyActiveContainer();
        }
    }

    /**
     * Flings backward (up) and waits the fling's end.
     */
    public void flingBackward() {
        try(LauncherInstrumentation.Closable c =
                    mLauncher.addContextLayer("want to fling backward in all apps")) {
            final UiObject2 allAppsContainer = verifyActiveContainer();
            // Start the gesture in the center, for symmetry with forward.
            allAppsContainer.setGestureMargins(0, mHeight / 2, 0, 0);
        allAppsContainer.fling(Direction.UP, (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            allAppsContainer.fling(Direction.UP,
                    (int) (FLING_SPEED * mLauncher.getDisplayDensity()));
            verifyActiveContainer();
        }
    }
}
+19 −15
Original line number Diff line number Diff line
@@ -42,6 +42,8 @@ public final class AllAppsFromOverview extends AllApps {
     */
    @NonNull
    public Overview switchBackToOverview() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to switch back from all apps to overview")) {
            final UiObject2 allAppsContainer = verifyActiveContainer();
            // Swipe from the search box to the bottom.
            final UiObject2 qsb = mLauncher.waitForObjectInContainer(
@@ -55,7 +57,9 @@ public final class AllAppsFromOverview extends AllApps {
            LauncherInstrumentation.log("AllAppsFromOverview.switchBackToOverview before swipe");
            mLauncher.swipe(start.x, start.y, start.x, endY, OVERVIEW_STATE_ORDINAL);

            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer("swiped down")) {
                return new Overview(mLauncher);
            }

        }
    }
}
+8 −5
Original line number Diff line number Diff line
@@ -57,12 +57,15 @@ public class Background extends LauncherInstrumentation.VisibleContainer {
     */
    @NonNull
    public BaseOverview switchToOverview() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to switch from background to overview")) {
            verifyActiveContainer();
            goToOverviewUnchecked(BACKGROUND_APP_STATE_ORDINAL);
            assertTrue("Overview not visible", mLauncher.getDevice().wait(
                    Until.hasObject(By.pkg(getOverviewPackageName())), WAIT_TIME_MS));
            return new BaseOverview(mLauncher);
        }
    }

    protected void goToOverviewUnchecked(int expectedState) {
        switch (mLauncher.getNavigationModel()) {
+49 −34
Original line number Diff line number Diff line
@@ -44,6 +44,8 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
     * Flings forward (left) and waits the fling's end.
     */
    public void flingForward() {
        try (LauncherInstrumentation.Closable c =
                     mLauncher.addContextLayer("want to fling forward in overview")) {
            LauncherInstrumentation.log("Overview.flingForward before fling");
            final UiObject2 overview = verifyActiveContainer();
            final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
@@ -52,11 +54,14 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            mLauncher.waitForIdle();
            verifyActiveContainer();
        }
    }

    /**
     * Dismissed all tasks by scrolling to Clear-all button and pressing it.
     */
    public Workspace dismissAllTasks() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "dismissing all tasks")) {
            final BySelector clearAllSelector = mLauncher.getLauncherObjectSelector("clear_all");
            for (int i = 0;
                    i < FLINGS_FOR_DISMISS_LIMIT
@@ -66,13 +71,19 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            }

            mLauncher.getObjectInContainer(verifyActiveContainer(), clearAllSelector).click();
            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
                    "dismissed all tasks")) {
                return new Workspace(mLauncher);
            }
        }
    }

    /**
     * Flings backward (right) and waits the fling's end.
     */
    public void flingBackward() {
        try (LauncherInstrumentation.Closable c =
                     mLauncher.addContextLayer("want to fling backward in overview")) {
            LauncherInstrumentation.log("Overview.flingBackward before fling");
            final UiObject2 overview = verifyActiveContainer();
            final int margin = (int) (50 * mLauncher.getDisplayDensity()) + 1;
@@ -81,6 +92,7 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            mLauncher.waitForIdle();
            verifyActiveContainer();
        }
    }

    /**
     * Gets the current task in the carousel, or fails if the carousel is empty.
@@ -89,10 +101,12 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
     */
    @NonNull
    public OverviewTask getCurrentTask() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to get current task")) {
            verifyActiveContainer();
            final List<UiObject2> taskViews = mLauncher.getDevice().findObjects(
                    mLauncher.getLauncherObjectSelector("snapshot"));
        LauncherInstrumentation.assertNotEquals("Unable to find a task", 0, taskViews.size());
            mLauncher.assertNotEquals("Unable to find a task", 0, taskViews.size());

            // taskViews contains up to 3 task views: the 'main' (having the widest visible
            // part) one in the center, and parts of its right and left siblings. Find the
@@ -104,3 +118,4 @@ public class BaseOverview extends LauncherInstrumentation.VisibleContainer {
            return new OverviewTask(mLauncher, widestTask, this);
        }
    }
}
 No newline at end of file
+9 −3
Original line number Diff line number Diff line
@@ -48,8 +48,14 @@ public abstract class Home extends Background {
    @NonNull
    @Override
    public Overview switchToOverview() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to switch from home to overview")) {
            verifyActiveContainer();
            goToOverviewUnchecked(OVERVIEW_STATE_ORDINAL);
            try (LauncherInstrumentation.Closable c1 = mLauncher.addContextLayer(
                    "performed the switch action")) {
                return new Overview(mLauncher);
            }
        }
    }
}
 No newline at end of file
Loading