Search in sources :

Example 66 with AccessiblePreferenceCategory

use of com.android.settings.AccessiblePreferenceCategory in project android_packages_apps_Settings by omnirom.

the class AccountPreferenceControllerTest method onResume_userReEnabled_shouldAddOneAccountPreference.

@Test
public void onResume_userReEnabled_shouldAddOneAccountPreference() {
    final List<UserInfo> infos = new ArrayList<>();
    infos.add(new UserInfo(1, "user 1", UserInfo.FLAG_DISABLED));
    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(1)).thenReturn(accounts);
    when(mAccountManager.getAccountsByTypeAsUser(eq("com.acct1"), any(UserHandle.class))).thenReturn(accounts);
    AuthenticatorDescription[] authDescs = { new AuthenticatorDescription("com.acct1", "com.android.settings", R.string.account_settings_title, 0, /* iconId */
    0, /* smallIconId */
    0, /* prefId */
    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);
    // First time resume will build the UI with no account
    mController.onResume();
    verify(preferenceGroup, never()).addPreference(argThat(titleMatches("Acct1")));
    // Enable the user
    infos.remove(0);
    infos.add(new UserInfo(1, "user 1", 0));
    // Resume should show the account for the user
    mController.onResume();
    verify(preferenceGroup).addPreference(argThat(titleMatches("Acct1")));
}
Also used : Context(android.content.Context) Account(android.accounts.Account) AuthenticatorDescription(android.accounts.AuthenticatorDescription) UserHandle(android.os.UserHandle) ArrayList(java.util.ArrayList) UserInfo(android.content.pm.UserInfo) AccessiblePreferenceCategory(com.android.settings.AccessiblePreferenceCategory) PreferenceManager(androidx.preference.PreferenceManager) Test(org.junit.Test)

Aggregations

Context (android.content.Context)66 AccessiblePreferenceCategory (com.android.settings.AccessiblePreferenceCategory)66 UserInfo (android.content.pm.UserInfo)58 ArrayList (java.util.ArrayList)58 Test (org.junit.Test)58 Account (android.accounts.Account)44 AuthenticatorDescription (android.accounts.AuthenticatorDescription)44 UserHandle (android.os.UserHandle)44 PreferenceManager (android.support.v7.preference.PreferenceManager)30 PreferenceManager (androidx.preference.PreferenceManager)14 Preference (android.support.v7.preference.Preference)10 AuthenticatorHelper (com.android.settingslib.accounts.AuthenticatorHelper)8 Config (org.robolectric.annotation.Config)7 PreferenceScreen (android.support.v7.preference.PreferenceScreen)5 TestConfig (com.android.settings.TestConfig)5 SearchFeatureProviderImpl (com.android.settings.search.SearchFeatureProviderImpl)5 Preference (androidx.preference.Preference)4 PreferenceScreen (androidx.preference.PreferenceScreen)2