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

Commit 0019e59d authored by Sunny Goyal's avatar Sunny Goyal Committed by Android (Google) Code Review
Browse files

Merge "Moving some tests off TAPL" into main

parents c6c724ac 5ad2d9f5
Loading
Loading
Loading
Loading
+21 −16
Original line number Diff line number Diff line
@@ -15,7 +15,9 @@
 */
package com.android.quickstep;

import static androidx.test.InstrumentationRegistry.getInstrumentation;
import static androidx.test.platform.app.InstrumentationRegistry.getInstrumentation;

import static com.android.launcher3.util.TestUtil.resolveSystemAppInfo;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
@@ -25,10 +27,13 @@ import android.app.PendingIntent;
import android.app.usage.UsageStatsManager;
import android.content.Intent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;
import androidx.test.runner.AndroidJUnit4;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.uioverrides.QuickstepLauncher;
import com.android.launcher3.util.BaseLauncherActivityTest;
import com.android.quickstep.views.DigitalWellBeingToast;
import com.android.quickstep.views.RecentsView;
import com.android.quickstep.views.TaskContainer;
@@ -41,30 +46,31 @@ import java.time.Duration;

@LargeTest
@RunWith(AndroidJUnit4.class)
public class TaplDigitalWellBeingToastTest extends AbstractQuickStepTest {
    private static final String CALCULATOR_PACKAGE =
            resolveSystemApp(Intent.CATEGORY_APP_CALCULATOR);
public class DigitalWellBeingToastTest extends BaseLauncherActivityTest<QuickstepLauncher> {

    public final String calculatorPackage =
            resolveSystemAppInfo(Intent.CATEGORY_APP_CALCULATOR).packageName;

