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

Commit ff8ec9f3 authored by Nikhil Kumar's avatar Nikhil Kumar
Browse files

Added unit tests for UserManager.isUserRunning()

Added unit tests for UserManager.isUserRunning() in mockingservicetest.
Removed additional state set from UMST.testIsUserVisibleOnDisplay_startedProfileOfcurrentUserInvalidDisplay.
Added new methods startUser() and stopUser() to set the user state in
RUNNING_UNLOCKED and STOPPING.

Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest

Bug: 244798930
Change-Id: I03c83ef36deb812b57424eebba37db7414773c3b
parent 7f415092
Loading
Loading
Loading
Loading
+10 −3
Original line number Diff line number Diff line
@@ -342,7 +342,6 @@ abstract class UserManagerServiceOrInternalTestCase extends ExtendedMockitoTestC
        addDefaultProfileAndParent();
        mockCurrentUser(PARENT_USER_ID);
        startDefaultProfile();
        setUserState(PROFILE_USER_ID, UserState.STATE_RUNNING_UNLOCKED);

        assertWithMessage("isUserVisibleOnDisplay(%s, %s)", PROFILE_USER_ID, INVALID_DISPLAY)
                .that(isUserVisibleOnDisplay(PROFILE_USER_ID, DEFAULT_DISPLAY)).isTrue();
@@ -584,11 +583,19 @@ abstract class UserManagerServiceOrInternalTestCase extends ExtendedMockitoTestC
    }

    protected final void startDefaultProfile() {
        setUserState(PROFILE_USER_ID, UserState.STATE_RUNNING_UNLOCKED);
        startUser(PROFILE_USER_ID);
    }

    protected final void stopDefaultProfile() {
        setUserState(PROFILE_USER_ID, UserState.STATE_STOPPING);
        stopUser(PROFILE_USER_ID);
    }

    protected final void startUser(@UserIdInt int userId) {
        setUserState(userId, UserState.STATE_RUNNING_UNLOCKED);
    }

    protected final void stopUser(@UserIdInt int userId) {
        setUserState(userId, UserState.STATE_STOPPING);
    }

    // NOTE: should only called by tests that indirectly needs to check user assignments (like
+36 −0
Original line number Diff line number Diff line
@@ -88,6 +88,42 @@ public final class UserManagerServiceTest extends UserManagerServiceOrInternalTe
                .that(mUms.isCurrentUserOrRunningProfileOfCurrentUser(PROFILE_USER_ID)).isFalse();
    }

    @Test
    public void testIsUserRunning_StartedUserShouldReturnTrue() {
        addUser(USER_ID);
        startUser(USER_ID);

        assertWithMessage("isUserRunning(%s)", USER_ID)
                .that(mUms.isUserRunning(USER_ID)).isTrue();
    }

    @Test
    public void testIsUserRunning_StoppedUserShouldReturnFalse() {
        addUser(USER_ID);
        stopUser(USER_ID);

        assertWithMessage("isUserRunning(%s)", USER_ID)
                .that(mUms.isUserRunning(USER_ID)).isFalse();
    }

    @Test
    public void testIsUserRunning_CurrentUserStartedWorkProfileShouldReturnTrue() {
        addDefaultProfileAndParent();
        startDefaultProfile();

        assertWithMessage("isUserRunning(%s)", PROFILE_USER_ID)
                .that(mUms.isUserRunning(PROFILE_USER_ID)).isTrue();
    }

    @Test
    public void testIsUserRunning_CurrentUserStoppedWorkProfileShouldReturnFalse() {
        addDefaultProfileAndParent();
        stopDefaultProfile();

        assertWithMessage("isUserRunning(%s)", PROFILE_USER_ID)
                .that(mUms.isUserRunning(PROFILE_USER_ID)).isFalse();
    }

    @Override
    protected boolean isUserVisible(int userId) {
        return mUms.isUserVisibleUnchecked(userId);