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

Commit 102b723d authored by Himanshu Gupta's avatar Himanshu Gupta
Browse files

Adding Tapl tests for User Installed App in PS.

This test verifies that a user installed app
is shown above the sys apps divider, within the
Private Space container.

Bug: 322882655
Test: atest NexusLauncherTests:com.android.quickstep.TaplPrivateSpaceTest
Flag: NA
Change-Id: Id85105339ae45c263d9ef52a3bb55784587e887d
parent 568e0bff
Loading
Loading
Loading
Loading
+35 −11
Original line number Diff line number Diff line
@@ -21,7 +21,6 @@ import static com.android.launcher3.LauncherState.NORMAL;

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

import android.util.Log;

@@ -29,6 +28,8 @@ import androidx.test.ext.junit.runners.AndroidJUnit4;
import androidx.test.filters.LargeTest;

import com.android.launcher3.tapl.LauncherInstrumentation;
import com.android.launcher3.tapl.PrivateSpaceContainer;
import com.android.launcher3.util.TestUtil;
import com.android.launcher3.util.rule.ScreenRecordRule;

import org.junit.After;
@@ -43,7 +44,9 @@ import java.util.Objects;
public class TaplPrivateSpaceTest extends AbstractQuickStepTest {

    private int mProfileUserId;
    private boolean mPrivateProfileSetupSuccessful;

    private static final String PRIVATE_PROFILE_NAME = "LauncherPrivateProfile";
    private static final String INSTALLED_APP_NAME = "Aardwolf";
    private static final String TAG = "TaplPrivateSpaceTest";

    @Override
@@ -52,8 +55,6 @@ public class TaplPrivateSpaceTest extends AbstractQuickStepTest {
        initialize(this);

        createAndStartPrivateProfileUser();
        assumeTrue("Private Profile Setup not successful, aborting",
                mPrivateProfileSetupSuccessful);

        mDevice.pressHome();
        waitForLauncherCondition("Launcher didn't start", Objects::nonNull);
@@ -72,7 +73,7 @@ public class TaplPrivateSpaceTest extends AbstractQuickStepTest {

    private void createAndStartPrivateProfileUser() {
        String createUserOutput = executeShellCommand("pm create-user --profileOf 0 --user-type "
                + "android.os.usertype.profile.PRIVATE LauncherPrivateProfile");
                + "android.os.usertype.profile.PRIVATE " + PRIVATE_PROFILE_NAME);
        updatePrivateProfileSetupSuccessful("pm create-user", createUserOutput);
        String[] tokens = createUserOutput.split("\\s+");
        mProfileUserId = Integer.parseInt(tokens[tokens.length - 1]);
@@ -86,24 +87,42 @@ public class TaplPrivateSpaceTest extends AbstractQuickStepTest {

    @After
    public void removePrivateProfile() {
        String userListOutput = executeShellCommand("pm list users");
        if (isPrivateProfilePresent("pm list users", userListOutput)) {
            String output = executeShellCommand("pm remove-user " + mProfileUserId);
            updateProfileRemovalSuccessful("pm remove-user", output);
            waitForPrivateSpaceRemoval();
        }
    }

    @Test
    @ScreenRecordRule.ScreenRecord // b/334946529
    public void testPrivateSpaceContainerIsPresent() {
        assumeTrue(mPrivateProfileSetupSuccessful);
        // Scroll to the bottom of All Apps
        executeOnLauncher(launcher -> launcher.getAppsView().resetAndScrollToPrivateSpaceHeader());
        waitForResumed("Launcher internal state is still Background");

        // Verify Unlocked View elements are present.
        assertNotNull("Private Space Unlocked View not found, or is not correct",
                mLauncher.getAllApps().getPrivateSpaceUnlockedView());
    }

    @Test
    @ScreenRecordRule.ScreenRecord // b/334946529
    public void testUserInstalledAppIsShownAboveDivider() throws IOException {
        // Ensure that the App is not installed in main user otherwise, it may not be found in
        // PS container.
        TestUtil.uninstallDummyApp();
        // Install the app in Private Profile
        TestUtil.installDummyAppForUser(mProfileUserId);
        waitForLauncherUIUpdate();
        // Scroll to the bottom of All Apps
        executeOnLauncher(launcher -> launcher.getAppsView().resetAndScrollToPrivateSpaceHeader());

        // Verify the Installed App is displayed in correct position.
        PrivateSpaceContainer psContainer = mLauncher.getAllApps().getPrivateSpaceUnlockedView();
        psContainer.verifyInstalledAppIsPresent(INSTALLED_APP_NAME);
    }

    private void waitForPrivateSpaceSetup() {
        waitForLauncherCondition("Private Profile not setup",
                launcher -> launcher.getAppsView().hasPrivateProfile(),
@@ -129,7 +148,7 @@ public class TaplPrivateSpaceTest extends AbstractQuickStepTest {
    private void updatePrivateProfileSetupSuccessful(String cli, String output) {
        Log.d(TAG, "updatePrivateProfileSetupSuccessful, cli=" + cli + " " + "output="
                + output);
        mPrivateProfileSetupSuccessful = output.startsWith("Success");
        assertTrue(output, output.startsWith("Success"));
    }

    private void updateProfileRemovalSuccessful(String cli, String output) {
@@ -137,6 +156,11 @@ public class TaplPrivateSpaceTest extends AbstractQuickStepTest {
        assertTrue(output, output.startsWith("Success"));
    }

    private boolean isPrivateProfilePresent(String cli, String output) {
        Log.d(TAG, "updatePrivateProfilePresent, cli=" + cli + " " + "output=" + output);
        return output.contains(PRIVATE_PROFILE_NAME);
    }

    private String executeShellCommand(String command) {
        try {
            return mDevice.executeShellCommand(command);
+14 −0
Original line number Diff line number Diff line
@@ -16,6 +16,8 @@

package com.android.launcher3.tapl;

import android.graphics.Point;

import androidx.test.uiautomator.UiObject2;

/**
@@ -57,4 +59,16 @@ public class PrivateSpaceContainer {
    private void verifyDividerIsPresent() {
        mLauncher.waitForObjectInContainer(mAppListRecycler, DIVIDER_RES_ID);
    }

    /**
     * Verifies that a user installed app is present above the divider.
     */
    public void verifyInstalledAppIsPresent(String appName) {
        HomeAppIcon appIcon = mLauncher.getAllApps().getAppIcon(appName);
        final Point iconCenter = appIcon.mObject.getVisibleCenter();
        UiObject2 divider = mLauncher.waitForObjectInContainer(mAppListRecycler, DIVIDER_RES_ID);
        final Point dividerCenter = divider.getVisibleCenter();
        mLauncher.assertTrue("Installed App: " + appName + " is not above the divider",
                iconCenter.y < dividerCenter.y);
    }
}