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

Commit 0606b1f2 authored by Schneider Victor-tulias's avatar Schneider Victor-tulias Committed by Android (Google) Code Review
Browse files

Merge "Add TAPL tests for the keyboard quick switch view" into main

parents 850a2824 41b42bf7
Loading
Loading
Loading
Loading
+187 −0
Original line number Diff line number Diff line
/*
 * Copyright (C) 2023 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.quickstep;

import android.content.Intent;

import androidx.annotation.NonNull;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.tapl.KeyboardQuickSwitch;
import com.android.launcher3.ui.TaplTestsLauncher3;

import org.junit.Assume;
import org.junit.Test;
import org.junit.runner.RunWith;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class TaplTestsKeyboardQuickSwitch extends AbstractQuickStepTest {

    private enum TestSurface {
        HOME, LAUNCHED_APP, HOME_ALL_APPS, WIDGETS,
    }

    private enum TestCase {
        DISMISS(0),
        LAUNCH_LAST_APP(0),
        LAUNCH_SELECTED_APP(1),
        LAUNCH_OVERVIEW(5);

        private final int mNumAdditionalRunningTasks;

        TestCase(int numAdditionalRunningTasks) {
            mNumAdditionalRunningTasks = numAdditionalRunningTasks;
        }
    }

    private static final String CALCULATOR_APP_PACKAGE =
            resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR);

    @Override
    public void setUp() throws Exception {
        Assume.assumeTrue(mLauncher.isTablet());
        super.setUp();
        TaplTestsLauncher3.initialize(this);
        startAppFast(CALCULATOR_APP_PACKAGE);
        startTestActivity(2);
    }

    @Test
    public void testDismiss_fromHome() {
        runTest(TestSurface.HOME, TestCase.DISMISS);
    }

    @Test
    public void testDismiss_fromApp() {
        runTest(TestSurface.LAUNCHED_APP, TestCase.DISMISS);
    }

    @Test
    public void testDismiss_fromHomeAllApps() {
        runTest(TestSurface.HOME_ALL_APPS, TestCase.DISMISS);
    }

    @Test
    public void testDismiss_fromWidgets() {
        runTest(TestSurface.WIDGETS, TestCase.DISMISS);
    }

    @Test
    public void testLaunchLastTask_fromHome() {
        runTest(TestSurface.HOME, TestCase.LAUNCH_LAST_APP);
    }

    @Test
    public void testLaunchLastTask_fromApp() {
        runTest(TestSurface.LAUNCHED_APP, TestCase.LAUNCH_LAST_APP);
    }

    @Test
    public void testLaunchLastTask_fromHomeAllApps() {
        runTest(TestSurface.HOME_ALL_APPS, TestCase.LAUNCH_LAST_APP);
    }

    @Test
    public void testLaunchLastTask_fromWidgets() {
        runTest(TestSurface.WIDGETS, TestCase.LAUNCH_LAST_APP);
    }

    @Test
    public void testLaunchSelectedTask_fromHome() {
        runTest(TestSurface.HOME, TestCase.LAUNCH_SELECTED_APP);
    }

    @Test
    public void testLaunchSelectedTask_fromApp() {
        runTest(TestSurface.LAUNCHED_APP, TestCase.LAUNCH_SELECTED_APP);
    }

    @Test
    public void testLaunchSelectedTask_fromHomeAllApps() {
        runTest(TestSurface.HOME_ALL_APPS, TestCase.LAUNCH_SELECTED_APP);
    }

    @Test
    public void testLaunchSelectedTask_fromWidgets() {
        runTest(TestSurface.WIDGETS, TestCase.LAUNCH_SELECTED_APP);
    }

    @Test
    public void testLaunchOverviewTask_fromHome() {
        runTest(TestSurface.HOME, TestCase.LAUNCH_OVERVIEW);
    }

    @Test
    public void testLaunchOverviewTask_fromApp() {
        runTest(TestSurface.LAUNCHED_APP, TestCase.LAUNCH_OVERVIEW);
    }

    @Test
    public void testLaunchOverviewTask_fromHomeAllApps() {
        runTest(TestSurface.HOME_ALL_APPS, TestCase.LAUNCH_OVERVIEW);
    }

    @Test
    public void testLaunchOverviewTask_fromWidgets() {
        runTest(TestSurface.WIDGETS, TestCase.LAUNCH_OVERVIEW);
    }

    private void runTest(@NonNull TestSurface testSurface, @NonNull TestCase testCase) {
        for (int i = 0; i < testCase.mNumAdditionalRunningTasks; i++) {
            startTestActivity(3 + i);
        }

        KeyboardQuickSwitch kqs;
        switch (testSurface) {
            case HOME:
                kqs = mLauncher.goHome().showQuickSwitchView();
                break;
            case LAUNCHED_APP:
                mLauncher.setIgnoreTaskbarVisibility(true);
                kqs = mLauncher.getLaunchedAppState().showQuickSwitchView();
                break;
            case HOME_ALL_APPS:
                kqs = mLauncher.goHome().switchToAllApps().showQuickSwitchView();
                break;
            case WIDGETS:
                kqs = mLauncher.goHome().openAllWidgets().showQuickSwitchView();
                break;
            default:
                throw new IllegalStateException(
                        "KeyboardQuickSwitch could not be initialized for test surface: "
                            + testSurface);
        }

        switch (testCase) {
            case DISMISS:
                kqs.dismiss();
                break;
            case LAUNCH_LAST_APP:
                kqs.launchFocusedAppTask(CALCULATOR_APP_PACKAGE);
                break;
            case LAUNCH_SELECTED_APP:
                kqs.moveFocusForward().launchFocusedAppTask(CALCULATOR_APP_PACKAGE);
                break;
            case LAUNCH_OVERVIEW:
                kqs.moveFocusBackward().moveFocusBackward().launchFocusedOverviewTask();
                break;
            default:
                throw new IllegalStateException("Cannot run test case: " + testCase);
        }
    }
}
+12 −1
Original line number Diff line number Diff line
@@ -42,7 +42,8 @@ import java.util.stream.Collectors;
/**
 * Operations on AllApps opened from Home. Also a parent for All Apps opened from Overview.
 */
