Don't shows Files when storage is adopted.

One regression from the previous storage view is that the
Files category should not show at all when the storage is adopted.

Fixes: 36786953
Test: Settings robotest

Change-Id: Ice365fabc3bfa66f4c5526ac78bbbfc5e15b7b35
This commit is contained in:
Daniel Nishi
2017-04-04 10:29:59 -07:00
parent cba520fc9d
commit 1f079fbae4
2 changed files with 96 additions and 1 deletions

View File

@@ -84,7 +84,7 @@ public class StorageItemPreferenceControllerTest {
FakeFeatureFactory.setupForTest(mContext);
mFakeFeatureFactory = (FakeFeatureFactory) FakeFeatureFactory.getFactory(mContext);
mMetricsFeatureProvider = mFakeFeatureFactory.getMetricsFeatureProvider();
mVolume = new VolumeInfo("id", 0, null, "id");
mVolume = spy(new VolumeInfo("id", 0, null, "id"));
// Note: null is passed as the Lifecycle because we are handling it outside of the normal
// Settings fragment lifecycle for test purposes.
mController = new StorageItemPreferenceController(mContext, mFragment, mVolume, mSvp);
@@ -305,4 +305,90 @@ public class StorageItemPreferenceControllerTest {
verify(system, times(2)).setIcon(any(Drawable.class));
verify(files, times(2)).setIcon(any(Drawable.class));
}
@Test
public void displayPreference_dontHideFilePreferenceWhenEmulatedInternalStorageUsed() {
StorageItemPreference audio = new StorageItemPreference(mContext);
StorageItemPreference image = new StorageItemPreference(mContext);
StorageItemPreference games = new StorageItemPreference(mContext);
StorageItemPreference apps = new StorageItemPreference(mContext);
StorageItemPreference system = new StorageItemPreference(mContext);
StorageItemPreference files = new StorageItemPreference(mContext);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
.thenReturn(audio);
when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
.thenReturn(image);
when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
.thenReturn(apps);
when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
.thenReturn(system);
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(true);
mController.displayPreference(screen);
verify(screen, times(0)).removePreference(files);
}
@Test
public void displayPreference_hideFilePreferenceWhenEmulatedStorageUnreadable() {
StorageItemPreference audio = new StorageItemPreference(mContext);
StorageItemPreference image = new StorageItemPreference(mContext);
StorageItemPreference games = new StorageItemPreference(mContext);
StorageItemPreference apps = new StorageItemPreference(mContext);
StorageItemPreference system = new StorageItemPreference(mContext);
StorageItemPreference files = new StorageItemPreference(mContext);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
.thenReturn(audio);
when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
.thenReturn(image);
when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
.thenReturn(apps);
when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
.thenReturn(system);
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(mVolume);
when(mVolume.isMountedReadable()).thenReturn(false);
mController.displayPreference(screen);
verify(screen).removePreference(files);
}
@Test
public void displayPreference_hideFilePreferenceWhenNoEmulatedInternalStorage() {
StorageItemPreference audio = new StorageItemPreference(mContext);
StorageItemPreference image = new StorageItemPreference(mContext);
StorageItemPreference games = new StorageItemPreference(mContext);
StorageItemPreference apps = new StorageItemPreference(mContext);
StorageItemPreference system = new StorageItemPreference(mContext);
StorageItemPreference files = new StorageItemPreference(mContext);
PreferenceScreen screen = mock(PreferenceScreen.class);
when(screen.findPreference(eq(StorageItemPreferenceController.AUDIO_KEY)))
.thenReturn(audio);
when(screen.findPreference(eq(StorageItemPreferenceController.PHOTO_KEY)))
.thenReturn(image);
when(screen.findPreference(eq(StorageItemPreferenceController.GAME_KEY))).thenReturn(games);
when(screen.findPreference(eq(StorageItemPreferenceController.OTHER_APPS_KEY)))
.thenReturn(apps);
when(screen.findPreference(eq(StorageItemPreferenceController.SYSTEM_KEY)))
.thenReturn(system);
when(screen.findPreference(eq(StorageItemPreferenceController.FILES_KEY)))
.thenReturn(files);
when(mSvp.findEmulatedForPrivate(any(VolumeInfo.class))).thenReturn(null);
mController.displayPreference(screen);
verify(screen).removePreference(files);
}
}