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

Commit da979256 authored by Nikhil Kumar's avatar Nikhil Kumar Committed by Android (Google) Code Review
Browse files

Merge "Added unit tests for UserManager.isUserRunning()"

parents f6bf809b ff8ec9f3
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);