Merge "Add assumptions to testRemoveUserWhenPossible_withProfiles." into udc-qpr-dev
This commit is contained in:
committed by
Android (Google) Code Review
commit
1394fb2a61
@@ -53,6 +53,8 @@ import org.junit.Before;
|
|||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.ExecutorService;
|
||||||
import java.util.concurrent.Executors;
|
import java.util.concurrent.Executors;
|
||||||
@@ -545,23 +547,42 @@ public final class UserManagerTest {
|
|||||||
public void testRemoveUserWhenPossible_withProfiles() throws Exception {
|
public void testRemoveUserWhenPossible_withProfiles() throws Exception {
|
||||||
assumeHeadlessModeEnabled();
|
assumeHeadlessModeEnabled();
|
||||||
assumeCloneEnabled();
|
assumeCloneEnabled();
|
||||||
final UserInfo parentUser = createUser("Human User", /* flags= */ 0);
|
final List<String> profileTypesToCreate = Arrays.asList(
|
||||||
final UserInfo cloneProfileUser = createProfileForUser("Clone Profile user",
|
|
||||||
UserManager.USER_TYPE_PROFILE_CLONE,
|
UserManager.USER_TYPE_PROFILE_CLONE,
|
||||||
parentUser.id);
|
UserManager.USER_TYPE_PROFILE_MANAGED
|
||||||
|
);
|
||||||
|
|
||||||
final UserInfo workProfileUser = createProfileForUser("Work Profile user",
|
final UserInfo parentUser = createUser("Human User", /* flags= */ 0);
|
||||||
UserManager.USER_TYPE_PROFILE_MANAGED,
|
assertWithMessage("Could not create parent user")
|
||||||
parentUser.id);
|
.that(parentUser).isNotNull();
|
||||||
|
|
||||||
|
final List<Integer> profileIds = new ArrayList<>();
|
||||||
|
for (String profileType : profileTypesToCreate) {
|
||||||
|
final String name = profileType.substring(profileType.lastIndexOf('.') + 1);
|
||||||
|
if (mUserManager.canAddMoreProfilesToUser(profileType, parentUser.id)) {
|
||||||
|
final UserInfo profile = createProfileForUser(name, profileType, parentUser.id);
|
||||||
|
assertWithMessage("Could not create " + name)
|
||||||
|
.that(profile).isNotNull();
|
||||||
|
profileIds.add(profile.id);
|
||||||
|
} else {
|
||||||
|
Slog.w(TAG, "Can not add " + name + " to user #" + parentUser.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// Test shouldn't pass or fail unless it's allowed to add profiles to secondary users.
|
||||||
|
assumeTrue("Not possible to create any profiles to user #" + parentUser.id,
|
||||||
|
profileIds.size() > 0);
|
||||||
|
|
||||||
assertThat(mUserManager.removeUserWhenPossible(parentUser.getUserHandle(),
|
assertThat(mUserManager.removeUserWhenPossible(parentUser.getUserHandle(),
|
||||||
/* overrideDevicePolicy= */ false))
|
/* overrideDevicePolicy= */ false))
|
||||||
.isEqualTo(UserManager.REMOVE_RESULT_REMOVED);
|
.isEqualTo(UserManager.REMOVE_RESULT_REMOVED);
|
||||||
waitForUserRemoval(parentUser.id);
|
waitForUserRemoval(parentUser.id);
|
||||||
|
|
||||||
assertThat(hasUser(parentUser.id)).isFalse();
|
assertWithMessage("Parent user still exists")
|
||||||
assertThat(hasUser(cloneProfileUser.id)).isFalse();
|
.that(hasUser(parentUser.id)).isFalse();
|
||||||
assertThat(hasUser(workProfileUser.id)).isFalse();
|
profileIds.forEach(id ->
|
||||||
|
assertWithMessage("Profile still exists")
|
||||||
|
.that(hasUser(id)).isFalse());
|
||||||
}
|
}
|
||||||
|
|
||||||
/** Tests creating a FULL user via specifying userType. */
|
/** Tests creating a FULL user via specifying userType. */
|
||||||
|
|||||||
Reference in New Issue
Block a user