use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_oneAccountRemoved_shouldRemoveOneAccountPreference.
@Test
public void onResume_oneAccountRemoved_shouldRemoveOneAccountPreference() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isRestrictedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
Account[] accounts = { new Account("Acct1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
Account[] accountType1 = { new Account("Acct11", "com.acct1"), new Account("Acct12", "com.acct1") };
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
// remove an account
accountType1 = new Account[] { new Account("Acct11", "com.acct1") };
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
mController.onResume();
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
verify(preferenceGroup, times(1)).removePreference(argThat(titleMatches("Acct12")));
}
use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_noAccountChange_shouldNotAddAccountPreference.
@Test
public void onResume_noAccountChange_shouldNotAddAccountPreference() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isRestrictedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
Account[] accounts = { new Account("Acct1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
Account[] accountType1 = new Account[2];
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
mController.onResume();
// each account should be added only once
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct11")));
verify(preferenceGroup).addPreference(argThat(titleMatches("Acct12")));
}
use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_oneProfile_shouldSetAccountTitleWithUserName.
@Test
public void onResume_oneProfile_shouldSetAccountTitleWithUserName() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_MANAGED_PROFILE));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isRestrictedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
verify(preferenceGroup).setTitle(mContext.getString(R.string.account_for_section_header, "user 1"));
}
use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_noPreferenceScreen_shouldNotCrash.
@Test
public void onResume_noPreferenceScreen_shouldNotCrash() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isRestrictedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
// Should not crash
}
use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.
the class AccountPreferenceControllerTest method onResume_oneNewAccount_shouldAddOneAccountPreference.
@Test
public void onResume_oneNewAccount_shouldAddOneAccountPreference() {
final List<UserInfo> infos = new ArrayList<>();
infos.add(new UserInfo(1, "user 1", 0));
when(mUserManager.isManagedProfile()).thenReturn(false);
when(mUserManager.isRestrictedProfile()).thenReturn(false);
when(mUserManager.getProfiles(anyInt())).thenReturn(infos);
Account[] accounts = { new Account("Acct1", "com.acct1") };
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(accounts);
Account[] accountType1 = new Account[2];
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, 0, 0, false) };
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt())).thenReturn(authDescs);
AccessiblePreferenceCategory preferenceGroup = mock(AccessiblePreferenceCategory.class);
when(preferenceGroup.getPreferenceManager()).thenReturn(mock(PreferenceManager.class));
when(mAccountHelper.createAccessiblePreferenceCategory(any(Context.class))).thenReturn(preferenceGroup);
mController.onResume();
// add a new account
accountType1 = new Account[3];
accountType1[0] = new Account("Acct11", "com.acct1");
accountType1[1] = new Account("Acct12", "com.acct1");
accountType1[2] = new Account("Acct13", "com.acct1");
when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accountType1);
mController.onResume();
// each account should be added only once
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct11")));
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct12")));
verify(preferenceGroup, times(1)).addPreference(argThat(titleMatches("Acct13")));
}
Aggregations