Merge "Improve launch time for Apps & notifications page"

This commit is contained in:
TreeHugger Robot
2019-02-26 08:50:20 +00:00
committed by Android (Google) Code Review
2 changed files with 57 additions and 19 deletions

View File

@@ -25,9 +25,9 @@ import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.argThat;
import static org.mockito.Mockito.doNothing;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@@ -146,6 +146,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.reloadData();
assertThat(mController.getAvailabilityStatus()).isEqualTo(AVAILABLE);
}
@@ -157,13 +158,17 @@ public class RecentAppsPreferenceControllerTest {
}
@Test
public void displayPreferenceAndUpdateState_shouldRefreshUi() {
doNothing().when(mController).refreshUi();
public void displayPreference_shouldNotReloadData() {
mController.displayPreference(mScreen);
mController.updateState(mScreen);
verify(mController, times(2)).refreshUi();
verify(mController, never()).reloadData();
}
@Test
public void displayPreference_shouldRefreshUi() {
mController.displayPreference(mScreen);
verify(mController).refreshUi();
}
@Test
@@ -173,6 +178,25 @@ public class RecentAppsPreferenceControllerTest {
assertThat(mController.mAppEntitiesController).isNotNull();
}
@Test
public void updateState_firstLaunch_shouldNotReloadData() {
mController.mIsFirstLaunch = true;
mController.updateState(mRecentAppsPreference);
verify(mController, never()).reloadData();
}
@Test
public void updateState_afterFirstLaunch_shouldReloadDataAndRefreshUi() {
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
verify(mController).reloadData();
verify(mController).refreshUi();
}
@Test
public void updateState_threeValidRecentOpenAppsSet_setAppEntityThreeTime() {
final List<UsageStats> stats = new ArrayList<>();
@@ -203,6 +227,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -243,6 +268,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -274,6 +300,7 @@ public class RecentAppsPreferenceControllerTest {
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mAppEntry.info = mApplicationInfo;
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -314,6 +341,7 @@ public class RecentAppsPreferenceControllerTest {
// Make sure stat2 is considered an instant app.
ReflectionHelpers.setStaticField(AppUtils.class, "sInstantAppDataProvider",
(InstantAppDataProvider) (ApplicationInfo info) -> info == stat2Entry.info);
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);
@@ -389,6 +417,7 @@ public class RecentAppsPreferenceControllerTest {
.thenReturn(new ResolveInfo());
when(mUsageStatsManager.queryUsageStats(anyInt(), anyLong(), anyLong()))
.thenReturn(stats);
mController.mIsFirstLaunch = false;
mController.updateState(mRecentAppsPreference);