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

Commit b6798a7f authored by nathch's avatar nathch
Browse files

Fix bad test for testGetUserForAncestralSerialNumber which was

previously marked as @Ignore.

The test was bad because it set 11 as the ancestral serial number for
the system user UserBackupManagerService but asserted that 11 corresponds
to user 1 - which is not the system user. This CL fixes the assert.

Also added corresponding test for non system user.

Fixes: 147012496

Test: atest com.android.server.backup.BackupManagerServiceTest
Change-Id: Iab736885264aa4befc644678e5fe66d602ed00e3
parent 4226274b
Loading
Loading
Loading
Loading
+1 −4
Original line number Diff line number Diff line
@@ -1406,10 +1406,7 @@ public class BackupManagerService extends IBackupManager.Stub {
        long oldId = Binder.clearCallingIdentity();
        final int[] userIds;
        try {
            userIds =
                    mContext
                            .getSystemService(UserManager.class)
                            .getProfileIds(callingUserId, false);
            userIds = getUserManager().getProfileIds(callingUserId, false);
        } finally {
            Binder.restoreCallingIdentity(oldId);
        }
+18 −5
Original line number Diff line number Diff line
@@ -57,7 +57,6 @@ import com.android.server.backup.utils.RandomAccessFileUtils;

import org.junit.After;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.InOrder;
@@ -523,7 +522,6 @@ public class BackupManagerServiceTest {
     * Test that {@link BackupManagerService#dump()} dumps system user information before non-system
     * user information.
     */

    @Test
    public void testDump_systemUserFirst() {
        String[] args = new String[0];
@@ -539,16 +537,31 @@ public class BackupManagerServiceTest {
    }

    @Test
    @Ignore("b/147012496")
    public void testGetUserForAncestralSerialNumber() {
    public void testGetUserForAncestralSerialNumber_forSystemUser() {
        BackupManagerServiceTestable.sBackupDisabled = false;
        BackupManagerService backupManagerService =
                new BackupManagerServiceTestable(mContextMock, mUserServices);
        when(mUserManagerMock.getProfileIds(UserHandle.getCallingUserId(), false))
                .thenReturn(new int[] {UserHandle.USER_SYSTEM, NON_USER_SYSTEM});
        when(mUserBackupManagerService.getAncestralSerialNumber()).thenReturn(11L);

        UserHandle user = backupManagerService.getUserForAncestralSerialNumber(11L);

        assertThat(user).isEqualTo(UserHandle.of(1));
        assertThat(user).isEqualTo(UserHandle.of(UserHandle.USER_SYSTEM));
    }

    @Test
    public void testGetUserForAncestralSerialNumber_forNonSystemUser() {
        BackupManagerServiceTestable.sBackupDisabled = false;
        BackupManagerService backupManagerService =
                new BackupManagerServiceTestable(mContextMock, mUserServices);
        when(mUserManagerMock.getProfileIds(UserHandle.getCallingUserId(), false))
                .thenReturn(new int[] {UserHandle.USER_SYSTEM, NON_USER_SYSTEM});
        when(mNonSystemUserBackupManagerService.getAncestralSerialNumber()).thenReturn(11L);

        UserHandle user = backupManagerService.getUserForAncestralSerialNumber(11L);

        assertThat(user).isEqualTo(UserHandle.of(NON_USER_SYSTEM));
    }

    @Test