Merge "Update strings and layout for enterprise privacy"
This commit is contained in:
committed by
Android (Google) Code Review
commit
eb3d371953
@@ -60,6 +60,8 @@ import static org.mockito.Mockito.when;
|
||||
public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
|
||||
private final ComponentName OWNER = new ComponentName("dummy", "component");
|
||||
private final ComponentName ADMIN_1 = new ComponentName("dummy", "admin1");
|
||||
private final ComponentName ADMIN_2 = new ComponentName("dummy", "admin2");
|
||||
private final String OWNER_ORGANIZATION = new String("ACME");
|
||||
private final Date TIMESTAMP = new Date(2011, 11, 11);
|
||||
private final int MY_USER_ID = UserHandle.myUserId();
|
||||
@@ -113,6 +115,15 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
assertThat(mProvider.isInCompMode()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeviceOwnerOrganizationName() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(null);
|
||||
assertThat(mProvider.getDeviceOwnerOrganizationName()).isNull();
|
||||
|
||||
when(mDevicePolicyManager.getDeviceOwnerOrganizationName()).thenReturn(OWNER_ORGANIZATION);
|
||||
assertThat(mProvider.getDeviceOwnerOrganizationName()).isEqualTo(OWNER_ORGANIZATION);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetDeviceOwnerDisclosure() {
|
||||
when(mDevicePolicyManager.getDeviceOwnerComponentOnAnyUser()).thenReturn(null);
|
||||
@@ -292,6 +303,21 @@ public final class EnterprisePrivacyFeatureProviderImplTest {
|
||||
assertThat(mProvider.getNumberOfOwnerInstalledCaCertsInManagedProfile()).isEqualTo(0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile() {
|
||||
when(mDevicePolicyManager.getActiveAdminsAsUser(MY_USER_ID))
|
||||
.thenReturn(Arrays.asList(new ComponentName[] {ADMIN_1, ADMIN_2}));
|
||||
when(mDevicePolicyManager.getActiveAdminsAsUser(MANAGED_PROFILE_USER_ID))
|
||||
.thenReturn(Arrays.asList(new ComponentName[] {ADMIN_1}));
|
||||
|
||||
assertThat(mProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile())
|
||||
.isEqualTo(2);
|
||||
|
||||
mProfiles.add(new UserInfo(MANAGED_PROFILE_USER_ID, "", "", UserInfo.FLAG_MANAGED_PROFILE));
|
||||
assertThat(mProvider.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile())
|
||||
.isEqualTo(3);
|
||||
}
|
||||
|
||||
private void resetAndInitializePackageManagerWrapper() {
|
||||
reset(mPackageManagerWrapper);
|
||||
when(mPackageManagerWrapper.hasSystemFeature(PackageManager.FEATURE_DEVICE_ADMIN))
|
||||
|
@@ -0,0 +1,104 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link EnterprisePrivacyPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class EnterprisePrivacyPreferenceControllerTest {
|
||||
|
||||
private final String MANAGED_GENERIC = "managed by organization";
|
||||
private final String MANAGED_WITH_NAME = "managed by Foo, Inc.";
|
||||
private final String MANAGING_ORGANIZATION = "Foo, Inc.";
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private EnterprisePrivacyPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new EnterprisePrivacyPreferenceController(mContext, null /* lifecycle */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
when(mContext.getString(R.string.enterprise_privacy_settings_summary_generic))
|
||||
.thenReturn(MANAGED_GENERIC);
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getDeviceOwnerOrganizationName())
|
||||
.thenReturn(null);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo(MANAGED_GENERIC);
|
||||
|
||||
when(mContext.getResources().getString(
|
||||
R.string.enterprise_privacy_settings_summary_with_name, MANAGING_ORGANIZATION))
|
||||
.thenReturn(MANAGED_WITH_NAME);
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.getDeviceOwnerOrganizationName())
|
||||
.thenReturn(MANAGING_ORGANIZATION);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo(MANAGED_WITH_NAME);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(false);
|
||||
assertThat(mController.isAvailable()).isFalse();
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider.hasDeviceOwner()).thenReturn(true);
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick() {
|
||||
assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo("enterprise_privacy");
|
||||
}
|
||||
}
|
@@ -0,0 +1,87 @@
|
||||
/*
|
||||
* Copyright (C) 2017 The Android Open Source Project
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.testutils.FakeFeatureFactory;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link ManageDeviceAdminPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class ManageDeviceAdminPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private ManageDeviceAdminPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new ManageDeviceAdminPreferenceController(mContext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
when(mFeatureFactory.enterprisePrivacyFeatureProvider
|
||||
.getNumberOfActiveDeviceAdminsForCurrentUserAndManagedProfile()).thenReturn(5);
|
||||
when(mContext.getResources().getQuantityString(R.plurals.number_of_device_admins, 5, 5))
|
||||
.thenReturn("5 active apps");
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("5 active apps");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testIsAvailable() {
|
||||
assertThat(mController.isAvailable()).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHandlePreferenceTreeClick() {
|
||||
assertThat(mController.handlePreferenceTreeClick(new Preference(mContext, null, 0, 0)))
|
||||
.isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetPreferenceKey() {
|
||||
assertThat(mController.getPreferenceKey()).isEqualTo("manage_device_admin");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user