Device management info: Refer to current user, not primary user
The device management info page should show information about the current user's policies, not the primary user's. Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I5d8afa7fae1c0f3a4da78b085365882827e6721b
This commit is contained in:
@@ -36,11 +36,11 @@ import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link AlwaysOnVpnPrimaryUserPreferenceController}.
|
||||
* Tests for {@link AlwaysOnVpnCurrentUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
public final class AlwaysOnVpnCurrentUserPreferenceControllerTest {
|
||||
|
||||
private final String VPN_SET_DEVICE = "VPN set";
|
||||
private final String VPN_SET_PERSONAL = "VPN set in personal profile";
|
||||
@@ -49,14 +49,14 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private AlwaysOnVpnPrimaryUserPreferenceController mController;
|
||||
private AlwaysOnVpnCurrentUserPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new AlwaysOnVpnPrimaryUserPreferenceController(mContext,
|
||||
mController = new AlwaysOnVpnCurrentUserPreferenceController(mContext,
|
||||
null /* lifecycle */);
|
||||
when(mContext.getString(R.string.enterprise_privacy_always_on_vpn_device))
|
||||
.thenReturn(VPN_SET_DEVICE);
|
||||
@@ -68,7 +68,7 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(true);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isInCompMode()).thenReturn(false);
|
||||
@@ -82,11 +82,11 @@ public final class AlwaysOnVpnPrimaryUserPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInPrimaryUser())
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.isAlwaysOnVpnSetInCurrentUser())
|
||||
.thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
@@ -195,13 +195,13 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAlwaysOnVpnSetInPrimaryUser() {
|
||||
public void testIsAlwaysOnVpnSetInCurrentUser() {
|
||||
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID)).thenReturn(null);
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isFalse();
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isFalse();
|
||||
|
||||
when(mConnectivityManger.getAlwaysOnVpnPackageForUser(MY_USER_ID))
|
||||
.thenReturn(VPN_PACKAGE_ID);
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInPrimaryUser()).isTrue();
|
||||
assertThat(mProvider.isAlwaysOnVpnSetInCurrentUser()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -230,16 +230,14 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetMaximumFailedPasswordsForWipeInPrimaryUser() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_NULL);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(0);
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getDeviceOwnerUserId()).thenReturn(UserHandle.USER_SYSTEM);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, UserHandle.USER_SYSTEM))
|
||||
public void testGetMaximumFailedPasswordsForWipeInCurrentUser() {
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(null);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MY_USER_ID))
|
||||
.thenReturn(10);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).isEqualTo(10);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(0);
|
||||
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MY_USER_ID)).thenReturn(OWNER);
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).isEqualTo(10);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -247,7 +245,6 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
when(mDevicePolicyManager.getProfileOwnerAsUser(MANAGED_PROFILE_USER_ID)).thenReturn(OWNER);
|
||||
when(mDevicePolicyManager.getMaximumFailedPasswordsForWipe(OWNER, MANAGED_PROFILE_USER_ID))
|
||||
.thenReturn(10);
|
||||
|
||||
assertThat(mProvider.getMaximumFailedPasswordsBeforeWipeInManagedProfile()).isEqualTo(0);
|
||||
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
|
||||
@@ -134,7 +134,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
EnterpriseSetDefaultAppsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnPrimaryUserPreferenceController.class);
|
||||
AlwaysOnVpnCurrentUserPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
@@ -142,7 +142,7 @@ public final class EnterprisePrivacySettingsTest {
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
CaCertsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||
FailedPasswordWipeCurrentUserPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);
|
||||
|
||||
@@ -27,29 +27,29 @@ import org.robolectric.annotation.Config;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link FailedPasswordWipePrimaryUserPreferenceController}.
|
||||
* Tests for {@link FailedPasswordWipeCurrentUserPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class FailedPasswordWipePrimaryUserPreferenceControllerTest extends
|
||||
public final class FailedPasswordWipeCurrentUserPreferenceControllerTest extends
|
||||
FailedPasswordWipePreferenceControllerTestBase {
|
||||
|
||||
private int mMaximumFailedPasswordsBeforeWipe = 0;
|
||||
|
||||
public FailedPasswordWipePrimaryUserPreferenceControllerTest() {
|
||||
super("failed_password_wipe_primary_user");
|
||||
public FailedPasswordWipeCurrentUserPreferenceControllerTest() {
|
||||
super("failed_password_wipe_current_user");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setUp() {
|
||||
super.setUp();
|
||||
mController = new FailedPasswordWipePrimaryUserPreferenceController(mContext,
|
||||
mController = new FailedPasswordWipeCurrentUserPreferenceController(mContext,
|
||||
null /* lifecycle */);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setMaximumFailedPasswordsBeforeWipe(int maximum) {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getMaximumFailedPasswordsBeforeWipeInPrimaryUser()).thenReturn(maximum);
|
||||
.getMaximumFailedPasswordsBeforeWipeInCurrentUser()).thenReturn(maximum);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user