Merge "Add a music apps view to the Storage Settings."
This commit is contained in:
@@ -0,0 +1,106 @@
|
||||
/*
|
||||
* 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;
|
||||
|
||||
import static com.google.common.truth.Truth.assertThat;
|
||||
|
||||
import static org.mockito.Matchers.any;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import android.app.Fragment;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
import android.os.UserHandle;
|
||||
import android.os.storage.VolumeInfo;
|
||||
import android.provider.DocumentsContract;
|
||||
import android.view.LayoutInflater;
|
||||
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.TestConfig;
|
||||
import com.android.settings.deviceinfo.storage.StorageStatsSource;
|
||||
import com.android.settingslib.deviceinfo.StorageVolumeProvider;
|
||||
|
||||
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.RuntimeEnvironment;
|
||||
import org.robolectric.annotation.Config;
|
||||
|
||||
|
||||
@RunWith(SettingsRobolectricTestRunner.class)
|
||||
@Config(manifest = TestConfig.MANIFEST_PATH, sdk = TestConfig.SDK_VERSION)
|
||||
public class MusicViewHolderControllerTest {
|
||||
@Mock(answer = Answers.RETURNS_DEEP_STUBS)
|
||||
private Fragment mFragment;
|
||||
@Mock
|
||||
private StorageVolumeProvider mSvp;
|
||||
@Mock
|
||||
private StorageStatsSource mSource;
|
||||
|
||||
private Context mContext;
|
||||
private MusicViewHolderController mController;
|
||||
private VolumeInfo mVolume;
|
||||
private AppViewHolder mHolder;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
mContext = RuntimeEnvironment.application;
|
||||
mVolume = new VolumeInfo("id", 0, null, "id");
|
||||
mController = new MusicViewHolderController(mContext, mSource, mVolume.fsUuid);
|
||||
|
||||
LayoutInflater inflater = LayoutInflater.from(mContext);
|
||||
mHolder = AppViewHolder.createOrRecycle(inflater, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldBeZeroBytesIfQueriedBeforeStorageQueryFinishes() {
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.summary.getText().toString()).isEqualTo("0.00B");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void storageShouldRepresentStorageStatsQuery() {
|
||||
when(mSource.getExternalStorageStats(any(String.class), any(UserHandle.class))).thenReturn(
|
||||
new StorageStatsSource.ExternalStorageStats(1, 1, 0, 0));
|
||||
|
||||
mController.queryStats();
|
||||
mController.setupView(mHolder);
|
||||
|
||||
assertThat(mHolder.summary.getText().toString()).isEqualTo("1.00B");
|
||||
}
|
||||
|
||||
@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(DocumentsContract.ACTION_BROWSE);
|
||||
assertThat(intent.getData()).isEqualTo(DocumentsContract.buildRootUri(
|
||||
"com.android.providers.media.documents",
|
||||
"audio_root"));
|
||||
}
|
||||
}
|
@@ -35,6 +35,7 @@ import android.view.View;
|
||||
import android.widget.LinearLayout;
|
||||
|
||||
import com.android.settings.R;
|
||||
import com.android.settings.Settings;
|
||||
import com.android.settings.SettingsActivity;
|
||||
import com.android.settings.SettingsRobolectricTestRunner;
|
||||
import com.android.settings.SubSettings;
|
||||
@@ -118,12 +119,15 @@ public class StorageItemPreferenceControllerTest {
|
||||
final ArgumentCaptor<Intent> argumentCaptor = ArgumentCaptor.forClass(Intent.class);
|
||||
verify(mFragment.getActivity()).startActivityAsUser(argumentCaptor.capture(),
|
||||
any(UserHandle.class));
|
||||
|
||||
Intent intent = argumentCaptor.getValue();
|
||||
assertThat(intent.getAction()).isEqualTo(DocumentsContract.ACTION_BROWSE);
|
||||
assertThat(intent.getData()).isEqualTo(DocumentsContract.buildRootUri(
|
||||
"com.android.providers.media.documents",
|
||||
"audio_root"));
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@@ -61,7 +61,6 @@ public class StorageSummaryDonutPreferenceControllerTest {
|
||||
final View view =
|
||||
inflater.inflate(
|
||||
mPreference.getLayoutResource(), new LinearLayout(mContext), false);
|
||||
|
||||
mHolder = new PreferenceViewHolder(view);
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user