use of com.android.settings.testutils.shadow.ShadowUserManager in project android_packages_apps_Settings by omnirom.
the class AccountDetailDashboardFragmentTest method onResume_accountMissing_shouldFinish.
@Test
public void onResume_accountMissing_shouldFinish() {
ShadowUserManager userManager = Shadow.extract(mContext.getSystemService(UserManager.class));
userManager.addUserProfile(new UserHandle(1));
ShadowAccountManager.addAccountForUser(1, new Account("test@test.com", "com.test"));
mFragment.finishIfAccountMissing();
verify(mFragment).finish();
}
use of com.android.settings.testutils.shadow.ShadowUserManager in project android_packages_apps_Settings by omnirom.
the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference.
@Test
public void refreshUi_userRestrictionsUnknownSourcesGlobally_disablesSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of com.android.settings.testutils.shadow.ShadowUserManager in project android_packages_apps_Settings by omnirom.
the class ExternalSourcesDetailsTest method refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference.
@Test
public void refreshUi_bothUnknownSourcesUserRestrictions_disableSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, true);
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES_GLOBALLY, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of com.android.settings.testutils.shadow.ShadowUserManager in project android_packages_apps_Settings by omnirom.
the class ExternalSourcesDetailsTest method refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference.
@Test
public void refreshUi_userRestrictionsUnknownSources_disablesSwitchPreference() {
// Mocks set up
final ExternalSourcesDetails fragment = new ExternalSourcesDetails();
final ContextWrapper context = RuntimeEnvironment.application;
final UserManager userManager = (UserManager) context.getSystemService(Context.USER_SERVICE);
final ShadowUserManager shadowUserManager = Shadow.extract(userManager);
ReflectionHelpers.setField(fragment, "mSwitchPref", mSwitchPref);
ReflectionHelpers.setField(fragment, "mPackageInfo", mPackageInfo);
mPackageInfo.applicationInfo = new ApplicationInfo();
ReflectionHelpers.setField(fragment, "mUserManager", userManager);
ReflectionHelpers.setField(mSwitchPref, "mHelper", mHelper);
final AppStateInstallAppsBridge appBridge = mock(AppStateInstallAppsBridge.class);
ReflectionHelpers.setField(fragment, "mAppBridge", appBridge);
when(appBridge.createInstallAppsStateFor(nullable(String.class), anyInt())).thenReturn(mock(InstallAppsState.class));
// Test restriction set up
shadowUserManager.setUserRestriction(UserHandle.of(UserHandle.myUserId()), UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, true);
doAnswer((answer) -> {
when(mSwitchPref.isDisabledByAdmin()).thenReturn(true);
return null;
}).when(mSwitchPref).checkRestrictionAndSetDisabled(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES);
// Code execution
assertThat(fragment.refreshUi()).isTrue();
// Assertions
assertThat(userManager.hasUserRestriction(UserManager.DISALLOW_INSTALL_UNKNOWN_SOURCES, UserHandle.of(UserHandle.myUserId()))).isTrue();
assertThat(mSwitchPref.isDisabledByAdmin()).isTrue();
}
use of com.android.settings.testutils.shadow.ShadowUserManager in project android_packages_apps_Settings by omnirom.
the class ActionDisabledByAdminDialogHelperTest method testMaybeSetLearnMoreButton.
@Test
public void testMaybeSetLearnMoreButton() {
UserManager userManager = RuntimeEnvironment.application.getSystemService(UserManager.class);
ShadowUserManager userManagerShadow = Shadow.extract(userManager);
// Set up for shadow call.
userManagerShadow.getSameProfileGroupIds().put(USER_ID, 0);
// Test that the button is shown when user IDs are in the same profile group
AlertDialog.Builder builder = mock(AlertDialog.Builder.class);
mHelper.prepareDialogBuilder(builder, /* restriction= */
null, ENFORCED_ADMIN);
verify(builder).setNeutralButton(anyInt(), any());
// Test that the button is not shown when user IDs are not in the same profile group
userManagerShadow.getSameProfileGroupIds().clear();
builder = mock(AlertDialog.Builder.class);
mHelper.prepareDialogBuilder(builder, /* restriction= */
null, ENFORCED_ADMIN);
verify(builder, never()).setNeutralButton(anyInt(), any());
}
Aggregations