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

Commit 7802ec4f authored by Ling Wo's avatar Ling Wo Committed by Android (Google) Code Review
Browse files

Merge "Uninstall an app from workspace via TAPL"

parents 979c84b9 5b59e75f
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -32,6 +32,7 @@ filegroup {
    srcs: [
      "src/com/android/launcher3/ui/AbstractLauncherUiTest.java",
      "src/com/android/launcher3/ui/PortraitLandscapeRunner.java",
      "src/com/android/launcher3/util/TestUtil.java",
      "src/com/android/launcher3/util/Wait.java",
      "src/com/android/launcher3/util/WidgetUtils.java",
      "src/com/android/launcher3/util/rule/FailureWatcher.java",
@@ -71,6 +72,11 @@ android_library {
    platform_apis: true,
}

android_library {
    name: "Launcher3TestResources",
    resource_dirs: ["res"],
}

android_test {
    name: "Launcher3Tests",
    srcs: [
+45 −1
Original line number Diff line number Diff line
@@ -38,6 +38,7 @@ import com.android.launcher3.tapl.Folder;
import com.android.launcher3.tapl.FolderIcon;
import com.android.launcher3.tapl.Widgets;
import com.android.launcher3.tapl.Workspace;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.widget.picker.WidgetsFullSheet;
import com.android.launcher3.widget.picker.WidgetsRecyclerView;

@@ -50,6 +51,7 @@ import org.junit.runner.RunWith;
@RunWith(AndroidJUnit4.class)
public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
    private static final String APP_NAME = "LauncherTestApp";
    private static final String DUMMY_APP_NAME = "Aardwolf";

    @Before
    public void setUp() throws Exception {
@@ -435,6 +437,48 @@ public class TaplTestsLauncher3 extends AbstractLauncherUiTest {
        }
    }

    private void verifyAppUninstalledFromAllApps(Workspace workspace, String appName) {
        final AllApps allApps = workspace.switchToAllApps();
        allApps.freeze();
        try {
            assertNull(appName + " app was found on all apps after being uninstalled",
                    allApps.tryGetAppIcon(appName));
        } finally {
            allApps.unfreeze();
        }
    }

    @Test
    @PortraitLandscape
    public void testUninstallFromWorkspace() throws Exception {
        TestUtil.installDummyApp();
        try {
            verifyAppUninstalledFromAllApps(
                    createShortcutIfNotExist(DUMMY_APP_NAME).uninstall(), DUMMY_APP_NAME);
        } finally {
            TestUtil.uninstallDummyApp();
        }
    }

    @Test
    @PortraitLandscape
    public void testUninstallFromAllApps() throws Exception {
        TestUtil.installDummyApp();
        try {
            Workspace workspace = mLauncher.getWorkspace();
            final AllApps allApps = workspace.switchToAllApps();
            allApps.freeze();
            try {
                workspace = allApps.getAppIcon(DUMMY_APP_NAME).uninstall();
            } finally {
                allApps.unfreeze();
            }
            verifyAppUninstalledFromAllApps(workspace, DUMMY_APP_NAME);
        } finally {
            TestUtil.uninstallDummyApp();
        }
    }

    public static String getAppPackageName() {
        return getInstrumentation().getContext().getPackageName();
    }
+4 −15
Original line number Diff line number Diff line
@@ -22,8 +22,6 @@ import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.UiObject2;

import com.android.launcher3.testing.TestProtocol;

import java.util.regex.Pattern;

public class AddToHomeScreenPrompt {
@@ -44,19 +42,10 @@ public class AddToHomeScreenPrompt {

    public void addAutomatically() {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck()) {
            if (mLauncher.getNavigationModel()
                    != LauncherInstrumentation.NavigationModel.THREE_BUTTON) {
                if (!mLauncher.isLauncher3()) {
                    mLauncher.expectEvent(
                            TestProtocol.SEQUENCE_TIS,
                            LauncherInstrumentation.EVENT_TOUCH_DOWN_TIS);
                    mLauncher.expectEvent(
                            TestProtocol.SEQUENCE_TIS, LauncherInstrumentation.EVENT_TOUCH_UP_TIS);
                }
            }
            mLauncher.clickObject(
                    mLauncher.waitForObjectInContainer(
                            mWidgetCell.getParent().getParent().getParent().getParent(),
                    By.text(ADD_AUTOMATICALLY)).click();
                            By.text(ADD_AUTOMATICALLY)));
            mLauncher.waitUntilLauncherObjectGone(getSelector());
        }
    }
+32 −16
Original line number Diff line number Diff line
@@ -22,6 +22,7 @@ import android.os.Bundle;
import android.widget.TextView;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.test.uiautomator.By;
import androidx.test.uiautomator.BySelector;
import androidx.test.uiautomator.Direction;
@@ -51,8 +52,8 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
        mLauncher.waitForObjectInContainer(appListRecycler, By.clazz(TextView.class));
        verifyNotFrozen("All apps freeze flags upon opening all apps");
        mIconHeight = mLauncher.getTestInfo(
                TestProtocol.REQUEST_ICON_HEIGHT).
                getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
                        TestProtocol.REQUEST_ICON_HEIGHT)
                .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
    }

    @Override
@@ -98,14 +99,14 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
    }

    /**
     * Finds an icon. Fails if the icon doesn't exist. Scrolls the app list when needed to make
     * sure the icon is visible.
     * Finds an icon. If the icon doesn't exist, return null.
     * Scrolls the app list when needed to make sure the icon is visible.
     *
     * @param appName name of the app.
     * @return The app.
     * @return The app if found, and null if not found.
     */
    @NonNull
    public AppIcon getAppIcon(String appName) {
    @Nullable
    public AppIcon tryGetAppIcon(String appName) {
        try (LauncherInstrumentation.Closable e = mLauncher.eventsCheck();
             LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                     "getting app icon " + appName + " on all apps")) {
@@ -150,19 +151,34 @@ public class AllApps extends LauncherInstrumentation.VisibleContainer {
                }
                verifyActiveContainer();
            }

            // Ignore bottom offset selection here as there might not be any scroll more scroll
            // region available.
            mLauncher.assertTrue("Unable to scroll to a clickable icon: " + appName,
                    hasClickableIcon(allAppsContainer, appListRecycler, appIconSelector,
                            deviceHeight));
            if (hasClickableIcon(
                    allAppsContainer, appListRecycler, appIconSelector, deviceHeight)) {

                final UiObject2 appIcon = mLauncher.waitForObjectInContainer(appListRecycler,
                        appIconSelector);
            return new AppIcon(mLauncher, appIcon);
                return new AllAppsAppIcon(mLauncher, appIcon);
            } else {
                return null;
            }
        }
    }

    /**
     * Finds an icon. Fails if the icon doesn't exist. Scrolls the app list when needed to make
     * sure the icon is visible.
     *
     * @param appName name of the app.
     * @return The app.
     */
    @NonNull
    public AppIcon getAppIcon(String appName) {
        AppIcon appIcon = tryGetAppIcon(appName);
        mLauncher.assertNotNull("Unable to scroll to a clickable icon: " + appName, appIcon);
        return appIcon;
    }

    private void scrollBackToBeginning() {
        try (LauncherInstrumentation.Closable c = mLauncher.addContextLayer(
                "want to scroll back in all apps")) {
+38 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2022 The Android Open Source Project
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.android.launcher3.tapl;

import androidx.test.uiautomator.UiObject2;

import java.util.regex.Pattern;

/**
 * App icon in all apps.
 */
final class AllAppsAppIcon extends AppIcon {

    private static final Pattern LONG_CLICK_EVENT = Pattern.compile("onAllAppsItemLongClick");

    AllAppsAppIcon(LauncherInstrumentation launcher, UiObject2 icon) {
        super(launcher, icon);
    }

    @Override
    protected Pattern getLongClickEvent() {
        return LONG_CLICK_EVENT;
    }
}
Loading