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

Commit 3af86029 authored by Yao Li's avatar Yao Li
Browse files

Fix UserManagerServiceTest mocking test

One existing test did not take into account the possibility of being
able to switch to the headless system user. Depending on the value of
config_canSwitchToHeadlessSystemUser on test device, this test may or
may not pass.

This CL explicitly sets the config value, to get consistent test result.

Bug: 391913130
Flag: EXEMPT bugfix
Test: atest FrameworksMockingServicesTests:com.android.server.pm.UserManagerServiceTest
Change-Id: I7cbe4c1786fc770faadecd213efb4aceaf50f016
parent ea391bb8
Loading
Loading
Loading
Loading
+13 −1
Original line number Diff line number Diff line
@@ -401,14 +401,26 @@ public final class UserManagerServiceTest {
    }

    @Test
    public void testGetBootUser_Headless_ThrowsIfOnlySystemUserExists() throws Exception {
    public void testGetBootUser_CannotSwitchToHeadlessSystemUser_ThrowsIfOnlySystemUserExists()
            throws Exception {
        setSystemUserHeadless(true);
        removeNonSystemUsers();
        mockCanSwitchToHeadlessSystemUser(false);

        assertThrows(UserManager.CheckedUserOperationException.class,
                () -> mUmi.getBootUser(/* waitUntilSet= */ false));
    }

    @Test
    public void testGetBootUser_CanSwitchToHeadlessSystemUser_NoThrowIfOnlySystemUserExists()
            throws Exception {
        setSystemUserHeadless(true);
        removeNonSystemUsers();
        mockCanSwitchToHeadlessSystemUser(true);

        assertThat(mUmi.getBootUser(/* waitUntilSet= */ false)).isEqualTo(UserHandle.USER_SYSTEM);
    }

    @Test
    public void testGetPreviousFullUserToEnterForeground() throws Exception {
        addUser(USER_ID);