    @Test
    public void testToast() throws Exception {
        startAppFast(CALCULATOR_PACKAGE);
    public void testToast() {
        startAppFast(calculatorPackage);

        final UsageStatsManager usageStatsManager =
                mTargetContext.getSystemService(UsageStatsManager.class);
                targetContext().getSystemService(UsageStatsManager.class);
        final int observerId = 0;

        try {
            final String[] packages = new String[]{CALCULATOR_PACKAGE};
            final String[] packages = new String[]{calculatorPackage};

            // Set time limit for app.
            runWithShellPermission(() ->
                    usageStatsManager.registerAppUsageLimitObserver(observerId, packages,
                            Duration.ofSeconds(600), Duration.ofSeconds(300),
                            PendingIntent.getActivity(mTargetContext, -1, new Intent()
                                            .setPackage(mTargetContext.getPackageName()),
                            PendingIntent.getActivity(targetContext(), -1, new Intent()
                                            .setPackage(targetContext().getPackageName()),
                                    PendingIntent.FLAG_MUTABLE)));

            mLauncher.goHome();
            loadLauncherSync();
            final DigitalWellBeingToast toast = getToast();

            waitForLauncherCondition("Toast is not visible", launcher -> toast.getHasLimit());
@@ -74,7 +80,7 @@ public class TaplDigitalWellBeingToastTest extends AbstractQuickStepTest {
            runWithShellPermission(
                    () -> usageStatsManager.unregisterAppUsageLimitObserver(observerId));

            mLauncher.goHome();
            goToState(LauncherState.NORMAL);
            assertFalse("Toast is visible", getToast().getHasLimit());
        } finally {
            runWithShellPermission(
@@ -83,12 +89,12 @@ public class TaplDigitalWellBeingToastTest extends AbstractQuickStepTest {
    }

    private DigitalWellBeingToast getToast() {
        mLauncher.getWorkspace().switchToOverview();
        goToState(LauncherState.OVERVIEW);
        final TaskView task = getOnceNotNull("No latest task", launcher -> getLatestTask(launcher));

        return getFromLauncher(launcher -> {
            TaskContainer taskContainer = task.getTaskContainers().get(0);
            assertTrue("Latest task is not Calculator", CALCULATOR_PACKAGE.equals(
            assertTrue("Latest task is not Calculator", calculatorPackage.equals(
                    taskContainer.getTask().getTopComponent().getPackageName()));
            return taskContainer.getDigitalWellBeingToast();
        });
@@ -105,6 +111,5 @@ public class TaplDigitalWellBeingToastTest extends AbstractQuickStepTest {
        } finally {
            getInstrumentation().getUiAutomation().dropShellPermissionIdentity();
        }

    }
}
+12 −0
Original line number Diff line number Diff line
@@ -29,7 +29,10 @@ import android.app.Instrumentation;
import android.app.blob.BlobHandle;
import android.app.blob.BlobStoreManager;
import android.content.Context;
import android.content.Intent;
import android.content.pm.ActivityInfo;
import android.content.pm.LauncherApps;
import android.content.pm.PackageManager;
import android.content.res.Resources;
import android.graphics.Point;
import android.os.AsyncTask;
@@ -231,6 +234,15 @@ public class TestUtil {
                .adoptShellPermissionIdentity(Manifest.permission.WRITE_SECURE_SETTINGS);
    }

    /**
     * Returns the activity info corresponding to the system app for the provided category
     */
    public static ActivityInfo resolveSystemAppInfo(String category) {
        return getInstrumentation().getTargetContext().getPackageManager().resolveActivity(
                new Intent(Intent.ACTION_MAIN).addCategory(category),
                PackageManager.MATCH_SYSTEM_ONLY).activityInfo;
    }

    /** Interface to indicate a runnable which can throw any exception. */
    public interface UncheckedRunnable {
        /** Method to run the task */
+12 −5
Original line number Diff line number Diff line
@@ -27,17 +27,23 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;

import com.android.launcher3.allapps.ActivityAllAppsContainerView;
import com.android.launcher3.allapps.SearchRecyclerView;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.BaseLauncherActivityTest;

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

@LargeTest
@RunWith(AndroidJUnit4.class)
public class LauncherIntentTest extends AbstractLauncherUiTest<Launcher> {
public class LauncherIntentTest extends BaseLauncherActivityTest<Launcher> {

    public final Intent allAppsIntent = new Intent(Intent.ACTION_ALL_APPS);

    @Before
    public void setUp() {
        loadLauncherSync();
    }

    @Test
    public void testAllAppsIntent() {
        // Try executing ALL_APPS intent
@@ -45,7 +51,6 @@ public class LauncherIntentTest extends AbstractLauncherUiTest<Launcher> {
        // A-Z view with Main adapter should be loaded
        assertOnMainAdapterAToZView();


        // Try Moving to search view now
        moveToSearchView();
        // Try executing ALL_APPS intent
@@ -63,12 +68,14 @@ public class LauncherIntentTest extends AbstractLauncherUiTest<Launcher> {
        // Search view should be in focus
        waitForLauncherCondition("Search view is not in focus.",
                launcher -> launcher.getAppsView().getSearchView().hasFocus());
        mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_C, 0);

        injectKeyEvent(KeyEvent.KEYCODE_C, true);
        // Upon key press, search recycler view should be loaded
        waitForLauncherCondition("Search view not active.",
                launcher -> launcher.getAppsView().getActiveRecyclerView()
                        instanceof SearchRecyclerView);
        mLauncher.unpressKeyCode(KeyEvent.KEYCODE_C, 0);

        injectKeyEvent(KeyEvent.KEYCODE_C, false);
    }

    // Checks if main adapter view is selected, search bar is out of focus and scroller is at start.
+92 −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.launcher3.allapps;

import android.view.KeyEvent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.util.BaseLauncherActivityTest;
import com.android.launcher3.views.ActivityContext;

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

@SmallTest
@RunWith(AndroidJUnit4.class)
public class KeyboardFocusTest extends BaseLauncherActivityTest<Launcher> {

    @Test
    public void testAllAppsFocusApp() {
        loadLauncherSync();
        goToState(LauncherState.ALL_APPS);
        freezeAllApps();

        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, true);
        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, false);
        waitForLauncherCondition("No focused child", launcher ->
                launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()
                        != null);
    }

    @Test
    public void testAllAppsExitSearchAndFocusApp() {
        loadLauncherSync();
        goToState(LauncherState.ALL_APPS);
        freezeAllApps();

        executeOnLauncher(launcher -> launcher.getAppsView().getSearchView().requestFocus());
        waitForLauncherCondition("Search view does not have focus.",
                launcher -> launcher.getAppsView().getSearchView().hasFocus());

        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, true);
        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, false);
        waitForLauncherCondition("No focused child", launcher ->
                launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()
                        != null);
    }

    @Test
    public void testAllAppsExitSearchAndFocusSearchResults() {
        loadLauncherSync();
        goToState(LauncherState.ALL_APPS);
        freezeAllApps();

        executeOnLauncher(launcher -> launcher.getAppsView().getSearchView().requestFocus());
        waitForLauncherCondition("Search view does not have focus.",
                launcher -> launcher.getAppsView().getSearchView().hasFocus());

        injectKeyEvent(KeyEvent.KEYCODE_C, true);
        waitForLauncherCondition("Search view not active.",
                launcher -> launcher.getAppsView().getActiveRecyclerView()
                        instanceof SearchRecyclerView);
        injectKeyEvent(KeyEvent.KEYCODE_C, false);

        executeOnLauncher(launcher -> launcher.getAppsView().getSearchUiManager().getEditText()
                .hideKeyboard(/* clearFocus= */ false));
        waitForLauncherCondition("Keyboard still visible.",
                ActivityContext::isSoftwareKeyboardHidden);

        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, true);
        injectKeyEvent(KeyEvent.KEYCODE_DPAD_DOWN, false);
        waitForLauncherCondition("No focused child", launcher ->
                launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()
                        != null);
    }
}
+0 −108
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.launcher3.allapps;

import static com.android.launcher3.util.rule.TestStabilityRule.LOCAL;
import static com.android.launcher3.util.rule.TestStabilityRule.PLATFORM_POSTSUBMIT;

import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;

import android.view.KeyEvent;

import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.SmallTest;

import com.android.launcher3.Launcher;
import com.android.launcher3.LauncherState;
import com.android.launcher3.tapl.HomeAllApps;
import com.android.launcher3.ui.AbstractLauncherUiTest;
import com.android.launcher3.util.rule.TestStabilityRule;
import com.android.launcher3.views.ActivityContext;

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

@SmallTest
@RunWith(AndroidJUnit4.class)
public class TaplKeyboardFocusTest extends AbstractLauncherUiTest<Launcher> {

    @Test
    public void testAllAppsFocusApp() {
        final HomeAllApps allApps = mLauncher.goHome().switchToAllApps();
        assertTrue("Launcher internal state is not All Apps",
                isInState(() -> LauncherState.ALL_APPS));
        allApps.freeze();
        try {
            mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
            executeOnLauncher(launcher -> assertNotNull("No focused child.",
                    launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()));
        } finally {
            allApps.unfreeze();
        }
    }

    @Test
    public void testAllAppsExitSearchAndFocusApp() {
        final HomeAllApps allApps = mLauncher.goHome().switchToAllApps();
        assertTrue("Launcher internal state is not All Apps",
                isInState(() -> LauncherState.ALL_APPS));
        allApps.freeze();
        try {
            executeOnLauncher(launcher -> launcher.getAppsView().getSearchView().requestFocus());
            waitForLauncherCondition("Search view does not have focus.",
                    launcher -> launcher.getAppsView().getSearchView().hasFocus());

            mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
            executeOnLauncher(launcher -> assertNotNull("No focused child.",
                    launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()));
        } finally {
            allApps.unfreeze();
        }
    }

    @Test
    public void testAllAppsExitSearchAndFocusSearchResults() {
        final HomeAllApps allApps = mLauncher.goHome().switchToAllApps();
        assertTrue("Launcher internal state is not All Apps",
                isInState(() -> LauncherState.ALL_APPS));
        allApps.freeze();
        try {
            executeOnLauncher(launcher -> launcher.getAppsView().getSearchView().requestFocus());
            waitForLauncherCondition("Search view does not have focus.",
                    launcher -> launcher.getAppsView().getSearchView().hasFocus());

            mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_C, 0);
            waitForLauncherCondition("Search view not active.",
                    launcher -> launcher.getAppsView().getActiveRecyclerView()
                            instanceof SearchRecyclerView);
            mLauncher.unpressKeyCode(KeyEvent.KEYCODE_C, 0);

            executeOnLauncher(launcher -> launcher.getAppsView().getSearchUiManager().getEditText()
                    .hideKeyboard(/* clearFocus= */ false));
            waitForLauncherCondition("Keyboard still visible.",
                    ActivityContext::isSoftwareKeyboardHidden);

            mLauncher.pressAndHoldKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
            mLauncher.unpressKeyCode(KeyEvent.KEYCODE_DPAD_DOWN, 0);
            waitForLauncherCondition("No focused child", launcher ->
                    launcher.getAppsView().getActiveRecyclerView().getApps().getFocusedChild()
                            != null);
        } finally {
            allApps.unfreeze();
        }
    }
}
Loading