Merge "Cache summary text to avoid flickering" into tm-dev am: bd4b23ba0d

Original change: https://googleplex-android-review.googlesource.com/c/platform/packages/apps/Settings/+/18328550

Change-Id: I2ed88c37d72f206af245a0c62037289e3015ad43
Signed-off-by: Automerger Merge Worker <android-build-automerger-merge-worker@system.gserviceaccount.com>
This commit is contained in:
Lifu Tang
2022-05-12 15:01:56 +00:00
committed by Automerger Merge Worker
2 changed files with 26 additions and 16 deletions

View File

@@ -56,31 +56,41 @@ public class TopLevelLocationPreferenceControllerTest {
}
@Test
public void getSummary_whenLocationIsOn_shouldShowLoadingString() {
public void getSummary_whenLocationIsOn_shouldPreservePreviousText() {
final int locationAppCount = 5;
// Retrieve summary text once.
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(locationAppCount);
mController.getSummary();
// Turn off location.
mLocationManager.setLocationEnabledForUser(false, android.os.Process.myUserHandle());
// Turn on location again and check if the previous summary text is still cached.
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
assertThat(mController.getSummary()).isEqualTo(
mContext.getString(R.string.location_settings_loading_app_permission_stats));
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on, locationAppCount,
locationAppCount));
}
@Test
public void getSummary_whenLocationAppCountIsOne_shouldShowSingularString() {
final int LOCATION_APP_COUNT = 1;
final int locationAppCount = 1;
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(LOCATION_APP_COUNT);
mController.setLocationAppCount(locationAppCount);
assertThat(mController.getSummary()).isEqualTo(
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on,
LOCATION_APP_COUNT, LOCATION_APP_COUNT));
locationAppCount, locationAppCount));
}
@Test
public void getSummary_whenLocationAppCountIsGreaterThanOne_shouldShowPluralString() {
final int LOCATION_APP_COUNT = 5;
final int locationAppCount = 5;
mLocationManager.setLocationEnabledForUser(true, android.os.Process.myUserHandle());
mController.setLocationAppCount(LOCATION_APP_COUNT);
mController.setLocationAppCount(locationAppCount);
assertThat(mController.getSummary()).isEqualTo(
mContext.getResources().getQuantityString(
R.plurals.location_settings_summary_location_on,
LOCATION_APP_COUNT, LOCATION_APP_COUNT));
locationAppCount, locationAppCount));
}
}