public abstract class AllApps extends LauncherInstrumentation.VisibleContainer {
public abstract class AllApps extends LauncherInstrumentation.VisibleContainer
        implements KeyboardQuickSwitchSource {
    // Defer updates flag used to defer all apps updates by a test's request.
    private static final int DEFER_UPDATES_TEST = 1 << 1;

@@ -65,6 +66,16 @@ public abstract class AllApps extends LauncherInstrumentation.VisibleContainer {
                .getInt(TestProtocol.TEST_INFO_RESPONSE_FIELD);
    }

    @Override
    public LauncherInstrumentation getLauncher() {
        return mLauncher;
    }

    @Override
    public LauncherInstrumentation.ContainerType getStartingContainerType() {
        return getContainerType();
    }

    private boolean hasClickableIcon(UiObject2 allAppsContainer, UiObject2 appListRecycler,
            BySelector appIconSelector, int displayBottom) {
        final UiObject2 icon;
+12 −1
Original line number Diff line number Diff line
@@ -39,7 +39,8 @@ import java.util.regex.Pattern;
 * Indicates the base state with a UI other than Overview running as foreground. It can also
 * indicate Launcher as long as Launcher is not in Overview state.
 */
public abstract class Background extends LauncherInstrumentation.VisibleContainer {
public abstract class Background extends LauncherInstrumentation.VisibleContainer
        implements KeyboardQuickSwitchSource {
    private static final int ZERO_BUTTON_SWIPE_UP_GESTURE_DURATION = 500;
    private static final Pattern SQUARE_BUTTON_EVENT = Pattern.compile("onOverviewToggle");

@@ -47,6 +48,16 @@ public abstract class Background extends LauncherInstrumentation.VisibleContaine
        super(launcher);
    }

    @Override
    public LauncherInstrumentation getLauncher() {
        return mLauncher;
    }

    @Override
    public LauncherInstrumentation.ContainerType getStartingContainerType() {
        return getContainerType();
    }

    /**
     * Swipes up or presses the square button to switch to Overview.
     * Returns the base overview, which can be either in Launcher or the fallback recents.
+5 −0
Original line number Diff line number Diff line
@@ -62,4 +62,9 @@ public abstract class Home extends Background {
    protected boolean zeroButtonToOverviewGestureStateTransitionWhileHolding() {
        return true;
    }

    @Override
    public boolean isHomeState() {
        return true;
    }
}
 No newline at end of file
+5 −0
Original line number Diff line number Diff line
@@ -113,4 +113,9 @@ public class HomeAllApps extends AllApps {
    protected void verifyVisibleContainerOnDismiss() {
        mLauncher.getWorkspace();
    }

    @Override
    public boolean isHomeState() {
        return true;
    }
}
Loading