Remove wrapper for device policy manager
Bug: 76167422 Test: robotests Change-Id: I69dc7341cf1ff408bc24c2a062586cef25b7b918
This commit is contained in:
@@ -50,10 +50,6 @@ import com.android.settings.testutils.shadow.ShadowAccountManager;
|
||||
import com.android.settings.testutils.shadow.ShadowContentResolver;
|
||||
import com.android.settings.testutils.shadow.ShadowDevicePolicyManager;
|
||||
import com.android.settings.testutils.shadow.ShadowUserManager;
|
||||
import com.android.settings.wrapper.DevicePolicyManagerWrapper;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -64,12 +60,14 @@ import org.robolectric.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
import org.robolectric.shadows.ShadowApplication;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(
|
||||
shadows = {
|
||||
@Config(shadows = {
|
||||
ShadowUserManager.class,
|
||||
ShadowDevicePolicyManager.class
|
||||
})
|
||||
})
|
||||
public class RemoveAccountPreferenceControllerTest {
|
||||
|
||||
private static final String KEY_REMOVE_ACCOUNT = "remove_account";
|
||||
@@ -78,8 +76,6 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
@Mock(answer = RETURNS_DEEP_STUBS)
|
||||
private AccountManager mAccountManager;
|
||||
@Mock
|
||||
private DevicePolicyManagerWrapper mDevicePolicyManager;
|
||||
@Mock
|
||||
private PreferenceFragment mFragment;
|
||||
@Mock
|
||||
private PreferenceManager mPreferenceManager;
|
||||
@@ -105,10 +101,10 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
when(mFragment.getFragmentManager()).thenReturn(mFragmentManager);
|
||||
when(mFragmentManager.beginTransaction()).thenReturn(mFragmentTransaction);
|
||||
when(mAccountManager.getAuthenticatorTypesAsUser(anyInt()))
|
||||
.thenReturn(new AuthenticatorDescription[0]);
|
||||
.thenReturn(new AuthenticatorDescription[0]);
|
||||
when(mAccountManager.getAccountsAsUser(anyInt())).thenReturn(new Account[0]);
|
||||
mController = new RemoveAccountPreferenceController(RuntimeEnvironment.application,
|
||||
mFragment, mDevicePolicyManager);
|
||||
mFragment);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -128,8 +124,8 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
mController.onClick(null);
|
||||
|
||||
verify(mFragmentTransaction).add(
|
||||
any(RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.class),
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
any(RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.class),
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -141,20 +137,20 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
|
||||
List<UserManager.EnforcingUser> enforcingUsers = new ArrayList<>();
|
||||
enforcingUsers.add(new UserManager.EnforcingUser(userId,
|
||||
UserManager.RESTRICTION_SOURCE_DEVICE_OWNER));
|
||||
UserManager.RESTRICTION_SOURCE_DEVICE_OWNER));
|
||||
ComponentName componentName = new ComponentName("test", "test");
|
||||
// Ensure that RestrictedLockUtils.checkIfRestrictionEnforced doesn't return null.
|
||||
ShadowUserManager.getShadow().setUserRestrictionSources(
|
||||
UserManager.DISALLOW_MODIFY_ACCOUNTS,
|
||||
UserHandle.of(userId),
|
||||
enforcingUsers);
|
||||
UserManager.DISALLOW_MODIFY_ACCOUNTS,
|
||||
UserHandle.of(userId),
|
||||
enforcingUsers);
|
||||
ShadowDevicePolicyManager.getShadow().setDeviceOwnerComponentOnAnyUser(componentName);
|
||||
|
||||
mController.onClick(null);
|
||||
|
||||
verify(mFragmentTransaction, never()).add(
|
||||
any(RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.class),
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
any(RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.class),
|
||||
eq(TAG_REMOVE_ACCOUNT_DIALOG));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -168,11 +164,11 @@ public class RemoveAccountPreferenceControllerTest {
|
||||
Account account = new Account("Account11", "com.acct1");
|
||||
UserHandle userHandle = new UserHandle(10);
|
||||
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog dialog =
|
||||
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(
|
||||
mFragment, account, userHandle);
|
||||
RemoveAccountPreferenceController.ConfirmRemoveAccountDialog.show(
|
||||
mFragment, account, userHandle);
|
||||
dialog.onCreate(new Bundle());
|
||||
dialog.onClick(null, 0);
|
||||
verify(mAccountManager).removeAccountAsUser(eq(account), nullable(Activity.class),
|
||||
nullable(AccountManagerCallback.class), nullable(Handler.class), eq(userHandle));
|
||||
nullable(AccountManagerCallback.class), nullable(Handler.class), eq(userHandle));
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user