Merge "Cleanup Storage Settings" into sc-dev
This commit is contained in:
@@ -1,104 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications.manageapplications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class MusicViewHolderControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private StorageStatsSource mSource;
|
||||
|
||||
private Context mContext;
|
||||
private MusicViewHolderController mController;
|
||||
private ApplicationViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
final String fsUuid = new VolumeInfo("id", 0, null, "id").fsUuid;
|
||||
mController = new MusicViewHolderController(mContext, mSource, fsUuid, UserHandle.of(-1));
|
||||
|
||||
View view = ApplicationViewHolder.newView(new FrameLayout(mContext));
|
||||
mHolder = new ApplicationViewHolder(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.mSummary.getText().toString()).isEqualTo(
|
||||
Formatter.formatFileSize(mContext, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldRepresentStorageStatsQuery() throws Exception {
|
||||
when(mSource.getExternalStorageStats(nullable(String.class), nullable(UserHandle.class)))
|
||||
.thenReturn(new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0, 0));
|
||||
|
||||
mController.queryStats();
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.mSummary.getText().toString()).isEqualTo(
|
||||
Formatter.formatFileSize(mContext, 1));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickingShouldIntentIntoFilesApp() {
|
||||
mController.onClick(mFragment);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
|
||||
assertThat(intent.getData()).isEqualTo(DocumentsContract.buildRootUri(
|
||||
"com.android.providers.media.documents",
|
||||
"audio_root"));
|
||||
assertThat(intent.getType()).isEqualTo(DocumentsContract.Root.MIME_TYPE_ITEM);
|
||||
}
|
||||
}
|
@@ -1,101 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2017 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.applications.manageapplications;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.text.format.Formatter;
|
||||
import android.view.View;
|
||||
import android.widget.FrameLayout;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.android.settingslib.applications.StorageStatsSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.Answers;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.robolectric.RobolectricTestRunner;
|
||||
import org.robolectric.RuntimeEnvironment;
|
||||
|
||||
@RunWith(RobolectricTestRunner.class)
|
||||
public class PhotosViewHolderControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private StorageStatsSource mSource;
|
||||
|
||||
private Context mContext;
|
||||
private PhotosViewHolderController mController;
|
||||
private ApplicationViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
final String fsUuid = new VolumeInfo("id", 0, null, "id").fsUuid;
|
||||
mController = new PhotosViewHolderController(mContext, mSource, fsUuid, UserHandle.of(-1));
|
||||
|
||||
final View view = ApplicationViewHolder.newView(new FrameLayout(mContext));
|
||||
mHolder = new ApplicationViewHolder(view);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.mSummary.getText().toString())
|
||||
.isEqualTo(Formatter.formatFileSize(mContext, 0));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldRepresentStorageStatsQuery() throws Exception {
|
||||
when(mSource.getExternalStorageStats(nullable(String.class), nullable(UserHandle.class)))
|
||||
.thenReturn(new StorageStatsSource.ExternalStorageStats(1, 0, 1, 10, 0));
|
||||
|
||||
mController.queryStats();
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.mSummary.getText().toString())
|
||||
.isEqualTo(Formatter.formatFileSize(mContext, 11));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void clickingShouldIntentIntoFilesApp() {
|
||||
mController.onClick(mFragment);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment).startActivity(argumentCaptor.capture());
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getType()).isEqualTo("image/*");
|
||||
assertThat(intent.getAction()).isEqualTo(android.content.Intent.ACTION_VIEW);
|
||||
assertThat(intent.getBooleanExtra(Intent.EXTRA_FROM_STORAGE, false)).isTrue();
|
||||
}
|
||||
}
|
@@ -20,6 +20,7 @@ import static com.android.settings.utils.FileSizeFormatter.MEGABYTE_IN_BYTES;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.anyInt;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.nullable;
|
||||
import static org.mockito.Mockito.mock;
|
||||
@@ -30,6 +31,7 @@ import static org.mockito.Mockito.when;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.content.res.Resources;
|
||||
import android.graphics.drawable.Drawable;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
@@ -172,38 +174,33 @@ public class StorageItemPreferenceControllerTest {
|
||||
@Test
|
||||
public void launchImagesIntent_resolveActionViewNull_settingsIntent() {
|
||||
mPreference.setKey(StorageItemPreferenceController.IMAGES_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mActivity).startActivityAsUser(argumentCaptor.capture(),
|
||||
nullable(UserHandle.class));
|
||||
verify(mockContext).startActivity(argumentCaptor.capture());
|
||||
|
||||
final Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ManageApplications.class.getName());
|
||||
assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
|
||||
.isEqualTo(R.string.storage_photos_videos);
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
|
||||
assertThat(intent.getData()).isEqualTo(mController.mImagesUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void launchAudiosIntent_resolveActionViewNull_settingsIntent() {
|
||||
mPreference.setKey(StorageItemPreferenceController.AUDIOS_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
nullable(UserHandle.class));
|
||||
verify(mockContext).startActivity(argumentCaptor.capture());
|
||||
final Intent intent = argumentCaptor.getValue();
|
||||
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ManageApplications.class.getName());
|
||||
assertThat(intent.getBundleExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_ARGUMENTS).getInt(
|
||||
ManageApplications.EXTRA_STORAGE_TYPE, 0))
|
||||
.isEqualTo(ManageApplications.STORAGE_TYPE_MUSIC);
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
|
||||
assertThat(intent.getData()).isEqualTo(mController.mAudiosUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -270,20 +267,18 @@ public class StorageItemPreferenceControllerTest {
|
||||
|
||||
@Test
|
||||
public void launchDocumentsAndOtherIntent_resolveActionViewNull_settingsIntent() {
|
||||
when(mSvp.findEmulatedForPrivate(nullable(VolumeInfo.class))).thenReturn(mVolume);
|
||||
when(mVolume.buildBrowseIntent()).thenReturn(new Intent());
|
||||
mPreference.setKey(StorageItemPreferenceController.DOCUMENTS_AND_OTHER_KEY);
|
||||
assertThat(mController.handlePreferenceTreeClick(mPreference))
|
||||
.isTrue();
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
nullable(UserHandle.class));
|
||||
verify(mockContext).startActivity(argumentCaptor.capture());
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
Intent browseIntent = mVolume.buildBrowseIntent();
|
||||
assertThat(intent.getAction()).isEqualTo(browseIntent.getAction());
|
||||
assertThat(intent.getData()).isEqualTo(browseIntent.getData());
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
|
||||
assertThat(intent.getData()).isEqualTo(mController.mDocumentsAndOtherUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -307,19 +302,17 @@ public class StorageItemPreferenceControllerTest {
|
||||
@Test
|
||||
public void launchVideosIntent_resolveActionViewNull_settingsIntent() {
|
||||
mPreference.setKey(StorageItemPreferenceController.VIDEOS_KEY);
|
||||
final Context mockContext = getMockContext();
|
||||
mController = new StorageItemPreferenceController(mockContext, mFragment, mVolume,
|
||||
mSvp);
|
||||
mController.handlePreferenceTreeClick(mPreference);
|
||||
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
nullable(UserHandle.class));
|
||||
verify(mockContext).startActivity(argumentCaptor.capture());
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_MAIN);
|
||||
assertThat(intent.getComponent().getClassName()).isEqualTo(SubSettings.class.getName());
|
||||
assertThat(intent.getStringExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT))
|
||||
.isEqualTo(ManageApplications.class.getName());
|
||||
assertThat(intent.getIntExtra(SettingsActivity.EXTRA_SHOW_FRAGMENT_TITLE_RESID, 0))
|
||||
.isEqualTo(R.string.storage_movies_tv);
|
||||
assertThat(intent.getAction()).isEqualTo(Intent.ACTION_VIEW);
|
||||
assertThat(intent.getData()).isEqualTo(mController.mVideosUri);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -463,4 +456,16 @@ public class StorageItemPreferenceControllerTest {
|
||||
assertThat(mController.mSystemPreference.isVisible()).isFalse();
|
||||
assertThat(mController.mTrashPreference.isVisible()).isFalse();
|
||||
}
|
||||
|
||||
/**
|
||||
* To verify startActivity, these test cases use mock Context because mContext is not an
|
||||
* activity context and AndroidRuntimeException throws for no FLAG_ACTIVITY_NEW_TASK.
|
||||
*/
|
||||
private Context getMockContext() {
|
||||
final Resources resources = mock(Resources.class);
|
||||
final Context context = mock(Context.class);
|
||||
when(context.getResources()).thenReturn(resources);
|
||||
when(resources.getString(anyInt())).thenReturn("");
|
||||
return context;
|
||||
}
|
||||
}
|
||||
|
@@ -31,10 +31,8 @@ import static com.android.settings.applications.manageapplications.ManageApplica
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MAIN;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MANAGE_SOURCES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MEDIA_MANAGEMENT_APPS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_MOVIES;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_NOTIFICATION;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_OVERLAY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_PHOTOGRAPHY;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_STORAGE;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_USAGE_ACCESS;
|
||||
import static com.android.settings.applications.manageapplications.ManageApplications.LIST_TYPE_WRITE_SETTINGS;
|
||||
@@ -75,7 +73,5 @@ public class AppFilterRegistryTest {
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_STORAGE)).isEqualTo(FILTER_APPS_ALL);
|
||||
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_GAMES)).isEqualTo(FILTER_APPS_ALL);
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_MOVIES)).isEqualTo(FILTER_APPS_ALL);
|
||||
assertThat(registry.getDefaultFilterType(LIST_TYPE_PHOTOGRAPHY)).isEqualTo(FILTER_APPS_ALL);
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user