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
This commit is contained in:
nathch
2020-01-10 18:37:26 +00:00
parent 4226274bf9
commit b6798a7fb6
2 changed files with 19 additions and 9 deletions

View File

@@ -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);
}

View File

@@ -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