Merge "Make the order of tabs same as profile creation" into main

This commit is contained in:
Manish Singh
2023-12-07 13:26:19 +00:00
committed by Android (Google) Code Review
2 changed files with 83 additions and 70 deletions

View File

@@ -17,6 +17,9 @@
package com.android.settings.dashboard.profileselector;
import static android.content.Intent.EXTRA_USER_ID;
import static android.os.UserManager.USER_TYPE_FULL_SYSTEM;
import static android.os.UserManager.USER_TYPE_PROFILE_MANAGED;
import static android.os.UserManager.USER_TYPE_PROFILE_PRIVATE;
import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.EXTRA_PROFILE;
import static com.android.settings.dashboard.profileselector.ProfileSelectFragment.PERSONAL_TAB;
@@ -30,9 +33,11 @@ import static org.mockito.Mockito.when;
import android.content.Context;
import android.content.Intent;
import android.content.pm.UserInfo;
import android.os.Bundle;
import android.os.Flags;
import android.platform.test.flag.junit.SetFlagsRule;
import android.util.ArraySet;
import androidx.fragment.app.Fragment;
import androidx.fragment.app.FragmentActivity;
@@ -51,7 +56,9 @@ import org.robolectric.RobolectricTestRunner;
import org.robolectric.RuntimeEnvironment;
import org.robolectric.annotation.Config;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
@RunWith(RobolectricTestRunner.class)
@@ -60,6 +67,9 @@ import java.util.Set;
com.android.settings.testutils.shadow.ShadowFragment.class,
})
public class ProfileSelectFragmentTest {
private static final String PRIMARY_USER_NAME = "primary";
private static final String MANAGED_USER_NAME = "managed";
private static final String PRIVATE_USER_NAME = "private";
private Context mContext;
private TestProfileSelectFragment mFragment;
@@ -151,6 +161,8 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenOnlyPersonal_returnsOneFragment() {
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
null /* bundle */,
@@ -162,6 +174,10 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenPrivateDisabled_returnsOneFragment() {
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
mUserManager.addProfile(
new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE));
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
null /* bundle */,
@@ -173,12 +189,6 @@ public class ProfileSelectFragmentTest {
public boolean isPrivateSpaceLocked(Context context) {
return true;
}
},
new ProfileSelectFragment.ManagedProfileInfoProvider() {
@Override
public boolean isManagedProfilePresent(Context context) {
return false;
}
});
assertThat(fragments).hasLength(1);
}
@@ -186,6 +196,10 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenPrivateEnabled_returnsTwoFragments() {
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
mUserManager.addProfile(
new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE));
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
null /* bundle */,
@@ -197,12 +211,6 @@ public class ProfileSelectFragmentTest {
public boolean isPrivateSpaceLocked(Context context) {
return false;
}
},
new ProfileSelectFragment.ManagedProfileInfoProvider() {
@Override
public boolean isManagedProfilePresent(Context context) {
return false;
}
});
assertThat(fragments).hasLength(2);
}
@@ -210,6 +218,10 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenManagedProfile_returnsTwoFragments() {
mSetFlagsRule.disableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
mUserManager.addProfile(
new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED));
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
null /* bundle */,
@@ -221,12 +233,6 @@ public class ProfileSelectFragmentTest {
public boolean isPrivateSpaceLocked(Context context) {
return false;
}
},
new ProfileSelectFragment.ManagedProfileInfoProvider() {
@Override
public boolean isManagedProfilePresent(Context context) {
return true;
}
});
assertThat(fragments).hasLength(2);
}
@@ -234,6 +240,12 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenAllProfiles_returnsThreeFragments() {
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
mUserManager.addProfile(
new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED));
mUserManager.addProfile(
new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE));
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
null /* bundle */,
@@ -245,12 +257,6 @@ public class ProfileSelectFragmentTest {
public boolean isPrivateSpaceLocked(Context context) {
return false;
}
},
new ProfileSelectFragment.ManagedProfileInfoProvider() {
@Override
public boolean isManagedProfilePresent(Context context) {
return true;
}
});
assertThat(fragments).hasLength(3);
}
@@ -258,6 +264,12 @@ public class ProfileSelectFragmentTest {
@Test
public void testGetFragments_whenAvailableBundle_returnsFragmentsWithCorrectBundles() {
mSetFlagsRule.enableFlags(Flags.FLAG_ALLOW_PRIVATE_PROFILE);
mUserManager.addProfile(
new UserInfo(0, PRIMARY_USER_NAME, null, 0, USER_TYPE_FULL_SYSTEM));
mUserManager.addProfile(
new UserInfo(10, MANAGED_USER_NAME, null, 0, USER_TYPE_PROFILE_MANAGED));
mUserManager.addProfile(
new UserInfo(11, PRIVATE_USER_NAME, null, 0, USER_TYPE_PROFILE_PRIVATE));
Bundle bundle = new Bundle();
Fragment[] fragments = ProfileSelectFragment.getFragments(
mContext,
@@ -270,20 +282,21 @@ public class ProfileSelectFragmentTest {
public boolean isPrivateSpaceLocked(Context context) {
return false;
}
},
new ProfileSelectFragment.ManagedProfileInfoProvider() {
@Override
public boolean isManagedProfilePresent(Context context) {
return true;
}
});
assertThat(fragments).hasLength(3);
assertThat(fragments[0].getArguments().getInt(EXTRA_PROFILE))
.isEqualTo(ProfileSelectFragment.ProfileType.PERSONAL);
assertThat(fragments[1].getArguments().getInt(EXTRA_PROFILE))
.isEqualTo(ProfileSelectFragment.ProfileType.WORK);
assertThat(fragments[2].getArguments().getInt(EXTRA_PROFILE))
.isEqualTo(ProfileSelectFragment.ProfileType.PRIVATE);
List<Integer> foundProfileTypesList = new ArrayList<>();
for (Fragment fragment : fragments) {
foundProfileTypesList.add(fragment.getArguments().getInt(EXTRA_PROFILE));
}
assertThat(foundProfileTypesList).hasSize(3);
Set<Integer> foundProfileTypes = new ArraySet<>(foundProfileTypesList);
assertThat(foundProfileTypes).containsExactly(
ProfileSelectFragment.ProfileType.PERSONAL,
ProfileSelectFragment.ProfileType.WORK,
ProfileSelectFragment.ProfileType.PRIVATE);
}
public static class TestProfileSelectFragment extends ProfileSelectFragment {