Update List of apps on device string,
remove "XX apps" string. Bug: 32692748 Test: m RunSettingsRoboTests Change-Id: I64f833497b5362f95cfc56a1057d97d9539ff029
This commit is contained in:
@@ -88,7 +88,7 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
mPackageManagerService, mDevicePolicyManager);
|
||||
}
|
||||
|
||||
private void verifyCalculateNumberOfInstalledApps(boolean async) {
|
||||
private void verifyCalculateNumberOfPolicyInstalledApps(boolean async) {
|
||||
setUpUsersAndInstalledApps();
|
||||
|
||||
when(mPackageManager.getInstallReason(APP_1, new UserHandle(MAIN_USER_ID)))
|
||||
@@ -96,18 +96,8 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
when(mPackageManager.getInstallReason(APP_2, new UserHandle(MANAGED_PROFILE_ID)))
|
||||
.thenReturn(PackageManager.INSTALL_REASON_POLICY);
|
||||
|
||||
// Count all installed apps.
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfInstalledApps(ApplicationFeatureProvider.IGNORE_INSTALL_REASON,
|
||||
async, (num) -> mAppCount = num);
|
||||
if (async) {
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
}
|
||||
assertThat(mAppCount).isEqualTo(2);
|
||||
|
||||
// Count apps with specific install reason only.
|
||||
mAppCount = -1;
|
||||
mProvider.calculateNumberOfInstalledApps(PackageManager.INSTALL_REASON_POLICY, async,
|
||||
mProvider.calculateNumberOfPolicyInstalledApps(async,
|
||||
(num) -> mAppCount = num);
|
||||
if (async) {
|
||||
ShadowApplication.runBackgroundTasks();
|
||||
@@ -117,12 +107,12 @@ public final class ApplicationFeatureProviderImplTest {
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledAppsSync() {
|
||||
verifyCalculateNumberOfInstalledApps(false /* async */);
|
||||
verifyCalculateNumberOfPolicyInstalledApps(false /* async */);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCalculateNumberOfInstalledAppsAsync() {
|
||||
verifyCalculateNumberOfInstalledApps(true /* async */);
|
||||
verifyCalculateNumberOfPolicyInstalledApps(true /* async */);
|
||||
}
|
||||
|
||||
private void verifyCalculateNumberOfAppsWithAdminGrantedPermissions(boolean async)
|
||||
|
@@ -156,7 +156,7 @@ public final class InstalledAppCounterTest {
|
||||
.thenReturn(PackageManager.INSTALL_REASON_UNKNOWN);
|
||||
|
||||
// Count the number of all apps installed, irrespective of install reason.
|
||||
count(ApplicationFeatureProvider.IGNORE_INSTALL_REASON, async);
|
||||
count(InstalledAppCounter.IGNORE_INSTALL_REASON, async);
|
||||
assertThat(mInstalledAppCount).isEqualTo(5);
|
||||
|
||||
// Verify that installed packages were retrieved for the users returned by
|
||||
|
@@ -17,8 +17,6 @@
|
||||
package com.android.settings.enterprise;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.pm.PackageManager;
|
||||
import android.content.res.Resources;
|
||||
import android.support.v7.preference.Preference;
|
||||
|
||||
import com.android.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
@@ -70,11 +68,10 @@ public final class EnterpriseInstalledPackagesPreferenceControllerTest {
|
||||
doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||
invocation.getArguments()[1]).onNumberOfAppsResult(number);
|
||||
return null;
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider)
|
||||
.calculateNumberOfInstalledApps(eq(PackageManager.INSTALL_REASON_POLICY),
|
||||
eq(async), anyObject());
|
||||
.calculateNumberOfPolicyInstalledApps(eq(async), anyObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -117,31 +117,34 @@ public final class EnterprisePrivacySettingsTest {
|
||||
|
||||
private void verifyPreferenceControllers(List<PreferenceController> controllers) {
|
||||
assertThat(controllers).isNotNull();
|
||||
assertThat(controllers.size()).isEqualTo(16);
|
||||
assertThat(controllers.get(0)).isInstanceOf(InstalledPackagesPreferenceController.class);
|
||||
assertThat(controllers.get(1)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||
assertThat(controllers.get(2)).isInstanceOf(BugReportsPreferenceController.class);
|
||||
assertThat(controllers.get(3)).isInstanceOf(SecurityLogsPreferenceController.class);
|
||||
assertThat(controllers.get(4)).isInstanceOf(
|
||||
assertThat(controllers.size()).isEqualTo(15);
|
||||
int position = 0;
|
||||
assertThat(controllers.get(position++)).isInstanceOf(NetworkLogsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(BugReportsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
SecurityLogsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
EnterpriseInstalledPackagesPreferenceController.class);
|
||||
assertThat(controllers.get(5)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AdminGrantedLocationPermissionsPreferenceController.class);
|
||||
assertThat(controllers.get(6)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AdminGrantedMicrophonePermissionPreferenceController.class);
|
||||
assertThat(controllers.get(7)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AdminGrantedCameraPermissionPreferenceController.class);
|
||||
assertThat(controllers.get(8)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
EnterpriseSetDefaultAppsPreferenceController.class);
|
||||
assertThat(controllers.get(9)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnPrimaryUserPreferenceController.class);
|
||||
assertThat(controllers.get(10)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
AlwaysOnVpnManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(11)).isInstanceOf(GlobalHttpProxyPreferenceController.class);
|
||||
assertThat(controllers.get(12)).isInstanceOf(CaCertsPreferenceController.class);
|
||||
assertThat(controllers.get(13)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
GlobalHttpProxyPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
CaCertsPreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipePrimaryUserPreferenceController.class);
|
||||
assertThat(controllers.get(14)).isInstanceOf(
|
||||
assertThat(controllers.get(position++)).isInstanceOf(
|
||||
FailedPasswordWipeManagedProfilePreferenceController.class);
|
||||
assertThat(controllers.get(15)).isInstanceOf(ImePreferenceController.class);
|
||||
assertThat(controllers.get(position++)).isInstanceOf(ImePreferenceController.class);
|
||||
}
|
||||
}
|
||||
|
@@ -1,107 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2016 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.internal.logging.nano.MetricsProto.MetricsEvent;
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.applications.ApplicationFeatureProvider;
|
||||
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.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
import static org.mockito.Mockito.anyObject;
|
||||
import static org.mockito.Mockito.doAnswer;
|
||||
import static org.mockito.Mockito.eq;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
/**
|
||||
* Tests for {@link InstalledPackagesPreferenceController}.
|
||||
*/
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public final class InstalledPackagesPreferenceControllerTest {
|
||||
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Context mContext;
|
||||
private FakeFeatureFactory mFeatureFactory;
|
||||
|
||||
private InstalledPackagesPreferenceController mController;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
FakeFeatureFactory.setupForTest(mContext);
|
||||
mFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
|
||||
mController = new InstalledPackagesPreferenceController(mContext);
|
||||
}
|
||||
|
||||
private void setNumberOfInstalledPackages(int number) {
|
||||
doAnswer(new Answer() {
|
||||
public Object answer(InvocationOnMock invocation) {
|
||||
((ApplicationFeatureProvider.NumberOfAppsCallback)
|
||||
invocation.getArguments()[2]).onNumberOfAppsResult(number);
|
||||
return null;
|
||||
}}).when(mFeatureFactory.applicationFeatureProvider).calculateNumberOfInstalledApps(
|
||||
eq(ApplicationFeatureProvider.IGNORE_INSTALL_REASON), eq(true), anyObject());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testUpdateState() {
|
||||
final Preference preference = new Preference(mContext, null, 0, 0);
|
||||
|
||||
setNumberOfInstalledPackages(0);
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("");
|
||||
|
||||
setNumberOfInstalledPackages(20);
|
||||
when(mContext.getResources().getQuantityString(R.plurals.enterprise_privacy_number_packages,
|
||||
20, 20)).thenReturn("20 packages");
|
||||
mController.updateState(preference);
|
||||
assertThat(preference.getSummary()).isEqualTo("20 packages");
|
||||
}
|
||||
|
||||
@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("installed_packages");
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user