Merge "Modify tests for SystemAppUpdateTracker." into tm-dev

This commit is contained in:
TreeHugger Robot
2022-03-08 10:41:08 +00:00
committed by Android (Google) Code Review

View File

@@ -98,11 +98,8 @@ public class SystemAppUpdateTrackerTest {
private ActivityTaskManagerInternal mMockActivityTaskManager; private ActivityTaskManagerInternal mMockActivityTaskManager;
@Mock @Mock
private ActivityManagerInternal mMockActivityManager; private ActivityManagerInternal mMockActivityManager;
@Mock
private LocaleManagerBackupHelper mMockLocaleManagerBackupHelper;
@Mock
PackageMonitor mMockPackageMonitor;
PackageMonitor mPackageMonitor;
private LocaleManagerService mLocaleManagerService; private LocaleManagerService mLocaleManagerService;
// Object under test. // Object under test.
@@ -114,11 +111,14 @@ public class SystemAppUpdateTrackerTest {
mMockActivityTaskManager = mock(ActivityTaskManagerInternal.class); mMockActivityTaskManager = mock(ActivityTaskManagerInternal.class);
mMockActivityManager = mock(ActivityManagerInternal.class); mMockActivityManager = mock(ActivityManagerInternal.class);
mMockPackageManagerInternal = mock(PackageManagerInternal.class); mMockPackageManagerInternal = mock(PackageManagerInternal.class);
mMockPackageMonitor = mock(PackageMonitor.class); LocaleManagerBackupHelper mockLocaleManagerBackupHelper =
mMockLocaleManagerBackupHelper = mock(ShadowLocaleManagerBackupHelper.class); mock(ShadowLocaleManagerBackupHelper.class);
// PackageMonitor is not needed in LocaleManagerService for these tests hence it is
// passed as null.
mLocaleManagerService = new LocaleManagerService(mMockContext, mLocaleManagerService = new LocaleManagerService(mMockContext,
mMockActivityTaskManager, mMockActivityManager, mMockActivityTaskManager, mMockActivityManager,
mMockPackageManagerInternal, mMockLocaleManagerBackupHelper, mMockPackageMonitor); mMockPackageManagerInternal, mockLocaleManagerBackupHelper,
/* mPackageMonitor= */ null);
doReturn(DEFAULT_USER_ID).when(mMockActivityManager) doReturn(DEFAULT_USER_ID).when(mMockActivityManager)
.handleIncomingUser(anyInt(), anyInt(), eq(DEFAULT_USER_ID), anyBoolean(), anyInt(), .handleIncomingUser(anyInt(), anyInt(), eq(DEFAULT_USER_ID), anyBoolean(), anyInt(),
@@ -134,6 +134,9 @@ public class SystemAppUpdateTrackerTest {
mSystemAppUpdateTracker = new SystemAppUpdateTracker(mMockContext, mSystemAppUpdateTracker = new SystemAppUpdateTracker(mMockContext,
mLocaleManagerService, mStoragefile); mLocaleManagerService, mStoragefile);
mPackageMonitor = new LocaleManagerServicePackageMonitor(
mockLocaleManagerBackupHelper, mSystemAppUpdateTracker);
} }
@After @After
@@ -148,7 +151,7 @@ public class SystemAppUpdateTrackerTest {
.when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_1), any()); .when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_1), any());
// Updates the app once so that it writes to the file. // Updates the app once so that it writes to the file.
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1,
Binder.getCallingUid()); Binder.getCallingUid());
// Clear the in-memory data of updated apps // Clear the in-memory data of updated apps
mSystemAppUpdateTracker.getUpdatedApps().clear(); mSystemAppUpdateTracker.getUpdatedApps().clear();
@@ -167,7 +170,7 @@ public class SystemAppUpdateTrackerTest {
DEFAULT_LOCALES)).when(mMockActivityTaskManager) DEFAULT_LOCALES)).when(mMockActivityTaskManager)
.getApplicationConfig(anyString(), anyInt()); .getApplicationConfig(anyString(), anyInt());
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1,
Binder.getCallingUid()); Binder.getCallingUid());
assertBroadcastSentToInstaller(DEFAULT_PACKAGE_NAME_1, DEFAULT_LOCALES); assertBroadcastSentToInstaller(DEFAULT_PACKAGE_NAME_1, DEFAULT_LOCALES);
@@ -186,7 +189,7 @@ public class SystemAppUpdateTrackerTest {
.getApplicationConfig(anyString(), anyInt()); .getApplicationConfig(anyString(), anyInt());
// first update // first update
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1,
Binder.getCallingUid()); Binder.getCallingUid());
assertBroadcastSentToInstaller(DEFAULT_PACKAGE_NAME_1, DEFAULT_LOCALES); assertBroadcastSentToInstaller(DEFAULT_PACKAGE_NAME_1, DEFAULT_LOCALES);
@@ -195,7 +198,7 @@ public class SystemAppUpdateTrackerTest {
verifyStorageFileContents(expectedAppList); verifyStorageFileContents(expectedAppList);
// second update // second update
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1,
Binder.getCallingUid()); Binder.getCallingUid());
// getApplicationLocales should be invoked only once on the first update. // getApplicationLocales should be invoked only once on the first update.
verify(mMockActivityTaskManager, times(1)) verify(mMockActivityTaskManager, times(1))
@@ -212,7 +215,7 @@ public class SystemAppUpdateTrackerTest {
/* isUpdatedSystemApp = */false)) /* isUpdatedSystemApp = */false))
.when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_2), any()); .when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_2), any());
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_2, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_2,
Binder.getCallingUid()); Binder.getCallingUid());
assertTrue(!mSystemAppUpdateTracker.getUpdatedApps().contains(DEFAULT_PACKAGE_NAME_2)); assertTrue(!mSystemAppUpdateTracker.getUpdatedApps().contains(DEFAULT_PACKAGE_NAME_2));
@@ -231,7 +234,7 @@ public class SystemAppUpdateTrackerTest {
.when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_1), any()); .when(mMockPackageManager).getApplicationInfo(eq(DEFAULT_PACKAGE_NAME_1), any());
doReturn(null).when(mMockPackageManager).getInstallSourceInfo(anyString()); doReturn(null).when(mMockPackageManager).getInstallSourceInfo(anyString());
mSystemAppUpdateTracker.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1, mPackageMonitor.onPackageUpdateFinished(DEFAULT_PACKAGE_NAME_1,
Binder.getCallingUid()); Binder.getCallingUid());
// getApplicationLocales should be never be invoked if not installer is not present. // getApplicationLocales should be never be invoked if not installer is not present.